Skip to content

Commit 6a941ef

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

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

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

Lines changed: 22 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,20 @@ 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+
29+
void MaybeMigrateSearchResultAdClickedInfoBarPref(PrefService* const prefs) {
30+
if (!prefs->HasPrefPath(kObsoleteShouldShowSearchResultAdClickedInfoBar)) {
31+
return;
32+
}
33+
34+
prefs->SetBoolean(
35+
prefs::kShouldShowSearchResultAdClickedInfoBar,
36+
prefs->GetBoolean(kObsoleteShouldShowSearchResultAdClickedInfoBar));
37+
prefs->ClearPref(kObsoleteShouldShowSearchResultAdClickedInfoBar);
38+
}
39+
2540
} // namespace
2641

2742
void RegisterProfilePrefsForMigration(PrefRegistrySimple* const registry) {
@@ -32,6 +47,10 @@ void RegisterProfilePrefsForMigration(PrefRegistrySimple* const registry) {
3247

3348
// Added 10/2024.
3449
registry->RegisterBooleanPref(kShouldMigrateVerifiedRewardsUser, false);
50+
51+
// Added 05/2025.
52+
registry->RegisterBooleanPref(kObsoleteShouldShowSearchResultAdClickedInfoBar,
53+
false);
3554
}
3655

3756
void MigrateObsoleteProfilePrefs(PrefService* const prefs) {
@@ -42,6 +61,9 @@ void MigrateObsoleteProfilePrefs(PrefService* const prefs) {
4261

4362
// Added 10/2024.
4463
prefs->ClearPref(kShouldMigrateVerifiedRewardsUser);
64+
65+
// Added 05/2025.
66+
MaybeMigrateSearchResultAdClickedInfoBarPref(prefs);
4567
}
4668

4769
} // namespace brave_ads

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

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

99
namespace brave_ads::prefs {
1010

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

@@ -68,9 +71,6 @@ inline constexpr char kNotificationAdDidFallbackToCustom[] =
6871
inline constexpr char kShouldShowOnboardingNotification[] =
6972
"brave.brave_ads.should_show_my_first_ad_notification";
7073

71-
inline constexpr char kShouldShowSearchResultAdClickedInfoBar[] =
72-
"brave.brave_ads.should_show_search_result_ad_clicked_infobar";
73-
7474
// Brave stats prefs.
7575
inline constexpr char kEnabledForLastProfile[] =
7676
"brave.brave_ads.enabled_last_profile";
@@ -80,6 +80,11 @@ inline constexpr char kEverEnabledForAnyProfile[] =
8080
// P2A prefs.
8181
inline constexpr char kP2APrefPathPrefix[] = "brave.weekly_storage.";
8282

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

8590
#endif // BRAVE_COMPONENTS_BRAVE_ADS_CORE_PUBLIC_PREFS_PREF_NAMES_H_

0 commit comments

Comments
 (0)