blob: 9cc52c4716cda2aa8b97ed9a10dbfaa9cc1ac022 [file] [log] [blame]
[email protected]487ba1462012-01-05 03:13:091// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]fecc1522009-10-15 21:08:292// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "chrome/browser/chromeos/preferences.h"
6
Meilin Wang8a1e95b42019-02-27 22:01:517#include <limits>
[email protected]396991402014-02-17 10:56:178#include <vector>
9
Ken Rockotb9bab542019-12-12 00:53:3010#include "ash/public/ash_interfaces.h"
Steven Bennetts93d3e5b12018-05-05 01:14:5011#include "ash/public/cpp/ash_constants.h"
James Cookc63b9fd2017-08-18 18:48:3212#include "ash/public/cpp/ash_pref_names.h"
Xiyuan Xia14619a22019-05-14 20:20:4413#include "ash/public/cpp/ash_prefs.h"
Miyoung Shin7e1b1b12019-08-02 12:23:5014#include "ash/public/mojom/cros_display_config.mojom.h"
Sebastien Marchandf1349f52019-01-25 03:16:4115#include "base/bind.h"
[email protected]775caec2011-09-01 17:14:3216#include "base/command_line.h"
Kyle Horimoto5ab70b902020-04-01 22:23:5917#include "base/feature_list.h"
[email protected]530cd622011-04-14 15:45:0018#include "base/i18n/time_formatting.h"
Zentaro Kavanagh65b3e112019-09-03 16:18:2319#include "base/metrics/histogram_functions.h"
asvitkineb56637512016-09-01 19:41:4020#include "base/metrics/histogram_macros.h"
[email protected]1988e1c2013-02-28 20:27:4221#include "base/strings/string_split.h"
[email protected]5c073322013-06-11 08:03:3022#include "base/strings/string_util.h"
[email protected]135cb802013-06-09 16:44:2023#include "base/strings/utf_string_conversions.h"
[email protected]c0a2128d92011-07-20 15:04:4624#include "chrome/browser/browser_process.h"
Hans Wennborg63344452019-10-15 10:15:2125#include "chrome/browser/browser_process_platform_part.h"
[email protected]fdf40f3e2013-07-11 23:55:4626#include "chrome/browser/chrome_notification_types.h"
[email protected]7585f4c2013-01-10 18:26:4127#include "chrome/browser/chromeos/accessibility/magnification_manager.h"
Zakhar Voit1f16c5e2018-10-26 12:08:2328#include "chrome/browser/chromeos/base/locale_util.h"
Henrique Grandinettidc2db072019-05-03 13:18:2629#include "chrome/browser/chromeos/child_accounts/parent_access_code/parent_access_service.h"
Erik Chenc9e8dfb2020-07-30 01:35:0930#include "chrome/browser/chromeos/crosapi/browser_util.h"
lukasza6364a022015-08-21 01:13:2431#include "chrome/browser/chromeos/drive/file_system_util.h"
Rachel Carpenter928b0e62020-06-17 01:06:5732#include "chrome/browser/chromeos/first_run/help_app_first_run_field_trial.h"
Alexander Alekseev45f84332020-10-29 07:25:3733#include "chrome/browser/chromeos/input_method/input_method_persistence.h"
michaelpg975f2182014-12-05 04:00:1434#include "chrome/browser/chromeos/input_method/input_method_syncer.h"
Roman Aleksandrov6a6a63c2020-07-02 11:26:4535#include "chrome/browser/chromeos/login/login_pref_names.h"
[email protected]295ca1a72014-07-01 16:14:3136#include "chrome/browser/chromeos/login/session/user_session_manager.h"
alemate2cb0d752017-08-11 05:22:1637#include "chrome/browser/chromeos/profiles/profile_helper.h"
38#include "chrome/browser/chromeos/settings/cros_settings.h"
James Cook42ba2652020-06-05 19:31:1539#include "chrome/browser/chromeos/sync/split_settings_sync_field_trial.h"
James Cookac8291e2019-12-20 23:42:4840#include "chrome/browser/chromeos/sync/turn_sync_on_helper.h"
[email protected]82eb8ec2011-12-20 22:24:3341#include "chrome/browser/chromeos/system/input_device_settings.h"
alemate75b7a5c2016-03-29 06:39:4642#include "chrome/browser/chromeos/system/timezone_resolver_manager.h"
alemate2cb0d752017-08-11 05:22:1643#include "chrome/browser/chromeos/system/timezone_util.h"
[email protected]b1d97272013-08-17 13:38:4944#include "chrome/browser/download/download_prefs.h"
sdefresneed27d86b2015-09-14 11:02:3845#include "chrome/browser/prefs/pref_service_syncable_util.h"
James Cook671818f2017-07-10 19:31:4546#include "chrome/browser/ui/ash/system_tray_client.h"
azurewei19663e22016-03-24 01:30:5247#include "chrome/common/chrome_features.h"
[email protected]fecc1522009-10-15 21:08:2948#include "chrome/common/pref_names.h"
Kyle Horimoto5ab70b902020-04-01 22:23:5949#include "chromeos/constants/chromeos_features.h"
Thomas Tellieraa0617902020-05-04 10:02:5950#include "chromeos/constants/chromeos_pref_names.h"
Steven Bennetts38e9bde22019-01-03 17:31:1051#include "chromeos/constants/chromeos_switches.h"
alemate2cb0d752017-08-11 05:22:1652#include "chromeos/settings/cros_settings_names.h"
reveman24158982017-01-10 05:58:4553#include "chromeos/system/devicemode.h"
[email protected]279690f82013-10-09 08:23:5254#include "chromeos/system/statistics_provider.h"
alemate48255f3d2015-01-30 18:11:4155#include "chromeos/timezone/timezone_resolver.h"
lukasza76b4a982015-08-08 00:36:3956#include "components/drive/drive_pref_names.h"
[email protected]1eab4e92014-05-09 02:17:1957#include "components/feedback/tracing_manager.h"
Alexandre Frechette572755b2019-02-13 22:30:2058#include "components/language/core/browser/pref_names.h"
Roman Sorokin1b1677d072017-10-16 12:27:4859#include "components/policy/proto/chrome_device_policy.pb.h"
[email protected]f0c8c4992014-05-15 17:37:2660#include "components/pref_registry/pref_registry_syncable.h"
brettwb1fc1b82016-02-02 00:19:0861#include "components/prefs/pref_member.h"
62#include "components/prefs/pref_registry_simple.h"
63#include "components/prefs/scoped_user_pref_update.h"
maxbogueea16ff412016-10-28 16:35:2964#include "components/sync_preferences/pref_service_syncable.h"
alemate8730a2f2015-12-19 07:13:0965#include "components/user_manager/known_user.h"
[email protected]2fda9972014-07-23 14:51:5966#include "components/user_manager/user.h"
alemate8730a2f2015-12-19 07:13:0967#include "components/user_manager/user_manager.h"
michaelpg975f2182014-12-05 04:00:1468#include "content/public/browser/browser_thread.h"
Darin Fishera26aa7e2019-09-02 20:22:5969#include "third_party/blink/public/mojom/speech/speech_synthesis.mojom.h"
xiaoyinhf39e3dd2016-06-18 04:50:2370#include "third_party/cros_system_api/dbus/update_engine/dbus-constants.h"
[email protected]8bbf6192013-07-18 11:14:0471#include "third_party/icu/source/i18n/unicode/timezone.h"
shuchen179b1f42014-11-27 17:24:4072#include "ui/base/ime/chromeos/extension_ime_util.h"
73#include "ui/base/ime/chromeos/ime_keyboard.h"
74#include "ui/base/ime/chromeos/input_method_manager.h"
Blake O'Hared00831e2017-10-06 12:37:2575#include "ui/chromeos/events/modifier_key.h"
penghuange5df2822017-03-16 22:54:3676#include "ui/chromeos/events/pref_names.h"
[email protected]86ccbd42013-09-18 18:11:5477#include "ui/events/event_constants.h"
78#include "ui/events/event_utils.h"
[email protected]a6483d22013-07-03 22:11:0079#include "url/gurl.h"
[email protected]fecc1522009-10-15 21:08:2980
[email protected]de1528d1a2012-05-14 10:36:1581namespace chromeos {
[email protected]fecc1522009-10-15 21:08:2982
xdaie6172c92017-02-24 19:01:5183namespace {
84
xdaie6172c92017-02-24 19:01:5185// The keyboard preferences that determine how we remap modifier keys. These
86// preferences will be saved in global user preferences dictionary so that they
87// can be used on signin screen.
88const char* const kLanguageRemapPrefs[] = {
Thomas Tellieraa0617902020-05-04 10:02:5989 ::prefs::kLanguageRemapSearchKeyTo,
90 ::prefs::kLanguageRemapControlKeyTo,
91 ::prefs::kLanguageRemapAltKeyTo,
92 ::prefs::kLanguageRemapCapsLockKeyTo,
93 ::prefs::kLanguageRemapEscapeKeyTo,
94 ::prefs::kLanguageRemapBackspaceKeyTo,
95 ::prefs::kLanguageRemapExternalCommandKeyTo,
96 ::prefs::kLanguageRemapExternalMetaKeyTo};
xdaie6172c92017-02-24 19:01:5197
Alexander Alekseev687cdb52017-11-11 02:40:0098// Migrates kResolveTimezoneByGeolocation value to
99// kResolveTimezoneByGeolocationMethod.
100// Default preference value will become another default value.
101// TODO(alemate): https://crbug.com/783367 Remove outdated prefs.
James Cook181be002020-05-05 20:55:19102void TryMigrateToResolveTimezoneByGeolocationMethod(
103 sync_preferences::PrefServiceSyncable* prefs) {
Thomas Tellieraa0617902020-05-04 10:02:59104 if (prefs->GetBoolean(::prefs::kResolveTimezoneByGeolocationMigratedToMethod))
Alexander Alekseev687cdb52017-11-11 02:40:00105 return;
106
James Cook181be002020-05-05 20:55:19107 // Timezone resolution method is a non-priority pref. Wait to migrate until
108 // that type of pref has synced.
109 bool is_syncing = chromeos::features::IsSplitSettingsSyncEnabled()
110 ? prefs->AreOsPrefsSyncing()
111 : prefs->IsSyncing();
112 if (!is_syncing)
113 return;
114
Thomas Tellieraa0617902020-05-04 10:02:59115 prefs->SetBoolean(::prefs::kResolveTimezoneByGeolocationMigratedToMethod,
116 true);
Alexander Alekseev687cdb52017-11-11 02:40:00117 const PrefService::Preference* old_preference =
Thomas Tellieraa0617902020-05-04 10:02:59118 prefs->FindPreference(::prefs::kResolveTimezoneByGeolocation);
Alexander Alekseev687cdb52017-11-11 02:40:00119 if (old_preference->IsDefaultValue())
120 return;
121
122 const PrefService::Preference* new_preference =
Thomas Tellieraa0617902020-05-04 10:02:59123 prefs->FindPreference(::prefs::kResolveTimezoneByGeolocationMethod);
Alexander Alekseev687cdb52017-11-11 02:40:00124 if (!new_preference->IsDefaultValue())
125 return;
126
127 const system::TimeZoneResolverManager::TimeZoneResolveMethod method(
128 old_preference->GetValue()->GetBool()
129 ? system::TimeZoneResolverManager::TimeZoneResolveMethod::IP_ONLY
130 : system::TimeZoneResolverManager::TimeZoneResolveMethod::DISABLED);
Thomas Tellieraa0617902020-05-04 10:02:59131 prefs->SetInteger(::prefs::kResolveTimezoneByGeolocationMethod,
Alexander Alekseev687cdb52017-11-11 02:40:00132 static_cast<int>(method));
133}
134
Kyle Horimoto5ab70b902020-04-01 22:23:59135bool AreScrollSettingsAllowed() {
136 return base::FeatureList::IsEnabled(features::kAllowScrollSettings);
137}
138
xdaie6172c92017-02-24 19:01:51139} // namespace
140
[email protected]2c62b3f2012-04-12 12:07:50141Preferences::Preferences()
James Cookbd0b7792017-11-17 03:24:26142 : Preferences(input_method::InputMethodManager::Get()) {}
[email protected]2c62b3f2012-04-12 12:07:50143
144Preferences::Preferences(input_method::InputMethodManager* input_method_manager)
[email protected]eb5624e2013-05-23 19:50:27145 : prefs_(NULL),
[email protected]daf37cc2013-11-01 18:10:26146 input_method_manager_(input_method_manager),
[email protected]50de64ea2014-02-19 06:25:50147 user_(NULL),
Steven Bennettsbce1cf5c2018-05-23 19:38:12148 user_is_primary_(false) {
Ken Rockotb9bab542019-12-12 00:53:30149 ash::BindCrosDisplayConfigController(
150 cros_display_config_.BindNewPipeAndPassReceiver());
Steven Bennettsbce1cf5c2018-05-23 19:38:12151}
[email protected]d743a5982010-11-08 17:54:09152
[email protected]7f914fd2012-12-20 23:55:25153Preferences::~Preferences() {
154 prefs_->RemoveObserver(this);
[email protected]4d390782014-08-15 09:22:58155 user_manager::UserManager::Get()->RemoveSessionStateObserver(this);
[email protected]7f914fd2012-12-20 23:55:25156}
[email protected]9199bd52010-07-01 05:04:41157
[email protected]fecc1522009-10-15 21:08:29158// static
[email protected]681958c2013-02-21 13:48:14159void Preferences::RegisterPrefs(PrefRegistrySimple* registry) {
Thomas Tellieraa0617902020-05-04 10:02:59160 registry->RegisterBooleanPref(::prefs::kOwnerPrimaryMouseButtonRight, false);
161 registry->RegisterBooleanPref(::prefs::kOwnerTapToClickEnabled, true);
James Cookc63b9fd2017-08-18 18:48:32162 // TODO(jamescook): Move ownership and registration into ash.
Thomas Tellieraa0617902020-05-04 10:02:59163 registry->RegisterStringPref(::prefs::kLogoutStartedLast, std::string());
164 registry->RegisterStringPref(::prefs::kSigninScreenTimezone, std::string());
165 registry->RegisterBooleanPref(::prefs::kResolveDeviceTimezoneByGeolocation,
alemate01c62ce2015-02-19 17:03:09166 true);
alemated70e82f2016-04-05 12:21:33167 registry->RegisterIntegerPref(
Thomas Tellieraa0617902020-05-04 10:02:59168 ::prefs::kResolveDeviceTimezoneByGeolocationMethod,
Alexander Alekseev687cdb52017-11-11 02:40:00169 static_cast<int>(
170 system::TimeZoneResolverManager::TimeZoneResolveMethod::IP_ONLY));
171 registry->RegisterIntegerPref(
Thomas Tellieraa0617902020-05-04 10:02:59172 ::prefs::kSystemTimezoneAutomaticDetectionPolicy,
alemated70e82f2016-04-05 12:21:33173 enterprise_management::SystemTimezoneProto::USERS_DECIDE);
Thomas Tellieraa0617902020-05-04 10:02:59174 registry->RegisterStringPref(::prefs::kMinimumAllowedChromeVersion, "");
Igorc5014d42020-10-12 12:48:17175 registry->RegisterBooleanPref(::prefs::kLacrosAllowed, true);
Steven Bennettsca108512018-05-02 11:05:03176
Xiyuan Xia14619a22019-05-14 20:20:44177 ash::RegisterLocalStatePrefs(registry);
James Cook42ba2652020-06-05 19:31:15178 split_settings_sync_field_trial::RegisterLocalStatePrefs(registry);
Rachel Carpenter928b0e62020-06-17 01:06:57179 help_app_first_run_field_trial::RegisterLocalStatePrefs(registry);
[email protected]681958c2013-02-21 13:48:14180}
181
182// static
[email protected]37ca3fe02013-07-05 15:32:44183void Preferences::RegisterProfilePrefs(
[email protected]443e9312013-05-06 06:17:34184 user_prefs::PrefRegistrySyncable* registry) {
James Cookac8291e2019-12-20 23:42:48185 // Some classes register their own prefs.
186 TurnSyncOnHelper::RegisterProfilePrefs(registry);
187 input_method::InputMethodSyncer::RegisterProfilePrefs(registry);
Erik Chenc9e8dfb2020-07-30 01:35:09188 crosapi::browser_util::RegisterProfilePrefs(registry);
James Cookac8291e2019-12-20 23:42:48189
[email protected]2c62b3f2012-04-12 12:07:50190 std::string hardware_keyboard_id;
191 // TODO(yusukes): Remove the runtime hack.
reveman24158982017-01-10 05:58:45192 if (IsRunningAsSystemCompositor()) {
[email protected]396991402014-02-17 10:56:17193 DCHECK(g_browser_process);
194 PrefService* local_state = g_browser_process->local_state();
195 DCHECK(local_state);
196 hardware_keyboard_id =
Thomas Tellieraa0617902020-05-04 10:02:59197 local_state->GetString(::prefs::kHardwareKeyboardLayout);
[email protected]2c62b3f2012-04-12 12:07:50198 } else {
199 hardware_keyboard_id = "xkb:us::eng"; // only for testing.
200 }
[email protected]a9a81812011-09-16 11:01:17201
Thomas Tellieraa0617902020-05-04 10:02:59202 registry->RegisterBooleanPref(::prefs::kPerformanceTracingEnabled, false);
[email protected]a1ea1292013-08-07 23:50:40203
Kush Sinha811150f2019-01-19 11:14:49204 // This pref is device specific and must not be synced.
205 registry->RegisterIntegerPref(
Thomas Tellieraa0617902020-05-04 10:02:59206 ::prefs::kAccountManagerNumTimesMigrationRanSuccessfully,
Kush Sinhae12d00d2019-01-24 18:30:05207 0 /* default_value */);
208
209 // This pref is device specific and must not be synced.
210 registry->RegisterIntegerPref(
Thomas Tellieraa0617902020-05-04 10:02:59211 ::prefs::kAccountManagerNumTimesWelcomeScreenShown,
212 0 /* default_value */);
Kush Sinha811150f2019-01-19 11:14:49213
[email protected]a1ea1292013-08-07 23:50:40214 registry->RegisterBooleanPref(
Thomas Tellieraa0617902020-05-04 10:02:59215 ::prefs::kTapToClickEnabled, true,
James Cookbf73f082019-10-23 03:19:04216 user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PRIORITY_PREF);
Thomas Tellieraa0617902020-05-04 10:02:59217 registry->RegisterBooleanPref(::prefs::kEnableTouchpadThreeFingerClick,
218 false);
phweissa16ceae22015-09-17 09:33:12219 // This preference can only be set to true by policy or command_line flag
220 // and it should not carry over to sessions were neither of these is set.
Thomas Tellieraa0617902020-05-04 10:02:59221 registry->RegisterBooleanPref(::prefs::kUnifiedDesktopEnabledByDefault, false,
phweissa16ceae22015-09-17 09:33:12222 PrefRegistry::NO_REGISTRATION_FLAGS);
Ana Salazareb7c25712020-02-03 20:27:26223 // TODO(anasalazar): Finish moving this to ash.
[email protected]443e9312013-05-06 06:17:34224 registry->RegisterBooleanPref(
Ana Salazareb7c25712020-02-03 20:27:26225 ash::prefs::kNaturalScroll,
James Cookbf73f082019-10-23 03:19:04226 base::CommandLine::ForCurrentProcess()->HasSwitch(
227 switches::kNaturalScrollDefault),
228 user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PRIORITY_PREF);
[email protected]443e9312013-05-06 06:17:34229 registry->RegisterBooleanPref(
Ana Salazareb7c25712020-02-03 20:27:26230 ash::prefs::kMouseReverseScroll, false,
James Cookbf73f082019-10-23 03:19:04231 user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PRIORITY_PREF);
Ana Salazareb7c25712020-02-03 20:27:26232
Lann Martin9a517ad2017-08-29 00:43:39233 registry->RegisterBooleanPref(
Thomas Tellieraa0617902020-05-04 10:02:59234 ::prefs::kPrimaryMouseButtonRight, false,
James Cookbf73f082019-10-23 03:19:04235 user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PRIORITY_PREF);
Zentaro Kavanagh65b3e112019-09-03 16:18:23236 registry->RegisterBooleanPref(
Thomas Tellieraa0617902020-05-04 10:02:59237 ::prefs::kMouseAcceleration, true,
James Cookbf73f082019-10-23 03:19:04238 user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PRIORITY_PREF);
Zentaro Kavanagh65b3e112019-09-03 16:18:23239 registry->RegisterBooleanPref(
Thomas Tellieraa0617902020-05-04 10:02:59240 ::prefs::kMouseScrollAcceleration, true,
Kyle Horimoto734f0752020-03-20 20:46:54241 user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PRIORITY_PREF);
242 registry->RegisterBooleanPref(
Thomas Tellieraa0617902020-05-04 10:02:59243 ::prefs::kTouchpadAcceleration, true,
James Cookbf73f082019-10-23 03:19:04244 user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PRIORITY_PREF);
Kyle Horimoto734f0752020-03-20 20:46:54245 registry->RegisterBooleanPref(
Thomas Tellieraa0617902020-05-04 10:02:59246 ::prefs::kTouchpadScrollAcceleration, true,
Kyle Horimoto734f0752020-03-20 20:46:54247 user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PRIORITY_PREF);
Thomas Tellieraa0617902020-05-04 10:02:59248 registry->RegisterBooleanPref(::prefs::kLabsMediaplayerEnabled, false);
249 registry->RegisterBooleanPref(::prefs::kLabsAdvancedFilesystemEnabled, false);
250 registry->RegisterBooleanPref(::prefs::kAppReinstallRecommendationEnabled,
Rob Schonberger76f37702019-05-03 05:52:25251 false);
James Cookc63b9fd2017-08-18 18:48:32252
[email protected]443e9312013-05-06 06:17:34253 registry->RegisterIntegerPref(
Thomas Tellieraa0617902020-05-04 10:02:59254 ::prefs::kMouseSensitivity, 3,
James Cookbf73f082019-10-23 03:19:04255 user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PRIORITY_PREF);
[email protected]443e9312013-05-06 06:17:34256 registry->RegisterIntegerPref(
Thomas Tellieraa0617902020-05-04 10:02:59257 ::prefs::kMouseScrollSensitivity, 3,
Kyle Horimoto734f0752020-03-20 20:46:54258 user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PRIORITY_PREF);
259 registry->RegisterIntegerPref(
Harry Cuttsc3331972020-11-17 03:54:46260 ::prefs::kPointingStickSensitivity, 3,
261 user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PRIORITY_PREF);
262 registry->RegisterIntegerPref(
Thomas Tellieraa0617902020-05-04 10:02:59263 ::prefs::kTouchpadSensitivity, 3,
James Cookbf73f082019-10-23 03:19:04264 user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PRIORITY_PREF);
Kyle Horimoto734f0752020-03-20 20:46:54265 registry->RegisterIntegerPref(
Thomas Tellieraa0617902020-05-04 10:02:59266 ::prefs::kTouchpadScrollSensitivity, 3,
Kyle Horimoto734f0752020-03-20 20:46:54267 user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PRIORITY_PREF);
[email protected]443e9312013-05-06 06:17:34268 registry->RegisterBooleanPref(
Thomas Tellieraa0617902020-05-04 10:02:59269 ::prefs::kUse24HourClock, base::GetHourClockType() == base::k24HourClock,
James Cookbf73f082019-10-23 03:19:04270 user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
[email protected]443e9312013-05-06 06:17:34271 registry->RegisterBooleanPref(
lukaszada911a62015-06-17 15:39:32272 drive::prefs::kDisableDrive, false,
James Cookbf73f082019-10-23 03:19:04273 user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
[email protected]443e9312013-05-06 06:17:34274 registry->RegisterBooleanPref(
lukaszada911a62015-06-17 15:39:32275 drive::prefs::kDisableDriveOverCellular, true,
James Cookbf73f082019-10-23 03:19:04276 user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
Sergei Datsenko3b10af0722018-10-11 05:13:29277 registry->RegisterBooleanPref(drive::prefs::kDriveFsWasLaunchedAtLeastOnce,
278 false);
Sergei Datsenko1bb73482018-07-25 01:21:50279 registry->RegisterStringPref(drive::prefs::kDriveFsProfileSalt, "");
Sam McNally63e4b8ce2018-09-05 05:39:51280 registry->RegisterBooleanPref(drive::prefs::kDriveFsPinnedMigrated, false);
Austin Tankiangeeff20ab2020-06-04 05:54:48281 registry->RegisterBooleanPref(drive::prefs::kDriveFsEnableVerboseLogging,
282 false);
Thomas Tellieraa0617902020-05-04 10:02:59283 // We don't sync ::prefs::kLanguageCurrentInputMethod and PreviousInputMethod
[email protected]aa96e372011-05-16 06:23:10284 // because they're just used to track the logout state of the device.
Thomas Tellieraa0617902020-05-04 10:02:59285 registry->RegisterStringPref(::prefs::kLanguageCurrentInputMethod, "");
286 registry->RegisterStringPref(::prefs::kLanguagePreviousInputMethod, "");
287 registry->RegisterListPref(::prefs::kLanguageAllowedInputMethods);
288 registry->RegisterListPref(::prefs::kAllowedLanguages);
289 registry->RegisterStringPref(::prefs::kLanguagePreloadEngines,
raymesaa608722015-04-27 03:00:25290 hardware_keyboard_id);
Thomas Tellieraa0617902020-05-04 10:02:59291 registry->RegisterStringPref(::prefs::kLanguageEnabledImes, "");
292 registry->RegisterDictionaryPref(
Keith Leed737ae32020-05-18 07:52:50293 chromeos::prefs::kAssistiveInputFeatureSettings);
My Nguyene49594a2020-05-27 07:58:11294 registry->RegisterBooleanPref(chromeos::prefs::kAssistPersonalInfoEnabled,
295 true);
My Nguyen49d04682020-06-18 05:29:02296 registry->RegisterBooleanPref(chromeos::prefs::kEmojiSuggestionEnabled, true);
My Nguyend45c3b812020-07-27 19:39:57297 registry->RegisterBooleanPref(
298 chromeos::prefs::kEmojiSuggestionEnterpriseAllowed, true);
Keith Leed737ae32020-05-18 07:52:50299 registry->RegisterDictionaryPref(
Thomas Tellieraa0617902020-05-04 10:02:59300 ::prefs::kLanguageInputMethodSpecificSettings);
[email protected]7ac5af92010-06-07 01:25:44301
[email protected]443e9312013-05-06 06:17:34302 registry->RegisterIntegerPref(
Thomas Tellieraa0617902020-05-04 10:02:59303 ::prefs::kLanguageRemapSearchKeyTo,
Blake O'Harea09fa45a2017-10-13 04:19:58304 static_cast<int>(ui::chromeos::ModifierKey::kSearchKey),
James Cookbf73f082019-10-23 03:19:04305 user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PRIORITY_PREF);
[email protected]443e9312013-05-06 06:17:34306 registry->RegisterIntegerPref(
Thomas Tellieraa0617902020-05-04 10:02:59307 ::prefs::kLanguageRemapControlKeyTo,
Blake O'Harea09fa45a2017-10-13 04:19:58308 static_cast<int>(ui::chromeos::ModifierKey::kControlKey),
James Cookbf73f082019-10-23 03:19:04309 user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PRIORITY_PREF);
[email protected]443e9312013-05-06 06:17:34310 registry->RegisterIntegerPref(
Thomas Tellieraa0617902020-05-04 10:02:59311 ::prefs::kLanguageRemapAltKeyTo,
Blake O'Harea09fa45a2017-10-13 04:19:58312 static_cast<int>(ui::chromeos::ModifierKey::kAltKey),
James Cookbf73f082019-10-23 03:19:04313 user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PRIORITY_PREF);
Meilin Wang8a1e95b42019-02-27 22:01:51314 registry->RegisterIntegerPref(
Thomas Tellieraa0617902020-05-04 10:02:59315 ::prefs::kLanguageRemapAssistantKeyTo,
Meilin Wang8a1e95b42019-02-27 22:01:51316 static_cast<int>(ui::chromeos::ModifierKey::kAssistantKey),
James Cookbf73f082019-10-23 03:19:04317 user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PRIORITY_PREF);
[email protected]0f424fd92013-05-08 21:12:19318 // We don't sync the CapsLock remapping pref, since the UI hides this pref
319 // on certain devices, so syncing a non-default value to a device that
320 // doesn't allow changing the pref would be odd. http://crbug.com/167237
[email protected]443e9312013-05-06 06:17:34321 registry->RegisterIntegerPref(
Thomas Tellieraa0617902020-05-04 10:02:59322 ::prefs::kLanguageRemapCapsLockKeyTo,
Blake O'Harea09fa45a2017-10-13 04:19:58323 static_cast<int>(ui::chromeos::ModifierKey::kCapsLockKey));
324 registry->RegisterIntegerPref(
Thomas Tellieraa0617902020-05-04 10:02:59325 ::prefs::kLanguageRemapEscapeKeyTo,
Blake O'Harea09fa45a2017-10-13 04:19:58326 static_cast<int>(ui::chromeos::ModifierKey::kEscapeKey),
James Cookbf73f082019-10-23 03:19:04327 user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PRIORITY_PREF);
michaelpg168ecd72016-08-25 04:00:42328 registry->RegisterIntegerPref(
Thomas Tellieraa0617902020-05-04 10:02:59329 ::prefs::kLanguageRemapBackspaceKeyTo,
Blake O'Harea09fa45a2017-10-13 04:19:58330 static_cast<int>(ui::chromeos::ModifierKey::kBackspaceKey),
James Cookbf73f082019-10-23 03:19:04331 user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PRIORITY_PREF);
Ahmed Fakhry629985b2018-07-30 20:57:32332 // The Command key on external Apple keyboards is remapped by default to Ctrl
333 // until the user changes it from the keyboard settings.
334 registry->RegisterIntegerPref(
Thomas Tellieraa0617902020-05-04 10:02:59335 ::prefs::kLanguageRemapExternalCommandKeyTo,
Ahmed Fakhry629985b2018-07-30 20:57:32336 static_cast<int>(ui::chromeos::ModifierKey::kControlKey),
James Cookbf73f082019-10-23 03:19:04337 user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PRIORITY_PREF);
Ahmed Fakhry629985b2018-07-30 20:57:32338 // The Meta key (Search or Windows keys) on external keyboards is remapped by
339 // default to Search until the user changes it from the keyboard settings.
340 registry->RegisterIntegerPref(
Thomas Tellieraa0617902020-05-04 10:02:59341 ::prefs::kLanguageRemapExternalMetaKeyTo,
Ahmed Fakhry629985b2018-07-30 20:57:32342 static_cast<int>(ui::chromeos::ModifierKey::kSearchKey),
James Cookbf73f082019-10-23 03:19:04343 user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PRIORITY_PREF);
[email protected]e2204a702013-10-29 21:58:54344 // The following pref isn't synced since the user may desire a different value
345 // depending on whether an external keyboard is attached to a particular
346 // device.
Thomas Tellieraa0617902020-05-04 10:02:59347 registry->RegisterBooleanPref(::prefs::kLanguageSendFunctionKeys, false);
[email protected]4ccc05e2010-10-06 19:32:15348
deratb4fee74c2016-12-17 04:11:46349 // Don't sync the note-taking app; it may not be installed on other devices.
Thomas Tellieraa0617902020-05-04 10:02:59350 registry->RegisterStringPref(::prefs::kNoteTakingAppId, std::string());
351 registry->RegisterBooleanPref(::prefs::kNoteTakingAppEnabledOnLockScreen,
352 true);
Brian Malcolmb0904f3a2020-07-31 23:13:48353 registry->RegisterListPref(::prefs::kNoteTakingAppsLockScreenAllowlist);
Thomas Tellieraa0617902020-05-04 10:02:59354 registry->RegisterBooleanPref(::prefs::kRestoreLastLockScreenNote, true);
355 registry->RegisterDictionaryPref(
356 ::prefs::kNoteTakingAppsLockScreenToastShown);
jdufault5d4c81c62016-07-28 20:22:06357
Thomas Tellieraa0617902020-05-04 10:02:59358 registry->RegisterBooleanPref(::prefs::kShowMobileDataNotification, true);
[email protected]d6ae9502011-05-05 18:23:09359
[email protected]443e9312013-05-06 06:17:34360 // Initially all existing users would see "What's new" for current version
361 // after update.
James Cookbf73f082019-10-23 03:19:04362 registry->RegisterStringPref(
Thomas Tellieraa0617902020-05-04 10:02:59363 ::prefs::kChromeOSReleaseNotesVersion, "0.0.0.0",
James Cookbf73f082019-10-23 03:19:04364 user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
[email protected]efb770c2012-05-04 22:31:48365
Thomas Tellieraa0617902020-05-04 10:02:59366 registry->RegisterBooleanPref(::prefs::kExternalStorageDisabled, false);
[email protected]3a229f42013-02-07 03:09:26367
Thomas Tellieraa0617902020-05-04 10:02:59368 registry->RegisterBooleanPref(::prefs::kExternalStorageReadOnly, false);
yamaguchicc8186b2016-08-08 06:38:54369
Thomas Tellieraa0617902020-05-04 10:02:59370 registry->RegisterStringPref(::prefs::kTermsOfServiceURL, "");
[email protected]fddc44fe2013-07-04 00:03:51371
Thomas Tellieraa0617902020-05-04 10:02:59372 registry->RegisterBooleanPref(::prefs::kTouchVirtualKeyboardEnabled, false);
michaelpg975f2182014-12-05 04:00:14373
alemate2cb0d752017-08-11 05:22:16374 std::string current_timezone_id;
375 if (chromeos::CrosSettings::IsInitialized()) {
376 // In unit tests CrosSettings is not always initialized.
377 chromeos::CrosSettings::Get()->GetString(kSystemTimezone,
378 &current_timezone_id);
379 }
380 // |current_timezone_id| will be empty if CrosSettings doesn't know the
381 // timezone yet.
Thomas Tellieraa0617902020-05-04 10:02:59382 registry->RegisterStringPref(::prefs::kUserTimezone, current_timezone_id);
alemate2cb0d752017-08-11 05:22:16383
alemate48255f3d2015-01-30 18:11:41384 registry->RegisterBooleanPref(
Thomas Tellieraa0617902020-05-04 10:02:59385 ::prefs::kResolveTimezoneByGeolocation, true,
James Cookbf73f082019-10-23 03:19:04386 user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
alemate48255f3d2015-01-30 18:11:41387
Alexander Alekseev687cdb52017-11-11 02:40:00388 registry->RegisterBooleanPref(
Thomas Tellieraa0617902020-05-04 10:02:59389 ::prefs::kResolveTimezoneByGeolocationMigratedToMethod, false,
James Cookbf73f082019-10-23 03:19:04390 user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
Alexander Alekseev687cdb52017-11-11 02:40:00391
Alexander Alekseevd99f60d2020-01-31 00:53:05392 bool allow_time_zone_resolve_by_default = true;
393 // CfM devices default to static timezone unless time zone resolving is
394 // explicitly enabled for the signin screen (usually by policy).
Alexander Alekseev40004e12020-03-22 06:53:10395 // We need local_state fully initialized, which does not happen in tests.
396 if (!g_browser_process->local_state() ||
397 g_browser_process->local_state()
398 ->GetAllPrefStoresInitializationStatus() ==
399 PrefService::INITIALIZATION_STATUS_WAITING ||
400 system::InputDeviceSettings::Get()->ForceKeyboardDrivenUINavigation() ||
Alexander Alekseevd99f60d2020-01-31 00:53:05401 !system::TimeZoneResolverManager::
402 IfServiceShouldBeRunningForSigninScreen()) {
403 allow_time_zone_resolve_by_default = false;
404 }
405
Alexander Alekseev687cdb52017-11-11 02:40:00406 registry->RegisterIntegerPref(
Thomas Tellieraa0617902020-05-04 10:02:59407 ::prefs::kResolveTimezoneByGeolocationMethod,
Alexander Alekseev687cdb52017-11-11 02:40:00408 static_cast<int>(
Alexander Alekseevd99f60d2020-01-31 00:53:05409 allow_time_zone_resolve_by_default
410 ? system::TimeZoneResolverManager::TimeZoneResolveMethod::IP_ONLY
411 : system::TimeZoneResolverManager::TimeZoneResolveMethod::
412 DISABLED),
James Cookbf73f082019-10-23 03:19:04413 user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
Alexander Alekseev687cdb52017-11-11 02:40:00414
Thomas Tellieraa0617902020-05-04 10:02:59415 registry->RegisterBooleanPref(
416 ::prefs::kCaptivePortalAuthenticationIgnoresProxy, true);
peletskyida0bbb12015-04-08 17:11:04417
Thomas Tellieraa0617902020-05-04 10:02:59418 registry->RegisterBooleanPref(::prefs::kForceMaximizeOnFirstRun, false);
azurewei103ed2122016-01-10 07:01:14419
Thomas Tellieraa0617902020-05-04 10:02:59420 registry->RegisterBooleanPref(::prefs::kLanguageImeMenuActivated, false);
malaykeshavdcf78b92016-05-19 00:42:28421
Thomas Tellieraa0617902020-05-04 10:02:59422 registry->RegisterInt64Pref(::prefs::kHatsLastInteractionTimestamp,
malaykeshavdcf78b92016-05-19 00:42:28423 base::Time().ToInternalValue());
xiaoyinhf39e3dd2016-06-18 04:50:23424
Thomas Tellieraa0617902020-05-04 10:02:59425 registry->RegisterInt64Pref(::prefs::kHatsSurveyCycleEndTimestamp,
malaykeshav4518a182016-10-10 19:47:29426 base::Time().ToInternalValue());
427
Thomas Tellieraa0617902020-05-04 10:02:59428 registry->RegisterBooleanPref(::prefs::kHatsDeviceIsSelected, false);
malaykeshav4518a182016-10-10 19:47:29429
Thomas Tellieraa0617902020-05-04 10:02:59430 registry->RegisterBooleanPref(::prefs::kPinUnlockFeatureNotificationShown,
malaykeshavb2b9f122016-07-13 09:25:54431 false);
sammiequond1c55392017-03-22 18:59:22432 registry->RegisterBooleanPref(
Thomas Tellieraa0617902020-05-04 10:02:59433 ::prefs::kFingerprintUnlockFeatureNotificationShown, false);
malaykeshavb2b9f122016-07-13 09:25:54434
xiaoyinhf39e3dd2016-06-18 04:50:23435 // We don't sync EOL related prefs because they are device specific.
Thomas Tellieraa0617902020-05-04 10:02:59436 registry->RegisterBooleanPref(::prefs::kEolNotificationDismissed, false);
437 registry->RegisterTimePref(::prefs::kEndOfLifeDate, base::Time());
438 registry->RegisterBooleanPref(::prefs::kFirstEolWarningDismissed, false);
439 registry->RegisterBooleanPref(::prefs::kSecondEolWarningDismissed, false);
Yves Arrouye454e1e572017-08-02 19:13:09440
Thomas Tellieraa0617902020-05-04 10:02:59441 registry->RegisterBooleanPref(::prefs::kCastReceiverEnabled, false);
442 registry->RegisterBooleanPref(::prefs::kShowArcSettingsOnSessionStart, false);
443 registry->RegisterBooleanPref(::prefs::kShowSyncSettingsOnSessionStart,
444 false);
Katie D8a5d91bf2018-04-19 02:50:32445
Roman Aleksandrov6a6a63c2020-07-02 11:26:45446 // OOBE and login related prefs.
Roman Sorokinc258ab02020-09-25 05:14:31447 registry->RegisterStringPref(chromeos::prefs::kLastLoginInputMethod,
448 std::string(),
449 PrefRegistry::NO_REGISTRATION_FLAGS);
Roman Aleksandrov6a6a63c2020-07-02 11:26:45450 registry->RegisterTimePref(chromeos::prefs::kOobeOnboardingTime,
451 base::Time());
452
Katie D8a5d91bf2018-04-19 02:50:32453 // Text-to-speech prefs.
454 registry->RegisterDictionaryPref(
Thomas Tellieraa0617902020-05-04 10:02:59455 ::prefs::kTextToSpeechLangToVoiceName,
James Cookbf73f082019-10-23 03:19:04456 user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
457 registry->RegisterDoublePref(
Thomas Tellieraa0617902020-05-04 10:02:59458 ::prefs::kTextToSpeechRate, blink::mojom::kSpeechSynthesisDefaultRate,
James Cookbf73f082019-10-23 03:19:04459 user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
460 registry->RegisterDoublePref(
Thomas Tellieraa0617902020-05-04 10:02:59461 ::prefs::kTextToSpeechPitch, blink::mojom::kSpeechSynthesisDefaultPitch,
James Cookbf73f082019-10-23 03:19:04462 user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
463 registry->RegisterDoublePref(
Thomas Tellieraa0617902020-05-04 10:02:59464 ::prefs::kTextToSpeechVolume, blink::mojom::kSpeechSynthesisDefaultVolume,
James Cookbf73f082019-10-23 03:19:04465 user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
Aga Wronska4eafa172018-05-26 00:39:26466
467 // By default showing Sync Consent is set to true. It can changed by policy.
Thomas Tellieraa0617902020-05-04 10:02:59468 registry->RegisterBooleanPref(::prefs::kEnableSyncConsent, true);
Mattias Nissler0ef395b2018-08-15 23:41:21469
James Cook6e731ae2020-05-22 01:46:47470 registry->RegisterBooleanPref(chromeos::prefs::kSyncOobeCompleted, false);
471
Thomas Tellieraa0617902020-05-04 10:02:59472 registry->RegisterBooleanPref(::prefs::kTPMFirmwareUpdateCleanupDismissed,
Mattias Nissler0ef395b2018-08-15 23:41:21473 false);
Jit Yao Yapd219c5f2019-05-24 13:07:43474
Thomas Tellieraa0617902020-05-04 10:02:59475 registry->RegisterBooleanPref(::prefs::kStartupBrowserWindowLaunchSuppressed,
Jit Yao Yapd219c5f2019-05-24 13:07:43476 false);
Regan Hsub3804902019-08-03 00:35:18477
Thomas Tellieraa0617902020-05-04 10:02:59478 registry->RegisterBooleanPref(::prefs::kSettingsShowOSBanner, true);
Jit Yao Yapb1c60242020-01-10 15:24:12479
480 // This pref is a per-session pref and must not be synced.
Thomas Tellieraa0617902020-05-04 10:02:59481 registry->RegisterStringPref(::prefs::kLoginExtensionApiLaunchExtensionId,
Jit Yao Yapb1c60242020-01-10 15:24:12482 std::string(),
483 PrefRegistry::NO_REGISTRATION_FLAGS);
Thomas Tellieraa0617902020-05-04 10:02:59484
485 registry->RegisterBooleanPref(
486 chromeos::prefs::kLoginDisplayPasswordButtonEnabled, true);
Rachel Wong847db0e32020-06-01 03:28:58487
Rachel Wong6066d45d2020-06-13 03:20:54488 registry->RegisterBooleanPref(
489 chromeos::prefs::kSuggestedContentEnabled, true,
490 user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
tby78ad33d2020-10-21 22:56:24491 registry->RegisterBooleanPref(
492 chromeos::prefs::kLauncherResultEverLaunched, false,
493 user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
Wei Lee5fd6c512020-11-26 07:52:27494
495 registry->RegisterBooleanPref(
496 chromeos::prefs::kHasCameraAppMigratedToSWA, false,
497 user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
[email protected]fecc1522009-10-15 21:08:29498}
499
maxbogueea16ff412016-10-28 16:35:29500void Preferences::InitUserPrefs(sync_preferences::PrefServiceSyncable* prefs) {
[email protected]155e1b42012-07-14 03:06:01501 prefs_ = prefs;
502
[email protected]e7bff3e2012-11-14 15:34:44503 BooleanPrefMember::NamedChangeCallback callback =
504 base::Bind(&Preferences::OnPreferenceChanged, base::Unretained(this));
505
Thomas Tellieraa0617902020-05-04 10:02:59506 performance_tracing_enabled_.Init(::prefs::kPerformanceTracingEnabled, prefs,
507 callback);
508 tap_to_click_enabled_.Init(::prefs::kTapToClickEnabled, prefs, callback);
509 three_finger_click_enabled_.Init(::prefs::kEnableTouchpadThreeFingerClick,
phweissa16ceae22015-09-17 09:33:12510 prefs, callback);
511 unified_desktop_enabled_by_default_.Init(
Thomas Tellieraa0617902020-05-04 10:02:59512 ::prefs::kUnifiedDesktopEnabledByDefault, prefs, callback);
Ana Salazareb7c25712020-02-03 20:27:26513 // TODO(anasalazar): Finish moving this to ash.
514 natural_scroll_.Init(ash::prefs::kNaturalScroll, prefs, callback);
515 mouse_reverse_scroll_.Init(ash::prefs::kMouseReverseScroll, prefs, callback);
516
Thomas Tellieraa0617902020-05-04 10:02:59517 mouse_sensitivity_.Init(::prefs::kMouseSensitivity, prefs, callback);
518 mouse_scroll_sensitivity_.Init(::prefs::kMouseScrollSensitivity, prefs,
Kyle Horimoto734f0752020-03-20 20:46:54519 callback);
Thomas Tellieraa0617902020-05-04 10:02:59520 touchpad_sensitivity_.Init(::prefs::kTouchpadSensitivity, prefs, callback);
521 touchpad_scroll_sensitivity_.Init(::prefs::kTouchpadScrollSensitivity, prefs,
Kyle Horimoto734f0752020-03-20 20:46:54522 callback);
Harry Cuttsc3331972020-11-17 03:54:46523 pointing_stick_sensitivity_.Init(::prefs::kPointingStickSensitivity, prefs,
524 callback);
Thomas Tellieraa0617902020-05-04 10:02:59525 primary_mouse_button_right_.Init(::prefs::kPrimaryMouseButtonRight, prefs,
526 callback);
527 mouse_acceleration_.Init(::prefs::kMouseAcceleration, prefs, callback);
528 mouse_scroll_acceleration_.Init(::prefs::kMouseScrollAcceleration, prefs,
Kyle Horimoto734f0752020-03-20 20:46:54529 callback);
Thomas Tellieraa0617902020-05-04 10:02:59530 touchpad_acceleration_.Init(::prefs::kTouchpadAcceleration, prefs, callback);
531 touchpad_scroll_acceleration_.Init(::prefs::kTouchpadScrollAcceleration,
532 prefs, callback);
533 download_default_directory_.Init(::prefs::kDownloadDefaultDirectory, prefs,
534 callback);
535 preload_engines_.Init(::prefs::kLanguagePreloadEngines, prefs, callback);
536 enabled_imes_.Init(::prefs::kLanguageEnabledImes, prefs, callback);
537 current_input_method_.Init(::prefs::kLanguageCurrentInputMethod, prefs,
538 callback);
539 previous_input_method_.Init(::prefs::kLanguagePreviousInputMethod, prefs,
Alexander Hendricha4c39532018-06-27 08:33:05540 callback);
Thomas Tellieraa0617902020-05-04 10:02:59541 allowed_input_methods_.Init(::prefs::kLanguageAllowedInputMethods, prefs,
542 callback);
543 allowed_languages_.Init(::prefs::kAllowedLanguages, prefs, callback);
Alexandre Frechette572755b2019-02-13 22:30:20544 preferred_languages_.Init(language::prefs::kPreferredLanguages, prefs,
Zakhar Voit1f16c5e2018-10-26 12:08:23545 callback);
Thomas Tellieraa0617902020-05-04 10:02:59546 ime_menu_activated_.Init(::prefs::kLanguageImeMenuActivated, prefs, callback);
azurewei048e27ba2016-03-16 09:00:23547 // Notifies the system tray to remove the IME items.
Elly Fong-Jonesc00b17c282019-02-20 14:32:22548 if (ime_menu_activated_.GetValue())
azurewei048e27ba2016-03-16 09:00:23549 input_method::InputMethodManager::Get()->ImeMenuActivationChanged(true);
[email protected]22bec1a2012-03-27 06:33:48550
Chloe Pelling186ed3e2020-04-27 01:08:34551 xkb_auto_repeat_enabled_.Init(ash::prefs::kXkbAutoRepeatEnabled, prefs,
552 callback);
553 xkb_auto_repeat_delay_pref_.Init(ash::prefs::kXkbAutoRepeatDelay, prefs,
554 callback);
555 xkb_auto_repeat_interval_pref_.Init(ash::prefs::kXkbAutoRepeatInterval, prefs,
556 callback);
chirantan1c4090c2014-11-18 22:34:12557
alemate48255f3d2015-01-30 18:11:41558 pref_change_registrar_.Init(prefs);
Thomas Tellieraa0617902020-05-04 10:02:59559 pref_change_registrar_.Add(::prefs::kUserTimezone, callback);
560 pref_change_registrar_.Add(::prefs::kResolveTimezoneByGeolocation, callback);
561 pref_change_registrar_.Add(::prefs::kResolveTimezoneByGeolocationMethod,
Alexander Alekseev687cdb52017-11-11 02:40:00562 callback);
Thomas Tellieraa0617902020-05-04 10:02:59563 pref_change_registrar_.Add(::prefs::kUse24HourClock, callback);
564 pref_change_registrar_.Add(::prefs::kParentAccessCodeConfig, callback);
vmpstr843b41a2017-03-01 21:15:03565 for (auto* remap_pref : kLanguageRemapPrefs)
xdaie6172c92017-02-24 19:01:51566 pref_change_registrar_.Add(remap_pref, callback);
[email protected]2c62b3f2012-04-12 12:07:50567}
568
[email protected]f0881cf2014-08-15 23:31:42569void Preferences::Init(Profile* profile, const user_manager::User* user) {
570 DCHECK(profile);
[email protected]aa003a52014-02-15 06:24:23571 DCHECK(user);
maxbogueea16ff412016-10-28 16:35:29572 sync_preferences::PrefServiceSyncable* prefs =
sdefresne50c1e522015-09-18 09:47:51573 PrefServiceSyncableFromProfile(profile);
michaelpg975f2182014-12-05 04:00:14574 // This causes OnIsSyncingChanged to be called when the value of
575 // PrefService::IsSyncing() changes.
576 prefs->AddObserver(this);
[email protected]aa003a52014-02-15 06:24:23577 user_ = user;
[email protected]4d390782014-08-15 09:22:58578 user_is_primary_ =
579 user_manager::UserManager::Get()->GetPrimaryUser() == user_;
[email protected]2c62b3f2012-04-12 12:07:50580 InitUserPrefs(prefs);
[email protected]4ccc05e2010-10-06 19:32:15581
[email protected]4d390782014-08-15 09:22:58582 user_manager::UserManager::Get()->AddSessionStateObserver(this);
[email protected]aa003a52014-02-15 06:24:23583
[email protected]f0881cf2014-08-15 23:31:42584 UserSessionManager* session_manager = UserSessionManager::GetInstance();
585 DCHECK(session_manager);
alemate829e2bf2014-09-06 13:24:46586 ime_state_ = session_manager->GetDefaultIMEState(profile);
[email protected]f0881cf2014-08-15 23:31:42587
alemated70e82f2016-04-05 12:21:33588 if (user_is_primary_) {
589 g_browser_process->platform_part()
590 ->GetTimezoneResolverManager()
591 ->SetPrimaryUserPrefs(prefs_);
592 }
593
[email protected]d7ca1ba2011-05-09 20:09:08594 // Initialize preferences to currently saved state.
[email protected]aa003a52014-02-15 06:24:23595 ApplyPreferences(REASON_INITIALIZATION, "");
alemate01c3b2c2015-02-10 18:26:09596
Alexander Alekseev45f84332020-10-29 07:25:37597 const std::string& login_input_method_used =
598 session_manager->user_context().GetLoginInputMethodUsed();
599
600 if (user_is_primary_ && !login_input_method_used.empty()) {
601 // Persist input method when transitioning from Login screen into the
602 // session.
603 input_method::InputMethodPersistence::SetUserLastLoginInputMethod(
604 login_input_method_used, input_method::InputMethodManager::Get(),
605 profile);
606 }
607
alemate01c3b2c2015-02-10 18:26:09608 // Note that |ime_state_| was modified by ApplyPreferences(), and
609 // SetState() is modifying |current_input_method_| (via
610 // PersistUserInputMethod() ). This way SetState() here may be called only
611 // after ApplyPreferences().
Shu Chen8e53e8e2018-07-10 01:56:41612 // As InputMethodManager only holds the active state for the active user,
613 // SetState() is only called if the preferences belongs to the active user.
614 // See https://crbug.com/841112.
615 if (user->is_active())
616 input_method_manager_->SetState(ime_state_);
alemate01c3b2c2015-02-10 18:26:09617
michaelpg975f2182014-12-05 04:00:14618 input_method_syncer_.reset(
619 new input_method::InputMethodSyncer(prefs, ime_state_));
620 input_method_syncer_->Initialize();
[email protected]26012e22010-12-01 06:44:27621
622 // If a guest is logged in, initialize the prefs as if this is the first
[email protected]bb9c5d72014-06-14 19:21:21623 // login. For a regular user this is done in
[email protected]295ca1a72014-07-01 16:14:31624 // UserSessionManager::InitProfilePreferences().
avi3ef9ec9e2014-12-22 22:50:17625 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
626 switches::kGuestSession))
[email protected]f0881cf2014-08-15 23:31:42627 session_manager->SetFirstLoginPrefs(profile, std::string(), std::string());
[email protected]fecc1522009-10-15 21:08:29628}
629
[email protected]f0881cf2014-08-15 23:31:42630void Preferences::InitUserPrefsForTesting(
maxbogueea16ff412016-10-28 16:35:29631 sync_preferences::PrefServiceSyncable* prefs,
[email protected]f0881cf2014-08-15 23:31:42632 const user_manager::User* user,
633 scoped_refptr<input_method::InputMethodManager::State> ime_state) {
[email protected]aa003a52014-02-15 06:24:23634 user_ = user;
[email protected]f0881cf2014-08-15 23:31:42635 ime_state_ = ime_state;
636
dcheng4c384d92014-09-15 23:29:45637 if (ime_state.get())
[email protected]f0881cf2014-08-15 23:31:42638 input_method_manager_->SetState(ime_state);
639
[email protected]2c62b3f2012-04-12 12:07:50640 InitUserPrefs(prefs);
michaelpg975f2182014-12-05 04:00:14641
642 input_method_syncer_.reset(
643 new input_method::InputMethodSyncer(prefs, ime_state_));
644 input_method_syncer_->Initialize();
[email protected]2c62b3f2012-04-12 12:07:50645}
646
647void Preferences::SetInputMethodListForTesting() {
648 SetInputMethodList();
649}
650
[email protected]e7bff3e2012-11-14 15:34:44651void Preferences::OnPreferenceChanged(const std::string& pref_name) {
[email protected]aa003a52014-02-15 06:24:23652 ApplyPreferences(REASON_PREF_CHANGED, pref_name);
[email protected]fecc1522009-10-15 21:08:29653}
654
Harry Cutts543a38d72020-11-12 20:08:08655void Preferences::ReportBooleanPrefApplication(
656 ApplyReason reason,
657 const std::string& changed_histogram_name,
658 const std::string& started_histogram_name,
659 bool sample) {
660 if (reason == REASON_PREF_CHANGED)
661 base::UmaHistogramBoolean(changed_histogram_name, sample);
662 else if (reason == REASON_INITIALIZATION)
663 base::UmaHistogramBoolean(started_histogram_name, sample);
664}
665
666void Preferences::ReportSensitivityPrefApplication(
667 ApplyReason reason,
668 const std::string& changed_histogram_name,
669 const std::string& started_histogram_name,
670 int sensitivity_int) {
671 system::PointerSensitivity sensitivity =
672 static_cast<system::PointerSensitivity>(sensitivity_int);
673 if (reason == REASON_PREF_CHANGED)
674 base::UmaHistogramEnumeration(changed_histogram_name, sensitivity);
675 else if (reason == REASON_INITIALIZATION)
676 base::UmaHistogramEnumeration(started_histogram_name, sensitivity);
677}
678
[email protected]aa003a52014-02-15 06:24:23679void Preferences::ApplyPreferences(ApplyReason reason,
680 const std::string& pref_name) {
681 DCHECK(reason != REASON_PREF_CHANGED || !pref_name.empty());
682 const bool user_is_owner =
alemate3ffbde6f2015-11-03 02:02:55683 user_manager::UserManager::Get()->GetOwnerAccountId() ==
684 user_->GetAccountId();
[email protected]aa003a52014-02-15 06:24:23685 const bool user_is_active = user_->is_active();
686
[email protected]bd36e172014-02-14 19:49:57687 system::TouchpadSettings touchpad_settings;
688 system::MouseSettings mouse_settings;
Harry Cuttsc3331972020-11-17 03:54:46689 system::PointingStickSettings pointing_stick_settings;
[email protected]aa003a52014-02-15 06:24:23690
691 if (user_is_primary_ && (reason == REASON_INITIALIZATION ||
Thomas Tellieraa0617902020-05-04 10:02:59692 pref_name == ::prefs::kPerformanceTracingEnabled)) {
[email protected]a1ea1292013-08-07 23:50:40693 const bool enabled = performance_tracing_enabled_.GetValue();
694 if (enabled)
695 tracing_manager_ = TracingManager::Create();
696 else
697 tracing_manager_.reset();
James Cook671818f2017-07-10 19:31:45698 SystemTrayClient::Get()->SetPerformanceTracingIconVisible(enabled);
[email protected]a1ea1292013-08-07 23:50:40699 }
Thomas Tellieraa0617902020-05-04 10:02:59700 if (reason != REASON_PREF_CHANGED ||
701 pref_name == ::prefs::kTapToClickEnabled) {
[email protected]b685fbd2012-03-24 09:23:04702 const bool enabled = tap_to_click_enabled_.GetValue();
Michael Giuffridac997aa72018-08-31 23:38:59703 if (user_is_active)
704 touchpad_settings.SetTapToClick(enabled);
Harry Cutts543a38d72020-11-12 20:08:08705 ReportBooleanPrefApplication(reason, "Touchpad.TapToClick.Changed",
706 "Touchpad.TapToClick.Started", enabled);
Michael Giuffridac997aa72018-08-31 23:38:59707
[email protected]022c3b92012-09-13 19:45:59708 // Save owner preference in local state to use on login screen.
[email protected]aa003a52014-02-15 06:24:23709 if (user_is_owner) {
[email protected]022c3b92012-09-13 19:45:59710 PrefService* prefs = g_browser_process->local_state();
Thomas Tellieraa0617902020-05-04 10:02:59711 if (prefs->GetBoolean(::prefs::kOwnerTapToClickEnabled) != enabled)
712 prefs->SetBoolean(::prefs::kOwnerTapToClickEnabled, enabled);
[email protected]022c3b92012-09-13 19:45:59713 }
[email protected]3b02de292010-05-13 06:05:05714 }
[email protected]aa003a52014-02-15 06:24:23715 if (reason != REASON_PREF_CHANGED ||
Thomas Tellieraa0617902020-05-04 10:02:59716 pref_name == ::prefs::kEnableTouchpadThreeFingerClick) {
[email protected]190349fd2012-05-02 00:10:47717 const bool enabled = three_finger_click_enabled_.GetValue();
[email protected]aa003a52014-02-15 06:24:23718 if (user_is_active)
719 touchpad_settings.SetThreeFingerClick(enabled);
Harry Cutts543a38d72020-11-12 20:08:08720 ReportBooleanPrefApplication(reason, "Touchpad.ThreeFingerClick.Changed",
721 "Touchpad.ThreeFingerClick.Started", enabled);
[email protected]190349fd2012-05-02 00:10:47722 }
phweissa16ceae22015-09-17 09:33:12723 if (reason != REASON_PREF_CHANGED ||
Thomas Tellieraa0617902020-05-04 10:02:59724 pref_name == ::prefs::kUnifiedDesktopEnabledByDefault) {
Steven Bennettsbce1cf5c2018-05-23 19:38:12725 // "Unified Desktop" is a per-user policy setting which will not be applied
726 // until a user logs in.
Henrique Ferreiro9bf26372019-10-15 11:15:58727 if (cros_display_config_) { // May be null in tests.
728 cros_display_config_->SetUnifiedDesktopEnabled(
Steven Bennettsbce1cf5c2018-05-23 19:38:12729 unified_desktop_enabled_by_default_.GetValue());
phweissa16ceae22015-09-17 09:33:12730 }
731 }
Ana Salazareb7c25712020-02-03 20:27:26732 // TODO(anasalazar): Finish moving this to ash.
733 if (reason != REASON_PREF_CHANGED ||
734 pref_name == ash::prefs::kNaturalScroll) {
[email protected]7f914fd2012-12-20 23:55:25735 // Force natural scroll default if we've sync'd and if the cmd line arg is
736 // set.
737 ForceNaturalScrollDefault();
[email protected]223059e2012-10-05 01:44:49738
[email protected]b685fbd2012-03-24 09:23:04739 const bool enabled = natural_scroll_.GetValue();
[email protected]223059e2012-10-05 01:44:49740 DVLOG(1) << "Natural scroll set to " << enabled;
[email protected]aa003a52014-02-15 06:24:23741 if (user_is_active)
[email protected]158775422014-04-03 18:15:59742 touchpad_settings.SetNaturalScroll(enabled);
Harry Cutts543a38d72020-11-12 20:08:08743 ReportBooleanPrefApplication(reason, "Touchpad.NaturalScroll.Changed",
744 "Touchpad.NaturalScroll.Started", enabled);
[email protected]b685fbd2012-03-24 09:23:04745 }
Ana Salazareb7c25712020-02-03 20:27:26746 if (reason != REASON_PREF_CHANGED ||
747 pref_name == ash::prefs::kMouseReverseScroll) {
748 const bool enabled = mouse_reverse_scroll_.GetValue();
749 if (user_is_active)
750 mouse_settings.SetReverseScroll(enabled);
Harry Cutts543a38d72020-11-12 20:08:08751 ReportBooleanPrefApplication(reason, "Mouse.ReverseScroll.Changed",
752 "Mouse.ReverseScroll.Started", enabled);
Ana Salazareb7c25712020-02-03 20:27:26753 }
754
Thomas Tellieraa0617902020-05-04 10:02:59755 if (reason != REASON_PREF_CHANGED ||
756 pref_name == ::prefs::kMouseSensitivity) {
Kyle Horimoto5ab70b902020-04-01 22:23:59757 const int sensitivity_int = mouse_sensitivity_.GetValue();
758 if (user_is_active) {
759 mouse_settings.SetSensitivity(sensitivity_int);
760
761 // With the flag off, also set scroll sensitivity (legacy fallback).
762 // TODO(https://crbug.com/836258): Remove check when flag is removed.
763 if (!AreScrollSettingsAllowed())
764 mouse_settings.SetScrollSensitivity(sensitivity_int);
765 }
Harry Cutts543a38d72020-11-12 20:08:08766 ReportSensitivityPrefApplication(reason, "Mouse.PointerSensitivity.Changed",
767 "Mouse.PointerSensitivity.Started",
768 sensitivity_int);
[email protected]563fb5f2012-03-31 00:39:28769 }
[email protected]aa003a52014-02-15 06:24:23770 if (reason != REASON_PREF_CHANGED ||
Thomas Tellieraa0617902020-05-04 10:02:59771 pref_name == ::prefs::kMouseScrollSensitivity) {
Kyle Horimoto5ab70b902020-04-01 22:23:59772 // With the flag off, use to normal sensitivity (legacy fallback).
773 // TODO(https://crbug.com/836258): Remove check when flag is removed.
774 const int sensitivity_int = AreScrollSettingsAllowed()
775 ? mouse_scroll_sensitivity_.GetValue()
776 : mouse_sensitivity_.GetValue();
Kyle Horimoto734f0752020-03-20 20:46:54777 if (user_is_active)
Kyle Horimoto5ab70b902020-04-01 22:23:59778 mouse_settings.SetScrollSensitivity(sensitivity_int);
Harry Cutts543a38d72020-11-12 20:08:08779 ReportSensitivityPrefApplication(reason, "Mouse.ScrollSensitivity.Changed",
780 "Mouse.ScrollSensitivity.Started",
781 sensitivity_int);
Kyle Horimoto734f0752020-03-20 20:46:54782 }
783 if (reason != REASON_PREF_CHANGED ||
Harry Cuttsc3331972020-11-17 03:54:46784 pref_name == ::prefs::kPointingStickSensitivity) {
785 const int sensitivity_int = pointing_stick_sensitivity_.GetValue();
786 if (user_is_active) {
787 pointing_stick_settings.SetSensitivity(sensitivity_int);
788 }
Harry Cuttsb1a178d2020-11-19 04:12:39789 ReportSensitivityPrefApplication(
790 reason, "PointingStick.PointerSensitivity.Changed",
791 "PointingStick.PointerSensitivity.Started", sensitivity_int);
Harry Cuttsc3331972020-11-17 03:54:46792 }
793 if (reason != REASON_PREF_CHANGED ||
Thomas Tellieraa0617902020-05-04 10:02:59794 pref_name == ::prefs::kTouchpadSensitivity) {
Kyle Horimoto5ab70b902020-04-01 22:23:59795 const int sensitivity_int = touchpad_sensitivity_.GetValue();
796 if (user_is_active) {
797 touchpad_settings.SetSensitivity(sensitivity_int);
798
799 // With the flag off, also set scroll sensitivity (legacy fallback).
800 // TODO(https://crbug.com/836258): Remove check when flag is removed.
801 if (!AreScrollSettingsAllowed())
802 touchpad_settings.SetScrollSensitivity(sensitivity_int);
803 }
Harry Cutts543a38d72020-11-12 20:08:08804 ReportSensitivityPrefApplication(
805 reason, "Touchpad.PointerSensitivity.Changed",
806 "Touchpad.PointerSensitivity.Started", sensitivity_int);
[email protected]3b02de292010-05-13 06:05:05807 }
[email protected]aa003a52014-02-15 06:24:23808 if (reason != REASON_PREF_CHANGED ||
Thomas Tellieraa0617902020-05-04 10:02:59809 pref_name == ::prefs::kTouchpadScrollSensitivity) {
Kyle Horimoto5ab70b902020-04-01 22:23:59810 // With the flag off, use normal sensitivity (legacy fallback).
811 // TODO(https://crbug.com/836258): Remove check when flag is removed.
812 const int sensitivity_int = AreScrollSettingsAllowed()
813 ? touchpad_scroll_sensitivity_.GetValue()
814 : touchpad_sensitivity_.GetValue();
Kyle Horimoto734f0752020-03-20 20:46:54815 if (user_is_active)
Kyle Horimoto5ab70b902020-04-01 22:23:59816 touchpad_settings.SetScrollSensitivity(sensitivity_int);
Harry Cutts543a38d72020-11-12 20:08:08817 ReportSensitivityPrefApplication(
818 reason, "Touchpad.ScrollSensitivity.Changed",
819 "Touchpad.ScrollSensitivity.Started", sensitivity_int);
Kyle Horimoto734f0752020-03-20 20:46:54820 }
821 if (reason != REASON_PREF_CHANGED ||
Thomas Tellieraa0617902020-05-04 10:02:59822 pref_name == ::prefs::kPrimaryMouseButtonRight) {
[email protected]0027fde12011-12-15 05:09:38823 const bool right = primary_mouse_button_right_.GetValue();
[email protected]aa003a52014-02-15 06:24:23824 if (user_is_active)
825 mouse_settings.SetPrimaryButtonRight(right);
Harry Cutts543a38d72020-11-12 20:08:08826 ReportBooleanPrefApplication(reason, "Mouse.PrimaryButtonRight.Changed",
827 "Mouse.PrimaryButtonRight.Started", right);
[email protected]022c3b92012-09-13 19:45:59828 // Save owner preference in local state to use on login screen.
[email protected]aa003a52014-02-15 06:24:23829 if (user_is_owner) {
[email protected]022c3b92012-09-13 19:45:59830 PrefService* prefs = g_browser_process->local_state();
Thomas Tellieraa0617902020-05-04 10:02:59831 if (prefs->GetBoolean(::prefs::kOwnerPrimaryMouseButtonRight) != right)
832 prefs->SetBoolean(::prefs::kOwnerPrimaryMouseButtonRight, right);
[email protected]022c3b92012-09-13 19:45:59833 }
[email protected]0027fde12011-12-15 05:09:38834 }
Thomas Tellieraa0617902020-05-04 10:02:59835 if (reason != REASON_PREF_CHANGED ||
836 pref_name == ::prefs::kMouseAcceleration) {
Zentaro Kavanagh65b3e112019-09-03 16:18:23837 const bool enabled = mouse_acceleration_.GetValue();
838 if (user_is_active)
839 mouse_settings.SetAcceleration(enabled);
Harry Cutts543a38d72020-11-12 20:08:08840 ReportBooleanPrefApplication(reason, "Mouse.Acceleration.Changed",
841 "Mouse.Acceleration.Started", enabled);
Zentaro Kavanagh65b3e112019-09-03 16:18:23842 }
843 if (reason != REASON_PREF_CHANGED ||
Thomas Tellieraa0617902020-05-04 10:02:59844 pref_name == ::prefs::kMouseScrollAcceleration) {
Kyle Horimoto734f0752020-03-20 20:46:54845 const bool enabled = mouse_scroll_acceleration_.GetValue();
846 if (user_is_active)
847 mouse_settings.SetScrollAcceleration(enabled);
Harry Cutts543a38d72020-11-12 20:08:08848 ReportBooleanPrefApplication(reason, "Mouse.ScrollAcceleration.Changed",
849 "Mouse.ScrollAcceleration.Started", enabled);
Kyle Horimoto734f0752020-03-20 20:46:54850 }
851 if (reason != REASON_PREF_CHANGED ||
Thomas Tellieraa0617902020-05-04 10:02:59852 pref_name == ::prefs::kTouchpadAcceleration) {
Zentaro Kavanagh65b3e112019-09-03 16:18:23853 const bool enabled = touchpad_acceleration_.GetValue();
854 if (user_is_active)
855 touchpad_settings.SetAcceleration(enabled);
Harry Cutts543a38d72020-11-12 20:08:08856 ReportBooleanPrefApplication(reason, "Touchpad.Acceleration.Changed",
857 "Touchpad.Acceleration.Started", enabled);
Zentaro Kavanagh65b3e112019-09-03 16:18:23858 }
Lann Martin9a517ad2017-08-29 00:43:39859 if (reason != REASON_PREF_CHANGED ||
Thomas Tellieraa0617902020-05-04 10:02:59860 pref_name == ::prefs::kTouchpadScrollAcceleration) {
Kyle Horimoto734f0752020-03-20 20:46:54861 const bool enabled = touchpad_scroll_acceleration_.GetValue();
862 if (user_is_active)
863 touchpad_settings.SetScrollAcceleration(enabled);
Harry Cutts543a38d72020-11-12 20:08:08864 ReportBooleanPrefApplication(reason, "Touchpad.ScrollAcceleration.Changed",
865 "Touchpad.ScrollAcceleration.Started",
866 enabled);
Kyle Horimoto734f0752020-03-20 20:46:54867 }
868 if (reason != REASON_PREF_CHANGED ||
Thomas Tellieraa0617902020-05-04 10:02:59869 pref_name == ::prefs::kDownloadDefaultDirectory) {
[email protected]d9d04df2012-10-12 07:06:35870 const bool default_download_to_drive = drive::util::IsUnderDriveMountPoint(
[email protected]78a6b642012-09-12 02:07:03871 download_default_directory_.GetValue());
Harry Cutts543a38d72020-11-12 20:08:08872 ReportBooleanPrefApplication(
873 reason, "FileBrowser.DownloadDestination.IsGoogleDrive.Changed",
874 "FileBrowser.DownloadDestination.IsGoogleDrive.Started",
875 default_download_to_drive);
[email protected]78a6b642012-09-12 02:07:03876 }
[email protected]8be9ff22010-06-08 02:13:54877
[email protected]aa003a52014-02-15 06:24:23878 if (reason != REASON_PREF_CHANGED ||
Chloe Pelling186ed3e2020-04-27 01:08:34879 pref_name == ash::prefs::kXkbAutoRepeatEnabled) {
[email protected]aa003a52014-02-15 06:24:23880 if (user_is_active) {
881 const bool enabled = xkb_auto_repeat_enabled_.GetValue();
[email protected]fbb141a2014-04-11 13:25:52882 input_method::InputMethodManager::Get()
883 ->GetImeKeyboard()
[email protected]aa003a52014-02-15 06:24:23884 ->SetAutoRepeatEnabled(enabled);
xdaic97cc0a2017-02-18 18:10:04885
886 user_manager::known_user::SetBooleanPref(
Chloe Pelling186ed3e2020-04-27 01:08:34887 user_->GetAccountId(), ash::prefs::kXkbAutoRepeatEnabled, enabled);
[email protected]aa003a52014-02-15 06:24:23888 }
889 }
890 if (reason != REASON_PREF_CHANGED ||
Chloe Pelling186ed3e2020-04-27 01:08:34891 pref_name == ash::prefs::kXkbAutoRepeatDelay ||
892 pref_name == ash::prefs::kXkbAutoRepeatInterval) {
[email protected]aa003a52014-02-15 06:24:23893 if (user_is_active)
894 UpdateAutoRepeatRate();
[email protected]74b42fc12010-07-20 10:15:41895 }
Alexander Hendricha4c39532018-06-27 08:33:05896 if (reason != REASON_PREF_CHANGED ||
Thomas Tellieraa0617902020-05-04 10:02:59897 pref_name == ::prefs::kLanguageAllowedInputMethods) {
Alexander Hendricha4c39532018-06-27 08:33:05898 const std::vector<std::string> allowed_input_methods =
899 allowed_input_methods_.GetValue();
900
901 bool managed_by_policy =
902 ime_state_->SetAllowedInputMethods(allowed_input_methods, false);
903
904 if (managed_by_policy) {
905 preload_engines_.SetValue(
906 base::JoinString(ime_state_->GetActiveInputMethodIds(), ","));
907 }
908 }
Thomas Tellieraa0617902020-05-04 10:02:59909 if (reason != REASON_PREF_CHANGED || pref_name == ::prefs::kAllowedLanguages)
Zakhar Voit1f16c5e2018-10-26 12:08:23910 locale_util::RemoveDisallowedLanguagesFromPreferred(prefs_);
911
912 if (reason != REASON_PREF_CHANGED ||
Alexandre Frechette572755b2019-02-13 22:30:20913 pref_name == language::prefs::kPreferredLanguages) {
Zakhar Voit1f16c5e2018-10-26 12:08:23914 // In case setting has been changed with sync it can contain disallowed
915 // values.
916 locale_util::RemoveDisallowedLanguagesFromPreferred(prefs_);
917 }
[email protected]a6e90772011-02-09 05:38:54918
[email protected]f0881cf2014-08-15 23:31:42919 if (reason == REASON_INITIALIZATION)
[email protected]2c62b3f2012-04-12 12:07:50920 SetInputMethodList();
[email protected]f0881cf2014-08-15 23:31:42921
Thomas Tellieraa0617902020-05-04 10:02:59922 if (pref_name == ::prefs::kLanguagePreloadEngines &&
[email protected]f0881cf2014-08-15 23:31:42923 reason == REASON_PREF_CHANGED) {
[email protected]7f132d02013-01-03 00:32:26924 SetLanguageConfigStringListAsCSV(language_prefs::kGeneralSectionName,
925 language_prefs::kPreloadEnginesConfigName,
[email protected]c67a30932012-03-14 05:23:00926 preload_engines_.GetValue());
[email protected]3b02de292010-05-13 06:05:05927 }
[email protected]22bec1a2012-03-27 06:33:48928
[email protected]f0881cf2014-08-15 23:31:42929 if ((reason == REASON_INITIALIZATION) ||
Thomas Tellieraa0617902020-05-04 10:02:59930 (pref_name == ::prefs::kLanguageEnabledImes &&
[email protected]f0881cf2014-08-15 23:31:42931 reason == REASON_PREF_CHANGED)) {
Yuichiro Hanada1dcf2e82018-07-02 22:38:38932 std::string value(enabled_imes_.GetValue());
[email protected]797c6802012-09-20 10:36:13933
[email protected]f0881cf2014-08-15 23:31:42934 std::vector<std::string> split_values;
brettwc6f82b12015-07-21 21:37:38935 if (!value.empty()) {
936 split_values = base::SplitString(value, ",", base::TRIM_WHITESPACE,
937 base::SPLIT_WANT_ALL);
938 }
[email protected]f0881cf2014-08-15 23:31:42939 ime_state_->SetEnabledExtensionImes(&split_values);
[email protected]797c6802012-09-20 10:36:13940 }
[email protected]aa003a52014-02-15 06:24:23941
Thomas Tellieraa0617902020-05-04 10:02:59942 if (pref_name == ::prefs::kLanguageImeMenuActivated &&
Elly Fong-Jonesc00b17c282019-02-20 14:32:22943 (reason == REASON_PREF_CHANGED || reason == REASON_ACTIVE_USER_CHANGED)) {
azurewei103ed2122016-01-10 07:01:14944 const bool activated = ime_menu_activated_.GetValue();
azureweif7a97e02016-02-04 08:12:48945 input_method::InputMethodManager::Get()->ImeMenuActivationChanged(
946 activated);
azurewei103ed2122016-01-10 07:01:14947 }
948
[email protected]aa003a52014-02-15 06:24:23949 if (user_is_active) {
950 system::InputDeviceSettings::Get()->UpdateTouchpadSettings(
951 touchpad_settings);
952 system::InputDeviceSettings::Get()->UpdateMouseSettings(mouse_settings);
Harry Cuttsc3331972020-11-17 03:54:46953 system::InputDeviceSettings::Get()->UpdatePointingStickSettings(
954 pointing_stick_settings);
[email protected]aa003a52014-02-15 06:24:23955 }
michaelpg592b07a2014-12-23 19:46:09956
Thomas Tellieraa0617902020-05-04 10:02:59957 if (pref_name == ::prefs::kUserTimezone &&
alemate2cb0d752017-08-11 05:22:16958 reason != REASON_ACTIVE_USER_CHANGED) {
959 system::UpdateSystemTimezone(ProfileHelper::Get()->GetProfileByUser(user_));
960 }
961
Thomas Tellieraa0617902020-05-04 10:02:59962 if ((pref_name == ::prefs::kResolveTimezoneByGeolocation ||
963 pref_name == ::prefs::kResolveTimezoneByGeolocationMethod) &&
alemate48255f3d2015-01-30 18:11:41964 reason != REASON_ACTIVE_USER_CHANGED) {
Thomas Tellieraa0617902020-05-04 10:02:59965 if (pref_name == ::prefs::kResolveTimezoneByGeolocationMethod &&
966 !prefs_->FindPreference(::prefs::kResolveTimezoneByGeolocationMethod)
Alexander Alekseev687cdb52017-11-11 02:40:00967 ->IsDefaultValue()) {
Thomas Tellieraa0617902020-05-04 10:02:59968 prefs_->SetBoolean(::prefs::kResolveTimezoneByGeolocationMigratedToMethod,
Alexander Alekseev687cdb52017-11-11 02:40:00969 true);
970 }
alemate48255f3d2015-01-30 18:11:41971 if (user_is_owner) {
Alexander Alekseev687cdb52017-11-11 02:40:00972 // Policy check is false here, because there is no owner for enterprise.
973 g_browser_process->local_state()->SetInteger(
Thomas Tellieraa0617902020-05-04 10:02:59974 ::prefs::kResolveDeviceTimezoneByGeolocationMethod,
Alexander Alekseev687cdb52017-11-11 02:40:00975 static_cast<int>(system::TimeZoneResolverManager::
976 GetEffectiveUserTimeZoneResolveMethod(
977 prefs_, false /* check_policy */)));
alemate48255f3d2015-01-30 18:11:41978 }
979 if (user_is_primary_) {
alemated70e82f2016-04-05 12:21:33980 g_browser_process->platform_part()
981 ->GetTimezoneResolverManager()
982 ->UpdateTimezoneResolver();
Alexander Alekseev687cdb52017-11-11 02:40:00983 if (system::TimeZoneResolverManager::
984 GetEffectiveUserTimeZoneResolveMethod(
985 prefs_, true /* check_policy */) ==
986 system::TimeZoneResolverManager::TimeZoneResolveMethod::
987 DISABLED &&
988 reason == REASON_PREF_CHANGED) {
alemate75b7a5c2016-03-29 06:39:46989 // Allow immediate timezone update on Stop + Start.
990 g_browser_process->local_state()->ClearPref(
991 TimeZoneResolver::kLastTimeZoneRefreshTime);
alemate48255f3d2015-01-30 18:11:41992 }
993 }
994 }
alemate6cf8c6e2015-07-23 06:58:50995
Thomas Tellieraa0617902020-05-04 10:02:59996 if (pref_name == ::prefs::kUse24HourClock ||
alemate6cf8c6e2015-07-23 06:58:50997 reason != REASON_ACTIVE_USER_CHANGED) {
Thomas Tellieraa0617902020-05-04 10:02:59998 const bool value = prefs_->GetBoolean(::prefs::kUse24HourClock);
alemate8730a2f2015-12-19 07:13:09999 user_manager::known_user::SetBooleanPref(user_->GetAccountId(),
Thomas Tellieraa0617902020-05-04 10:02:591000 ::prefs::kUse24HourClock, value);
alemate6cf8c6e2015-07-23 06:58:501001 }
afakhrye2bc0da542016-11-09 19:41:571002
Thomas Tellieraa0617902020-05-04 10:02:591003 if (pref_name == ::prefs::kParentAccessCodeConfig ||
Henrique Grandinetti07dca142019-04-05 20:38:351004 reason != REASON_PREF_CHANGED) {
1005 const base::Value* value =
Thomas Tellieraa0617902020-05-04 10:02:591006 prefs_->GetDictionary(::prefs::kParentAccessCodeConfig);
1007 if (value &&
1008 prefs_->IsManagedPreference(::prefs::kParentAccessCodeConfig) &&
Henrique Grandinettidc2db072019-05-03 13:18:261009 user_->IsChild()) {
Thomas Tellieraa0617902020-05-04 10:02:591010 user_manager::known_user::SetPref(
1011 user_->GetAccountId(), ::prefs::kKnownUserParentAccessCodeConfig,
1012 value->Clone());
Henrique Grandinettidc2db072019-05-03 13:18:261013 parent_access::ParentAccessService::Get().LoadConfigForUser(user_);
Henrique Grandinetti07dca142019-04-05 20:38:351014 } else {
1015 user_manager::known_user::RemovePref(
Thomas Tellieraa0617902020-05-04 10:02:591016 user_->GetAccountId(), ::prefs::kKnownUserParentAccessCodeConfig);
Henrique Grandinetti07dca142019-04-05 20:38:351017 }
1018 }
1019
vmpstr843b41a2017-03-01 21:15:031020 for (auto* remap_pref : kLanguageRemapPrefs) {
xdaie6172c92017-02-24 19:01:511021 if (pref_name == remap_pref || reason != REASON_ACTIVE_USER_CHANGED) {
1022 const int value = prefs_->GetInteger(remap_pref);
1023 user_manager::known_user::SetIntegerPref(user_->GetAccountId(),
1024 remap_pref, value);
1025 }
1026 }
Thomas Tellieraa0617902020-05-04 10:02:591027
1028 if (pref_name == chromeos::prefs::kLoginDisplayPasswordButtonEnabled ||
1029 reason != REASON_ACTIVE_USER_CHANGED) {
1030 const bool value =
1031 prefs_->GetBoolean(chromeos::prefs::kLoginDisplayPasswordButtonEnabled);
1032 user_manager::known_user::SetBooleanPref(
1033 user_->GetAccountId(),
1034 chromeos::prefs::kLoginDisplayPasswordButtonEnabled, value);
1035 }
[email protected]fecc1522009-10-15 21:08:291036}
1037
[email protected]7f914fd2012-12-20 23:55:251038void Preferences::OnIsSyncingChanged() {
1039 DVLOG(1) << "OnIsSyncingChanged";
Alexander Alekseev687cdb52017-11-11 02:40:001040 TryMigrateToResolveTimezoneByGeolocationMethod(prefs_);
[email protected]7f914fd2012-12-20 23:55:251041 ForceNaturalScrollDefault();
1042}
1043
Ana Salazareb7c25712020-02-03 20:27:261044// TODO(anasalazar): Finish moving this to ash::TouchDevicesController.
[email protected]7f914fd2012-12-20 23:55:251045void Preferences::ForceNaturalScrollDefault() {
1046 DVLOG(1) << "ForceNaturalScrollDefault";
James Cook181be002020-05-05 20:55:191047 // Natural scroll is a priority pref.
1048 bool is_syncing = chromeos::features::IsSplitSettingsSyncEnabled()
1049 ? prefs_->AreOsPriorityPrefsSyncing()
1050 : prefs_->IsPrioritySyncing();
avi3ef9ec9e2014-12-22 22:50:171051 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
[email protected]bbd08262013-10-30 09:04:271052 switches::kNaturalScrollDefault) &&
James Cook181be002020-05-05 20:55:191053 is_syncing && !prefs_->GetUserPrefValue(ash::prefs::kNaturalScroll)) {
[email protected]7f914fd2012-12-20 23:55:251054 DVLOG(1) << "Natural scroll forced to true";
1055 natural_scroll_.SetValue(true);
Harry Cutts950265f2020-10-22 18:11:471056 base::UmaHistogramBoolean("Touchpad.NaturalScroll.Forced", true);
[email protected]7f914fd2012-12-20 23:55:251057 }
1058}
1059
[email protected]d01bb8072010-04-12 13:00:151060void Preferences::SetLanguageConfigStringListAsCSV(const char* section,
1061 const char* name,
[email protected]ddd231e2010-06-29 20:35:191062 const std::string& value) {
[email protected]e24c2c92010-10-23 01:39:241063 VLOG(1) << "Setting " << name << " to '" << value << "'";
[email protected]d01bb8072010-04-12 13:00:151064
[email protected]ddd231e2010-06-29 20:35:191065 std::vector<std::string> split_values;
brettwc6f82b12015-07-21 21:37:381066 if (!value.empty()) {
1067 split_values = base::SplitString(value, ",", base::TRIM_WHITESPACE,
1068 base::SPLIT_WANT_ALL);
1069 }
[email protected]ddd231e2010-06-29 20:35:191070
[email protected]b071452e2014-06-02 19:17:121071 // Transfers the xkb id to extension-xkb id.
1072 if (input_method_manager_->MigrateInputMethods(&split_values))
brettwd94a22142015-07-15 05:19:261073 preload_engines_.SetValue(base::JoinString(split_values, ","));
[email protected]fdcd4412014-03-05 06:01:581074
[email protected]7f132d02013-01-03 00:32:261075 if (section == std::string(language_prefs::kGeneralSectionName) &&
1076 name == std::string(language_prefs::kPreloadEnginesConfigName)) {
[email protected]f0881cf2014-08-15 23:31:421077 ime_state_->ReplaceEnabledInputMethods(split_values);
[email protected]dbc9b192012-04-18 05:55:341078 return;
1079 }
[email protected]70aa5b32010-04-05 08:30:341080}
1081
[email protected]2c62b3f2012-04-12 12:07:501082void Preferences::SetInputMethodList() {
1083 // When |preload_engines_| are set, InputMethodManager::ChangeInputMethod()
1084 // might be called to change the current input method to the first one in the
1085 // |preload_engines_| list. This also updates previous/current input method
1086 // prefs. That's why GetValue() calls are placed before the
1087 // SetLanguageConfigStringListAsCSV() call below.
1088 const std::string previous_input_method_id =
1089 previous_input_method_.GetValue();
1090 const std::string current_input_method_id = current_input_method_.GetValue();
[email protected]7f132d02013-01-03 00:32:261091 SetLanguageConfigStringListAsCSV(language_prefs::kGeneralSectionName,
1092 language_prefs::kPreloadEnginesConfigName,
[email protected]2c62b3f2012-04-12 12:07:501093 preload_engines_.GetValue());
1094
1095 // ChangeInputMethod() has to be called AFTER the value of |preload_engines_|
1096 // is sent to the InputMethodManager. Otherwise, the ChangeInputMethod request
1097 // might be ignored as an invalid input method ID. The ChangeInputMethod()
1098 // calls are also necessary to restore the previous/current input method prefs
1099 // which could have been modified by the SetLanguageConfigStringListAsCSV call
1100 // above to the original state.
1101 if (!previous_input_method_id.empty())
[email protected]f0881cf2014-08-15 23:31:421102 ime_state_->ChangeInputMethod(previous_input_method_id,
1103 false /* show_message */);
[email protected]2c62b3f2012-04-12 12:07:501104 if (!current_input_method_id.empty())
[email protected]f0881cf2014-08-15 23:31:421105 ime_state_->ChangeInputMethod(current_input_method_id,
1106 false /* show_message */);
[email protected]2c62b3f2012-04-12 12:07:501107}
1108
[email protected]a995b392010-08-11 04:38:591109void Preferences::UpdateAutoRepeatRate() {
[email protected]c010f632011-04-01 06:44:391110 input_method::AutoRepeatRate rate;
[email protected]c67a30932012-03-14 05:23:001111 rate.initial_delay_in_ms = xkb_auto_repeat_delay_pref_.GetValue();
1112 rate.repeat_interval_in_ms = xkb_auto_repeat_interval_pref_.GetValue();
[email protected]a995b392010-08-11 04:38:591113 DCHECK(rate.initial_delay_in_ms > 0);
1114 DCHECK(rate.repeat_interval_in_ms > 0);
Wei Lee5fd6c512020-11-26 07:52:271115 input_method::InputMethodManager::Get()->GetImeKeyboard()->SetAutoRepeatRate(
1116 rate);
xdaic97cc0a2017-02-18 18:10:041117
1118 user_manager::known_user::SetIntegerPref(user_->GetAccountId(),
Chloe Pelling186ed3e2020-04-27 01:08:341119 ash::prefs::kXkbAutoRepeatDelay,
xdaic97cc0a2017-02-18 18:10:041120 rate.initial_delay_in_ms);
Chloe Pelling186ed3e2020-04-27 01:08:341121 user_manager::known_user::SetIntegerPref(user_->GetAccountId(),
1122 ash::prefs::kXkbAutoRepeatInterval,
1123 rate.repeat_interval_in_ms);
[email protected]a995b392010-08-11 04:38:591124}
1125
Evan Stade0881dea2019-09-04 18:22:491126void Preferences::ActiveUserChanged(user_manager::User* active_user) {
[email protected]aa003a52014-02-15 06:24:231127 if (active_user != user_)
1128 return;
1129 ApplyPreferences(REASON_ACTIVE_USER_CHANGED, "");
1130}
1131
[email protected]fecc1522009-10-15 21:08:291132} // namespace chromeos