1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/chromeos/preferences.h"
9 #include "ash/autoclick/autoclick_controller.h"
10 #include "ash/shell.h"
11 #include "base/command_line.h"
12 #include "base/i18n/time_formatting.h"
13 #include "base/metrics/histogram.h"
14 #include "base/prefs/pref_member.h"
15 #include "base/prefs/pref_registry_simple.h"
16 #include "base/prefs/scoped_user_pref_update.h"
17 #include "base/strings/string_split.h"
18 #include "base/strings/string_util.h"
19 #include "base/strings/utf_string_conversions.h"
20 #include "base/sys_info.h"
21 #include "chrome/browser/browser_process.h"
22 #include "chrome/browser/chrome_notification_types.h"
23 #include "chrome/browser/chromeos/accessibility/magnification_manager.h"
24 #include "chrome/browser/chromeos/drive/file_system_util.h"
25 #include "chrome/browser/chromeos/input_method/input_method_syncer.h"
26 #include "chrome/browser/chromeos/login/session/user_session_manager.h"
27 #include "chrome/browser/chromeos/net/wake_on_wifi_manager.h"
28 #include "chrome/browser/chromeos/system/input_device_settings.h"
29 #include "chrome/browser/download/download_prefs.h"
30 #include "chrome/browser/prefs/pref_service_syncable.h"
31 #include "chrome/common/chrome_switches.h"
32 #include "chrome/common/pref_names.h"
33 #include "chromeos/chromeos_switches.h"
34 #include "chromeos/system/statistics_provider.h"
35 #include "chromeos/timezone/timezone_resolver.h"
36 #include "components/drive/drive_pref_names.h"
37 #include "components/feedback/tracing_manager.h"
38 #include "components/pref_registry/pref_registry_syncable.h"
39 #include "components/user_manager/user.h"
40 #include "content/public/browser/browser_thread.h"
41 #include "third_party/icu/source/i18n/unicode/timezone.h"
42 #include "ui/base/ime/chromeos/extension_ime_util.h"
43 #include "ui/base/ime/chromeos/ime_keyboard.h"
44 #include "ui/base/ime/chromeos/input_method_manager.h"
45 #include "ui/chromeos/accessibility_types.h"
46 #include "ui/events/event_constants.h"
47 #include "ui/events/event_utils.h"
52 static const char kFallbackInputMethodLocale
[] = "en-US";
54 Preferences::Preferences()
56 input_method_manager_(input_method::InputMethodManager::Get()),
58 user_is_primary_(false) {
59 // Do not observe shell, if there is no shell instance; e.g., in some unit
61 if (ash::Shell::HasInstance())
62 ash::Shell::GetInstance()->AddShellObserver(this);
65 Preferences::Preferences(input_method::InputMethodManager
* input_method_manager
)
67 input_method_manager_(input_method_manager
),
69 user_is_primary_(false) {
70 // Do not observe shell, if there is no shell instance; e.g., in some unit
72 if (ash::Shell::HasInstance())
73 ash::Shell::GetInstance()->AddShellObserver(this);
76 Preferences::~Preferences() {
77 prefs_
->RemoveObserver(this);
78 user_manager::UserManager::Get()->RemoveSessionStateObserver(this);
79 // If shell instance is destoryed before this preferences instance, there is
80 // no need to remove this shell observer.
81 if (ash::Shell::HasInstance())
82 ash::Shell::GetInstance()->RemoveShellObserver(this);
86 void Preferences::RegisterPrefs(PrefRegistrySimple
* registry
) {
87 registry
->RegisterBooleanPref(prefs::kOwnerPrimaryMouseButtonRight
, false);
88 registry
->RegisterBooleanPref(prefs::kOwnerTapToClickEnabled
, true);
89 registry
->RegisterBooleanPref(prefs::kAccessibilityVirtualKeyboardEnabled
,
91 registry
->RegisterStringPref(prefs::kLogoutStartedLast
, std::string());
92 registry
->RegisterBooleanPref(prefs::kResolveDeviceTimezoneByGeolocation
,
97 void Preferences::RegisterProfilePrefs(
98 user_prefs::PrefRegistrySyncable
* registry
) {
99 std::string hardware_keyboard_id
;
100 // TODO(yusukes): Remove the runtime hack.
101 if (base::SysInfo::IsRunningOnChromeOS()) {
102 DCHECK(g_browser_process
);
103 PrefService
* local_state
= g_browser_process
->local_state();
105 hardware_keyboard_id
=
106 local_state
->GetString(prefs::kHardwareKeyboardLayout
);
108 hardware_keyboard_id
= "xkb:us::eng"; // only for testing.
111 registry
->RegisterBooleanPref(prefs::kPerformanceTracingEnabled
, false);
113 registry
->RegisterBooleanPref(
114 prefs::kTapToClickEnabled
,
116 user_prefs::PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF
);
117 registry
->RegisterBooleanPref(
118 prefs::kTapDraggingEnabled
,
120 user_prefs::PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF
);
121 registry
->RegisterBooleanPref(prefs::kEnableTouchpadThreeFingerClick
, false);
122 registry
->RegisterBooleanPref(
123 prefs::kNaturalScroll
, base::CommandLine::ForCurrentProcess()->HasSwitch(
124 switches::kNaturalScrollDefault
),
125 user_prefs::PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF
);
126 registry
->RegisterBooleanPref(
127 prefs::kPrimaryMouseButtonRight
,
129 user_prefs::PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF
);
130 registry
->RegisterBooleanPref(prefs::kLabsMediaplayerEnabled
, false);
131 registry
->RegisterBooleanPref(prefs::kLabsAdvancedFilesystemEnabled
, false);
132 registry
->RegisterBooleanPref(
133 prefs::kAccessibilityStickyKeysEnabled
,
135 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
136 registry
->RegisterBooleanPref(
137 prefs::kAccessibilityLargeCursorEnabled
,
139 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
140 registry
->RegisterBooleanPref(prefs::kAccessibilitySpokenFeedbackEnabled
,
142 registry
->RegisterBooleanPref(
143 prefs::kAccessibilityHighContrastEnabled
,
145 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
146 registry
->RegisterBooleanPref(
147 prefs::kAccessibilityScreenMagnifierCenterFocus
,
149 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
150 registry
->RegisterBooleanPref(
151 prefs::kAccessibilityScreenMagnifierEnabled
, false,
152 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
153 registry
->RegisterIntegerPref(
154 prefs::kAccessibilityScreenMagnifierType
,
155 ui::kDefaultMagnifierType
,
156 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
157 registry
->RegisterDoublePref(prefs::kAccessibilityScreenMagnifierScale
,
158 std::numeric_limits
<double>::min());
159 registry
->RegisterBooleanPref(
160 prefs::kAccessibilityAutoclickEnabled
,
162 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
163 registry
->RegisterIntegerPref(
164 prefs::kAccessibilityAutoclickDelayMs
,
165 ash::AutoclickController::kDefaultAutoclickDelayMs
,
166 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
167 registry
->RegisterBooleanPref(
168 prefs::kAccessibilityVirtualKeyboardEnabled
,
170 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
171 registry
->RegisterBooleanPref(
172 prefs::kShouldAlwaysShowAccessibilityMenu
,
174 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
175 registry
->RegisterIntegerPref(
176 prefs::kMouseSensitivity
,
178 user_prefs::PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF
);
179 registry
->RegisterIntegerPref(
180 prefs::kTouchpadSensitivity
,
182 user_prefs::PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF
);
183 registry
->RegisterBooleanPref(
184 prefs::kUse24HourClock
,
185 base::GetHourClockType() == base::k24HourClock
,
186 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
187 registry
->RegisterBooleanPref(
188 drive::prefs::kDisableDrive
, false,
189 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
190 registry
->RegisterBooleanPref(
191 drive::prefs::kDisableDriveOverCellular
, true,
192 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
193 registry
->RegisterBooleanPref(
194 drive::prefs::kDisableDriveHostedFiles
, false,
195 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
196 // We don't sync prefs::kLanguageCurrentInputMethod and PreviousInputMethod
197 // because they're just used to track the logout state of the device.
198 registry
->RegisterStringPref(prefs::kLanguageCurrentInputMethod
, "");
199 registry
->RegisterStringPref(prefs::kLanguagePreviousInputMethod
, "");
200 registry
->RegisterStringPref(prefs::kLanguagePreferredLanguages
,
201 kFallbackInputMethodLocale
);
202 registry
->RegisterStringPref(prefs::kLanguagePreloadEngines
,
203 hardware_keyboard_id
);
204 registry
->RegisterStringPref(prefs::kLanguageEnabledExtensionImes
, "");
206 registry
->RegisterIntegerPref(
207 prefs::kLanguageRemapSearchKeyTo
,
208 input_method::kSearchKey
,
209 user_prefs::PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF
);
210 registry
->RegisterIntegerPref(
211 prefs::kLanguageRemapControlKeyTo
,
212 input_method::kControlKey
,
213 user_prefs::PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF
);
214 registry
->RegisterIntegerPref(
215 prefs::kLanguageRemapAltKeyTo
,
216 input_method::kAltKey
,
217 user_prefs::PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF
);
218 // We don't sync the CapsLock remapping pref, since the UI hides this pref
219 // on certain devices, so syncing a non-default value to a device that
220 // doesn't allow changing the pref would be odd. http://crbug.com/167237
221 registry
->RegisterIntegerPref(prefs::kLanguageRemapCapsLockKeyTo
,
222 input_method::kCapsLockKey
);
223 registry
->RegisterIntegerPref(
224 prefs::kLanguageRemapDiamondKeyTo
,
225 input_method::kControlKey
,
226 user_prefs::PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF
);
227 // The following pref isn't synced since the user may desire a different value
228 // depending on whether an external keyboard is attached to a particular
230 registry
->RegisterBooleanPref(prefs::kLanguageSendFunctionKeys
, false);
231 registry
->RegisterBooleanPref(
232 prefs::kLanguageXkbAutoRepeatEnabled
,
234 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
235 registry
->RegisterIntegerPref(
236 prefs::kLanguageXkbAutoRepeatDelay
,
237 language_prefs::kXkbAutoRepeatDelayInMs
,
238 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
239 registry
->RegisterIntegerPref(
240 prefs::kLanguageXkbAutoRepeatInterval
,
241 language_prefs::kXkbAutoRepeatIntervalInMs
,
242 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
244 // We don't sync wake-on-wifi related prefs because they are device specific.
245 registry
->RegisterBooleanPref(prefs::kWakeOnWifiSsid
, true);
247 // 3G first-time usage promo will be shown at least once.
248 registry
->RegisterBooleanPref(prefs::kShow3gPromoNotification
, true);
250 // Number of times Data Saver prompt has been shown on 3G data network.
251 registry
->RegisterIntegerPref(
252 prefs::kDataSaverPromptsShown
,
254 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
256 // Initially all existing users would see "What's new" for current version
258 registry
->RegisterStringPref(prefs::kChromeOSReleaseNotesVersion
,
260 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
262 registry
->RegisterBooleanPref(prefs::kExternalStorageDisabled
, false);
264 registry
->RegisterStringPref(prefs::kTermsOfServiceURL
, "");
266 registry
->RegisterBooleanPref(prefs::kTouchHudProjectionEnabled
, false);
268 registry
->RegisterBooleanPref(prefs::kTouchVirtualKeyboardEnabled
, false);
270 input_method::InputMethodSyncer::RegisterProfilePrefs(registry
);
272 registry
->RegisterBooleanPref(
273 prefs::kResolveTimezoneByGeolocation
, true,
274 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
276 registry
->RegisterBooleanPref(prefs::kCaptivePortalAuthenticationIgnoresProxy
,
279 registry
->RegisterBooleanPref(prefs::kForceMaximizeOnFirstRun
, false);
282 void Preferences::InitUserPrefs(PrefServiceSyncable
* prefs
) {
285 BooleanPrefMember::NamedChangeCallback callback
=
286 base::Bind(&Preferences::OnPreferenceChanged
, base::Unretained(this));
288 performance_tracing_enabled_
.Init(prefs::kPerformanceTracingEnabled
,
290 tap_to_click_enabled_
.Init(prefs::kTapToClickEnabled
, prefs
, callback
);
291 tap_dragging_enabled_
.Init(prefs::kTapDraggingEnabled
, prefs
, callback
);
292 three_finger_click_enabled_
.Init(prefs::kEnableTouchpadThreeFingerClick
,
294 natural_scroll_
.Init(prefs::kNaturalScroll
, prefs
, callback
);
295 mouse_sensitivity_
.Init(prefs::kMouseSensitivity
, prefs
, callback
);
296 touchpad_sensitivity_
.Init(prefs::kTouchpadSensitivity
, prefs
, callback
);
297 primary_mouse_button_right_
.Init(prefs::kPrimaryMouseButtonRight
,
299 download_default_directory_
.Init(prefs::kDownloadDefaultDirectory
,
301 touch_hud_projection_enabled_
.Init(prefs::kTouchHudProjectionEnabled
,
303 preload_engines_
.Init(prefs::kLanguagePreloadEngines
, prefs
, callback
);
304 enabled_extension_imes_
.Init(prefs::kLanguageEnabledExtensionImes
,
306 current_input_method_
.Init(prefs::kLanguageCurrentInputMethod
,
308 previous_input_method_
.Init(prefs::kLanguagePreviousInputMethod
,
311 xkb_auto_repeat_enabled_
.Init(
312 prefs::kLanguageXkbAutoRepeatEnabled
, prefs
, callback
);
313 xkb_auto_repeat_delay_pref_
.Init(
314 prefs::kLanguageXkbAutoRepeatDelay
, prefs
, callback
);
315 xkb_auto_repeat_interval_pref_
.Init(
316 prefs::kLanguageXkbAutoRepeatInterval
, prefs
, callback
);
318 wake_on_wifi_ssid_
.Init(prefs::kWakeOnWifiSsid
, prefs
, callback
);
320 pref_change_registrar_
.Init(prefs
);
321 pref_change_registrar_
.Add(prefs::kResolveTimezoneByGeolocation
, callback
);
322 pref_change_registrar_
.Add(prefs::kUse24HourClock
, callback
);
325 void Preferences::Init(Profile
* profile
, const user_manager::User
* user
) {
328 PrefServiceSyncable
* prefs
= PrefServiceSyncable::FromProfile(profile
);
329 // This causes OnIsSyncingChanged to be called when the value of
330 // PrefService::IsSyncing() changes.
331 prefs
->AddObserver(this);
334 user_manager::UserManager::Get()->GetPrimaryUser() == user_
;
335 InitUserPrefs(prefs
);
337 user_manager::UserManager::Get()->AddSessionStateObserver(this);
339 UserSessionManager
* session_manager
= UserSessionManager::GetInstance();
340 DCHECK(session_manager
);
341 ime_state_
= session_manager
->GetDefaultIMEState(profile
);
343 // Initialize preferences to currently saved state.
344 ApplyPreferences(REASON_INITIALIZATION
, "");
346 // Note that |ime_state_| was modified by ApplyPreferences(), and
347 // SetState() is modifying |current_input_method_| (via
348 // PersistUserInputMethod() ). This way SetState() here may be called only
349 // after ApplyPreferences().
350 input_method_manager_
->SetState(ime_state_
);
352 input_method_syncer_
.reset(
353 new input_method::InputMethodSyncer(prefs
, ime_state_
));
354 input_method_syncer_
->Initialize();
356 // If a guest is logged in, initialize the prefs as if this is the first
357 // login. For a regular user this is done in
358 // UserSessionManager::InitProfilePreferences().
359 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
360 switches::kGuestSession
))
361 session_manager
->SetFirstLoginPrefs(profile
, std::string(), std::string());
364 void Preferences::InitUserPrefsForTesting(
365 PrefServiceSyncable
* prefs
,
366 const user_manager::User
* user
,
367 scoped_refptr
<input_method::InputMethodManager::State
> ime_state
) {
369 ime_state_
= ime_state
;
372 input_method_manager_
->SetState(ime_state
);
374 InitUserPrefs(prefs
);
376 input_method_syncer_
.reset(
377 new input_method::InputMethodSyncer(prefs
, ime_state_
));
378 input_method_syncer_
->Initialize();
381 void Preferences::SetInputMethodListForTesting() {
382 SetInputMethodList();
385 void Preferences::OnPreferenceChanged(const std::string
& pref_name
) {
386 ApplyPreferences(REASON_PREF_CHANGED
, pref_name
);
389 void Preferences::ApplyPreferences(ApplyReason reason
,
390 const std::string
& pref_name
) {
391 DCHECK(reason
!= REASON_PREF_CHANGED
|| !pref_name
.empty());
392 const bool user_is_owner
=
393 user_manager::UserManager::Get()->GetOwnerEmail() == user_
->email();
394 const bool user_is_active
= user_
->is_active();
396 system::TouchpadSettings touchpad_settings
;
397 system::MouseSettings mouse_settings
;
399 if (user_is_primary_
&& (reason
== REASON_INITIALIZATION
||
400 pref_name
== prefs::kPerformanceTracingEnabled
)) {
401 const bool enabled
= performance_tracing_enabled_
.GetValue();
403 tracing_manager_
= TracingManager::Create();
405 tracing_manager_
.reset();
407 if (reason
!= REASON_PREF_CHANGED
|| pref_name
== prefs::kTapToClickEnabled
) {
408 const bool enabled
= tap_to_click_enabled_
.GetValue();
410 touchpad_settings
.SetTapToClick(enabled
);
411 if (reason
== REASON_PREF_CHANGED
)
412 UMA_HISTOGRAM_BOOLEAN("Touchpad.TapToClick.Changed", enabled
);
413 else if (reason
== REASON_INITIALIZATION
)
414 UMA_HISTOGRAM_BOOLEAN("Touchpad.TapToClick.Started", enabled
);
416 // Save owner preference in local state to use on login screen.
418 PrefService
* prefs
= g_browser_process
->local_state();
419 if (prefs
->GetBoolean(prefs::kOwnerTapToClickEnabled
) != enabled
)
420 prefs
->SetBoolean(prefs::kOwnerTapToClickEnabled
, enabled
);
423 if (reason
!= REASON_PREF_CHANGED
||
424 pref_name
== prefs::kTapDraggingEnabled
) {
425 const bool enabled
= tap_dragging_enabled_
.GetValue();
427 touchpad_settings
.SetTapDragging(enabled
);
428 if (reason
== REASON_PREF_CHANGED
)
429 UMA_HISTOGRAM_BOOLEAN("Touchpad.TapDragging.Changed", enabled
);
430 else if (reason
== REASON_INITIALIZATION
)
431 UMA_HISTOGRAM_BOOLEAN("Touchpad.TapDragging.Started", enabled
);
433 if (reason
!= REASON_PREF_CHANGED
||
434 pref_name
== prefs::kEnableTouchpadThreeFingerClick
) {
435 const bool enabled
= three_finger_click_enabled_
.GetValue();
437 touchpad_settings
.SetThreeFingerClick(enabled
);
438 if (reason
== REASON_PREF_CHANGED
)
439 UMA_HISTOGRAM_BOOLEAN("Touchpad.ThreeFingerClick.Changed", enabled
);
440 else if (reason
== REASON_INITIALIZATION
)
441 UMA_HISTOGRAM_BOOLEAN("Touchpad.ThreeFingerClick.Started", enabled
);
443 if (reason
!= REASON_PREF_CHANGED
|| pref_name
== prefs::kNaturalScroll
) {
444 // Force natural scroll default if we've sync'd and if the cmd line arg is
446 ForceNaturalScrollDefault();
448 const bool enabled
= natural_scroll_
.GetValue();
449 DVLOG(1) << "Natural scroll set to " << enabled
;
451 touchpad_settings
.SetNaturalScroll(enabled
);
452 if (reason
== REASON_PREF_CHANGED
)
453 UMA_HISTOGRAM_BOOLEAN("Touchpad.NaturalScroll.Changed", enabled
);
454 else if (reason
== REASON_INITIALIZATION
)
455 UMA_HISTOGRAM_BOOLEAN("Touchpad.NaturalScroll.Started", enabled
);
457 if (reason
!= REASON_PREF_CHANGED
|| pref_name
== prefs::kMouseSensitivity
) {
458 const int sensitivity
= mouse_sensitivity_
.GetValue();
460 mouse_settings
.SetSensitivity(sensitivity
);
461 if (reason
== REASON_PREF_CHANGED
) {
462 UMA_HISTOGRAM_ENUMERATION("Mouse.PointerSensitivity.Changed",
464 system::kMaxPointerSensitivity
+ 1);
465 } else if (reason
== REASON_INITIALIZATION
) {
466 UMA_HISTOGRAM_ENUMERATION("Mouse.PointerSensitivity.Started",
468 system::kMaxPointerSensitivity
+ 1);
471 if (reason
!= REASON_PREF_CHANGED
||
472 pref_name
== prefs::kTouchpadSensitivity
) {
473 const int sensitivity
= touchpad_sensitivity_
.GetValue();
475 touchpad_settings
.SetSensitivity(sensitivity
);
476 if (reason
== REASON_PREF_CHANGED
) {
477 UMA_HISTOGRAM_ENUMERATION("Touchpad.PointerSensitivity.Changed",
479 system::kMaxPointerSensitivity
+ 1);
480 } else if (reason
== REASON_INITIALIZATION
) {
481 UMA_HISTOGRAM_ENUMERATION("Touchpad.PointerSensitivity.Started",
483 system::kMaxPointerSensitivity
+ 1);
486 if (reason
!= REASON_PREF_CHANGED
||
487 pref_name
== prefs::kPrimaryMouseButtonRight
) {
488 const bool right
= primary_mouse_button_right_
.GetValue();
490 mouse_settings
.SetPrimaryButtonRight(right
);
491 if (reason
== REASON_PREF_CHANGED
)
492 UMA_HISTOGRAM_BOOLEAN("Mouse.PrimaryButtonRight.Changed", right
);
493 else if (reason
== REASON_INITIALIZATION
)
494 UMA_HISTOGRAM_BOOLEAN("Mouse.PrimaryButtonRight.Started", right
);
495 // Save owner preference in local state to use on login screen.
497 PrefService
* prefs
= g_browser_process
->local_state();
498 if (prefs
->GetBoolean(prefs::kOwnerPrimaryMouseButtonRight
) != right
)
499 prefs
->SetBoolean(prefs::kOwnerPrimaryMouseButtonRight
, right
);
502 if (reason
!= REASON_PREF_CHANGED
||
503 pref_name
== prefs::kDownloadDefaultDirectory
) {
504 const bool default_download_to_drive
= drive::util::IsUnderDriveMountPoint(
505 download_default_directory_
.GetValue());
506 if (reason
== REASON_PREF_CHANGED
)
507 UMA_HISTOGRAM_BOOLEAN(
508 "FileBrowser.DownloadDestination.IsGoogleDrive.Changed",
509 default_download_to_drive
);
510 else if (reason
== REASON_INITIALIZATION
)
511 UMA_HISTOGRAM_BOOLEAN(
512 "FileBrowser.DownloadDestination.IsGoogleDrive.Started",
513 default_download_to_drive
);
515 if (reason
!= REASON_PREF_CHANGED
||
516 pref_name
== prefs::kTouchHudProjectionEnabled
) {
517 if (user_is_active
) {
518 const bool enabled
= touch_hud_projection_enabled_
.GetValue();
519 // There may not be a shell, e.g., in some unit tests.
520 if (ash::Shell::HasInstance())
521 ash::Shell::GetInstance()->SetTouchHudProjectionEnabled(enabled
);
525 if (reason
!= REASON_PREF_CHANGED
||
526 pref_name
== prefs::kLanguageXkbAutoRepeatEnabled
) {
527 if (user_is_active
) {
528 const bool enabled
= xkb_auto_repeat_enabled_
.GetValue();
529 input_method::InputMethodManager::Get()
531 ->SetAutoRepeatEnabled(enabled
);
534 if (reason
!= REASON_PREF_CHANGED
||
535 pref_name
== prefs::kLanguageXkbAutoRepeatDelay
||
536 pref_name
== prefs::kLanguageXkbAutoRepeatInterval
) {
538 UpdateAutoRepeatRate();
541 if (reason
== REASON_INITIALIZATION
)
542 SetInputMethodList();
544 if (pref_name
== prefs::kLanguagePreloadEngines
&&
545 reason
== REASON_PREF_CHANGED
) {
546 SetLanguageConfigStringListAsCSV(language_prefs::kGeneralSectionName
,
547 language_prefs::kPreloadEnginesConfigName
,
548 preload_engines_
.GetValue());
551 if ((reason
== REASON_INITIALIZATION
) ||
552 (pref_name
== prefs::kLanguageEnabledExtensionImes
&&
553 reason
== REASON_PREF_CHANGED
)) {
554 std::string
value(enabled_extension_imes_
.GetValue());
556 std::vector
<std::string
> split_values
;
557 if (!value
.empty()) {
558 split_values
= base::SplitString(value
, ",", base::TRIM_WHITESPACE
,
559 base::SPLIT_WANT_ALL
);
561 ime_state_
->SetEnabledExtensionImes(&split_values
);
564 if (user_is_active
) {
565 system::InputDeviceSettings::Get()->UpdateTouchpadSettings(
567 system::InputDeviceSettings::Get()->UpdateMouseSettings(mouse_settings
);
570 if (user_is_primary_
&& (reason
!= REASON_PREF_CHANGED
||
571 pref_name
== prefs::kWakeOnWifiSsid
)) {
572 int features
= wake_on_wifi_ssid_
.GetValue() ?
573 WakeOnWifiManager::WAKE_ON_SSID
: WakeOnWifiManager::WAKE_ON_NONE
;
574 // The flag enables wake on packets but doesn't update a preference.
575 if (base::CommandLine::ForCurrentProcess()->
576 HasSwitch(switches::kWakeOnPackets
)) {
577 features
|= WakeOnWifiManager::WAKE_ON_PACKET
;
579 WakeOnWifiManager::Get()->OnPreferenceChanged(
580 static_cast<WakeOnWifiManager::WakeOnWifiFeature
>(features
));
583 if (pref_name
== prefs::kResolveTimezoneByGeolocation
&&
584 reason
!= REASON_ACTIVE_USER_CHANGED
) {
585 const bool value
= prefs_
->GetBoolean(prefs::kResolveTimezoneByGeolocation
);
587 g_browser_process
->local_state()->SetBoolean(
588 prefs::kResolveDeviceTimezoneByGeolocation
, value
);
590 if (user_is_primary_
) {
592 g_browser_process
->platform_part()->GetTimezoneResolver()->Start();
594 g_browser_process
->platform_part()->GetTimezoneResolver()->Stop();
595 if (reason
== REASON_PREF_CHANGED
) {
596 // Allow immediate timezone update on Stop + Start.
597 g_browser_process
->local_state()->ClearPref(
598 TimeZoneResolver::kLastTimeZoneRefreshTime
);
604 if (pref_name
== prefs::kUse24HourClock
||
605 reason
!= REASON_ACTIVE_USER_CHANGED
) {
606 const bool value
= prefs_
->GetBoolean(prefs::kUse24HourClock
);
607 user_manager::UserManager::Get()->SetKnownUserBooleanPref(
608 user_
->GetUserID(), prefs::kUse24HourClock
, value
);
612 void Preferences::OnIsSyncingChanged() {
613 DVLOG(1) << "OnIsSyncingChanged";
614 ForceNaturalScrollDefault();
617 void Preferences::ForceNaturalScrollDefault() {
618 DVLOG(1) << "ForceNaturalScrollDefault";
619 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
620 switches::kNaturalScrollDefault
) &&
621 prefs_
->IsSyncing() && !prefs_
->GetUserPrefValue(prefs::kNaturalScroll
)) {
622 DVLOG(1) << "Natural scroll forced to true";
623 natural_scroll_
.SetValue(true);
624 UMA_HISTOGRAM_BOOLEAN("Touchpad.NaturalScroll.Forced", true);
628 void Preferences::SetLanguageConfigStringListAsCSV(const char* section
,
630 const std::string
& value
) {
631 VLOG(1) << "Setting " << name
<< " to '" << value
<< "'";
633 std::vector
<std::string
> split_values
;
634 if (!value
.empty()) {
635 split_values
= base::SplitString(value
, ",", base::TRIM_WHITESPACE
,
636 base::SPLIT_WANT_ALL
);
639 // Transfers the xkb id to extension-xkb id.
640 if (input_method_manager_
->MigrateInputMethods(&split_values
))
641 preload_engines_
.SetValue(base::JoinString(split_values
, ","));
643 if (section
== std::string(language_prefs::kGeneralSectionName
) &&
644 name
== std::string(language_prefs::kPreloadEnginesConfigName
)) {
645 ime_state_
->ReplaceEnabledInputMethods(split_values
);
650 void Preferences::SetInputMethodList() {
651 // When |preload_engines_| are set, InputMethodManager::ChangeInputMethod()
652 // might be called to change the current input method to the first one in the
653 // |preload_engines_| list. This also updates previous/current input method
654 // prefs. That's why GetValue() calls are placed before the
655 // SetLanguageConfigStringListAsCSV() call below.
656 const std::string previous_input_method_id
=
657 previous_input_method_
.GetValue();
658 const std::string current_input_method_id
= current_input_method_
.GetValue();
659 SetLanguageConfigStringListAsCSV(language_prefs::kGeneralSectionName
,
660 language_prefs::kPreloadEnginesConfigName
,
661 preload_engines_
.GetValue());
663 // ChangeInputMethod() has to be called AFTER the value of |preload_engines_|
664 // is sent to the InputMethodManager. Otherwise, the ChangeInputMethod request
665 // might be ignored as an invalid input method ID. The ChangeInputMethod()
666 // calls are also necessary to restore the previous/current input method prefs
667 // which could have been modified by the SetLanguageConfigStringListAsCSV call
668 // above to the original state.
669 if (!previous_input_method_id
.empty())
670 ime_state_
->ChangeInputMethod(previous_input_method_id
,
671 false /* show_message */);
672 if (!current_input_method_id
.empty())
673 ime_state_
->ChangeInputMethod(current_input_method_id
,
674 false /* show_message */);
677 void Preferences::UpdateAutoRepeatRate() {
678 input_method::AutoRepeatRate rate
;
679 rate
.initial_delay_in_ms
= xkb_auto_repeat_delay_pref_
.GetValue();
680 rate
.repeat_interval_in_ms
= xkb_auto_repeat_interval_pref_
.GetValue();
681 DCHECK(rate
.initial_delay_in_ms
> 0);
682 DCHECK(rate
.repeat_interval_in_ms
> 0);
683 input_method::InputMethodManager::Get()
685 ->SetAutoRepeatRate(rate
);
688 void Preferences::OnTouchHudProjectionToggled(bool enabled
) {
689 if (touch_hud_projection_enabled_
.GetValue() == enabled
)
691 if (!user_
->is_active())
693 touch_hud_projection_enabled_
.SetValue(enabled
);
696 void Preferences::ActiveUserChanged(const user_manager::User
* active_user
) {
697 if (active_user
!= user_
)
699 ApplyPreferences(REASON_ACTIVE_USER_CHANGED
, "");
702 } // namespace chromeos