blob: e0cb1f5d608fb8c16ef07f856c35a2fdfe295d05 [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
[email protected]396991402014-02-17 10:56:177#include <vector>
8
[email protected]3c5ec44b2013-10-22 08:53:389#include "ash/autoclick/autoclick_controller.h"
[email protected]d141b922013-07-09 08:13:1710#include "ash/shell.h"
[email protected]775caec2011-09-01 17:14:3211#include "base/command_line.h"
[email protected]530cd622011-04-14 15:45:0012#include "base/i18n/time_formatting.h"
[email protected]d7ca1ba2011-05-09 20:09:0813#include "base/metrics/histogram.h"
[email protected]1ab137b2013-03-21 03:33:1814#include "base/prefs/pref_member.h"
[email protected]681958c2013-02-21 13:48:1415#include "base/prefs/pref_registry_simple.h"
[email protected]9eec53fe2013-10-30 20:21:1716#include "base/prefs/scoped_user_pref_update.h"
[email protected]1988e1c2013-02-28 20:27:4217#include "base/strings/string_split.h"
[email protected]5c073322013-06-11 08:03:3018#include "base/strings/string_util.h"
[email protected]135cb802013-06-09 16:44:2019#include "base/strings/utf_string_conversions.h"
[email protected]49c4cf852013-09-27 19:28:2420#include "base/sys_info.h"
[email protected]c0a2128d92011-07-20 15:04:4621#include "chrome/browser/browser_process.h"
[email protected]fdf40f3e2013-07-11 23:55:4622#include "chrome/browser/chrome_notification_types.h"
[email protected]7585f4c2013-01-10 18:26:4123#include "chrome/browser/chromeos/accessibility/magnification_manager.h"
[email protected]4fa2fd5d2013-04-26 03:42:5224#include "chrome/browser/chromeos/drive/file_system_util.h"
michaelpg975f2182014-12-05 04:00:1425#include "chrome/browser/chromeos/input_method/input_method_syncer.h"
[email protected]295ca1a72014-07-01 16:14:3126#include "chrome/browser/chromeos/login/session/user_session_manager.h"
chirantan1c4090c2014-11-18 22:34:1227#include "chrome/browser/chromeos/net/wake_on_wifi_manager.h"
[email protected]82eb8ec2011-12-20 22:24:3328#include "chrome/browser/chromeos/system/input_device_settings.h"
[email protected]b1d97272013-08-17 13:38:4929#include "chrome/browser/download/download_prefs.h"
[email protected]c753f142013-02-10 13:14:0430#include "chrome/browser/prefs/pref_service_syncable.h"
[email protected]775caec2011-09-01 17:14:3231#include "chrome/common/chrome_switches.h"
[email protected]fecc1522009-10-15 21:08:2932#include "chrome/common/pref_names.h"
[email protected]931d1042013-04-05 17:50:4433#include "chromeos/chromeos_switches.h"
[email protected]279690f82013-10-09 08:23:5234#include "chromeos/system/statistics_provider.h"
alemate48255f3d2015-01-30 18:11:4135#include "chromeos/timezone/timezone_resolver.h"
[email protected]1eab4e92014-05-09 02:17:1936#include "components/feedback/tracing_manager.h"
[email protected]f0c8c4992014-05-15 17:37:2637#include "components/pref_registry/pref_registry_syncable.h"
[email protected]2fda9972014-07-23 14:51:5938#include "components/user_manager/user.h"
michaelpg975f2182014-12-05 04:00:1439#include "content/public/browser/browser_thread.h"
[email protected]8bbf6192013-07-18 11:14:0440#include "third_party/icu/source/i18n/unicode/timezone.h"
shuchen179b1f42014-11-27 17:24:4041#include "ui/base/ime/chromeos/extension_ime_util.h"
42#include "ui/base/ime/chromeos/ime_keyboard.h"
43#include "ui/base/ime/chromeos/input_method_manager.h"
pkotwicz0991c822014-10-31 04:21:0344#include "ui/chromeos/accessibility_types.h"
[email protected]86ccbd42013-09-18 18:11:5445#include "ui/events/event_constants.h"
46#include "ui/events/event_utils.h"
[email protected]a6483d22013-07-03 22:11:0047#include "url/gurl.h"
[email protected]fecc1522009-10-15 21:08:2948
[email protected]de1528d1a2012-05-14 10:36:1549namespace chromeos {
[email protected]fecc1522009-10-15 21:08:2950
[email protected]9199bd52010-07-01 05:04:4151static const char kFallbackInputMethodLocale[] = "en-US";
[email protected]4793c942010-09-21 23:17:1752
[email protected]2c62b3f2012-04-12 12:07:5053Preferences::Preferences()
[email protected]155e1b42012-07-14 03:06:0154 : prefs_(NULL),
[email protected]daf37cc2013-11-01 18:10:2655 input_method_manager_(input_method::InputMethodManager::Get()),
[email protected]aa003a52014-02-15 06:24:2356 user_(NULL),
57 user_is_primary_(false) {
[email protected]d141b922013-07-09 08:13:1758 // Do not observe shell, if there is no shell instance; e.g., in some unit
59 // tests.
60 if (ash::Shell::HasInstance())
61 ash::Shell::GetInstance()->AddShellObserver(this);
[email protected]2c62b3f2012-04-12 12:07:5062}
63
64Preferences::Preferences(input_method::InputMethodManager* input_method_manager)
[email protected]eb5624e2013-05-23 19:50:2765 : prefs_(NULL),
[email protected]daf37cc2013-11-01 18:10:2666 input_method_manager_(input_method_manager),
[email protected]50de64ea2014-02-19 06:25:5067 user_(NULL),
68 user_is_primary_(false) {
[email protected]d141b922013-07-09 08:13:1769 // Do not observe shell, if there is no shell instance; e.g., in some unit
70 // tests.
71 if (ash::Shell::HasInstance())
72 ash::Shell::GetInstance()->AddShellObserver(this);
[email protected]2c62b3f2012-04-12 12:07:5073}
[email protected]d743a5982010-11-08 17:54:0974
[email protected]7f914fd2012-12-20 23:55:2575Preferences::~Preferences() {
76 prefs_->RemoveObserver(this);
[email protected]4d390782014-08-15 09:22:5877 user_manager::UserManager::Get()->RemoveSessionStateObserver(this);
[email protected]d141b922013-07-09 08:13:1778 // If shell instance is destoryed before this preferences instance, there is
79 // no need to remove this shell observer.
80 if (ash::Shell::HasInstance())
81 ash::Shell::GetInstance()->RemoveShellObserver(this);
[email protected]7f914fd2012-12-20 23:55:2582}
[email protected]9199bd52010-07-01 05:04:4183
[email protected]fecc1522009-10-15 21:08:2984// static
[email protected]681958c2013-02-21 13:48:1485void Preferences::RegisterPrefs(PrefRegistrySimple* registry) {
[email protected]681958c2013-02-21 13:48:1486 registry->RegisterBooleanPref(prefs::kOwnerPrimaryMouseButtonRight, false);
87 registry->RegisterBooleanPref(prefs::kOwnerTapToClickEnabled, true);
[email protected]ced247a2014-06-13 19:14:1988 registry->RegisterBooleanPref(prefs::kAccessibilityVirtualKeyboardEnabled,
89 false);
[email protected]b01b9e22014-06-03 22:20:1990 registry->RegisterStringPref(prefs::kLogoutStartedLast, std::string());
alemate48255f3d2015-01-30 18:11:4191 registry->RegisterBooleanPref(prefs::kResolveDeviceTimezoneByGeolocation,
alemate01c62ce2015-02-19 17:03:0992 true);
[email protected]681958c2013-02-21 13:48:1493}
94
95// static
[email protected]37ca3fe02013-07-05 15:32:4496void Preferences::RegisterProfilePrefs(
[email protected]443e9312013-05-06 06:17:3497 user_prefs::PrefRegistrySyncable* registry) {
[email protected]2c62b3f2012-04-12 12:07:5098 std::string hardware_keyboard_id;
99 // TODO(yusukes): Remove the runtime hack.
[email protected]49c4cf852013-09-27 19:28:24100 if (base::SysInfo::IsRunningOnChromeOS()) {
[email protected]396991402014-02-17 10:56:17101 DCHECK(g_browser_process);
102 PrefService* local_state = g_browser_process->local_state();
103 DCHECK(local_state);
104 hardware_keyboard_id =
105 local_state->GetString(prefs::kHardwareKeyboardLayout);
[email protected]2c62b3f2012-04-12 12:07:50106 } else {
107 hardware_keyboard_id = "xkb:us::eng"; // only for testing.
108 }
[email protected]a9a81812011-09-16 11:01:17109
[email protected]443e9312013-05-06 06:17:34110 registry->RegisterBooleanPref(
[email protected]a1ea1292013-08-07 23:50:40111 prefs::kPerformanceTracingEnabled,
112 false,
113 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
114
115 registry->RegisterBooleanPref(
[email protected]443e9312013-05-06 06:17:34116 prefs::kTapToClickEnabled,
117 true,
[email protected]0e1aef1b2013-08-07 00:49:35118 user_prefs::PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF);
[email protected]443e9312013-05-06 06:17:34119 registry->RegisterBooleanPref(
120 prefs::kTapDraggingEnabled,
121 false,
[email protected]0e1aef1b2013-08-07 00:49:35122 user_prefs::PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF);
[email protected]443e9312013-05-06 06:17:34123 registry->RegisterBooleanPref(
124 prefs::kEnableTouchpadThreeFingerClick,
125 false,
126 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
127 registry->RegisterBooleanPref(
avi3ef9ec9e2014-12-22 22:50:17128 prefs::kNaturalScroll, base::CommandLine::ForCurrentProcess()->HasSwitch(
129 switches::kNaturalScrollDefault),
[email protected]0e1aef1b2013-08-07 00:49:35130 user_prefs::PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF);
[email protected]443e9312013-05-06 06:17:34131 registry->RegisterBooleanPref(
132 prefs::kPrimaryMouseButtonRight,
133 false,
[email protected]0e1aef1b2013-08-07 00:49:35134 user_prefs::PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF);
[email protected]443e9312013-05-06 06:17:34135 registry->RegisterBooleanPref(
136 prefs::kLabsMediaplayerEnabled,
137 false,
138 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
139 registry->RegisterBooleanPref(
140 prefs::kLabsAdvancedFilesystemEnabled,
141 false,
142 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
143 registry->RegisterBooleanPref(
[email protected]ced247a2014-06-13 19:14:19144 prefs::kAccessibilityStickyKeysEnabled,
[email protected]3206f5f2013-06-12 18:13:06145 false,
[email protected]52560862013-09-23 04:24:56146 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
[email protected]3206f5f2013-06-12 18:13:06147 registry->RegisterBooleanPref(
[email protected]ced247a2014-06-13 19:14:19148 prefs::kAccessibilityLargeCursorEnabled,
[email protected]8126b812013-06-06 03:49:17149 false,
150 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
151 registry->RegisterBooleanPref(
[email protected]ced247a2014-06-13 19:14:19152 prefs::kAccessibilitySpokenFeedbackEnabled,
[email protected]1dfebfc2013-06-04 03:14:32153 false,
[email protected]58983d42013-08-16 13:16:23154 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
[email protected]1dfebfc2013-06-04 03:14:32155 registry->RegisterBooleanPref(
[email protected]ced247a2014-06-13 19:14:19156 prefs::kAccessibilityHighContrastEnabled,
[email protected]1dfebfc2013-06-04 03:14:32157 false,
[email protected]52560862013-09-23 04:24:56158 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
[email protected]1dfebfc2013-06-04 03:14:32159 registry->RegisterBooleanPref(
[email protected]ced247a2014-06-13 19:14:19160 prefs::kAccessibilityScreenMagnifierEnabled,
[email protected]443e9312013-05-06 06:17:34161 false,
[email protected]52560862013-09-23 04:24:56162 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
[email protected]443e9312013-05-06 06:17:34163 registry->RegisterIntegerPref(
[email protected]ced247a2014-06-13 19:14:19164 prefs::kAccessibilityScreenMagnifierType,
pkotwicz0991c822014-10-31 04:21:03165 ui::kDefaultMagnifierType,
[email protected]52560862013-09-23 04:24:56166 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
[email protected]443e9312013-05-06 06:17:34167 registry->RegisterDoublePref(
[email protected]ced247a2014-06-13 19:14:19168 prefs::kAccessibilityScreenMagnifierScale,
[email protected]443e9312013-05-06 06:17:34169 std::numeric_limits<double>::min(),
170 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
171 registry->RegisterBooleanPref(
[email protected]ced247a2014-06-13 19:14:19172 prefs::kAccessibilityAutoclickEnabled,
[email protected]1c881562013-10-12 07:52:58173 false,
174 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
[email protected]3c5ec44b2013-10-22 08:53:38175 registry->RegisterIntegerPref(
[email protected]ced247a2014-06-13 19:14:19176 prefs::kAccessibilityAutoclickDelayMs,
[email protected]3c5ec44b2013-10-22 08:53:38177 ash::AutoclickController::kDefaultAutoclickDelayMs,
178 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
[email protected]1c881562013-10-12 07:52:58179 registry->RegisterBooleanPref(
[email protected]ced247a2014-06-13 19:14:19180 prefs::kAccessibilityVirtualKeyboardEnabled,
181 false,
182 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
[email protected]e1b299b2014-01-29 23:53:41183 registry->RegisterBooleanPref(
[email protected]443e9312013-05-06 06:17:34184 prefs::kShouldAlwaysShowAccessibilityMenu,
185 false,
[email protected]52560862013-09-23 04:24:56186 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
[email protected]443e9312013-05-06 06:17:34187 registry->RegisterIntegerPref(
188 prefs::kMouseSensitivity,
189 3,
[email protected]0e1aef1b2013-08-07 00:49:35190 user_prefs::PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF);
[email protected]443e9312013-05-06 06:17:34191 registry->RegisterIntegerPref(
192 prefs::kTouchpadSensitivity,
193 3,
[email protected]0e1aef1b2013-08-07 00:49:35194 user_prefs::PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF);
[email protected]443e9312013-05-06 06:17:34195 registry->RegisterBooleanPref(
196 prefs::kUse24HourClock,
197 base::GetHourClockType() == base::k24HourClock,
198 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
199 registry->RegisterBooleanPref(
200 prefs::kDisableDrive,
201 false,
202 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
203 registry->RegisterBooleanPref(
204 prefs::kDisableDriveOverCellular,
205 true,
206 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
207 registry->RegisterBooleanPref(
208 prefs::kDisableDriveHostedFiles,
209 false,
210 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
[email protected]aa96e372011-05-16 06:23:10211 // We don't sync prefs::kLanguageCurrentInputMethod and PreviousInputMethod
212 // because they're just used to track the logout state of the device.
[email protected]443e9312013-05-06 06:17:34213 registry->RegisterStringPref(
214 prefs::kLanguageCurrentInputMethod,
215 "",
216 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
217 registry->RegisterStringPref(
218 prefs::kLanguagePreviousInputMethod,
219 "",
220 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
[email protected]443e9312013-05-06 06:17:34221 registry->RegisterStringPref(
222 prefs::kLanguagePreferredLanguages,
223 kFallbackInputMethodLocale,
224 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
225 registry->RegisterStringPref(
226 prefs::kLanguagePreloadEngines,
227 hardware_keyboard_id,
228 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
229 registry->RegisterStringPref(
[email protected]aef1af4b12013-05-09 04:50:23230 prefs::kLanguageEnabledExtensionImes,
[email protected]443e9312013-05-06 06:17:34231 "",
232 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
[email protected]7ac5af92010-06-07 01:25:44233
[email protected]443e9312013-05-06 06:17:34234 registry->RegisterIntegerPref(
235 prefs::kLanguageRemapSearchKeyTo,
236 input_method::kSearchKey,
[email protected]0e1aef1b2013-08-07 00:49:35237 user_prefs::PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF);
[email protected]443e9312013-05-06 06:17:34238 registry->RegisterIntegerPref(
239 prefs::kLanguageRemapControlKeyTo,
240 input_method::kControlKey,
[email protected]0e1aef1b2013-08-07 00:49:35241 user_prefs::PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF);
[email protected]443e9312013-05-06 06:17:34242 registry->RegisterIntegerPref(
243 prefs::kLanguageRemapAltKeyTo,
244 input_method::kAltKey,
[email protected]0e1aef1b2013-08-07 00:49:35245 user_prefs::PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF);
[email protected]0f424fd92013-05-08 21:12:19246 // We don't sync the CapsLock remapping pref, since the UI hides this pref
247 // on certain devices, so syncing a non-default value to a device that
248 // doesn't allow changing the pref would be odd. http://crbug.com/167237
[email protected]443e9312013-05-06 06:17:34249 registry->RegisterIntegerPref(
250 prefs::kLanguageRemapCapsLockKeyTo,
251 input_method::kCapsLockKey,
[email protected]0f424fd92013-05-08 21:12:19252 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
[email protected]443e9312013-05-06 06:17:34253 registry->RegisterIntegerPref(
254 prefs::kLanguageRemapDiamondKeyTo,
255 input_method::kControlKey,
[email protected]0e1aef1b2013-08-07 00:49:35256 user_prefs::PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF);
[email protected]e2204a702013-10-29 21:58:54257 // The following pref isn't synced since the user may desire a different value
258 // depending on whether an external keyboard is attached to a particular
259 // device.
260 registry->RegisterBooleanPref(
261 prefs::kLanguageSendFunctionKeys,
262 false,
263 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
[email protected]443e9312013-05-06 06:17:34264 registry->RegisterBooleanPref(
265 prefs::kLanguageXkbAutoRepeatEnabled,
266 true,
[email protected]08e672652014-07-25 01:24:14267 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
[email protected]443e9312013-05-06 06:17:34268 registry->RegisterIntegerPref(
269 prefs::kLanguageXkbAutoRepeatDelay,
270 language_prefs::kXkbAutoRepeatDelayInMs,
[email protected]08e672652014-07-25 01:24:14271 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
[email protected]443e9312013-05-06 06:17:34272 registry->RegisterIntegerPref(
273 prefs::kLanguageXkbAutoRepeatInterval,
274 language_prefs::kXkbAutoRepeatIntervalInMs,
[email protected]08e672652014-07-25 01:24:14275 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
[email protected]4ccc05e2010-10-06 19:32:15276
chirantan1c4090c2014-11-18 22:34:12277 // We don't sync wake-on-wifi related prefs because they are device specific.
michaelpg592b07a2014-12-23 19:46:09278 registry->RegisterBooleanPref(
279 prefs::kWakeOnWifiSsid,
280 true,
chirantan1c4090c2014-11-18 22:34:12281 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
282
[email protected]ea1eba52010-11-23 18:05:38283 // Mobile plan notifications default to on.
[email protected]443e9312013-05-06 06:17:34284 registry->RegisterBooleanPref(
285 prefs::kShowPlanNotifications,
286 true,
287 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
[email protected]c74fffa2011-04-27 13:32:24288
289 // 3G first-time usage promo will be shown at least once.
[email protected]443e9312013-05-06 06:17:34290 registry->RegisterBooleanPref(
291 prefs::kShow3gPromoNotification,
292 true,
293 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
[email protected]d6ae9502011-05-05 18:23:09294
glevin6ac071f72015-04-07 21:47:32295 // Number of times Data Saver prompt has been shown on 3G data network.
296 registry->RegisterIntegerPref(
297 prefs::kDataSaverPromptsShown,
298 0,
299 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
300
[email protected]443e9312013-05-06 06:17:34301 // Initially all existing users would see "What's new" for current version
302 // after update.
[email protected]c753f142013-02-10 13:14:04303 registry->RegisterStringPref(prefs::kChromeOSReleaseNotesVersion,
304 "0.0.0.0",
[email protected]443e9312013-05-06 06:17:34305 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
[email protected]efb770c2012-05-04 22:31:48306
[email protected]443e9312013-05-06 06:17:34307 registry->RegisterBooleanPref(
308 prefs::kExternalStorageDisabled,
309 false,
310 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
[email protected]3a229f42013-02-07 03:09:26311
[email protected]443e9312013-05-06 06:17:34312 registry->RegisterStringPref(
313 prefs::kTermsOfServiceURL,
314 "",
315 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
[email protected]fddc44fe2013-07-04 00:03:51316
[email protected]d141b922013-07-09 08:13:17317 registry->RegisterBooleanPref(
318 prefs::kTouchHudProjectionEnabled,
319 false,
320 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
[email protected]7a226972014-06-19 11:12:43321
322 registry->RegisterBooleanPref(
323 prefs::kTouchVirtualKeyboardEnabled,
324 false,
325 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
michaelpg975f2182014-12-05 04:00:14326
alemated17ddcb2015-03-04 22:15:37327 input_method::InputMethodSyncer::RegisterProfilePrefs(registry);
328
alemate48255f3d2015-01-30 18:11:41329 registry->RegisterBooleanPref(
alemate01c62ce2015-02-19 17:03:09330 prefs::kResolveTimezoneByGeolocation, true,
alemate8e4a04d2015-03-05 19:31:47331 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
alemate48255f3d2015-01-30 18:11:41332
alemated17ddcb2015-03-04 22:15:37333 registry->RegisterBooleanPref(
334 prefs::kCaptivePortalAuthenticationIgnoresProxy, true,
335 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
[email protected]fecc1522009-10-15 21:08:29336}
337
[email protected]5b199522012-12-22 17:24:44338void Preferences::InitUserPrefs(PrefServiceSyncable* prefs) {
[email protected]155e1b42012-07-14 03:06:01339 prefs_ = prefs;
340
[email protected]e7bff3e2012-11-14 15:34:44341 BooleanPrefMember::NamedChangeCallback callback =
342 base::Bind(&Preferences::OnPreferenceChanged, base::Unretained(this));
343
[email protected]a1ea1292013-08-07 23:50:40344 performance_tracing_enabled_.Init(prefs::kPerformanceTracingEnabled,
345 prefs, callback);
[email protected]e7bff3e2012-11-14 15:34:44346 tap_to_click_enabled_.Init(prefs::kTapToClickEnabled, prefs, callback);
347 tap_dragging_enabled_.Init(prefs::kTapDraggingEnabled, prefs, callback);
[email protected]190349fd2012-05-02 00:10:47348 three_finger_click_enabled_.Init(prefs::kEnableTouchpadThreeFingerClick,
[email protected]e7bff3e2012-11-14 15:34:44349 prefs, callback);
[email protected]e7bff3e2012-11-14 15:34:44350 natural_scroll_.Init(prefs::kNaturalScroll, prefs, callback);
[email protected]e7bff3e2012-11-14 15:34:44351 mouse_sensitivity_.Init(prefs::kMouseSensitivity, prefs, callback);
352 touchpad_sensitivity_.Init(prefs::kTouchpadSensitivity, prefs, callback);
[email protected]aa003a52014-02-15 06:24:23353 primary_mouse_button_right_.Init(prefs::kPrimaryMouseButtonRight,
[email protected]e7bff3e2012-11-14 15:34:44354 prefs, callback);
[email protected]78a6b642012-09-12 02:07:03355 download_default_directory_.Init(prefs::kDownloadDefaultDirectory,
[email protected]e7bff3e2012-11-14 15:34:44356 prefs, callback);
[email protected]d141b922013-07-09 08:13:17357 touch_hud_projection_enabled_.Init(prefs::kTouchHudProjectionEnabled,
358 prefs, callback);
[email protected]e7bff3e2012-11-14 15:34:44359 preload_engines_.Init(prefs::kLanguagePreloadEngines, prefs, callback);
[email protected]aef1af4b12013-05-09 04:50:23360 enabled_extension_imes_.Init(prefs::kLanguageEnabledExtensionImes,
361 prefs, callback);
[email protected]e7bff3e2012-11-14 15:34:44362 current_input_method_.Init(prefs::kLanguageCurrentInputMethod,
363 prefs, callback);
364 previous_input_method_.Init(prefs::kLanguagePreviousInputMethod,
365 prefs, callback);
[email protected]22bec1a2012-03-27 06:33:48366
[email protected]c67a30932012-03-14 05:23:00367 xkb_auto_repeat_enabled_.Init(
[email protected]e7bff3e2012-11-14 15:34:44368 prefs::kLanguageXkbAutoRepeatEnabled, prefs, callback);
[email protected]c67a30932012-03-14 05:23:00369 xkb_auto_repeat_delay_pref_.Init(
[email protected]e7bff3e2012-11-14 15:34:44370 prefs::kLanguageXkbAutoRepeatDelay, prefs, callback);
[email protected]c67a30932012-03-14 05:23:00371 xkb_auto_repeat_interval_pref_.Init(
[email protected]e7bff3e2012-11-14 15:34:44372 prefs::kLanguageXkbAutoRepeatInterval, prefs, callback);
chirantan1c4090c2014-11-18 22:34:12373
michaelpg592b07a2014-12-23 19:46:09374 wake_on_wifi_ssid_.Init(prefs::kWakeOnWifiSsid, prefs, callback);
alemate48255f3d2015-01-30 18:11:41375
376 pref_change_registrar_.Init(prefs);
377 pref_change_registrar_.Add(prefs::kResolveTimezoneByGeolocation, callback);
[email protected]2c62b3f2012-04-12 12:07:50378}
379
[email protected]f0881cf2014-08-15 23:31:42380void Preferences::Init(Profile* profile, const user_manager::User* user) {
381 DCHECK(profile);
[email protected]aa003a52014-02-15 06:24:23382 DCHECK(user);
[email protected]f0881cf2014-08-15 23:31:42383 PrefServiceSyncable* prefs = PrefServiceSyncable::FromProfile(profile);
michaelpg975f2182014-12-05 04:00:14384 // This causes OnIsSyncingChanged to be called when the value of
385 // PrefService::IsSyncing() changes.
386 prefs->AddObserver(this);
[email protected]aa003a52014-02-15 06:24:23387 user_ = user;
[email protected]4d390782014-08-15 09:22:58388 user_is_primary_ =
389 user_manager::UserManager::Get()->GetPrimaryUser() == user_;
[email protected]2c62b3f2012-04-12 12:07:50390 InitUserPrefs(prefs);
[email protected]4ccc05e2010-10-06 19:32:15391
[email protected]4d390782014-08-15 09:22:58392 user_manager::UserManager::Get()->AddSessionStateObserver(this);
[email protected]aa003a52014-02-15 06:24:23393
[email protected]f0881cf2014-08-15 23:31:42394 UserSessionManager* session_manager = UserSessionManager::GetInstance();
395 DCHECK(session_manager);
alemate829e2bf2014-09-06 13:24:46396 ime_state_ = session_manager->GetDefaultIMEState(profile);
[email protected]f0881cf2014-08-15 23:31:42397
[email protected]d7ca1ba2011-05-09 20:09:08398 // Initialize preferences to currently saved state.
[email protected]aa003a52014-02-15 06:24:23399 ApplyPreferences(REASON_INITIALIZATION, "");
alemate01c3b2c2015-02-10 18:26:09400
401 // Note that |ime_state_| was modified by ApplyPreferences(), and
402 // SetState() is modifying |current_input_method_| (via
403 // PersistUserInputMethod() ). This way SetState() here may be called only
404 // after ApplyPreferences().
405 input_method_manager_->SetState(ime_state_);
406
michaelpg975f2182014-12-05 04:00:14407 input_method_syncer_.reset(
408 new input_method::InputMethodSyncer(prefs, ime_state_));
409 input_method_syncer_->Initialize();
[email protected]26012e22010-12-01 06:44:27410
411 // If a guest is logged in, initialize the prefs as if this is the first
[email protected]bb9c5d72014-06-14 19:21:21412 // login. For a regular user this is done in
[email protected]295ca1a72014-07-01 16:14:31413 // UserSessionManager::InitProfilePreferences().
avi3ef9ec9e2014-12-22 22:50:17414 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
415 switches::kGuestSession))
[email protected]f0881cf2014-08-15 23:31:42416 session_manager->SetFirstLoginPrefs(profile, std::string(), std::string());
[email protected]fecc1522009-10-15 21:08:29417}
418
[email protected]f0881cf2014-08-15 23:31:42419void Preferences::InitUserPrefsForTesting(
420 PrefServiceSyncable* prefs,
421 const user_manager::User* user,
422 scoped_refptr<input_method::InputMethodManager::State> ime_state) {
[email protected]aa003a52014-02-15 06:24:23423 user_ = user;
[email protected]f0881cf2014-08-15 23:31:42424 ime_state_ = ime_state;
425
dcheng4c384d92014-09-15 23:29:45426 if (ime_state.get())
[email protected]f0881cf2014-08-15 23:31:42427 input_method_manager_->SetState(ime_state);
428
[email protected]2c62b3f2012-04-12 12:07:50429 InitUserPrefs(prefs);
michaelpg975f2182014-12-05 04:00:14430
431 input_method_syncer_.reset(
432 new input_method::InputMethodSyncer(prefs, ime_state_));
433 input_method_syncer_->Initialize();
[email protected]2c62b3f2012-04-12 12:07:50434}
435
436void Preferences::SetInputMethodListForTesting() {
437 SetInputMethodList();
438}
439
[email protected]e7bff3e2012-11-14 15:34:44440void Preferences::OnPreferenceChanged(const std::string& pref_name) {
[email protected]aa003a52014-02-15 06:24:23441 ApplyPreferences(REASON_PREF_CHANGED, pref_name);
[email protected]fecc1522009-10-15 21:08:29442}
443
[email protected]aa003a52014-02-15 06:24:23444void Preferences::ApplyPreferences(ApplyReason reason,
445 const std::string& pref_name) {
446 DCHECK(reason != REASON_PREF_CHANGED || !pref_name.empty());
447 const bool user_is_owner =
[email protected]4d390782014-08-15 09:22:58448 user_manager::UserManager::Get()->GetOwnerEmail() == user_->email();
[email protected]aa003a52014-02-15 06:24:23449 const bool user_is_active = user_->is_active();
450
[email protected]bd36e172014-02-14 19:49:57451 system::TouchpadSettings touchpad_settings;
452 system::MouseSettings mouse_settings;
[email protected]aa003a52014-02-15 06:24:23453
454 if (user_is_primary_ && (reason == REASON_INITIALIZATION ||
455 pref_name == prefs::kPerformanceTracingEnabled)) {
[email protected]a1ea1292013-08-07 23:50:40456 const bool enabled = performance_tracing_enabled_.GetValue();
457 if (enabled)
458 tracing_manager_ = TracingManager::Create();
459 else
460 tracing_manager_.reset();
461 }
[email protected]aa003a52014-02-15 06:24:23462 if (reason != REASON_PREF_CHANGED || pref_name == prefs::kTapToClickEnabled) {
[email protected]b685fbd2012-03-24 09:23:04463 const bool enabled = tap_to_click_enabled_.GetValue();
[email protected]aa003a52014-02-15 06:24:23464 if (user_is_active)
465 touchpad_settings.SetTapToClick(enabled);
466 if (reason == REASON_PREF_CHANGED)
[email protected]d7ca1ba2011-05-09 20:09:08467 UMA_HISTOGRAM_BOOLEAN("Touchpad.TapToClick.Changed", enabled);
[email protected]aa003a52014-02-15 06:24:23468 else if (reason == REASON_INITIALIZATION)
[email protected]d7ca1ba2011-05-09 20:09:08469 UMA_HISTOGRAM_BOOLEAN("Touchpad.TapToClick.Started", enabled);
[email protected]022c3b92012-09-13 19:45:59470
471 // Save owner preference in local state to use on login screen.
[email protected]aa003a52014-02-15 06:24:23472 if (user_is_owner) {
[email protected]022c3b92012-09-13 19:45:59473 PrefService* prefs = g_browser_process->local_state();
474 if (prefs->GetBoolean(prefs::kOwnerTapToClickEnabled) != enabled)
475 prefs->SetBoolean(prefs::kOwnerTapToClickEnabled, enabled);
476 }
[email protected]3b02de292010-05-13 06:05:05477 }
[email protected]aa003a52014-02-15 06:24:23478 if (reason != REASON_PREF_CHANGED ||
479 pref_name == prefs::kTapDraggingEnabled) {
[email protected]1b46af02012-10-31 05:23:54480 const bool enabled = tap_dragging_enabled_.GetValue();
[email protected]aa003a52014-02-15 06:24:23481 if (user_is_active)
482 touchpad_settings.SetTapDragging(enabled);
483 if (reason == REASON_PREF_CHANGED)
[email protected]1b46af02012-10-31 05:23:54484 UMA_HISTOGRAM_BOOLEAN("Touchpad.TapDragging.Changed", enabled);
[email protected]aa003a52014-02-15 06:24:23485 else if (reason == REASON_INITIALIZATION)
[email protected]1b46af02012-10-31 05:23:54486 UMA_HISTOGRAM_BOOLEAN("Touchpad.TapDragging.Started", enabled);
487 }
[email protected]aa003a52014-02-15 06:24:23488 if (reason != REASON_PREF_CHANGED ||
489 pref_name == prefs::kEnableTouchpadThreeFingerClick) {
[email protected]190349fd2012-05-02 00:10:47490 const bool enabled = three_finger_click_enabled_.GetValue();
[email protected]aa003a52014-02-15 06:24:23491 if (user_is_active)
492 touchpad_settings.SetThreeFingerClick(enabled);
493 if (reason == REASON_PREF_CHANGED)
[email protected]190349fd2012-05-02 00:10:47494 UMA_HISTOGRAM_BOOLEAN("Touchpad.ThreeFingerClick.Changed", enabled);
[email protected]aa003a52014-02-15 06:24:23495 else if (reason == REASON_INITIALIZATION)
[email protected]190349fd2012-05-02 00:10:47496 UMA_HISTOGRAM_BOOLEAN("Touchpad.ThreeFingerClick.Started", enabled);
497 }
[email protected]aa003a52014-02-15 06:24:23498 if (reason != REASON_PREF_CHANGED || pref_name == prefs::kNaturalScroll) {
[email protected]7f914fd2012-12-20 23:55:25499 // Force natural scroll default if we've sync'd and if the cmd line arg is
500 // set.
501 ForceNaturalScrollDefault();
[email protected]223059e2012-10-05 01:44:49502
[email protected]b685fbd2012-03-24 09:23:04503 const bool enabled = natural_scroll_.GetValue();
[email protected]223059e2012-10-05 01:44:49504 DVLOG(1) << "Natural scroll set to " << enabled;
[email protected]aa003a52014-02-15 06:24:23505 if (user_is_active)
[email protected]158775422014-04-03 18:15:59506 touchpad_settings.SetNaturalScroll(enabled);
[email protected]aa003a52014-02-15 06:24:23507 if (reason == REASON_PREF_CHANGED)
[email protected]b685fbd2012-03-24 09:23:04508 UMA_HISTOGRAM_BOOLEAN("Touchpad.NaturalScroll.Changed", enabled);
[email protected]aa003a52014-02-15 06:24:23509 else if (reason == REASON_INITIALIZATION)
[email protected]b685fbd2012-03-24 09:23:04510 UMA_HISTOGRAM_BOOLEAN("Touchpad.NaturalScroll.Started", enabled);
511 }
[email protected]aa003a52014-02-15 06:24:23512 if (reason != REASON_PREF_CHANGED || pref_name == prefs::kMouseSensitivity) {
[email protected]563fb5f2012-03-31 00:39:28513 const int sensitivity = mouse_sensitivity_.GetValue();
[email protected]aa003a52014-02-15 06:24:23514 if (user_is_active)
515 mouse_settings.SetSensitivity(sensitivity);
516 if (reason == REASON_PREF_CHANGED) {
[email protected]3a337d32013-07-02 05:14:24517 UMA_HISTOGRAM_ENUMERATION("Mouse.PointerSensitivity.Changed",
518 sensitivity,
519 system::kMaxPointerSensitivity + 1);
[email protected]aa003a52014-02-15 06:24:23520 } else if (reason == REASON_INITIALIZATION) {
[email protected]3a337d32013-07-02 05:14:24521 UMA_HISTOGRAM_ENUMERATION("Mouse.PointerSensitivity.Started",
522 sensitivity,
523 system::kMaxPointerSensitivity + 1);
[email protected]563fb5f2012-03-31 00:39:28524 }
525 }
[email protected]aa003a52014-02-15 06:24:23526 if (reason != REASON_PREF_CHANGED ||
527 pref_name == prefs::kTouchpadSensitivity) {
[email protected]563fb5f2012-03-31 00:39:28528 const int sensitivity = touchpad_sensitivity_.GetValue();
[email protected]aa003a52014-02-15 06:24:23529 if (user_is_active)
530 touchpad_settings.SetSensitivity(sensitivity);
531 if (reason == REASON_PREF_CHANGED) {
[email protected]3a337d32013-07-02 05:14:24532 UMA_HISTOGRAM_ENUMERATION("Touchpad.PointerSensitivity.Changed",
533 sensitivity,
534 system::kMaxPointerSensitivity + 1);
[email protected]aa003a52014-02-15 06:24:23535 } else if (reason == REASON_INITIALIZATION) {
[email protected]3a337d32013-07-02 05:14:24536 UMA_HISTOGRAM_ENUMERATION("Touchpad.PointerSensitivity.Started",
537 sensitivity,
538 system::kMaxPointerSensitivity + 1);
[email protected]d7ca1ba2011-05-09 20:09:08539 }
[email protected]3b02de292010-05-13 06:05:05540 }
[email protected]aa003a52014-02-15 06:24:23541 if (reason != REASON_PREF_CHANGED ||
542 pref_name == prefs::kPrimaryMouseButtonRight) {
[email protected]0027fde12011-12-15 05:09:38543 const bool right = primary_mouse_button_right_.GetValue();
[email protected]aa003a52014-02-15 06:24:23544 if (user_is_active)
545 mouse_settings.SetPrimaryButtonRight(right);
546 if (reason == REASON_PREF_CHANGED)
[email protected]6c8599e2012-01-20 04:31:58547 UMA_HISTOGRAM_BOOLEAN("Mouse.PrimaryButtonRight.Changed", right);
[email protected]aa003a52014-02-15 06:24:23548 else if (reason == REASON_INITIALIZATION)
[email protected]6c8599e2012-01-20 04:31:58549 UMA_HISTOGRAM_BOOLEAN("Mouse.PrimaryButtonRight.Started", right);
[email protected]022c3b92012-09-13 19:45:59550 // Save owner preference in local state to use on login screen.
[email protected]aa003a52014-02-15 06:24:23551 if (user_is_owner) {
[email protected]022c3b92012-09-13 19:45:59552 PrefService* prefs = g_browser_process->local_state();
553 if (prefs->GetBoolean(prefs::kOwnerPrimaryMouseButtonRight) != right)
554 prefs->SetBoolean(prefs::kOwnerPrimaryMouseButtonRight, right);
555 }
[email protected]0027fde12011-12-15 05:09:38556 }
[email protected]aa003a52014-02-15 06:24:23557 if (reason != REASON_PREF_CHANGED ||
558 pref_name == prefs::kDownloadDefaultDirectory) {
[email protected]d9d04df2012-10-12 07:06:35559 const bool default_download_to_drive = drive::util::IsUnderDriveMountPoint(
[email protected]78a6b642012-09-12 02:07:03560 download_default_directory_.GetValue());
[email protected]aa003a52014-02-15 06:24:23561 if (reason == REASON_PREF_CHANGED)
[email protected]e8307a12012-09-12 20:06:34562 UMA_HISTOGRAM_BOOLEAN(
563 "FileBrowser.DownloadDestination.IsGoogleDrive.Changed",
[email protected]78a6b642012-09-12 02:07:03564 default_download_to_drive);
[email protected]aa003a52014-02-15 06:24:23565 else if (reason == REASON_INITIALIZATION)
[email protected]e8307a12012-09-12 20:06:34566 UMA_HISTOGRAM_BOOLEAN(
567 "FileBrowser.DownloadDestination.IsGoogleDrive.Started",
[email protected]78a6b642012-09-12 02:07:03568 default_download_to_drive);
569 }
[email protected]aa003a52014-02-15 06:24:23570 if (reason != REASON_PREF_CHANGED ||
571 pref_name == prefs::kTouchHudProjectionEnabled) {
572 if (user_is_active) {
573 const bool enabled = touch_hud_projection_enabled_.GetValue();
michaelpg975f2182014-12-05 04:00:14574 // There may not be a shell, e.g., in some unit tests.
575 if (ash::Shell::HasInstance())
576 ash::Shell::GetInstance()->SetTouchHudProjectionEnabled(enabled);
[email protected]aa003a52014-02-15 06:24:23577 }
[email protected]d141b922013-07-09 08:13:17578 }
[email protected]8be9ff22010-06-08 02:13:54579
[email protected]aa003a52014-02-15 06:24:23580 if (reason != REASON_PREF_CHANGED ||
581 pref_name == prefs::kLanguageXkbAutoRepeatEnabled) {
582 if (user_is_active) {
583 const bool enabled = xkb_auto_repeat_enabled_.GetValue();
[email protected]fbb141a2014-04-11 13:25:52584 input_method::InputMethodManager::Get()
585 ->GetImeKeyboard()
[email protected]aa003a52014-02-15 06:24:23586 ->SetAutoRepeatEnabled(enabled);
587 }
588 }
589 if (reason != REASON_PREF_CHANGED ||
590 pref_name == prefs::kLanguageXkbAutoRepeatDelay ||
591 pref_name == prefs::kLanguageXkbAutoRepeatInterval) {
592 if (user_is_active)
593 UpdateAutoRepeatRate();
[email protected]74b42fc12010-07-20 10:15:41594 }
[email protected]a6e90772011-02-09 05:38:54595
[email protected]f0881cf2014-08-15 23:31:42596 if (reason == REASON_INITIALIZATION)
[email protected]2c62b3f2012-04-12 12:07:50597 SetInputMethodList();
[email protected]f0881cf2014-08-15 23:31:42598
599 if (pref_name == prefs::kLanguagePreloadEngines &&
600 reason == REASON_PREF_CHANGED) {
[email protected]7f132d02013-01-03 00:32:26601 SetLanguageConfigStringListAsCSV(language_prefs::kGeneralSectionName,
602 language_prefs::kPreloadEnginesConfigName,
[email protected]c67a30932012-03-14 05:23:00603 preload_engines_.GetValue());
[email protected]3b02de292010-05-13 06:05:05604 }
[email protected]22bec1a2012-03-27 06:33:48605
[email protected]f0881cf2014-08-15 23:31:42606 if ((reason == REASON_INITIALIZATION) ||
607 (pref_name == prefs::kLanguageEnabledExtensionImes &&
608 reason == REASON_PREF_CHANGED)) {
609 std::string value(enabled_extension_imes_.GetValue());
[email protected]797c6802012-09-20 10:36:13610
[email protected]f0881cf2014-08-15 23:31:42611 std::vector<std::string> split_values;
612 if (!value.empty())
613 base::SplitString(value, ',', &split_values);
[email protected]797c6802012-09-20 10:36:13614
[email protected]f0881cf2014-08-15 23:31:42615 ime_state_->SetEnabledExtensionImes(&split_values);
[email protected]797c6802012-09-20 10:36:13616 }
[email protected]aa003a52014-02-15 06:24:23617
618 if (user_is_active) {
619 system::InputDeviceSettings::Get()->UpdateTouchpadSettings(
620 touchpad_settings);
621 system::InputDeviceSettings::Get()->UpdateMouseSettings(mouse_settings);
622 }
michaelpg592b07a2014-12-23 19:46:09623
624 if (user_is_primary_ && (reason != REASON_PREF_CHANGED ||
625 pref_name == prefs::kWakeOnWifiSsid)) {
626 int features = wake_on_wifi_ssid_.GetValue() ?
627 WakeOnWifiManager::WAKE_ON_SSID : WakeOnWifiManager::WAKE_ON_NONE;
628 // The flag enables wake on packets but doesn't update a preference.
avi79bf9132014-12-25 17:48:05629 if (base::CommandLine::ForCurrentProcess()->
630 HasSwitch(switches::kWakeOnPackets)) {
michaelpg592b07a2014-12-23 19:46:09631 features |= WakeOnWifiManager::WAKE_ON_PACKET;
avi79bf9132014-12-25 17:48:05632 }
michaelpg592b07a2014-12-23 19:46:09633 WakeOnWifiManager::Get()->OnPreferenceChanged(
634 static_cast<WakeOnWifiManager::WakeOnWifiFeature>(features));
635 }
alemate48255f3d2015-01-30 18:11:41636
637 if (pref_name == prefs::kResolveTimezoneByGeolocation &&
638 reason != REASON_ACTIVE_USER_CHANGED) {
639 const bool value = prefs_->GetBoolean(prefs::kResolveTimezoneByGeolocation);
640 if (user_is_owner) {
641 g_browser_process->local_state()->SetBoolean(
642 prefs::kResolveDeviceTimezoneByGeolocation, value);
643 }
644 if (user_is_primary_) {
645 if (value) {
646 g_browser_process->platform_part()->GetTimezoneResolver()->Start();
647 } else {
648 g_browser_process->platform_part()->GetTimezoneResolver()->Stop();
649 if (reason == REASON_PREF_CHANGED) {
650 // Allow immediate timezone update on Stop + Start.
651 g_browser_process->local_state()->ClearPref(
652 TimeZoneResolver::kLastTimeZoneRefreshTime);
653 }
654 }
655 }
656 }
[email protected]fecc1522009-10-15 21:08:29657}
658
[email protected]7f914fd2012-12-20 23:55:25659void Preferences::OnIsSyncingChanged() {
660 DVLOG(1) << "OnIsSyncingChanged";
661 ForceNaturalScrollDefault();
662}
663
664void Preferences::ForceNaturalScrollDefault() {
665 DVLOG(1) << "ForceNaturalScrollDefault";
avi3ef9ec9e2014-12-22 22:50:17666 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
[email protected]bbd08262013-10-30 09:04:27667 switches::kNaturalScrollDefault) &&
avi3ef9ec9e2014-12-22 22:50:17668 prefs_->IsSyncing() && !prefs_->GetUserPrefValue(prefs::kNaturalScroll)) {
[email protected]7f914fd2012-12-20 23:55:25669 DVLOG(1) << "Natural scroll forced to true";
670 natural_scroll_.SetValue(true);
671 UMA_HISTOGRAM_BOOLEAN("Touchpad.NaturalScroll.Forced", true);
672 }
673}
674
[email protected]d01bb8072010-04-12 13:00:15675void Preferences::SetLanguageConfigStringListAsCSV(const char* section,
676 const char* name,
[email protected]ddd231e2010-06-29 20:35:19677 const std::string& value) {
[email protected]e24c2c92010-10-23 01:39:24678 VLOG(1) << "Setting " << name << " to '" << value << "'";
[email protected]d01bb8072010-04-12 13:00:15679
[email protected]ddd231e2010-06-29 20:35:19680 std::vector<std::string> split_values;
681 if (!value.empty())
[email protected]76eb0242010-10-14 00:35:36682 base::SplitString(value, ',', &split_values);
[email protected]ddd231e2010-06-29 20:35:19683
[email protected]b071452e2014-06-02 19:17:12684 // Transfers the xkb id to extension-xkb id.
685 if (input_method_manager_->MigrateInputMethods(&split_values))
[email protected]fdcd4412014-03-05 06:01:58686 preload_engines_.SetValue(JoinString(split_values, ','));
687
[email protected]7f132d02013-01-03 00:32:26688 if (section == std::string(language_prefs::kGeneralSectionName) &&
689 name == std::string(language_prefs::kPreloadEnginesConfigName)) {
[email protected]f0881cf2014-08-15 23:31:42690 ime_state_->ReplaceEnabledInputMethods(split_values);
[email protected]dbc9b192012-04-18 05:55:34691 return;
692 }
[email protected]70aa5b32010-04-05 08:30:34693}
694
[email protected]2c62b3f2012-04-12 12:07:50695void Preferences::SetInputMethodList() {
696 // When |preload_engines_| are set, InputMethodManager::ChangeInputMethod()
697 // might be called to change the current input method to the first one in the
698 // |preload_engines_| list. This also updates previous/current input method
699 // prefs. That's why GetValue() calls are placed before the
700 // SetLanguageConfigStringListAsCSV() call below.
701 const std::string previous_input_method_id =
702 previous_input_method_.GetValue();
703 const std::string current_input_method_id = current_input_method_.GetValue();
[email protected]7f132d02013-01-03 00:32:26704 SetLanguageConfigStringListAsCSV(language_prefs::kGeneralSectionName,
705 language_prefs::kPreloadEnginesConfigName,
[email protected]2c62b3f2012-04-12 12:07:50706 preload_engines_.GetValue());
707
708 // ChangeInputMethod() has to be called AFTER the value of |preload_engines_|
709 // is sent to the InputMethodManager. Otherwise, the ChangeInputMethod request
710 // might be ignored as an invalid input method ID. The ChangeInputMethod()
711 // calls are also necessary to restore the previous/current input method prefs
712 // which could have been modified by the SetLanguageConfigStringListAsCSV call
713 // above to the original state.
714 if (!previous_input_method_id.empty())
[email protected]f0881cf2014-08-15 23:31:42715 ime_state_->ChangeInputMethod(previous_input_method_id,
716 false /* show_message */);
[email protected]2c62b3f2012-04-12 12:07:50717 if (!current_input_method_id.empty())
[email protected]f0881cf2014-08-15 23:31:42718 ime_state_->ChangeInputMethod(current_input_method_id,
719 false /* show_message */);
[email protected]2c62b3f2012-04-12 12:07:50720}
721
[email protected]a995b392010-08-11 04:38:59722void Preferences::UpdateAutoRepeatRate() {
[email protected]c010f632011-04-01 06:44:39723 input_method::AutoRepeatRate rate;
[email protected]c67a30932012-03-14 05:23:00724 rate.initial_delay_in_ms = xkb_auto_repeat_delay_pref_.GetValue();
725 rate.repeat_interval_in_ms = xkb_auto_repeat_interval_pref_.GetValue();
[email protected]a995b392010-08-11 04:38:59726 DCHECK(rate.initial_delay_in_ms > 0);
727 DCHECK(rate.repeat_interval_in_ms > 0);
[email protected]fbb141a2014-04-11 13:25:52728 input_method::InputMethodManager::Get()
729 ->GetImeKeyboard()
[email protected]b4d95fb2014-02-12 14:48:07730 ->SetAutoRepeatRate(rate);
[email protected]a995b392010-08-11 04:38:59731}
732
[email protected]d141b922013-07-09 08:13:17733void Preferences::OnTouchHudProjectionToggled(bool enabled) {
734 if (touch_hud_projection_enabled_.GetValue() == enabled)
735 return;
[email protected]aa003a52014-02-15 06:24:23736 if (!user_->is_active())
737 return;
[email protected]d141b922013-07-09 08:13:17738 touch_hud_projection_enabled_.SetValue(enabled);
739}
740
[email protected]2fda9972014-07-23 14:51:59741void Preferences::ActiveUserChanged(const user_manager::User* active_user) {
[email protected]aa003a52014-02-15 06:24:23742 if (active_user != user_)
743 return;
744 ApplyPreferences(REASON_ACTIVE_USER_CHANGED, "");
745}
746
[email protected]fecc1522009-10-15 21:08:29747} // namespace chromeos