blob: c34a92eaa5aff9ff4f643191b8b25c779c4280b4 [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"
phweissa16ceae22015-09-17 09:33:1210#include "ash/display/display_manager.h"
[email protected]d141b922013-07-09 08:13:1711#include "ash/shell.h"
[email protected]775caec2011-09-01 17:14:3212#include "base/command_line.h"
[email protected]530cd622011-04-14 15:45:0013#include "base/i18n/time_formatting.h"
[email protected]d7ca1ba2011-05-09 20:09:0814#include "base/metrics/histogram.h"
[email protected]1ab137b2013-03-21 03:33:1815#include "base/prefs/pref_member.h"
[email protected]681958c2013-02-21 13:48:1416#include "base/prefs/pref_registry_simple.h"
[email protected]9eec53fe2013-10-30 20:21:1717#include "base/prefs/scoped_user_pref_update.h"
[email protected]1988e1c2013-02-28 20:27:4218#include "base/strings/string_split.h"
[email protected]5c073322013-06-11 08:03:3019#include "base/strings/string_util.h"
[email protected]135cb802013-06-09 16:44:2020#include "base/strings/utf_string_conversions.h"
[email protected]49c4cf852013-09-27 19:28:2421#include "base/sys_info.h"
[email protected]c0a2128d92011-07-20 15:04:4622#include "chrome/browser/browser_process.h"
[email protected]fdf40f3e2013-07-11 23:55:4623#include "chrome/browser/chrome_notification_types.h"
[email protected]7585f4c2013-01-10 18:26:4124#include "chrome/browser/chromeos/accessibility/magnification_manager.h"
lukasza6364a022015-08-21 01:13:2425#include "chrome/browser/chromeos/drive/file_system_util.h"
michaelpg975f2182014-12-05 04:00:1426#include "chrome/browser/chromeos/input_method/input_method_syncer.h"
[email protected]295ca1a72014-07-01 16:14:3127#include "chrome/browser/chromeos/login/session/user_session_manager.h"
chirantan1c4090c2014-11-18 22:34:1228#include "chrome/browser/chromeos/net/wake_on_wifi_manager.h"
[email protected]82eb8ec2011-12-20 22:24:3329#include "chrome/browser/chromeos/system/input_device_settings.h"
[email protected]b1d97272013-08-17 13:38:4930#include "chrome/browser/download/download_prefs.h"
sdefresneed27d86b2015-09-14 11:02:3831#include "chrome/browser/prefs/pref_service_syncable_util.h"
[email protected]775caec2011-09-01 17:14:3232#include "chrome/common/chrome_switches.h"
[email protected]fecc1522009-10-15 21:08:2933#include "chrome/common/pref_names.h"
[email protected]931d1042013-04-05 17:50:4434#include "chromeos/chromeos_switches.h"
[email protected]279690f82013-10-09 08:23:5235#include "chromeos/system/statistics_provider.h"
alemate48255f3d2015-01-30 18:11:4136#include "chromeos/timezone/timezone_resolver.h"
lukasza76b4a982015-08-08 00:36:3937#include "components/drive/drive_pref_names.h"
[email protected]1eab4e92014-05-09 02:17:1938#include "components/feedback/tracing_manager.h"
[email protected]f0c8c4992014-05-15 17:37:2639#include "components/pref_registry/pref_registry_syncable.h"
sdefresne875d0782015-09-16 12:01:2840#include "components/syncable_prefs/pref_service_syncable.h"
[email protected]2fda9972014-07-23 14:51:5941#include "components/user_manager/user.h"
michaelpg975f2182014-12-05 04:00:1442#include "content/public/browser/browser_thread.h"
[email protected]8bbf6192013-07-18 11:14:0443#include "third_party/icu/source/i18n/unicode/timezone.h"
shuchen179b1f42014-11-27 17:24:4044#include "ui/base/ime/chromeos/extension_ime_util.h"
45#include "ui/base/ime/chromeos/ime_keyboard.h"
46#include "ui/base/ime/chromeos/input_method_manager.h"
pkotwicz0991c822014-10-31 04:21:0347#include "ui/chromeos/accessibility_types.h"
[email protected]86ccbd42013-09-18 18:11:5448#include "ui/events/event_constants.h"
49#include "ui/events/event_utils.h"
[email protected]a6483d22013-07-03 22:11:0050#include "url/gurl.h"
[email protected]fecc1522009-10-15 21:08:2951
[email protected]de1528d1a2012-05-14 10:36:1552namespace chromeos {
[email protected]fecc1522009-10-15 21:08:2953
[email protected]9199bd52010-07-01 05:04:4154static const char kFallbackInputMethodLocale[] = "en-US";
[email protected]4793c942010-09-21 23:17:1755
[email protected]2c62b3f2012-04-12 12:07:5056Preferences::Preferences()
[email protected]155e1b42012-07-14 03:06:0157 : prefs_(NULL),
[email protected]daf37cc2013-11-01 18:10:2658 input_method_manager_(input_method::InputMethodManager::Get()),
[email protected]aa003a52014-02-15 06:24:2359 user_(NULL),
60 user_is_primary_(false) {
[email protected]d141b922013-07-09 08:13:1761 // Do not observe shell, if there is no shell instance; e.g., in some unit
62 // tests.
63 if (ash::Shell::HasInstance())
64 ash::Shell::GetInstance()->AddShellObserver(this);
[email protected]2c62b3f2012-04-12 12:07:5065}
66
67Preferences::Preferences(input_method::InputMethodManager* input_method_manager)
[email protected]eb5624e2013-05-23 19:50:2768 : prefs_(NULL),
[email protected]daf37cc2013-11-01 18:10:2669 input_method_manager_(input_method_manager),
[email protected]50de64ea2014-02-19 06:25:5070 user_(NULL),
71 user_is_primary_(false) {
[email protected]d141b922013-07-09 08:13:1772 // Do not observe shell, if there is no shell instance; e.g., in some unit
73 // tests.
74 if (ash::Shell::HasInstance())
75 ash::Shell::GetInstance()->AddShellObserver(this);
[email protected]2c62b3f2012-04-12 12:07:5076}
[email protected]d743a5982010-11-08 17:54:0977
[email protected]7f914fd2012-12-20 23:55:2578Preferences::~Preferences() {
79 prefs_->RemoveObserver(this);
[email protected]4d390782014-08-15 09:22:5880 user_manager::UserManager::Get()->RemoveSessionStateObserver(this);
[email protected]d141b922013-07-09 08:13:1781 // If shell instance is destoryed before this preferences instance, there is
82 // no need to remove this shell observer.
83 if (ash::Shell::HasInstance())
84 ash::Shell::GetInstance()->RemoveShellObserver(this);
[email protected]7f914fd2012-12-20 23:55:2585}
[email protected]9199bd52010-07-01 05:04:4186
[email protected]fecc1522009-10-15 21:08:2987// static
[email protected]681958c2013-02-21 13:48:1488void Preferences::RegisterPrefs(PrefRegistrySimple* registry) {
[email protected]681958c2013-02-21 13:48:1489 registry->RegisterBooleanPref(prefs::kOwnerPrimaryMouseButtonRight, false);
90 registry->RegisterBooleanPref(prefs::kOwnerTapToClickEnabled, true);
[email protected]ced247a2014-06-13 19:14:1991 registry->RegisterBooleanPref(prefs::kAccessibilityVirtualKeyboardEnabled,
92 false);
[email protected]b01b9e22014-06-03 22:20:1993 registry->RegisterStringPref(prefs::kLogoutStartedLast, std::string());
alemate48255f3d2015-01-30 18:11:4194 registry->RegisterBooleanPref(prefs::kResolveDeviceTimezoneByGeolocation,
alemate01c62ce2015-02-19 17:03:0995 true);
[email protected]681958c2013-02-21 13:48:1496}
97
98// static
[email protected]37ca3fe02013-07-05 15:32:4499void Preferences::RegisterProfilePrefs(
[email protected]443e9312013-05-06 06:17:34100 user_prefs::PrefRegistrySyncable* registry) {
[email protected]2c62b3f2012-04-12 12:07:50101 std::string hardware_keyboard_id;
102 // TODO(yusukes): Remove the runtime hack.
[email protected]49c4cf852013-09-27 19:28:24103 if (base::SysInfo::IsRunningOnChromeOS()) {
[email protected]396991402014-02-17 10:56:17104 DCHECK(g_browser_process);
105 PrefService* local_state = g_browser_process->local_state();
106 DCHECK(local_state);
107 hardware_keyboard_id =
108 local_state->GetString(prefs::kHardwareKeyboardLayout);
[email protected]2c62b3f2012-04-12 12:07:50109 } else {
110 hardware_keyboard_id = "xkb:us::eng"; // only for testing.
111 }
[email protected]a9a81812011-09-16 11:01:17112
raymesaa608722015-04-27 03:00:25113 registry->RegisterBooleanPref(prefs::kPerformanceTracingEnabled, false);
[email protected]a1ea1292013-08-07 23:50:40114
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);
raymesaa608722015-04-27 03:00:25123 registry->RegisterBooleanPref(prefs::kEnableTouchpadThreeFingerClick, false);
phweissa16ceae22015-09-17 09:33:12124 // This preference can only be set to true by policy or command_line flag
125 // and it should not carry over to sessions were neither of these is set.
126 registry->RegisterBooleanPref(prefs::kUnifiedDesktopEnabledByDefault, false,
127 PrefRegistry::NO_REGISTRATION_FLAGS);
[email protected]443e9312013-05-06 06:17:34128 registry->RegisterBooleanPref(
avi3ef9ec9e2014-12-22 22:50:17129 prefs::kNaturalScroll, base::CommandLine::ForCurrentProcess()->HasSwitch(
130 switches::kNaturalScrollDefault),
[email protected]0e1aef1b2013-08-07 00:49:35131 user_prefs::PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF);
[email protected]443e9312013-05-06 06:17:34132 registry->RegisterBooleanPref(
133 prefs::kPrimaryMouseButtonRight,
134 false,
[email protected]0e1aef1b2013-08-07 00:49:35135 user_prefs::PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF);
raymesaa608722015-04-27 03:00:25136 registry->RegisterBooleanPref(prefs::kLabsMediaplayerEnabled, false);
137 registry->RegisterBooleanPref(prefs::kLabsAdvancedFilesystemEnabled, false);
[email protected]443e9312013-05-06 06:17:34138 registry->RegisterBooleanPref(
[email protected]ced247a2014-06-13 19:14:19139 prefs::kAccessibilityStickyKeysEnabled,
[email protected]3206f5f2013-06-12 18:13:06140 false,
[email protected]52560862013-09-23 04:24:56141 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
[email protected]3206f5f2013-06-12 18:13:06142 registry->RegisterBooleanPref(
[email protected]ced247a2014-06-13 19:14:19143 prefs::kAccessibilityLargeCursorEnabled,
[email protected]8126b812013-06-06 03:49:17144 false,
145 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
raymesaa608722015-04-27 03:00:25146 registry->RegisterBooleanPref(prefs::kAccessibilitySpokenFeedbackEnabled,
147 false);
[email protected]1dfebfc2013-06-04 03:14:32148 registry->RegisterBooleanPref(
[email protected]ced247a2014-06-13 19:14:19149 prefs::kAccessibilityHighContrastEnabled,
[email protected]1dfebfc2013-06-04 03:14:32150 false,
[email protected]52560862013-09-23 04:24:56151 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
[email protected]1dfebfc2013-06-04 03:14:32152 registry->RegisterBooleanPref(
jennyzb894b6d2015-06-01 20:12:18153 prefs::kAccessibilityScreenMagnifierCenterFocus,
154 true,
155 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
156 registry->RegisterBooleanPref(
157 prefs::kAccessibilityScreenMagnifierEnabled, false,
[email protected]52560862013-09-23 04:24:56158 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
[email protected]443e9312013-05-06 06:17:34159 registry->RegisterIntegerPref(
[email protected]ced247a2014-06-13 19:14:19160 prefs::kAccessibilityScreenMagnifierType,
pkotwicz0991c822014-10-31 04:21:03161 ui::kDefaultMagnifierType,
[email protected]52560862013-09-23 04:24:56162 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
raymesaa608722015-04-27 03:00:25163 registry->RegisterDoublePref(prefs::kAccessibilityScreenMagnifierScale,
164 std::numeric_limits<double>::min());
[email protected]443e9312013-05-06 06:17:34165 registry->RegisterBooleanPref(
[email protected]ced247a2014-06-13 19:14:19166 prefs::kAccessibilityAutoclickEnabled,
[email protected]1c881562013-10-12 07:52:58167 false,
168 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
[email protected]3c5ec44b2013-10-22 08:53:38169 registry->RegisterIntegerPref(
[email protected]ced247a2014-06-13 19:14:19170 prefs::kAccessibilityAutoclickDelayMs,
[email protected]3c5ec44b2013-10-22 08:53:38171 ash::AutoclickController::kDefaultAutoclickDelayMs,
172 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
[email protected]1c881562013-10-12 07:52:58173 registry->RegisterBooleanPref(
[email protected]ced247a2014-06-13 19:14:19174 prefs::kAccessibilityVirtualKeyboardEnabled,
175 false,
176 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
[email protected]e1b299b2014-01-29 23:53:41177 registry->RegisterBooleanPref(
[email protected]443e9312013-05-06 06:17:34178 prefs::kShouldAlwaysShowAccessibilityMenu,
179 false,
[email protected]52560862013-09-23 04:24:56180 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
[email protected]443e9312013-05-06 06:17:34181 registry->RegisterIntegerPref(
182 prefs::kMouseSensitivity,
183 3,
[email protected]0e1aef1b2013-08-07 00:49:35184 user_prefs::PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF);
[email protected]443e9312013-05-06 06:17:34185 registry->RegisterIntegerPref(
186 prefs::kTouchpadSensitivity,
187 3,
[email protected]0e1aef1b2013-08-07 00:49:35188 user_prefs::PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF);
[email protected]443e9312013-05-06 06:17:34189 registry->RegisterBooleanPref(
190 prefs::kUse24HourClock,
191 base::GetHourClockType() == base::k24HourClock,
192 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
193 registry->RegisterBooleanPref(
lukaszada911a62015-06-17 15:39:32194 drive::prefs::kDisableDrive, false,
[email protected]443e9312013-05-06 06:17:34195 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
196 registry->RegisterBooleanPref(
lukaszada911a62015-06-17 15:39:32197 drive::prefs::kDisableDriveOverCellular, true,
[email protected]443e9312013-05-06 06:17:34198 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
199 registry->RegisterBooleanPref(
lukaszada911a62015-06-17 15:39:32200 drive::prefs::kDisableDriveHostedFiles, false,
[email protected]443e9312013-05-06 06:17:34201 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
[email protected]aa96e372011-05-16 06:23:10202 // We don't sync prefs::kLanguageCurrentInputMethod and PreviousInputMethod
203 // because they're just used to track the logout state of the device.
raymesaa608722015-04-27 03:00:25204 registry->RegisterStringPref(prefs::kLanguageCurrentInputMethod, "");
205 registry->RegisterStringPref(prefs::kLanguagePreviousInputMethod, "");
206 registry->RegisterStringPref(prefs::kLanguagePreferredLanguages,
207 kFallbackInputMethodLocale);
208 registry->RegisterStringPref(prefs::kLanguagePreloadEngines,
209 hardware_keyboard_id);
210 registry->RegisterStringPref(prefs::kLanguageEnabledExtensionImes, "");
[email protected]7ac5af92010-06-07 01:25:44211
[email protected]443e9312013-05-06 06:17:34212 registry->RegisterIntegerPref(
213 prefs::kLanguageRemapSearchKeyTo,
214 input_method::kSearchKey,
[email protected]0e1aef1b2013-08-07 00:49:35215 user_prefs::PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF);
[email protected]443e9312013-05-06 06:17:34216 registry->RegisterIntegerPref(
217 prefs::kLanguageRemapControlKeyTo,
218 input_method::kControlKey,
[email protected]0e1aef1b2013-08-07 00:49:35219 user_prefs::PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF);
[email protected]443e9312013-05-06 06:17:34220 registry->RegisterIntegerPref(
221 prefs::kLanguageRemapAltKeyTo,
222 input_method::kAltKey,
[email protected]0e1aef1b2013-08-07 00:49:35223 user_prefs::PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF);
[email protected]0f424fd92013-05-08 21:12:19224 // We don't sync the CapsLock remapping pref, since the UI hides this pref
225 // on certain devices, so syncing a non-default value to a device that
226 // doesn't allow changing the pref would be odd. http://crbug.com/167237
raymesaa608722015-04-27 03:00:25227 registry->RegisterIntegerPref(prefs::kLanguageRemapCapsLockKeyTo,
228 input_method::kCapsLockKey);
[email protected]443e9312013-05-06 06:17:34229 registry->RegisterIntegerPref(
230 prefs::kLanguageRemapDiamondKeyTo,
231 input_method::kControlKey,
[email protected]0e1aef1b2013-08-07 00:49:35232 user_prefs::PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF);
[email protected]e2204a702013-10-29 21:58:54233 // The following pref isn't synced since the user may desire a different value
234 // depending on whether an external keyboard is attached to a particular
235 // device.
raymesaa608722015-04-27 03:00:25236 registry->RegisterBooleanPref(prefs::kLanguageSendFunctionKeys, false);
[email protected]443e9312013-05-06 06:17:34237 registry->RegisterBooleanPref(
238 prefs::kLanguageXkbAutoRepeatEnabled,
239 true,
[email protected]08e672652014-07-25 01:24:14240 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
[email protected]443e9312013-05-06 06:17:34241 registry->RegisterIntegerPref(
242 prefs::kLanguageXkbAutoRepeatDelay,
243 language_prefs::kXkbAutoRepeatDelayInMs,
[email protected]08e672652014-07-25 01:24:14244 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
[email protected]443e9312013-05-06 06:17:34245 registry->RegisterIntegerPref(
246 prefs::kLanguageXkbAutoRepeatInterval,
247 language_prefs::kXkbAutoRepeatIntervalInMs,
[email protected]08e672652014-07-25 01:24:14248 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
[email protected]4ccc05e2010-10-06 19:32:15249
chirantan1c4090c2014-11-18 22:34:12250 // We don't sync wake-on-wifi related prefs because they are device specific.
raymesaa608722015-04-27 03:00:25251 registry->RegisterBooleanPref(prefs::kWakeOnWifiSsid, true);
chirantan1c4090c2014-11-18 22:34:12252
[email protected]c74fffa2011-04-27 13:32:24253 // 3G first-time usage promo will be shown at least once.
raymesaa608722015-04-27 03:00:25254 registry->RegisterBooleanPref(prefs::kShow3gPromoNotification, true);
[email protected]d6ae9502011-05-05 18:23:09255
glevin6ac071f72015-04-07 21:47:32256 // Number of times Data Saver prompt has been shown on 3G data network.
glevin4c4d5fa12015-07-08 17:25:51257 registry->RegisterIntegerPref(
258 prefs::kDataSaverPromptsShown,
259 0,
260 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
glevin6ac071f72015-04-07 21:47:32261
[email protected]443e9312013-05-06 06:17:34262 // Initially all existing users would see "What's new" for current version
263 // after update.
[email protected]c753f142013-02-10 13:14:04264 registry->RegisterStringPref(prefs::kChromeOSReleaseNotesVersion,
265 "0.0.0.0",
[email protected]443e9312013-05-06 06:17:34266 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
[email protected]efb770c2012-05-04 22:31:48267
raymesaa608722015-04-27 03:00:25268 registry->RegisterBooleanPref(prefs::kExternalStorageDisabled, false);
[email protected]3a229f42013-02-07 03:09:26269
raymesaa608722015-04-27 03:00:25270 registry->RegisterStringPref(prefs::kTermsOfServiceURL, "");
[email protected]fddc44fe2013-07-04 00:03:51271
raymesaa608722015-04-27 03:00:25272 registry->RegisterBooleanPref(prefs::kTouchHudProjectionEnabled, false);
[email protected]7a226972014-06-19 11:12:43273
raymesaa608722015-04-27 03:00:25274 registry->RegisterBooleanPref(prefs::kTouchVirtualKeyboardEnabled, false);
michaelpg975f2182014-12-05 04:00:14275
alemated17ddcb2015-03-04 22:15:37276 input_method::InputMethodSyncer::RegisterProfilePrefs(registry);
277
alemate48255f3d2015-01-30 18:11:41278 registry->RegisterBooleanPref(
alemate01c62ce2015-02-19 17:03:09279 prefs::kResolveTimezoneByGeolocation, true,
alemate8e4a04d2015-03-05 19:31:47280 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
alemate48255f3d2015-01-30 18:11:41281
raymesaa608722015-04-27 03:00:25282 registry->RegisterBooleanPref(prefs::kCaptivePortalAuthenticationIgnoresProxy,
283 true);
peletskyida0bbb12015-04-08 17:11:04284
raymesaa608722015-04-27 03:00:25285 registry->RegisterBooleanPref(prefs::kForceMaximizeOnFirstRun, false);
[email protected]fecc1522009-10-15 21:08:29286}
287
[email protected]5b199522012-12-22 17:24:44288void Preferences::InitUserPrefs(PrefServiceSyncable* prefs) {
[email protected]155e1b42012-07-14 03:06:01289 prefs_ = prefs;
290
[email protected]e7bff3e2012-11-14 15:34:44291 BooleanPrefMember::NamedChangeCallback callback =
292 base::Bind(&Preferences::OnPreferenceChanged, base::Unretained(this));
293
[email protected]a1ea1292013-08-07 23:50:40294 performance_tracing_enabled_.Init(prefs::kPerformanceTracingEnabled,
295 prefs, callback);
[email protected]e7bff3e2012-11-14 15:34:44296 tap_to_click_enabled_.Init(prefs::kTapToClickEnabled, prefs, callback);
297 tap_dragging_enabled_.Init(prefs::kTapDraggingEnabled, prefs, callback);
[email protected]190349fd2012-05-02 00:10:47298 three_finger_click_enabled_.Init(prefs::kEnableTouchpadThreeFingerClick,
phweissa16ceae22015-09-17 09:33:12299 prefs, callback);
300 unified_desktop_enabled_by_default_.Init(
301 prefs::kUnifiedDesktopEnabledByDefault, prefs, callback);
[email protected]e7bff3e2012-11-14 15:34:44302 natural_scroll_.Init(prefs::kNaturalScroll, prefs, callback);
[email protected]e7bff3e2012-11-14 15:34:44303 mouse_sensitivity_.Init(prefs::kMouseSensitivity, prefs, callback);
304 touchpad_sensitivity_.Init(prefs::kTouchpadSensitivity, prefs, callback);
[email protected]aa003a52014-02-15 06:24:23305 primary_mouse_button_right_.Init(prefs::kPrimaryMouseButtonRight,
[email protected]e7bff3e2012-11-14 15:34:44306 prefs, callback);
[email protected]78a6b642012-09-12 02:07:03307 download_default_directory_.Init(prefs::kDownloadDefaultDirectory,
[email protected]e7bff3e2012-11-14 15:34:44308 prefs, callback);
[email protected]d141b922013-07-09 08:13:17309 touch_hud_projection_enabled_.Init(prefs::kTouchHudProjectionEnabled,
310 prefs, callback);
[email protected]e7bff3e2012-11-14 15:34:44311 preload_engines_.Init(prefs::kLanguagePreloadEngines, prefs, callback);
[email protected]aef1af4b12013-05-09 04:50:23312 enabled_extension_imes_.Init(prefs::kLanguageEnabledExtensionImes,
313 prefs, callback);
[email protected]e7bff3e2012-11-14 15:34:44314 current_input_method_.Init(prefs::kLanguageCurrentInputMethod,
315 prefs, callback);
316 previous_input_method_.Init(prefs::kLanguagePreviousInputMethod,
317 prefs, callback);
[email protected]22bec1a2012-03-27 06:33:48318
[email protected]c67a30932012-03-14 05:23:00319 xkb_auto_repeat_enabled_.Init(
[email protected]e7bff3e2012-11-14 15:34:44320 prefs::kLanguageXkbAutoRepeatEnabled, prefs, callback);
[email protected]c67a30932012-03-14 05:23:00321 xkb_auto_repeat_delay_pref_.Init(
[email protected]e7bff3e2012-11-14 15:34:44322 prefs::kLanguageXkbAutoRepeatDelay, prefs, callback);
[email protected]c67a30932012-03-14 05:23:00323 xkb_auto_repeat_interval_pref_.Init(
[email protected]e7bff3e2012-11-14 15:34:44324 prefs::kLanguageXkbAutoRepeatInterval, prefs, callback);
chirantan1c4090c2014-11-18 22:34:12325
michaelpg592b07a2014-12-23 19:46:09326 wake_on_wifi_ssid_.Init(prefs::kWakeOnWifiSsid, prefs, callback);
alemate48255f3d2015-01-30 18:11:41327
328 pref_change_registrar_.Init(prefs);
329 pref_change_registrar_.Add(prefs::kResolveTimezoneByGeolocation, callback);
alemate6cf8c6e2015-07-23 06:58:50330 pref_change_registrar_.Add(prefs::kUse24HourClock, callback);
[email protected]2c62b3f2012-04-12 12:07:50331}
332
[email protected]f0881cf2014-08-15 23:31:42333void Preferences::Init(Profile* profile, const user_manager::User* user) {
334 DCHECK(profile);
[email protected]aa003a52014-02-15 06:24:23335 DCHECK(user);
sdefresneed27d86b2015-09-14 11:02:38336 PrefServiceSyncable* prefs = PrefServiceSyncableFromProfile(profile);
michaelpg975f2182014-12-05 04:00:14337 // This causes OnIsSyncingChanged to be called when the value of
338 // PrefService::IsSyncing() changes.
339 prefs->AddObserver(this);
[email protected]aa003a52014-02-15 06:24:23340 user_ = user;
[email protected]4d390782014-08-15 09:22:58341 user_is_primary_ =
342 user_manager::UserManager::Get()->GetPrimaryUser() == user_;
[email protected]2c62b3f2012-04-12 12:07:50343 InitUserPrefs(prefs);
[email protected]4ccc05e2010-10-06 19:32:15344
[email protected]4d390782014-08-15 09:22:58345 user_manager::UserManager::Get()->AddSessionStateObserver(this);
[email protected]aa003a52014-02-15 06:24:23346
[email protected]f0881cf2014-08-15 23:31:42347 UserSessionManager* session_manager = UserSessionManager::GetInstance();
348 DCHECK(session_manager);
alemate829e2bf2014-09-06 13:24:46349 ime_state_ = session_manager->GetDefaultIMEState(profile);
[email protected]f0881cf2014-08-15 23:31:42350
[email protected]d7ca1ba2011-05-09 20:09:08351 // Initialize preferences to currently saved state.
[email protected]aa003a52014-02-15 06:24:23352 ApplyPreferences(REASON_INITIALIZATION, "");
alemate01c3b2c2015-02-10 18:26:09353
354 // Note that |ime_state_| was modified by ApplyPreferences(), and
355 // SetState() is modifying |current_input_method_| (via
356 // PersistUserInputMethod() ). This way SetState() here may be called only
357 // after ApplyPreferences().
358 input_method_manager_->SetState(ime_state_);
359
michaelpg975f2182014-12-05 04:00:14360 input_method_syncer_.reset(
361 new input_method::InputMethodSyncer(prefs, ime_state_));
362 input_method_syncer_->Initialize();
[email protected]26012e22010-12-01 06:44:27363
364 // If a guest is logged in, initialize the prefs as if this is the first
[email protected]bb9c5d72014-06-14 19:21:21365 // login. For a regular user this is done in
[email protected]295ca1a72014-07-01 16:14:31366 // UserSessionManager::InitProfilePreferences().
avi3ef9ec9e2014-12-22 22:50:17367 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
368 switches::kGuestSession))
[email protected]f0881cf2014-08-15 23:31:42369 session_manager->SetFirstLoginPrefs(profile, std::string(), std::string());
[email protected]fecc1522009-10-15 21:08:29370}
371
[email protected]f0881cf2014-08-15 23:31:42372void Preferences::InitUserPrefsForTesting(
373 PrefServiceSyncable* prefs,
374 const user_manager::User* user,
375 scoped_refptr<input_method::InputMethodManager::State> ime_state) {
[email protected]aa003a52014-02-15 06:24:23376 user_ = user;
[email protected]f0881cf2014-08-15 23:31:42377 ime_state_ = ime_state;
378
dcheng4c384d92014-09-15 23:29:45379 if (ime_state.get())
[email protected]f0881cf2014-08-15 23:31:42380 input_method_manager_->SetState(ime_state);
381
[email protected]2c62b3f2012-04-12 12:07:50382 InitUserPrefs(prefs);
michaelpg975f2182014-12-05 04:00:14383
384 input_method_syncer_.reset(
385 new input_method::InputMethodSyncer(prefs, ime_state_));
386 input_method_syncer_->Initialize();
[email protected]2c62b3f2012-04-12 12:07:50387}
388
389void Preferences::SetInputMethodListForTesting() {
390 SetInputMethodList();
391}
392
[email protected]e7bff3e2012-11-14 15:34:44393void Preferences::OnPreferenceChanged(const std::string& pref_name) {
[email protected]aa003a52014-02-15 06:24:23394 ApplyPreferences(REASON_PREF_CHANGED, pref_name);
[email protected]fecc1522009-10-15 21:08:29395}
396
[email protected]aa003a52014-02-15 06:24:23397void Preferences::ApplyPreferences(ApplyReason reason,
398 const std::string& pref_name) {
399 DCHECK(reason != REASON_PREF_CHANGED || !pref_name.empty());
400 const bool user_is_owner =
[email protected]4d390782014-08-15 09:22:58401 user_manager::UserManager::Get()->GetOwnerEmail() == user_->email();
[email protected]aa003a52014-02-15 06:24:23402 const bool user_is_active = user_->is_active();
403
[email protected]bd36e172014-02-14 19:49:57404 system::TouchpadSettings touchpad_settings;
405 system::MouseSettings mouse_settings;
[email protected]aa003a52014-02-15 06:24:23406
407 if (user_is_primary_ && (reason == REASON_INITIALIZATION ||
408 pref_name == prefs::kPerformanceTracingEnabled)) {
[email protected]a1ea1292013-08-07 23:50:40409 const bool enabled = performance_tracing_enabled_.GetValue();
410 if (enabled)
411 tracing_manager_ = TracingManager::Create();
412 else
413 tracing_manager_.reset();
414 }
[email protected]aa003a52014-02-15 06:24:23415 if (reason != REASON_PREF_CHANGED || pref_name == prefs::kTapToClickEnabled) {
[email protected]b685fbd2012-03-24 09:23:04416 const bool enabled = tap_to_click_enabled_.GetValue();
[email protected]aa003a52014-02-15 06:24:23417 if (user_is_active)
418 touchpad_settings.SetTapToClick(enabled);
419 if (reason == REASON_PREF_CHANGED)
[email protected]d7ca1ba2011-05-09 20:09:08420 UMA_HISTOGRAM_BOOLEAN("Touchpad.TapToClick.Changed", enabled);
[email protected]aa003a52014-02-15 06:24:23421 else if (reason == REASON_INITIALIZATION)
[email protected]d7ca1ba2011-05-09 20:09:08422 UMA_HISTOGRAM_BOOLEAN("Touchpad.TapToClick.Started", enabled);
[email protected]022c3b92012-09-13 19:45:59423
424 // Save owner preference in local state to use on login screen.
[email protected]aa003a52014-02-15 06:24:23425 if (user_is_owner) {
[email protected]022c3b92012-09-13 19:45:59426 PrefService* prefs = g_browser_process->local_state();
427 if (prefs->GetBoolean(prefs::kOwnerTapToClickEnabled) != enabled)
428 prefs->SetBoolean(prefs::kOwnerTapToClickEnabled, enabled);
429 }
[email protected]3b02de292010-05-13 06:05:05430 }
[email protected]aa003a52014-02-15 06:24:23431 if (reason != REASON_PREF_CHANGED ||
432 pref_name == prefs::kTapDraggingEnabled) {
[email protected]1b46af02012-10-31 05:23:54433 const bool enabled = tap_dragging_enabled_.GetValue();
[email protected]aa003a52014-02-15 06:24:23434 if (user_is_active)
435 touchpad_settings.SetTapDragging(enabled);
436 if (reason == REASON_PREF_CHANGED)
[email protected]1b46af02012-10-31 05:23:54437 UMA_HISTOGRAM_BOOLEAN("Touchpad.TapDragging.Changed", enabled);
[email protected]aa003a52014-02-15 06:24:23438 else if (reason == REASON_INITIALIZATION)
[email protected]1b46af02012-10-31 05:23:54439 UMA_HISTOGRAM_BOOLEAN("Touchpad.TapDragging.Started", enabled);
440 }
[email protected]aa003a52014-02-15 06:24:23441 if (reason != REASON_PREF_CHANGED ||
442 pref_name == prefs::kEnableTouchpadThreeFingerClick) {
[email protected]190349fd2012-05-02 00:10:47443 const bool enabled = three_finger_click_enabled_.GetValue();
[email protected]aa003a52014-02-15 06:24:23444 if (user_is_active)
445 touchpad_settings.SetThreeFingerClick(enabled);
446 if (reason == REASON_PREF_CHANGED)
[email protected]190349fd2012-05-02 00:10:47447 UMA_HISTOGRAM_BOOLEAN("Touchpad.ThreeFingerClick.Changed", enabled);
[email protected]aa003a52014-02-15 06:24:23448 else if (reason == REASON_INITIALIZATION)
[email protected]190349fd2012-05-02 00:10:47449 UMA_HISTOGRAM_BOOLEAN("Touchpad.ThreeFingerClick.Started", enabled);
450 }
phweissa16ceae22015-09-17 09:33:12451 if (reason != REASON_PREF_CHANGED ||
452 pref_name == prefs::kUnifiedDesktopEnabledByDefault) {
453 const bool enabled = unified_desktop_enabled_by_default_.GetValue();
454 if (ash::Shell::HasInstance()) {
455 ash::Shell::GetInstance()->display_manager()
456 ->SetUnifiedDesktopEnabled(enabled);
457 }
458 }
[email protected]aa003a52014-02-15 06:24:23459 if (reason != REASON_PREF_CHANGED || pref_name == prefs::kNaturalScroll) {
[email protected]7f914fd2012-12-20 23:55:25460 // Force natural scroll default if we've sync'd and if the cmd line arg is
461 // set.
462 ForceNaturalScrollDefault();
[email protected]223059e2012-10-05 01:44:49463
[email protected]b685fbd2012-03-24 09:23:04464 const bool enabled = natural_scroll_.GetValue();
[email protected]223059e2012-10-05 01:44:49465 DVLOG(1) << "Natural scroll set to " << enabled;
[email protected]aa003a52014-02-15 06:24:23466 if (user_is_active)
[email protected]158775422014-04-03 18:15:59467 touchpad_settings.SetNaturalScroll(enabled);
[email protected]aa003a52014-02-15 06:24:23468 if (reason == REASON_PREF_CHANGED)
[email protected]b685fbd2012-03-24 09:23:04469 UMA_HISTOGRAM_BOOLEAN("Touchpad.NaturalScroll.Changed", enabled);
[email protected]aa003a52014-02-15 06:24:23470 else if (reason == REASON_INITIALIZATION)
[email protected]b685fbd2012-03-24 09:23:04471 UMA_HISTOGRAM_BOOLEAN("Touchpad.NaturalScroll.Started", enabled);
472 }
[email protected]aa003a52014-02-15 06:24:23473 if (reason != REASON_PREF_CHANGED || pref_name == prefs::kMouseSensitivity) {
[email protected]563fb5f2012-03-31 00:39:28474 const int sensitivity = mouse_sensitivity_.GetValue();
[email protected]aa003a52014-02-15 06:24:23475 if (user_is_active)
476 mouse_settings.SetSensitivity(sensitivity);
477 if (reason == REASON_PREF_CHANGED) {
[email protected]3a337d32013-07-02 05:14:24478 UMA_HISTOGRAM_ENUMERATION("Mouse.PointerSensitivity.Changed",
479 sensitivity,
480 system::kMaxPointerSensitivity + 1);
[email protected]aa003a52014-02-15 06:24:23481 } else if (reason == REASON_INITIALIZATION) {
[email protected]3a337d32013-07-02 05:14:24482 UMA_HISTOGRAM_ENUMERATION("Mouse.PointerSensitivity.Started",
483 sensitivity,
484 system::kMaxPointerSensitivity + 1);
[email protected]563fb5f2012-03-31 00:39:28485 }
486 }
[email protected]aa003a52014-02-15 06:24:23487 if (reason != REASON_PREF_CHANGED ||
488 pref_name == prefs::kTouchpadSensitivity) {
[email protected]563fb5f2012-03-31 00:39:28489 const int sensitivity = touchpad_sensitivity_.GetValue();
[email protected]aa003a52014-02-15 06:24:23490 if (user_is_active)
491 touchpad_settings.SetSensitivity(sensitivity);
492 if (reason == REASON_PREF_CHANGED) {
[email protected]3a337d32013-07-02 05:14:24493 UMA_HISTOGRAM_ENUMERATION("Touchpad.PointerSensitivity.Changed",
494 sensitivity,
495 system::kMaxPointerSensitivity + 1);
[email protected]aa003a52014-02-15 06:24:23496 } else if (reason == REASON_INITIALIZATION) {
[email protected]3a337d32013-07-02 05:14:24497 UMA_HISTOGRAM_ENUMERATION("Touchpad.PointerSensitivity.Started",
498 sensitivity,
499 system::kMaxPointerSensitivity + 1);
[email protected]d7ca1ba2011-05-09 20:09:08500 }
[email protected]3b02de292010-05-13 06:05:05501 }
[email protected]aa003a52014-02-15 06:24:23502 if (reason != REASON_PREF_CHANGED ||
503 pref_name == prefs::kPrimaryMouseButtonRight) {
[email protected]0027fde12011-12-15 05:09:38504 const bool right = primary_mouse_button_right_.GetValue();
[email protected]aa003a52014-02-15 06:24:23505 if (user_is_active)
506 mouse_settings.SetPrimaryButtonRight(right);
507 if (reason == REASON_PREF_CHANGED)
[email protected]6c8599e2012-01-20 04:31:58508 UMA_HISTOGRAM_BOOLEAN("Mouse.PrimaryButtonRight.Changed", right);
[email protected]aa003a52014-02-15 06:24:23509 else if (reason == REASON_INITIALIZATION)
[email protected]6c8599e2012-01-20 04:31:58510 UMA_HISTOGRAM_BOOLEAN("Mouse.PrimaryButtonRight.Started", right);
[email protected]022c3b92012-09-13 19:45:59511 // Save owner preference in local state to use on login screen.
[email protected]aa003a52014-02-15 06:24:23512 if (user_is_owner) {
[email protected]022c3b92012-09-13 19:45:59513 PrefService* prefs = g_browser_process->local_state();
514 if (prefs->GetBoolean(prefs::kOwnerPrimaryMouseButtonRight) != right)
515 prefs->SetBoolean(prefs::kOwnerPrimaryMouseButtonRight, right);
516 }
[email protected]0027fde12011-12-15 05:09:38517 }
[email protected]aa003a52014-02-15 06:24:23518 if (reason != REASON_PREF_CHANGED ||
519 pref_name == prefs::kDownloadDefaultDirectory) {
[email protected]d9d04df2012-10-12 07:06:35520 const bool default_download_to_drive = drive::util::IsUnderDriveMountPoint(
[email protected]78a6b642012-09-12 02:07:03521 download_default_directory_.GetValue());
[email protected]aa003a52014-02-15 06:24:23522 if (reason == REASON_PREF_CHANGED)
[email protected]e8307a12012-09-12 20:06:34523 UMA_HISTOGRAM_BOOLEAN(
524 "FileBrowser.DownloadDestination.IsGoogleDrive.Changed",
[email protected]78a6b642012-09-12 02:07:03525 default_download_to_drive);
[email protected]aa003a52014-02-15 06:24:23526 else if (reason == REASON_INITIALIZATION)
[email protected]e8307a12012-09-12 20:06:34527 UMA_HISTOGRAM_BOOLEAN(
528 "FileBrowser.DownloadDestination.IsGoogleDrive.Started",
[email protected]78a6b642012-09-12 02:07:03529 default_download_to_drive);
530 }
[email protected]aa003a52014-02-15 06:24:23531 if (reason != REASON_PREF_CHANGED ||
532 pref_name == prefs::kTouchHudProjectionEnabled) {
533 if (user_is_active) {
534 const bool enabled = touch_hud_projection_enabled_.GetValue();
michaelpg975f2182014-12-05 04:00:14535 // There may not be a shell, e.g., in some unit tests.
536 if (ash::Shell::HasInstance())
537 ash::Shell::GetInstance()->SetTouchHudProjectionEnabled(enabled);
[email protected]aa003a52014-02-15 06:24:23538 }
[email protected]d141b922013-07-09 08:13:17539 }
[email protected]8be9ff22010-06-08 02:13:54540
[email protected]aa003a52014-02-15 06:24:23541 if (reason != REASON_PREF_CHANGED ||
542 pref_name == prefs::kLanguageXkbAutoRepeatEnabled) {
543 if (user_is_active) {
544 const bool enabled = xkb_auto_repeat_enabled_.GetValue();
[email protected]fbb141a2014-04-11 13:25:52545 input_method::InputMethodManager::Get()
546 ->GetImeKeyboard()
[email protected]aa003a52014-02-15 06:24:23547 ->SetAutoRepeatEnabled(enabled);
548 }
549 }
550 if (reason != REASON_PREF_CHANGED ||
551 pref_name == prefs::kLanguageXkbAutoRepeatDelay ||
552 pref_name == prefs::kLanguageXkbAutoRepeatInterval) {
553 if (user_is_active)
554 UpdateAutoRepeatRate();
[email protected]74b42fc12010-07-20 10:15:41555 }
[email protected]a6e90772011-02-09 05:38:54556
[email protected]f0881cf2014-08-15 23:31:42557 if (reason == REASON_INITIALIZATION)
[email protected]2c62b3f2012-04-12 12:07:50558 SetInputMethodList();
[email protected]f0881cf2014-08-15 23:31:42559
560 if (pref_name == prefs::kLanguagePreloadEngines &&
561 reason == REASON_PREF_CHANGED) {
[email protected]7f132d02013-01-03 00:32:26562 SetLanguageConfigStringListAsCSV(language_prefs::kGeneralSectionName,
563 language_prefs::kPreloadEnginesConfigName,
[email protected]c67a30932012-03-14 05:23:00564 preload_engines_.GetValue());
[email protected]3b02de292010-05-13 06:05:05565 }
[email protected]22bec1a2012-03-27 06:33:48566
[email protected]f0881cf2014-08-15 23:31:42567 if ((reason == REASON_INITIALIZATION) ||
568 (pref_name == prefs::kLanguageEnabledExtensionImes &&
569 reason == REASON_PREF_CHANGED)) {
570 std::string value(enabled_extension_imes_.GetValue());
[email protected]797c6802012-09-20 10:36:13571
[email protected]f0881cf2014-08-15 23:31:42572 std::vector<std::string> split_values;
brettwc6f82b12015-07-21 21:37:38573 if (!value.empty()) {
574 split_values = base::SplitString(value, ",", base::TRIM_WHITESPACE,
575 base::SPLIT_WANT_ALL);
576 }
[email protected]f0881cf2014-08-15 23:31:42577 ime_state_->SetEnabledExtensionImes(&split_values);
[email protected]797c6802012-09-20 10:36:13578 }
[email protected]aa003a52014-02-15 06:24:23579
580 if (user_is_active) {
581 system::InputDeviceSettings::Get()->UpdateTouchpadSettings(
582 touchpad_settings);
583 system::InputDeviceSettings::Get()->UpdateMouseSettings(mouse_settings);
584 }
michaelpg592b07a2014-12-23 19:46:09585
586 if (user_is_primary_ && (reason != REASON_PREF_CHANGED ||
587 pref_name == prefs::kWakeOnWifiSsid)) {
588 int features = wake_on_wifi_ssid_.GetValue() ?
589 WakeOnWifiManager::WAKE_ON_SSID : WakeOnWifiManager::WAKE_ON_NONE;
590 // The flag enables wake on packets but doesn't update a preference.
avi79bf9132014-12-25 17:48:05591 if (base::CommandLine::ForCurrentProcess()->
592 HasSwitch(switches::kWakeOnPackets)) {
michaelpg592b07a2014-12-23 19:46:09593 features |= WakeOnWifiManager::WAKE_ON_PACKET;
avi79bf9132014-12-25 17:48:05594 }
michaelpg592b07a2014-12-23 19:46:09595 WakeOnWifiManager::Get()->OnPreferenceChanged(
596 static_cast<WakeOnWifiManager::WakeOnWifiFeature>(features));
597 }
alemate48255f3d2015-01-30 18:11:41598
599 if (pref_name == prefs::kResolveTimezoneByGeolocation &&
600 reason != REASON_ACTIVE_USER_CHANGED) {
601 const bool value = prefs_->GetBoolean(prefs::kResolveTimezoneByGeolocation);
602 if (user_is_owner) {
603 g_browser_process->local_state()->SetBoolean(
604 prefs::kResolveDeviceTimezoneByGeolocation, value);
605 }
606 if (user_is_primary_) {
607 if (value) {
608 g_browser_process->platform_part()->GetTimezoneResolver()->Start();
609 } else {
610 g_browser_process->platform_part()->GetTimezoneResolver()->Stop();
611 if (reason == REASON_PREF_CHANGED) {
612 // Allow immediate timezone update on Stop + Start.
613 g_browser_process->local_state()->ClearPref(
614 TimeZoneResolver::kLastTimeZoneRefreshTime);
615 }
616 }
617 }
618 }
alemate6cf8c6e2015-07-23 06:58:50619
620 if (pref_name == prefs::kUse24HourClock ||
621 reason != REASON_ACTIVE_USER_CHANGED) {
622 const bool value = prefs_->GetBoolean(prefs::kUse24HourClock);
623 user_manager::UserManager::Get()->SetKnownUserBooleanPref(
624 user_->GetUserID(), prefs::kUse24HourClock, value);
625 }
[email protected]fecc1522009-10-15 21:08:29626}
627
[email protected]7f914fd2012-12-20 23:55:25628void Preferences::OnIsSyncingChanged() {
629 DVLOG(1) << "OnIsSyncingChanged";
630 ForceNaturalScrollDefault();
631}
632
633void Preferences::ForceNaturalScrollDefault() {
634 DVLOG(1) << "ForceNaturalScrollDefault";
avi3ef9ec9e2014-12-22 22:50:17635 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
[email protected]bbd08262013-10-30 09:04:27636 switches::kNaturalScrollDefault) &&
avi3ef9ec9e2014-12-22 22:50:17637 prefs_->IsSyncing() && !prefs_->GetUserPrefValue(prefs::kNaturalScroll)) {
[email protected]7f914fd2012-12-20 23:55:25638 DVLOG(1) << "Natural scroll forced to true";
639 natural_scroll_.SetValue(true);
640 UMA_HISTOGRAM_BOOLEAN("Touchpad.NaturalScroll.Forced", true);
641 }
642}
643
[email protected]d01bb8072010-04-12 13:00:15644void Preferences::SetLanguageConfigStringListAsCSV(const char* section,
645 const char* name,
[email protected]ddd231e2010-06-29 20:35:19646 const std::string& value) {
[email protected]e24c2c92010-10-23 01:39:24647 VLOG(1) << "Setting " << name << " to '" << value << "'";
[email protected]d01bb8072010-04-12 13:00:15648
[email protected]ddd231e2010-06-29 20:35:19649 std::vector<std::string> split_values;
brettwc6f82b12015-07-21 21:37:38650 if (!value.empty()) {
651 split_values = base::SplitString(value, ",", base::TRIM_WHITESPACE,
652 base::SPLIT_WANT_ALL);
653 }
[email protected]ddd231e2010-06-29 20:35:19654
[email protected]b071452e2014-06-02 19:17:12655 // Transfers the xkb id to extension-xkb id.
656 if (input_method_manager_->MigrateInputMethods(&split_values))
brettwd94a22142015-07-15 05:19:26657 preload_engines_.SetValue(base::JoinString(split_values, ","));
[email protected]fdcd4412014-03-05 06:01:58658
[email protected]7f132d02013-01-03 00:32:26659 if (section == std::string(language_prefs::kGeneralSectionName) &&
660 name == std::string(language_prefs::kPreloadEnginesConfigName)) {
[email protected]f0881cf2014-08-15 23:31:42661 ime_state_->ReplaceEnabledInputMethods(split_values);
[email protected]dbc9b192012-04-18 05:55:34662 return;
663 }
[email protected]70aa5b32010-04-05 08:30:34664}
665
[email protected]2c62b3f2012-04-12 12:07:50666void Preferences::SetInputMethodList() {
667 // When |preload_engines_| are set, InputMethodManager::ChangeInputMethod()
668 // might be called to change the current input method to the first one in the
669 // |preload_engines_| list. This also updates previous/current input method
670 // prefs. That's why GetValue() calls are placed before the
671 // SetLanguageConfigStringListAsCSV() call below.
672 const std::string previous_input_method_id =
673 previous_input_method_.GetValue();
674 const std::string current_input_method_id = current_input_method_.GetValue();
[email protected]7f132d02013-01-03 00:32:26675 SetLanguageConfigStringListAsCSV(language_prefs::kGeneralSectionName,
676 language_prefs::kPreloadEnginesConfigName,
[email protected]2c62b3f2012-04-12 12:07:50677 preload_engines_.GetValue());
678
679 // ChangeInputMethod() has to be called AFTER the value of |preload_engines_|
680 // is sent to the InputMethodManager. Otherwise, the ChangeInputMethod request
681 // might be ignored as an invalid input method ID. The ChangeInputMethod()
682 // calls are also necessary to restore the previous/current input method prefs
683 // which could have been modified by the SetLanguageConfigStringListAsCSV call
684 // above to the original state.
685 if (!previous_input_method_id.empty())
[email protected]f0881cf2014-08-15 23:31:42686 ime_state_->ChangeInputMethod(previous_input_method_id,
687 false /* show_message */);
[email protected]2c62b3f2012-04-12 12:07:50688 if (!current_input_method_id.empty())
[email protected]f0881cf2014-08-15 23:31:42689 ime_state_->ChangeInputMethod(current_input_method_id,
690 false /* show_message */);
[email protected]2c62b3f2012-04-12 12:07:50691}
692
[email protected]a995b392010-08-11 04:38:59693void Preferences::UpdateAutoRepeatRate() {
[email protected]c010f632011-04-01 06:44:39694 input_method::AutoRepeatRate rate;
[email protected]c67a30932012-03-14 05:23:00695 rate.initial_delay_in_ms = xkb_auto_repeat_delay_pref_.GetValue();
696 rate.repeat_interval_in_ms = xkb_auto_repeat_interval_pref_.GetValue();
[email protected]a995b392010-08-11 04:38:59697 DCHECK(rate.initial_delay_in_ms > 0);
698 DCHECK(rate.repeat_interval_in_ms > 0);
[email protected]fbb141a2014-04-11 13:25:52699 input_method::InputMethodManager::Get()
700 ->GetImeKeyboard()
[email protected]b4d95fb2014-02-12 14:48:07701 ->SetAutoRepeatRate(rate);
[email protected]a995b392010-08-11 04:38:59702}
703
[email protected]d141b922013-07-09 08:13:17704void Preferences::OnTouchHudProjectionToggled(bool enabled) {
705 if (touch_hud_projection_enabled_.GetValue() == enabled)
706 return;
[email protected]aa003a52014-02-15 06:24:23707 if (!user_->is_active())
708 return;
[email protected]d141b922013-07-09 08:13:17709 touch_hud_projection_enabled_.SetValue(enabled);
710}
711
[email protected]2fda9972014-07-23 14:51:59712void Preferences::ActiveUserChanged(const user_manager::User* active_user) {
[email protected]aa003a52014-02-15 06:24:23713 if (active_user != user_)
714 return;
715 ApplyPreferences(REASON_ACTIVE_USER_CHANGED, "");
716}
717
[email protected]fecc1522009-10-15 21:08:29718} // namespace chromeos