Migrate remaining Autobot SharedPreferences to PrefService.
This CL migrates the preferences for enabling Autofill Assistant,
Autofill Assistant consent and enabling Autofill Assistant trigger
scripts to Chrome's PrefService to allow easier access from C++ and
exposing them to enterprise policies.
While the majority of preference accesses from Java could be replaced
by direct calls to PrefService or moved to C++, there remain two
instances of Java code in //components/autofill_assistant that access
preferences. These are encapsulated in a new, small class
AutofillAssistantPreferencesManager that replaces
AutofillAssistantPreferencesUtil.
The CL's size is due to interdependencies between the migrated
preferences that prohobits easily moving them independently.
Bug: 1352553
Change-Id: Id2695cc952749b31bed5866635ae807b273b3eb3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3904226
Reviewed-by: Dominic Battré <[email protected]>
Reviewed-by: Marc Treib <[email protected]>
Commit-Queue: Jan Keitel <[email protected]>
Reviewed-by: Clemens Arbesser <[email protected]>
Reviewed-by: Luca Hunkeler <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1051186}
diff --git a/chrome/browser/prefs/browser_prefs.cc b/chrome/browser/prefs/browser_prefs.cc
index bc40f93a..1c21d02 100644
--- a/chrome/browser/prefs/browser_prefs.cc
+++ b/chrome/browser/prefs/browser_prefs.cc
@@ -1956,16 +1956,30 @@
// Added 09/2022.
#if BUILDFLAG(IS_ANDROID)
- if (absl::optional<bool> shared_pref =
- android::shared_preferences::GetAndClearBoolean(
- autofill_assistant::prefs::
- kDeprecatedAutofillAssistantTriggerScriptsIsFirstTimeUser);
- shared_pref) {
- profile_prefs->SetBoolean(
- autofill_assistant::prefs::
- kAutofillAssistantTriggerScriptsIsFirstTimeUser,
- shared_pref.value());
- }
+ auto migrate_shared_pref = [profile_prefs](const std::string& source,
+ const std::string& target) {
+ if (absl::optional<bool> shared_pref =
+ android::shared_preferences::GetAndClearBoolean(source);
+ shared_pref) {
+ profile_prefs->SetBoolean(target, shared_pref.value());
+ }
+ };
+
+ migrate_shared_pref(
+ autofill_assistant::prefs::kDeprecatedAutofillAssistantConsent,
+ autofill_assistant::prefs::kAutofillAssistantConsent);
+ migrate_shared_pref(
+ autofill_assistant::prefs::kDeprecatedAutofillAssistantEnabled,
+ autofill_assistant::prefs::kAutofillAssistantEnabled);
+ migrate_shared_pref(
+ autofill_assistant::prefs::
+ kDeprecatedAutofillAssistantTriggerScriptsEnabled,
+ autofill_assistant::prefs::kAutofillAssistantTriggerScriptsEnabled);
+ migrate_shared_pref(
+ autofill_assistant::prefs::
+ kDeprecatedAutofillAssistantTriggerScriptsIsFirstTimeUser,
+ autofill_assistant::prefs::
+ kAutofillAssistantTriggerScriptsIsFirstTimeUser);
#endif
// Added 09/2022.