Skip to content

Commit

Permalink
Migrate old ViewCounterService pref: brave.count_to_branded_wallpaper
Browse files Browse the repository at this point in the history
  • Loading branch information
petemill committed Sep 25, 2023
1 parent 649c917 commit 22c14c5
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
5 changes: 5 additions & 0 deletions browser/brave_profile_prefs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "brave/components/de_amp/common/pref_names.h"
#include "brave/components/debounce/browser/debounce_service.h"
#include "brave/components/ipfs/buildflags/buildflags.h"
#include "brave/components/ntp_background_images/browser/view_counter_service.h"
#include "brave/components/ntp_background_images/buildflags/buildflags.h"
#include "brave/components/omnibox/browser/brave_omnibox_prefs.h"
#include "brave/components/request_otr/common/buildflags/buildflags.h"
Expand Down Expand Up @@ -270,6 +271,10 @@ void RegisterProfilePrefsForMigration(
registry->RegisterListPref(pref);
}
#endif

// Added 2023-09
ntp_background_images::ViewCounterService::RegisterProfilePrefsForMigration(
registry);
}

void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
Expand Down
5 changes: 5 additions & 0 deletions chromium_src/chrome/browser/prefs/browser_prefs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "brave/components/brave_wallet/browser/keyring_service.h"
#include "brave/components/constants/pref_names.h"
#include "brave/components/decentralized_dns/core/utils.h"
#include "brave/components/ntp_background_images/browser/view_counter_service.h"
#include "brave/components/ntp_background_images/buildflags/buildflags.h"
#include "brave/components/omnibox/browser/brave_omnibox_prefs.h"
#include "brave/components/tor/buildflags/buildflags.h"
Expand Down Expand Up @@ -229,6 +230,10 @@ void MigrateObsoleteProfilePrefs(Profile* profile) {
}
#endif

// Added 2023-09
ntp_background_images::ViewCounterService::MigrateObsoleteProfilePrefs(
profile->GetPrefs());

// END_MIGRATE_OBSOLETE_PROFILE_PREFS
}

Expand Down
15 changes: 15 additions & 0 deletions components/ntp_background_images/browser/view_counter_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ constexpr char kSponsoredNewTabsHistogramName[] =
"Brave.NTP.SponsoredNewTabsCreated";
constexpr int kSponsoredNewTabsBuckets[] = {0, 10, 20, 30, 40, 50};

// Obsolete pref
constexpr char kObsoleteCountToBrandedWallpaperPref[] =
"brave.count_to_branded_wallpaper";

} // namespace

namespace ntp_background_images {
Expand All @@ -72,6 +76,17 @@ void ViewCounterService::RegisterProfilePrefs(
prefs::kNewTabPageShowBackgroundImage, true);
}

void ViewCounterService::RegisterProfilePrefsForMigration(
user_prefs::PrefRegistrySyncable* registry) {
// Added 09/2023
registry->RegisterIntegerPref(kObsoleteCountToBrandedWallpaperPref, 0);
}

void ViewCounterService::MigrateObsoleteProfilePrefs(PrefService* prefs) {
// Added 09/2023
prefs->ClearPref(kObsoleteCountToBrandedWallpaperPref);
}

ViewCounterService::ViewCounterService(
NTPBackgroundImagesService* service,
BraveNTPCustomBackgroundService* custom_service,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ class ViewCounterService : public KeyedService,

static void RegisterLocalStatePrefs(PrefRegistrySimple* registry);
static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
static void RegisterProfilePrefsForMigration(
user_prefs::PrefRegistrySyncable* registry);
static void MigrateObsoleteProfilePrefs(PrefService* prefs);

// Lets the counter know that a New Tab Page view has occured.
// This should always be called as it will evaluate whether the user has
Expand Down

0 comments on commit 22c14c5

Please sign in to comment.