[sync] Remove legacy SyncRequested pref

It has been practically unused for some time, and most of it is dead
code ever since the feature toggle was cleaned up in
https://crrev.com/c/4886256.

On Ash, it needs to be migrated to a newly-introduced preference
tailored to the actual underlying need, which is being able to remember
that the server returned DISABLE_SYNC_ON_CLIENT (i.e. the user reset
sync via dashboard).

Change-Id: I0239447173b32d7d007ebf733dde23a5de1859e1
Bug: 1443446, 1219990
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4886762
Reviewed-by: Gauthier Ambard <[email protected]>
Commit-Queue: Mikel Astiz <[email protected]>
Reviewed-by: Marc Treib <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1203901}
diff --git a/chrome/browser/prefs/browser_prefs.cc b/chrome/browser/prefs/browser_prefs.cc
index 0825338..769d4b2 100644
--- a/chrome/browser/prefs/browser_prefs.cc
+++ b/chrome/browser/prefs/browser_prefs.cc
@@ -60,7 +60,6 @@
 #include "chrome/browser/preloading/preloading_prefs.h"
 #include "chrome/browser/printing/print_preview_sticky_settings.h"
 #include "chrome/browser/profiles/chrome_version_service.h"
-#include "chrome/browser/profiles/profile.h"
 #include "chrome/browser/profiles/profile_attributes_entry.h"
 #include "chrome/browser/profiles/profile_attributes_storage.h"
 #include "chrome/browser/profiles/profile_impl.h"
@@ -167,6 +166,7 @@
 #include "components/site_engagement/content/site_engagement_service.h"
 #include "components/subresource_filter/content/browser/ruleset_service.h"
 #include "components/supervised_user/core/common/buildflags.h"
+#include "components/sync/base/pref_names.h"
 #include "components/sync/service/glue/sync_transport_data_prefs.h"
 #include "components/sync/service/sync_prefs.h"
 #include "components/sync_device_info/device_info_prefs.h"
@@ -956,6 +956,9 @@
 const char kSettingsMigratedToUPM[] = "profile.settings_migrated_to_upm";
 #endif
 
+// Deprecated 10/2023.
+inline constexpr char kSyncRequested[] = "sync.requested";
+
 // Register local state used only for migration (clearing or moving to a new
 // key).
 void RegisterLocalStatePrefsForMigration(PrefRegistrySimple* registry) {
@@ -1340,6 +1343,20 @@
 #if BUILDFLAG(IS_ANDROID)
   registry->RegisterBooleanPref(kSettingsMigratedToUPM, false);
 #endif
+  registry->RegisterBooleanPref(kSyncRequested, false);
+}
+
+void ClearSyncRequestedPrefAndMaybeMigrate(PrefService* profile_prefs) {
+#if BUILDFLAG(IS_CHROMEOS_ASH)
+  // On Ash specifically, if `kSyncRequested` was set to false explicitly, the
+  // value needs to be migrated to syncer::internal::kSyncDisabledViaDashboard.
+  if (profile_prefs->GetUserPrefValue(kSyncRequested) != nullptr &&
+      !profile_prefs->GetUserPrefValue(kSyncRequested)->GetBool()) {
+    profile_prefs->SetBoolean(
+        syncer::prefs::internal::kSyncDisabledViaDashboard, true);
+  }
+#endif
+  profile_prefs->ClearPref(kSyncRequested);
 }
 
 }  // namespace
@@ -2202,7 +2219,7 @@
 
 // This method should be periodically pruned of year+ old migrations.
 // See chrome/browser/prefs/README.md for details.
-void MigrateObsoleteProfilePrefs(Profile* profile) {
+void MigrateObsoleteProfilePrefs(PrefService* profile_prefs) {
   // IMPORTANT NOTE: This code is *not* run on iOS Chrome. If a pref is migrated
   // or cleared here, and that pref is also used in iOS Chrome, it may also need
   // to be migrated or cleared specifically for iOS as well. This could be by
@@ -2213,8 +2230,6 @@
   // BEGIN_MIGRATE_OBSOLETE_PROFILE_PREFS
   // Please don't delete the preceding line. It is used by PRESUBMIT.py.
 
-  PrefService* profile_prefs = profile->GetPrefs();
-
   // Check MigrateDeprecatedAutofillPrefs() to see if this is safe to remove.
   autofill::prefs::MigrateDeprecatedAutofillPrefs(profile_prefs);
 
@@ -2514,6 +2529,9 @@
   profile_prefs->ClearPref(kSettingsMigratedToUPM);
 #endif
 
+  // Added 10/2023.
+  ClearSyncRequestedPrefAndMaybeMigrate(profile_prefs);
+
   // Please don't delete the following line. It is used by PRESUBMIT.py.
   // END_MIGRATE_OBSOLETE_PROFILE_PREFS