Skip to content

Commit 4b78f62

Browse files
committed
[ads] Preserve search ad info bar preference when clearing ads data
1 parent fa2f988 commit 4b78f62

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

components/brave_ads/core/internal/prefs/obsolete_pref_util.cc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include "brave/components/brave_ads/core/public/prefs/obsolete_pref_util.h"
77

8+
#include "brave/components/brave_ads/core/public/prefs/pref_names.h"
89
#include "components/prefs/pref_registry_simple.h"
910
#include "components/prefs/pref_service.h"
1011

@@ -22,6 +23,9 @@ constexpr char kHasMigratedRewardsState[] =
2223
constexpr char kShouldMigrateVerifiedRewardsUser[] =
2324
"brave.brave_ads.rewards.verified_user.should_migrate";
2425

26+
constexpr char kObsoleteShouldShowSearchResultAdClickedInfoBar[] =
27+
"brave.brave_ads.should_show_search_result_ad_clicked_infobar";
28+
2529
} // namespace
2630

2731
void RegisterProfilePrefsForMigration(PrefRegistrySimple* const registry) {
@@ -32,6 +36,10 @@ void RegisterProfilePrefsForMigration(PrefRegistrySimple* const registry) {
3236

3337
// Added 10/2024.
3438
registry->RegisterBooleanPref(kShouldMigrateVerifiedRewardsUser, false);
39+
40+
// Added 12/2024.
41+
registry->RegisterBooleanPref(kObsoleteShouldShowSearchResultAdClickedInfoBar,
42+
false);
3543
}
3644

3745
void MigrateObsoleteProfilePrefs(PrefService* const prefs) {
@@ -42,6 +50,14 @@ void MigrateObsoleteProfilePrefs(PrefService* const prefs) {
4250

4351
// Added 10/2024.
4452
prefs->ClearPref(kShouldMigrateVerifiedRewardsUser);
53+
54+
// Added 05/2025.
55+
if (prefs->HasPrefPath(kObsoleteShouldShowSearchResultAdClickedInfoBar)) {
56+
prefs->SetBoolean(
57+
prefs::kShouldShowSearchResultAdClickedInfoBar,
58+
prefs->GetBoolean(kObsoleteShouldShowSearchResultAdClickedInfoBar));
59+
prefs->ClearPref(kObsoleteShouldShowSearchResultAdClickedInfoBar);
60+
}
4561
}
4662

4763
} // namespace brave_ads

components/brave_ads/core/public/prefs/pref_names.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
namespace brave_ads::prefs {
1010

11+
// IMPORTANT: Prefs that need clearing should be prefixed with `brave.brave_ads`
12+
1113
// Ads prefs.
1214
inline constexpr char kDiagnosticId[] = "brave.brave_ads.diagnostics.id";
1315

@@ -68,9 +70,6 @@ inline constexpr char kNotificationAdDidFallbackToCustom[] =
6870
inline constexpr char kShouldShowOnboardingNotification[] =
6971
"brave.brave_ads.should_show_my_first_ad_notification";
7072

71-
inline constexpr char kShouldShowSearchResultAdClickedInfoBar[] =
72-
"brave.brave_ads.should_show_search_result_ad_clicked_infobar";
73-
7473
// Brave stats prefs.
7574
inline constexpr char kEnabledForLastProfile[] =
7675
"brave.brave_ads.enabled_last_profile";
@@ -80,6 +79,11 @@ inline constexpr char kEverEnabledForAnyProfile[] =
8079
// P2A prefs.
8180
inline constexpr char kP2APrefPathPrefix[] = "brave.weekly_storage.";
8281

82+
// We don't prefix `brave.brave_ads.` to this pref path because we don't want
83+
// them cleared if the user clears ads data or resets Brave Rewards.
84+
inline constexpr char kShouldShowSearchResultAdClickedInfoBar[] =
85+
"brave.search.search_result_ad.should_show_clicked_infobar";
86+
8387
} // namespace brave_ads::prefs
8488

8589
#endif // BRAVE_COMPONENTS_BRAVE_ADS_CORE_PUBLIC_PREFS_PREF_NAMES_H_

0 commit comments

Comments
 (0)