[Privacy Sandbox] Clear Ad API prefs on startup if feature enabled Introduces `ClearAdPrivacyPrefs` method to set the Privacy Sandbox M1 Ad API prefs (Topics, Site Suggested Ads, and Ad Measurement) to false. This clearing logic is invoked during the profile pref migration in browser_prefs.cc and is gated by the `PrivacySandboxAdPrivacyUxDeprecation` feature. Bug: 494265981 Change-Id: I8bf5b1e431aed528452548970991b1510d8e04b0 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7689451 Reviewed-by: Dominic Battre <battre@chromium.org> Commit-Queue: Jacob Stanley <jacobstanley@google.com> Reviewed-by: Abe Boujane <boujane@google.com> Cr-Commit-Position: refs/heads/main@{#1603732}
diff --git a/chrome/browser/prefs/browser_prefs.cc b/chrome/browser/prefs/browser_prefs.cc index 80034925..daf00320 100644 --- a/chrome/browser/prefs/browser_prefs.cc +++ b/chrome/browser/prefs/browser_prefs.cc
@@ -2734,6 +2734,9 @@ // Added 03/2026. profile_prefs->ClearPref(kNtpContextMenuClickCount); + // Added 03/2026. + privacy_sandbox::ClearAdPrivacyPrefs(profile_prefs); + // Please don't delete the following line. It is used by PRESUBMIT.py. // END_MIGRATE_OBSOLETE_PROFILE_PREFS
diff --git a/chrome/browser/privacy_sandbox/BUILD.gn b/chrome/browser/privacy_sandbox/BUILD.gn index 71cbf4a..0a55b744 100644 --- a/chrome/browser/privacy_sandbox/BUILD.gn +++ b/chrome/browser/privacy_sandbox/BUILD.gn
@@ -105,7 +105,10 @@ source_set("settings_browser_test") { testonly = true defines = [ "HAS_OUT_OF_PROC_TEST_RUNNER" ] - sources = [ "privacy_sandbox_settings_browsertest.cc" ] + sources = [ + "privacy_sandbox_ad_privacy_deprecation_browsertest.cc", + "privacy_sandbox_settings_browsertest.cc", + ] deps = [ "//base/test:test_support", "//chrome/browser/browsing_data:constants",
diff --git a/chrome/browser/privacy_sandbox/privacy_sandbox_ad_privacy_deprecation_browsertest.cc b/chrome/browser/privacy_sandbox/privacy_sandbox_ad_privacy_deprecation_browsertest.cc new file mode 100644 index 0000000..5078c4f --- /dev/null +++ b/chrome/browser/privacy_sandbox/privacy_sandbox_ad_privacy_deprecation_browsertest.cc
@@ -0,0 +1,77 @@ +// Copyright 2026 The Chromium Authors +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "base/test/scoped_feature_list.h" +#include "chrome/browser/profiles/profile.h" +#include "chrome/browser/ui/browser.h" +#include "chrome/test/base/in_process_browser_test.h" +#include "components/prefs/pref_service.h" +#include "components/privacy_sandbox/privacy_sandbox_features.h" +#include "components/privacy_sandbox/privacy_sandbox_prefs.h" +#include "content/public/test/browser_test.h" + +namespace privacy_sandbox { + +class PrivacySandboxAdPrivacyDeprecationTest : public InProcessBrowserTest { + public: + PrivacySandboxAdPrivacyDeprecationTest() { + feature_list_.InitAndEnableFeature(kPrivacySandboxAdPrivacyUxDeprecation); + } + + private: + base::test::ScopedFeatureList feature_list_; +}; + +IN_PROC_BROWSER_TEST_F(PrivacySandboxAdPrivacyDeprecationTest, + PRE_PrefsSetToFalse) { + browser()->profile()->GetPrefs()->SetBoolean( + prefs::kPrivacySandboxM1TopicsEnabled, true); + browser()->profile()->GetPrefs()->SetBoolean( + prefs::kPrivacySandboxM1FledgeEnabled, true); + browser()->profile()->GetPrefs()->SetBoolean( + prefs::kPrivacySandboxM1AdMeasurementEnabled, true); +} + +IN_PROC_BROWSER_TEST_F(PrivacySandboxAdPrivacyDeprecationTest, + PrefsSetToFalse) { + EXPECT_FALSE(browser()->profile()->GetPrefs()->GetBoolean( + prefs::kPrivacySandboxM1TopicsEnabled)); + EXPECT_FALSE(browser()->profile()->GetPrefs()->GetBoolean( + prefs::kPrivacySandboxM1FledgeEnabled)); + EXPECT_FALSE(browser()->profile()->GetPrefs()->GetBoolean( + prefs::kPrivacySandboxM1AdMeasurementEnabled)); +} + +class PrivacySandboxAdPrivacyDeprecationDisabledTest + : public InProcessBrowserTest { + public: + PrivacySandboxAdPrivacyDeprecationDisabledTest() { + feature_list_.InitAndDisableFeature(kPrivacySandboxAdPrivacyUxDeprecation); + } + + private: + base::test::ScopedFeatureList feature_list_; +}; + +IN_PROC_BROWSER_TEST_F(PrivacySandboxAdPrivacyDeprecationDisabledTest, + PRE_PrefsNotSetToFalse) { + browser()->profile()->GetPrefs()->SetBoolean( + prefs::kPrivacySandboxM1TopicsEnabled, true); + browser()->profile()->GetPrefs()->SetBoolean( + prefs::kPrivacySandboxM1FledgeEnabled, true); + browser()->profile()->GetPrefs()->SetBoolean( + prefs::kPrivacySandboxM1AdMeasurementEnabled, true); +} + +IN_PROC_BROWSER_TEST_F(PrivacySandboxAdPrivacyDeprecationDisabledTest, + PrefsNotSetToFalse) { + EXPECT_TRUE(browser()->profile()->GetPrefs()->GetBoolean( + prefs::kPrivacySandboxM1TopicsEnabled)); + EXPECT_TRUE(browser()->profile()->GetPrefs()->GetBoolean( + prefs::kPrivacySandboxM1FledgeEnabled)); + EXPECT_TRUE(browser()->profile()->GetPrefs()->GetBoolean( + prefs::kPrivacySandboxM1AdMeasurementEnabled)); +} + +} // namespace privacy_sandbox
diff --git a/components/privacy_sandbox/BUILD.gn b/components/privacy_sandbox/BUILD.gn index 8cfd809..8603524 100644 --- a/components/privacy_sandbox/BUILD.gn +++ b/components/privacy_sandbox/BUILD.gn
@@ -12,6 +12,7 @@ ] deps = [ + ":features", "//components/pref_registry", "//components/prefs", ]
diff --git a/components/privacy_sandbox/privacy_sandbox_prefs.cc b/components/privacy_sandbox/privacy_sandbox_prefs.cc index c2cd5d6..b9474e9 100644 --- a/components/privacy_sandbox/privacy_sandbox_prefs.cc +++ b/components/privacy_sandbox/privacy_sandbox_prefs.cc
@@ -7,6 +7,8 @@ #include "base/time/time.h" #include "components/pref_registry/pref_registry_syncable.h" #include "components/prefs/pref_registry_simple.h" +#include "components/prefs/pref_service.h" +#include "components/privacy_sandbox/privacy_sandbox_features.h" namespace privacy_sandbox { @@ -72,4 +74,13 @@ registry->RegisterBooleanPref(prefs::kTrackingProtection3pcdEnabled, false); } +void ClearAdPrivacyPrefs(PrefService* prefs) { + if (!base::FeatureList::IsEnabled(kPrivacySandboxAdPrivacyUxDeprecation)) { + return; + } + prefs->ClearPref(prefs::kPrivacySandboxM1TopicsEnabled); + prefs->ClearPref(prefs::kPrivacySandboxM1FledgeEnabled); + prefs->ClearPref(prefs::kPrivacySandboxM1AdMeasurementEnabled); +} + } // namespace privacy_sandbox
diff --git a/components/privacy_sandbox/privacy_sandbox_prefs.h b/components/privacy_sandbox/privacy_sandbox_prefs.h index e4afdb9..46a8526 100644 --- a/components/privacy_sandbox/privacy_sandbox_prefs.h +++ b/components/privacy_sandbox/privacy_sandbox_prefs.h
@@ -6,6 +6,7 @@ #define COMPONENTS_PRIVACY_SANDBOX_PRIVACY_SANDBOX_PREFS_H_ class PrefRegistrySimple; +class PrefService; namespace prefs { @@ -181,6 +182,10 @@ // Registers user preferences related to privacy sandbox. void RegisterProfilePrefs(PrefRegistrySimple* registry); +// If the Ad Privacy Deprecation feature is enabled, this function will set all +// the Ad API prefs to false if it is already set to true. +void ClearAdPrivacyPrefs(PrefService* pref_service); + } // namespace privacy_sandbox #endif // COMPONENTS_PRIVACY_SANDBOX_PRIVACY_SANDBOX_PREFS_H_