Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bandwidth improvements #5437

Merged
merged 7 commits into from
May 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions browser/ui/webui/brave_new_tab_message_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ base::DictionaryValue GetStatsDictionary(PrefService* prefs) {
stats_data.SetInteger(
"javascriptBlockedStat",
prefs->GetUint64(kJavascriptBlocked));
stats_data.SetInteger(
"httpsUpgradesStat",
prefs->GetUint64(kHttpsUpgrades));
stats_data.SetInteger(
"fingerprintingBlockedStat",
prefs->GetUint64(kFingerprintingBlocked));
Expand Down
4 changes: 2 additions & 2 deletions components/brave_new_tab_ui/api/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
export type Stats = {
adsBlockedStat: number,
javascriptBlockedStat: number,
httpsUpgradesStat: number,
fingerprintingBlockedStat: number
fingerprintingBlockedStat: number,
bandwidthSavedStat: number
}

type StatsUpdatedHandler = (statsData: Stats) => void
Expand Down
46 changes: 39 additions & 7 deletions components/brave_new_tab_ui/containers/newTab/stats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,37 @@ class Stats extends React.Component<Props, {}> {
return this.props.stats.adsBlockedStat || 0
}

get httpsUpgradedCount () {
return this.props.stats.httpsUpgradesStat || 0
get estimatedBandwidthSaved () {
const estimatedBWSaved = this.props.stats.bandwidthSavedStat
if (estimatedBWSaved) {
const bytes = estimatedBWSaved < 1024
const kilobytes = estimatedBWSaved < 1024 * 1024
const megabytes = estimatedBWSaved < 1024 * 1024 * 1024

let counter
let id
if (bytes) {
counter = estimatedBWSaved
id = 'B'
} else if (kilobytes) {
counter = (estimatedBWSaved / 1024).toFixed(0)
id = 'KB'
} else if (megabytes) {
counter = (estimatedBWSaved / 1024 / 1024).toFixed(1)
id = 'MB'
} else {
counter = (estimatedBWSaved / 1024 / 1024 / 1024).toFixed(2)
id = 'GB'
}

return {
id,
value: counter,
args: JSON.stringify({ value: counter })
}
} else {
return false
}
}

get estimatedTimeSaved () {
Expand Down Expand Up @@ -59,19 +88,22 @@ class Stats extends React.Component<Props, {}> {

render () {
const trackedBlockersCount = this.adblockCount.toLocaleString()
const httpsUpgradedCount = this.httpsUpgradedCount.toLocaleString()
const timeSaved = this.estimatedTimeSaved
const bandwidthSaved = this.estimatedBandwidthSaved

return (
<StatsContainer>
<StatsItem
description={getLocale('adsTrackersBlocked')}
counter={trackedBlockersCount}
/>
<StatsItem
description={getLocale('httpsUpgraded')}
counter={httpsUpgradedCount}
/>
{bandwidthSaved &&
<StatsItem
counter={bandwidthSaved.value}
text={getLocale(bandwidthSaved.id)}
description={getLocale('estimatedBandwidthSaved')}
/>
}
<StatsItem
counter={timeSaved.value}
text={getLocale(timeSaved.id)}
Expand Down
2 changes: 1 addition & 1 deletion components/brave_new_tab_ui/storage/new_tab_storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const defaultState: NewTab.State = {
stats: {
adsBlockedStat: 0,
javascriptBlockedStat: 0,
httpsUpgradesStat: 0,
bandwidthSavedStat: 0,
fingerprintingBlockedStat: 0
},
rewardsState: {
Expand Down
2 changes: 2 additions & 0 deletions components/brave_perf_predictor/browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ source_set("browser") {
"bandwidth_savings_predictor.h",
"named_third_party_registry.cc",
"named_third_party_registry.h",
"named_third_party_registry_factory.cc",
"named_third_party_registry_factory.h",
"p3a_bandwidth_savings_tracker.cc",
"p3a_bandwidth_savings_tracker.h",
"perf_predictor_page_metrics_observer.cc",
Expand Down
Loading