Roll out diacritics on by default to NZ

Quite a bit of blast radius to pass the country as a parameter from chrome->ash

BUG:b:286314257

Change-Id: Id509ad2a089a0b14944e3647b4dcdb7a397dd012
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4651009
Reviewed-by: Xiaoqian Dai <[email protected]>
Reviewed-by: Hidehiko Abe <[email protected]>
Reviewed-by: Zentaro Kavanagh <[email protected]>
Commit-Queue: John Palmer <[email protected]>
Reviewed-by: Dominic Battre <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1183476}
diff --git a/chrome/browser/about_flags.cc b/chrome/browser/about_flags.cc
index 563c021..40274e7 100644
--- a/chrome/browser/about_flags.cc
+++ b/chrome/browser/about_flags.cc
@@ -5386,13 +5386,6 @@
      flag_descriptions::kDiacriticsOnPhysicalKeyboardLongpressDescription,
      kOsCrOS,
      FEATURE_VALUE_TYPE(ash::features::kDiacriticsOnPhysicalKeyboardLongpress)},
-    {"enable-cros-diacritics-on-physical-keyboard-longpress-on-by-default",
-     flag_descriptions::kDiacriticsOnPhysicalKeyboardLongpressDefaultOnName,
-     flag_descriptions::
-         kDiacriticsOnPhysicalKeyboardLongpressDefaultOnDescription,
-     kOsCrOS,
-     FEATURE_VALUE_TYPE(
-         ash::features::kDiacriticsOnPhysicalKeyboardLongpressDefaultOn)},
     {"enable-cros-diacritics-use-replace-surrounding-text",
      flag_descriptions::kDiacriticsUseReplaceSurroundingTextName,
      flag_descriptions::kDiacriticsUseReplaceSurroundingTextDescription,
diff --git a/chrome/browser/flag_descriptions.cc b/chrome/browser/flag_descriptions.cc
index 26095da..eca564d 100644
--- a/chrome/browser/flag_descriptions.cc
+++ b/chrome/browser/flag_descriptions.cc
@@ -6274,13 +6274,6 @@
     "Enable diacritics and other varient character selection on physical "
     "keyboard longpress.";
 
-const char kDiacriticsOnPhysicalKeyboardLongpressDefaultOnName[] =
-    "Enable diacritics and variant character selection on PK longpress by "
-    "default.";
-const char kDiacriticsOnPhysicalKeyboardLongpressDefaultOnDescription[] =
-    "Enable diacritics and other varient character selection on physical "
-    "keyboard longpress by default.";
-
 const char kDiacriticsUseReplaceSurroundingTextName[] =
     "Use ReplaceSurroundingText API for longpress diacritics.";
 const char kDiacriticsUseReplaceSurroundingTextDescription[] =
diff --git a/chrome/browser/flag_descriptions.h b/chrome/browser/flag_descriptions.h
index 9298621..e31f974 100644
--- a/chrome/browser/flag_descriptions.h
+++ b/chrome/browser/flag_descriptions.h
@@ -3611,9 +3611,6 @@
 extern const char kDiacriticsOnPhysicalKeyboardLongpressName[];
 extern const char kDiacriticsOnPhysicalKeyboardLongpressDescription[];
 
-extern const char kDiacriticsOnPhysicalKeyboardLongpressDefaultOnName[];
-extern const char kDiacriticsOnPhysicalKeyboardLongpressDefaultOnDescription[];
-
 extern const char kDiacriticsUseReplaceSurroundingTextName[];
 extern const char kDiacriticsUseReplaceSurroundingTextDescription[];
 
diff --git a/chrome/browser/prefs/browser_prefs.cc b/chrome/browser/prefs/browser_prefs.cc
index 0f55529..04ffa22 100644
--- a/chrome/browser/prefs/browser_prefs.cc
+++ b/chrome/browser/prefs/browser_prefs.cc
@@ -5,6 +5,7 @@
 #include "chrome/browser/prefs/browser_prefs.h"
 
 #include <string>
+#include <string_view>
 
 #include "ash/constants/ash_constants.h"
 #include "base/time/time.h"
@@ -1392,6 +1393,16 @@
 
 }  // namespace
 
+std::string GetCountry() {
+  if (!g_browser_process || !g_browser_process->variations_service()) {
+    // This should only happen in tests. Ideally this would be guarded by
+    // CHECK_IS_TEST, but that is not set on Android, so no specific guard.
+    return std::string();
+  }
+  return std::string(
+      g_browser_process->variations_service()->GetStoredPermanentCountry());
+}
+
 void RegisterLocalState(PrefRegistrySimple* registry) {
   // Call outs to individual subsystems that register Local State (browser-wide)
   // prefs en masse. See RegisterProfilePrefs for per-profile prefs. Please
@@ -2051,7 +2062,7 @@
   ::android::RegisterUserProfilePrefs(registry);
 #endif
 #if BUILDFLAG(IS_CHROMEOS_ASH)
-  ash::RegisterUserProfilePrefs(registry);
+  ash::RegisterUserProfilePrefs(registry, locale);
 #endif
 }
 
@@ -2060,9 +2071,10 @@
 }
 
 #if BUILDFLAG(IS_CHROMEOS_ASH)
-void RegisterSigninProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
+void RegisterSigninProfilePrefs(user_prefs::PrefRegistrySyncable* registry,
+                                std::string_view country) {
   RegisterProfilePrefs(registry, g_browser_process->GetApplicationLocale());
-  ash::RegisterSigninProfilePrefs(registry);
+  ash::RegisterSigninProfilePrefs(registry, country);
 }
 
 #endif
diff --git a/chrome/browser/prefs/browser_prefs.h b/chrome/browser/prefs/browser_prefs.h
index 24fca42..6e148d76 100644
--- a/chrome/browser/prefs/browser_prefs.h
+++ b/chrome/browser/prefs/browser_prefs.h
@@ -6,6 +6,7 @@
 #define CHROME_BROWSER_PREFS_BROWSER_PREFS_H_
 
 #include <string>
+#include <string_view>
 
 #include "build/build_config.h"
 #include "build/chromeos_buildflags.h"
@@ -18,6 +19,10 @@
 class PrefRegistrySyncable;
 }
 
+// Gets the current country from the browser process. May be empty if the
+// browser process cannot supply the country.
+std::string GetCountry();
+
 // Register all prefs that will be used via the local state PrefService.
 void RegisterLocalState(PrefRegistrySimple* registry);
 
@@ -34,8 +39,13 @@
 
 #if BUILDFLAG(IS_CHROMEOS_ASH)
 // Register all prefs that will be used via a PrefService attached to the
-// sign-in profile using the locale of |g_browser_process|.
-void RegisterSigninProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
+// sign-in profile using the locale of |g_browser_process|. |country| should be
+// the permanent country code stored for this client in lowercase ISO 3166-1
+// alpha-2. It can be used to pick country specific default values. May be
+// empty May be empty in which case country specific preferences will be unable
+// to be set.
+void RegisterSigninProfilePrefs(user_prefs::PrefRegistrySyncable* registry,
+                                std::string_view country);
 #endif
 
 // Migrate/cleanup deprecated prefs in |local_state|. Over time, long deprecated
diff --git a/chrome/browser/profiles/pref_service_builder_utils.cc b/chrome/browser/profiles/pref_service_builder_utils.cc
index 32dcc126..a2b2024 100644
--- a/chrome/browser/profiles/pref_service_builder_utils.cc
+++ b/chrome/browser/profiles/pref_service_builder_utils.cc
@@ -32,6 +32,7 @@
 #include "components/prefs/pref_value_store.h"
 #include "components/supervised_user/core/common/buildflags.h"
 #include "components/sync_preferences/pref_service_syncable.h"
+#include "components/variations/service/variations_service.h"
 #include "content/public/browser/network_service_instance.h"
 #include "services/preferences/public/mojom/tracked_preference_validation_delegate.mojom.h"
 #include "ui/base/l10n/l10n_util.h"
@@ -70,7 +71,7 @@
                           user_prefs::PrefRegistrySyncable* pref_registry) {
 #if BUILDFLAG(IS_CHROMEOS_ASH)
   if (is_signin_profile)
-    RegisterSigninProfilePrefs(pref_registry);
+    RegisterSigninProfilePrefs(pref_registry, GetCountry());
   else
 #endif
     RegisterUserProfilePrefs(pref_registry, locale);
diff --git a/chrome/browser/startup_data.cc b/chrome/browser/startup_data.cc
index 0cd401d..8df7fa5 100644
--- a/chrome/browser/startup_data.cc
+++ b/chrome/browser/startup_data.cc
@@ -24,6 +24,7 @@
 #include "base/functional/bind.h"
 #include "base/path_service.h"
 #include "chrome/browser/android/profile_key_startup_accessor.h"
+#include "chrome/browser/browser_process.h"
 #include "chrome/browser/policy/profile_policy_connector.h"
 #include "chrome/browser/policy/profile_policy_connector_builder.h"
 #include "chrome/browser/policy/schema_registry_service.h"
@@ -43,6 +44,7 @@
 #include "components/policy/core/common/cloud/user_cloud_policy_store.h"
 #include "components/pref_registry/pref_registry_syncable.h"
 #include "components/sync_preferences/pref_service_syncable.h"
+#include "components/variations/service/variations_service.h"
 #include "content/public/browser/network_service_instance.h"
 #include "mojo/public/cpp/bindings/pending_remote.h"
 #include "services/preferences/public/mojom/tracked_preference_validation_delegate.mojom.h"