@@ -44,10 +44,22 @@ void BraveProfileWriter::AddCookies(
44
44
void BraveProfileWriter::UpdateStats (const BraveStats& stats) {
45
45
PrefService* prefs = profile_->GetOriginalProfile ()->GetPrefs ();
46
46
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
+ }
53
65
}
0 commit comments