Migrate kGoogleServicesLastAccountId to kGoogleServicesLastGaiaId

The old preference was most of the time a GaiaID, but could sometimes
(rarely) be an email.
This was in particular the case on old Ash profiles.

This is confusing and causing issues for the Lacros migration.

This CL fixes the pref to always be a GaiaID. If it was an email, it is
simply discarded.
Discarding the pref is not a problem:
- it is only used in to detect cross account Sync issues.
- only Ash had an email there, and Ash cannot change the sync account,
  so there cannot be cross account sync issues on that platform.
- Lacros may also have an email there (copied from Ash) on the very
  first run. There cannot be a cross sync account issue on first run.

Bug: 1340791
Change-Id: Iafc64bbdac2690bce9aa577395cb6effa696c5ca
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3944995
Auto-Submit: David Roger <[email protected]>
Reviewed-by: Sylvain Defresne <[email protected]>
Commit-Queue: David Roger <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1060924}
diff --git a/chrome/browser/prefs/browser_prefs.cc b/chrome/browser/prefs/browser_prefs.cc
index 5a2fa91..cd8e923e 100644
--- a/chrome/browser/prefs/browser_prefs.cc
+++ b/chrome/browser/prefs/browser_prefs.cc
@@ -144,6 +144,7 @@
 #include "components/services/storage/public/cpp/storage_prefs.h"
 #include "components/sessions/core/session_id_generator.h"
 #include "components/signin/public/base/signin_buildflags.h"
+#include "components/signin/public/base/signin_pref_names.h"
 #include "components/signin/public/identity_manager/identity_manager.h"
 #include "components/site_engagement/content/site_engagement_service.h"
 #include "components/subresource_filter/content/browser/ruleset_service.h"
@@ -1990,11 +1991,23 @@
   // Added 09/2022.
   profile_prefs->ClearPref(kFirstPartySetsEnabled);
 
-#if BUILDFLAG(IS_ANDROID)
   // Added 10/2022
+#if BUILDFLAG(IS_ANDROID)
   feed::MigrateObsoleteProfilePrefsOct_2022(profile_prefs);
 #endif  // BUILDFLAG(IS_ANDROID)
 
+  // Once this migration is complete, the tracked preference
+  // `kGoogleServicesLastAccountIdDeprecated` can be removed.
+  if (profile_prefs->HasPrefPath(
+          prefs::kGoogleServicesLastAccountIdDeprecated)) {
+    std::string account_id =
+        profile_prefs->GetString(prefs::kGoogleServicesLastAccountIdDeprecated);
+    profile_prefs->ClearPref(prefs::kGoogleServicesLastAccountIdDeprecated);
+    bool is_email = account_id.find('@') != std::string::npos;
+    if (!is_email && !account_id.empty())
+      profile_prefs->SetString(prefs::kGoogleServicesLastGaiaId, account_id);
+  }
+
   // Please don't delete the following line. It is used by PRESUBMIT.py.
   // END_MIGRATE_OBSOLETE_PROFILE_PREFS