Skip to content

Commit a921ba4

Browse files
authored
Merge pull request #318 from brave/avoid-multiple-stats-imports
Avoid importing stats multiple times from multiple imports
2 parents 1581d1f + abc9ed3 commit a921ba4

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

browser/importer/brave_profile_writer.cc

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,22 @@ void BraveProfileWriter::AddCookies(
4444
void BraveProfileWriter::UpdateStats(const BraveStats& stats) {
4545
PrefService* prefs = profile_->GetOriginalProfile()->GetPrefs();
4646

47-
prefs->SetUint64(kAdsBlocked,
48-
prefs->GetUint64(kAdsBlocked) + stats.adblock_count);
49-
prefs->SetUint64(kTrackersBlocked,
50-
prefs->GetUint64(kTrackersBlocked) + stats.trackingProtection_count);
51-
prefs->SetUint64(kHttpsUpgrades,
52-
prefs->GetUint64(kHttpsUpgrades) + stats.httpsEverywhere_count);
47+
const uint64_t ads_blocked = prefs->GetUint64(kAdsBlocked);
48+
const uint64_t trackers_blocked = prefs->GetUint64(kTrackersBlocked);
49+
const uint64_t https_upgrades = prefs->GetUint64(kHttpsUpgrades);
50+
51+
// Only update the current stats if they are less than the imported
52+
// stats; intended to prevent incorrectly updating the stats multiple
53+
// times from multiple imports.
54+
if (ads_blocked < uint64_t{stats.adblock_count}) {
55+
prefs->SetUint64(kAdsBlocked, ads_blocked + stats.adblock_count);
56+
}
57+
if (trackers_blocked < uint64_t{stats.trackingProtection_count}) {
58+
prefs->SetUint64(kTrackersBlocked,
59+
trackers_blocked + stats.trackingProtection_count);
60+
}
61+
if (https_upgrades < uint64_t{stats.httpsEverywhere_count}) {
62+
prefs->SetUint64(kHttpsUpgrades,
63+
https_upgrades + stats.httpsEverywhere_count);
64+
}
5365
}

0 commit comments

Comments
 (0)