Auto-verify setting should not inherit 3rd-party cookie blocking state

At rollout, the Auto-verify content setting (defined as "ANTI_ABUSE")
inherited the user's 3rd party cookie blocking setting. This was because
the Auto-verify setting controls the Private State Tokens API and we
wanted to ensure that if someone already had 3PC turned off at that
point, we weren't loosening that cross-site data sharing ability.

However, with the introduction of the 3rd party cookie deprecation
experiment we no longer want the Auto-verify content setting to inherit
the 3rd party cookie blocking setting. Private State Tokens (PST) were
built to replace some of the functionality of 3rd party cookies in a
more privacy preserving way, and PST is one of the APIs we want to test
during the 3PCD experiment. So we do not want PSTs to be blocked by
default for new clients during the 3PCD experiment.

This will not affect existing clients whose Auto-verify setting has
already inherited the 3PC blocking setting, or clients that have
manually blocked the Auto-verify setting. This just changes the
initialization logic for the Auto-verify setting, so that it will be
enabled by default for new clients.

Bug: 1498978, 1408778
Change-Id: I76cc2c1d4f2ac0ede3c7605cb2a6419d48e7653c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5003105
Commit-Queue: Ryan Kalla <[email protected]>
Reviewed-by: Dominic Battre <[email protected]>
Reviewed-by: Christian Dullweber <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1219521}
diff --git a/chrome/browser/extensions/api/content_settings/content_settings_apitest.cc b/chrome/browser/extensions/api/content_settings/content_settings_apitest.cc
index 2f899b1..2581f91 100644
--- a/chrome/browser/extensions/api/content_settings/content_settings_apitest.cc
+++ b/chrome/browser/extensions/api/content_settings/content_settings_apitest.cc
@@ -202,12 +202,8 @@
                                      ContentSettingsType::AUTOMATIC_DOWNLOADS));
     EXPECT_EQ(CONTENT_SETTING_ALLOW,
               map->GetContentSetting(url, url, ContentSettingsType::AUTOPLAY));
-    // TODO(http://b/306414714): Clean up this expectation
     EXPECT_EQ(
-        base::FeatureList::IsEnabled(
-            content_settings::features::kTrackingProtection3pcd)
-            ? CONTENT_SETTING_BLOCK
-            : CONTENT_SETTING_ALLOW,
+        CONTENT_SETTING_ALLOW,
         map->GetContentSetting(url, url, ContentSettingsType::ANTI_ABUSE));
   }
 
diff --git a/chrome/browser/prefs/browser_prefs.cc b/chrome/browser/prefs/browser_prefs.cc
index 1e7a865..5da1b6f 100644
--- a/chrome/browser/prefs/browser_prefs.cc
+++ b/chrome/browser/prefs/browser_prefs.cc
@@ -951,6 +951,10 @@
     "ash.night_light.cached_longitude";
 #endif
 
+// Deprecated 11/2023.
+const char kPrivacySandboxAntiAbuseInitialized[] =
+    "privacy_sandbox.anti_abuse_initialized";
+
 // Register local state used only for migration (clearing or moving to a new
 // key).
 void RegisterLocalStatePrefsForMigration(PrefRegistrySimple* registry) {
@@ -1342,6 +1346,9 @@
   registry->RegisterDoublePref(kNightLightCachedLatitude, 0.0);
   registry->RegisterDoublePref(kNightLightCachedLongitude, 0.0);
 #endif  // BUILDFLAG(IS_CHROMEOS_ASH)
+
+  // Deprecated 11/2023.
+  registry->RegisterBooleanPref(kPrivacySandboxAntiAbuseInitialized, false);
 }
 
 void ClearSyncRequestedPrefAndMaybeMigrate(PrefService* profile_prefs) {
@@ -2524,6 +2531,9 @@
   profile_prefs->ClearPref(kNightLightCachedLongitude);
 #endif  // BUILDFLAG(IS_CHROMEOS_ASH)
 
+  // Added 11/2023
+  profile_prefs->ClearPref(kPrivacySandboxAntiAbuseInitialized);
+
   // 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/privacy_sandbox_service_impl.cc b/chrome/browser/privacy_sandbox/privacy_sandbox_service_impl.cc
index a908d81..f6806b5 100644
--- a/chrome/browser/privacy_sandbox/privacy_sandbox_service_impl.cc
+++ b/chrome/browser/privacy_sandbox/privacy_sandbox_service_impl.cc
@@ -319,10 +319,6 @@
   // TODO(crbug.com/1351327): Remove this logic when most users have run init.
   MaybeInitializeFirstPartySetsPref();
 
-  // Check for anti-abuse content setting init at each startup.
-  // TODO(crbug.com/1408778): Remove this logic when most users have run init.
-  MaybeInitializeAntiAbuseContentSetting();
-
   // Record preference state for UMA at each startup.
   LogPrivacySandboxState();
 }
@@ -1542,26 +1538,6 @@
       prefs::kPrivacySandboxFirstPartySetsDataAccessAllowedInitialized, true);
 }
 
-void PrivacySandboxServiceImpl::MaybeInitializeAntiAbuseContentSetting() {
-  // If initialization has already run, it is not required.
-  if (pref_service_->GetBoolean(prefs::kPrivacySandboxAntiAbuseInitialized)) {
-    return;
-  }
-
-  // If the user blocks 3P cookies, disable the anti-abuse content setting.
-  // As this logic relies on checking synced preference state, it is possible
-  // that synced state is available when this decision is made. To err on the
-  // side of privacy, this init logic is run per-device (the pref recording that
-  // init has been run is not synced). If any of the user's devices local state
-  // would disable the setting, it is disabled across all devices.
-  if (AreThirdPartyCookiesBlocked(cookie_settings_.get())) {
-    host_content_settings_map_->SetDefaultContentSetting(
-        ContentSettingsType::ANTI_ABUSE, ContentSetting::CONTENT_SETTING_BLOCK);
-  }
-
-  pref_service_->SetBoolean(prefs::kPrivacySandboxAntiAbuseInitialized, true);
-}
-
 void PrivacySandboxServiceImpl::RecordUpdatedTopicsConsent(
     privacy_sandbox::TopicsConsentUpdateSource source,
     bool did_consent) const {
diff --git a/chrome/browser/privacy_sandbox/privacy_sandbox_service_impl.h b/chrome/browser/privacy_sandbox/privacy_sandbox_service_impl.h
index 876d0558..69427787 100644
--- a/chrome/browser/privacy_sandbox/privacy_sandbox_service_impl.h
+++ b/chrome/browser/privacy_sandbox/privacy_sandbox_service_impl.h
@@ -331,11 +331,6 @@
   // so, sets the default value based on the user's current cookie settings.
   void MaybeInitializeFirstPartySetsPref();
 
-  // Checks to see if initialization of the user's anti-abuse content setting is
-  // required, and if so, sets the default value based on the user's current
-  // cookie settings.
-  void MaybeInitializeAntiAbuseContentSetting();
-
   // Updates the preferences which store the current Topics consent information.
   void RecordUpdatedTopicsConsent(
       privacy_sandbox::TopicsConsentUpdateSource source,
diff --git a/chrome/browser/privacy_sandbox/privacy_sandbox_service_impl_unittest.cc b/chrome/browser/privacy_sandbox/privacy_sandbox_service_impl_unittest.cc
index a4066de..d0f947b9 100644
--- a/chrome/browser/privacy_sandbox/privacy_sandbox_service_impl_unittest.cc
+++ b/chrome/browser/privacy_sandbox/privacy_sandbox_service_impl_unittest.cc
@@ -783,16 +783,6 @@
       prefs::kPrivacySandboxFirstPartySetsDataAccessAllowedInitialized);
 }
 
-// Remove any user preference settings for Anti-abuse related preferences,
-// returning them to their default value.
-void ResetAntiAbuseSettings(
-    sync_preferences::TestingPrefServiceSyncable* pref_service,
-    HostContentSettingsMap* host_content_settings_map) {
-  pref_service->RemoveUserPref(prefs::kPrivacySandboxAntiAbuseInitialized);
-  host_content_settings_map->SetDefaultContentSetting(
-      ContentSettingsType::ANTI_ABUSE, CONTENT_SETTING_ALLOW);
-}
-
 std::vector<int> GetTopicsSettingsStringIdentifiers(bool did_consent,
                                                     bool has_current_topics,
                                                     bool has_blocked_topics) {
@@ -2923,60 +2913,6 @@
       net::SchemefulSite(GURL("https://google.de"))));
 }
 
-TEST_F(PrivacySandboxServiceTest, AntiAbuseContentSettingInit) {
-  // Check that the init of the Anti-abuse pref occurs correctly.
-  ResetAntiAbuseSettings(prefs(), host_content_settings_map());
-  prefs()->SetUserPref(
-      prefs::kCookieControlsMode,
-      std::make_unique<base::Value>(static_cast<int>(
-          content_settings::CookieControlsMode::kBlockThirdParty)));
-
-  // If the user blocks 3PC, and the pref has not been previously init, it
-  // should be.
-  ResetAntiAbuseSettings(prefs(), host_content_settings_map());
-  CreateService();
-  EXPECT_EQ(host_content_settings_map()->GetDefaultContentSetting(
-                ContentSettingsType::ANTI_ABUSE, nullptr),
-            CONTENT_SETTING_BLOCK);
-  EXPECT_TRUE(prefs()->GetBoolean(prefs::kPrivacySandboxAntiAbuseInitialized));
-
-  // Once the setting has been init, it should not be re-init, and updated user
-  // cookie settings should not impact it.
-  ResetAntiAbuseSettings(prefs(), host_content_settings_map());
-  prefs()->SetUserPref(prefs::kCookieControlsMode,
-                       std::make_unique<base::Value>(static_cast<int>(
-                           content_settings::CookieControlsMode::kOff)));
-
-  CreateService();
-  EXPECT_EQ(host_content_settings_map()->GetDefaultContentSetting(
-                ContentSettingsType::ANTI_ABUSE, nullptr),
-            CONTENT_SETTING_ALLOW);
-  EXPECT_TRUE(prefs()->GetBoolean(prefs::kPrivacySandboxAntiAbuseInitialized));
-
-  prefs()->SetUserPref(
-      prefs::kCookieControlsMode,
-      std::make_unique<base::Value>(static_cast<int>(
-          content_settings::CookieControlsMode::kBlockThirdParty)));
-  CreateService();
-  EXPECT_EQ(host_content_settings_map()->GetDefaultContentSetting(
-                ContentSettingsType::ANTI_ABUSE, nullptr),
-            CONTENT_SETTING_ALLOW);
-  EXPECT_TRUE(prefs()->GetBoolean(prefs::kPrivacySandboxAntiAbuseInitialized));
-
-  // Blocking all cookies should also init the Anti-abuse setting to blocked.
-  ResetAntiAbuseSettings(prefs(), host_content_settings_map());
-  prefs()->SetUserPref(prefs::kCookieControlsMode,
-                       std::make_unique<base::Value>(static_cast<int>(
-                           content_settings::CookieControlsMode::kOff)));
-
-  cookie_settings()->SetDefaultCookieSetting(CONTENT_SETTING_BLOCK);
-  CreateService();
-  EXPECT_EQ(host_content_settings_map()->GetDefaultContentSetting(
-                ContentSettingsType::ANTI_ABUSE, nullptr),
-            CONTENT_SETTING_BLOCK);
-  EXPECT_TRUE(prefs()->GetBoolean(prefs::kPrivacySandboxAntiAbuseInitialized));
-}
-
 class PrivacySandboxServiceTestNonRegularProfile
     : public PrivacySandboxServiceTest {
   profile_metrics::BrowserProfileType GetProfileType() override {
diff --git a/components/privacy_sandbox/privacy_sandbox_prefs.cc b/components/privacy_sandbox/privacy_sandbox_prefs.cc
index 1012399..90e3ef2 100644
--- a/components/privacy_sandbox/privacy_sandbox_prefs.cc
+++ b/components/privacy_sandbox/privacy_sandbox_prefs.cc
@@ -67,8 +67,6 @@
       static_cast<int>(TopicsConsentUpdateSource::kDefaultValue));
   registry->RegisterStringPref(
       prefs::kPrivacySandboxTopicsConsentTextAtLastUpdate, "");
-  registry->RegisterBooleanPref(prefs::kPrivacySandboxAntiAbuseInitialized,
-                                false);
 
   // Register prefs for tracking protection.
   tracking_protection::RegisterProfilePrefs(registry);
diff --git a/components/privacy_sandbox/privacy_sandbox_prefs.h b/components/privacy_sandbox/privacy_sandbox_prefs.h
index 0a5025b..43bfbadb 100644
--- a/components/privacy_sandbox/privacy_sandbox_prefs.h
+++ b/components/privacy_sandbox/privacy_sandbox_prefs.h
@@ -169,11 +169,6 @@
 inline constexpr char kPrivacySandboxTopicsConsentTextAtLastUpdate[] =
     "privacy_sandbox.topics_consent.text_at_last_update";
 
-// Boolean that indicates whether the user's anti-abuse preference has been
-// initialized.
-inline constexpr char kPrivacySandboxAntiAbuseInitialized[] =
-    "privacy_sandbox.anti_abuse_initialized";
-
 }  // namespace prefs
 
 namespace privacy_sandbox {