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_util.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/profiles/profile_helper.h"
29 #include "chrome/browser/chromeos/system/input_device_settings.h"
30 #include "chrome/browser/download/download_prefs.h"
31 #include "chrome/browser/prefs/pref_service_syncable.h"
32 #include "chrome/common/chrome_switches.h"
33 #include "chrome/common/pref_names.h"
34 #include "chromeos/chromeos_switches.h"
35 #include "chromeos/system/statistics_provider.h"
36 #include "components/feedback/tracing_manager.h"
37 #include "components/pref_registry/pref_registry_syncable.h"
38 #include "components/user_manager/user.h"
39 #include "third_party/icu/source/i18n/unicode/timezone.h"
40 #include "ui/base/ime/chromeos/extension_ime_util.h"
41 #include "ui/base/ime/chromeos/ime_keyboard.h"
42 #include "ui/base/ime/chromeos/input_method_manager.h"
43 #include "ui/chromeos/accessibility_types.h"
44 #include "ui/events/event_constants.h"
45 #include "ui/events/event_utils.h"
50 static const char kFallbackInputMethodLocale
[] = "en-US";
52 Preferences::Preferences()
54 input_method_manager_(input_method::InputMethodManager::Get()),
56 user_is_primary_(false) {
57 // Do not observe shell, if there is no shell instance; e.g., in some unit
59 if (ash::Shell::HasInstance())
60 ash::Shell::GetInstance()->AddShellObserver(this);
63 Preferences::Preferences(input_method::InputMethodManager
* input_method_manager
)
65 input_method_manager_(input_method_manager
),
67 user_is_primary_(false) {
68 // Do not observe shell, if there is no shell instance; e.g., in some unit
70 if (ash::Shell::HasInstance())
71 ash::Shell::GetInstance()->AddShellObserver(this);
74 Preferences::~Preferences() {
75 prefs_
->RemoveObserver(this);
76 user_manager::UserManager::Get()->RemoveSessionStateObserver(this);
77 // If shell instance is destoryed before this preferences instance, there is
78 // no need to remove this shell observer.
79 if (ash::Shell::HasInstance())
80 ash::Shell::GetInstance()->RemoveShellObserver(this);
84 void Preferences::RegisterPrefs(PrefRegistrySimple
* registry
) {
85 registry
->RegisterBooleanPref(prefs::kOwnerPrimaryMouseButtonRight
, false);
86 registry
->RegisterBooleanPref(prefs::kOwnerTapToClickEnabled
, true);
87 registry
->RegisterBooleanPref(prefs::kAccessibilityVirtualKeyboardEnabled
,
89 registry
->RegisterStringPref(prefs::kLogoutStartedLast
, std::string());
93 void Preferences::RegisterProfilePrefs(
94 user_prefs::PrefRegistrySyncable
* registry
) {
95 std::string hardware_keyboard_id
;
96 // TODO(yusukes): Remove the runtime hack.
97 if (base::SysInfo::IsRunningOnChromeOS()) {
98 DCHECK(g_browser_process
);
99 PrefService
* local_state
= g_browser_process
->local_state();
101 hardware_keyboard_id
=
102 local_state
->GetString(prefs::kHardwareKeyboardLayout
);
104 hardware_keyboard_id
= "xkb:us::eng"; // only for testing.
107 registry
->RegisterBooleanPref(
108 prefs::kPerformanceTracingEnabled
,
110 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
112 registry
->RegisterBooleanPref(
113 prefs::kTapToClickEnabled
,
115 user_prefs::PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF
);
116 registry
->RegisterBooleanPref(
117 prefs::kTapDraggingEnabled
,
119 user_prefs::PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF
);
120 registry
->RegisterBooleanPref(
121 prefs::kEnableTouchpadThreeFingerClick
,
123 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
124 registry
->RegisterBooleanPref(
125 prefs::kNaturalScroll
,
126 CommandLine::ForCurrentProcess()->HasSwitch(
127 switches::kNaturalScrollDefault
),
128 user_prefs::PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF
);
129 registry
->RegisterBooleanPref(
130 prefs::kPrimaryMouseButtonRight
,
132 user_prefs::PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF
);
133 registry
->RegisterBooleanPref(
134 prefs::kLabsMediaplayerEnabled
,
136 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
137 registry
->RegisterBooleanPref(
138 prefs::kLabsAdvancedFilesystemEnabled
,
140 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
141 registry
->RegisterBooleanPref(
142 prefs::kAccessibilityStickyKeysEnabled
,
144 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
145 registry
->RegisterBooleanPref(
146 prefs::kAccessibilityLargeCursorEnabled
,
148 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
149 registry
->RegisterBooleanPref(
150 prefs::kAccessibilitySpokenFeedbackEnabled
,
152 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
153 registry
->RegisterBooleanPref(
154 prefs::kAccessibilityHighContrastEnabled
,
156 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
157 registry
->RegisterBooleanPref(
158 prefs::kAccessibilityScreenMagnifierEnabled
,
160 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
161 registry
->RegisterIntegerPref(
162 prefs::kAccessibilityScreenMagnifierType
,
163 ui::kDefaultMagnifierType
,
164 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
165 registry
->RegisterDoublePref(
166 prefs::kAccessibilityScreenMagnifierScale
,
167 std::numeric_limits
<double>::min(),
168 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
169 registry
->RegisterBooleanPref(
170 prefs::kAccessibilityAutoclickEnabled
,
172 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
173 registry
->RegisterIntegerPref(
174 prefs::kAccessibilityAutoclickDelayMs
,
175 ash::AutoclickController::kDefaultAutoclickDelayMs
,
176 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
177 registry
->RegisterBooleanPref(
178 prefs::kAccessibilityVirtualKeyboardEnabled
,
180 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
181 registry
->RegisterBooleanPref(
182 prefs::kShouldAlwaysShowAccessibilityMenu
,
184 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
185 registry
->RegisterIntegerPref(
186 prefs::kMouseSensitivity
,
188 user_prefs::PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF
);
189 registry
->RegisterIntegerPref(
190 prefs::kTouchpadSensitivity
,
192 user_prefs::PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF
);
193 registry
->RegisterBooleanPref(
194 prefs::kUse24HourClock
,
195 base::GetHourClockType() == base::k24HourClock
,
196 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
197 registry
->RegisterBooleanPref(
198 prefs::kDisableDrive
,
200 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
201 registry
->RegisterBooleanPref(
202 prefs::kDisableDriveOverCellular
,
204 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
205 registry
->RegisterBooleanPref(
206 prefs::kDisableDriveHostedFiles
,
208 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
209 // We don't sync prefs::kLanguageCurrentInputMethod and PreviousInputMethod
210 // because they're just used to track the logout state of the device.
211 registry
->RegisterStringPref(
212 prefs::kLanguageCurrentInputMethod
,
214 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
215 registry
->RegisterStringPref(
216 prefs::kLanguagePreviousInputMethod
,
218 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
219 // We don't sync the list of input methods and preferred languages since a
220 // user might use two or more devices with different hardware keyboards.
222 registry
->RegisterStringPref(
223 prefs::kLanguagePreferredLanguages
,
224 kFallbackInputMethodLocale
,
225 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
226 registry
->RegisterStringPref(
227 prefs::kLanguagePreloadEngines
,
228 hardware_keyboard_id
,
229 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
230 registry
->RegisterStringPref(
231 prefs::kLanguageEnabledExtensionImes
,
233 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
235 registry
->RegisterIntegerPref(
236 prefs::kLanguageRemapSearchKeyTo
,
237 input_method::kSearchKey
,
238 user_prefs::PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF
);
239 registry
->RegisterIntegerPref(
240 prefs::kLanguageRemapControlKeyTo
,
241 input_method::kControlKey
,
242 user_prefs::PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF
);
243 registry
->RegisterIntegerPref(
244 prefs::kLanguageRemapAltKeyTo
,
245 input_method::kAltKey
,
246 user_prefs::PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF
);
247 // We don't sync the CapsLock remapping pref, since the UI hides this pref
248 // on certain devices, so syncing a non-default value to a device that
249 // doesn't allow changing the pref would be odd. http://crbug.com/167237
250 registry
->RegisterIntegerPref(
251 prefs::kLanguageRemapCapsLockKeyTo
,
252 input_method::kCapsLockKey
,
253 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
254 registry
->RegisterIntegerPref(
255 prefs::kLanguageRemapDiamondKeyTo
,
256 input_method::kControlKey
,
257 user_prefs::PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF
);
258 // The following pref isn't synced since the user may desire a different value
259 // depending on whether an external keyboard is attached to a particular
261 registry
->RegisterBooleanPref(
262 prefs::kLanguageSendFunctionKeys
,
264 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
265 registry
->RegisterBooleanPref(
266 prefs::kLanguageXkbAutoRepeatEnabled
,
268 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
269 registry
->RegisterIntegerPref(
270 prefs::kLanguageXkbAutoRepeatDelay
,
271 language_prefs::kXkbAutoRepeatDelayInMs
,
272 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
273 registry
->RegisterIntegerPref(
274 prefs::kLanguageXkbAutoRepeatInterval
,
275 language_prefs::kXkbAutoRepeatIntervalInMs
,
276 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
278 // We don't sync wake-on-wifi related prefs because they are device specific.
279 // TODO(chirantan): Default this to on when we are ready to launch.
280 registry
->RegisterIntegerPref(
281 prefs::kWakeOnWiFiEnabled
,
282 base::CommandLine::ForCurrentProcess()->HasSwitch(
283 switches::kWakeOnPackets
)
284 ? WakeOnWifiManager::WAKE_ON_PACKET_AND_SSID
285 : WakeOnWifiManager::WAKE_ON_NONE
,
286 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
288 // Mobile plan notifications default to on.
289 registry
->RegisterBooleanPref(
290 prefs::kShowPlanNotifications
,
292 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
294 // 3G first-time usage promo will be shown at least once.
295 registry
->RegisterBooleanPref(
296 prefs::kShow3gPromoNotification
,
298 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
300 // Initially all existing users would see "What's new" for current version
302 registry
->RegisterStringPref(prefs::kChromeOSReleaseNotesVersion
,
304 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF
);
306 registry
->RegisterBooleanPref(
307 prefs::kExternalStorageDisabled
,
309 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
311 registry
->RegisterStringPref(
312 prefs::kTermsOfServiceURL
,
314 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
316 registry
->RegisterBooleanPref(
317 prefs::kTouchHudProjectionEnabled
,
319 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
321 registry
->RegisterBooleanPref(
322 prefs::kTouchVirtualKeyboardEnabled
,
324 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
327 void Preferences::InitUserPrefs(PrefServiceSyncable
* prefs
) {
330 BooleanPrefMember::NamedChangeCallback callback
=
331 base::Bind(&Preferences::OnPreferenceChanged
, base::Unretained(this));
333 performance_tracing_enabled_
.Init(prefs::kPerformanceTracingEnabled
,
335 tap_to_click_enabled_
.Init(prefs::kTapToClickEnabled
, prefs
, callback
);
336 tap_dragging_enabled_
.Init(prefs::kTapDraggingEnabled
, prefs
, callback
);
337 three_finger_click_enabled_
.Init(prefs::kEnableTouchpadThreeFingerClick
,
339 natural_scroll_
.Init(prefs::kNaturalScroll
, prefs
, callback
);
340 mouse_sensitivity_
.Init(prefs::kMouseSensitivity
, prefs
, callback
);
341 touchpad_sensitivity_
.Init(prefs::kTouchpadSensitivity
, prefs
, callback
);
342 primary_mouse_button_right_
.Init(prefs::kPrimaryMouseButtonRight
,
344 download_default_directory_
.Init(prefs::kDownloadDefaultDirectory
,
346 touch_hud_projection_enabled_
.Init(prefs::kTouchHudProjectionEnabled
,
348 preload_engines_
.Init(prefs::kLanguagePreloadEngines
, prefs
, callback
);
349 enabled_extension_imes_
.Init(prefs::kLanguageEnabledExtensionImes
,
351 current_input_method_
.Init(prefs::kLanguageCurrentInputMethod
,
353 previous_input_method_
.Init(prefs::kLanguagePreviousInputMethod
,
356 xkb_auto_repeat_enabled_
.Init(
357 prefs::kLanguageXkbAutoRepeatEnabled
, prefs
, callback
);
358 xkb_auto_repeat_delay_pref_
.Init(
359 prefs::kLanguageXkbAutoRepeatDelay
, prefs
, callback
);
360 xkb_auto_repeat_interval_pref_
.Init(
361 prefs::kLanguageXkbAutoRepeatInterval
, prefs
, callback
);
363 wake_on_wifi_enabled_
.Init(prefs::kWakeOnWiFiEnabled
, prefs
, callback
);
366 void Preferences::Init(Profile
* profile
, const user_manager::User
* user
) {
369 PrefServiceSyncable
* prefs
= PrefServiceSyncable::FromProfile(profile
);
372 user_manager::UserManager::Get()->GetPrimaryUser() == user_
;
373 InitUserPrefs(prefs
);
375 user_manager::UserManager::Get()->AddSessionStateObserver(this);
377 // This causes OnIsSyncingChanged to be called when the value of
378 // PrefService::IsSyncing() changes.
379 prefs
->AddObserver(this);
381 UserSessionManager
* session_manager
= UserSessionManager::GetInstance();
382 DCHECK(session_manager
);
383 ime_state_
= session_manager
->GetDefaultIMEState(profile
);
384 input_method_manager_
->SetState(ime_state_
);
386 // Initialize preferences to currently saved state.
387 ApplyPreferences(REASON_INITIALIZATION
, "");
389 // If a guest is logged in, initialize the prefs as if this is the first
390 // login. For a regular user this is done in
391 // UserSessionManager::InitProfilePreferences().
392 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kGuestSession
))
393 session_manager
->SetFirstLoginPrefs(profile
, std::string(), std::string());
396 void Preferences::InitUserPrefsForTesting(
397 PrefServiceSyncable
* prefs
,
398 const user_manager::User
* user
,
399 scoped_refptr
<input_method::InputMethodManager::State
> ime_state
) {
401 ime_state_
= ime_state
;
404 input_method_manager_
->SetState(ime_state
);
406 InitUserPrefs(prefs
);
409 void Preferences::SetInputMethodListForTesting() {
410 SetInputMethodList();
413 void Preferences::OnPreferenceChanged(const std::string
& pref_name
) {
414 ApplyPreferences(REASON_PREF_CHANGED
, pref_name
);
417 void Preferences::ApplyPreferences(ApplyReason reason
,
418 const std::string
& pref_name
) {
419 DCHECK(reason
!= REASON_PREF_CHANGED
|| !pref_name
.empty());
420 const bool user_is_owner
=
421 user_manager::UserManager::Get()->GetOwnerEmail() == user_
->email();
422 const bool user_is_active
= user_
->is_active();
424 system::TouchpadSettings touchpad_settings
;
425 system::MouseSettings mouse_settings
;
427 if (user_is_primary_
&& (reason
== REASON_INITIALIZATION
||
428 pref_name
== prefs::kPerformanceTracingEnabled
)) {
429 const bool enabled
= performance_tracing_enabled_
.GetValue();
431 tracing_manager_
= TracingManager::Create();
433 tracing_manager_
.reset();
435 if (reason
!= REASON_PREF_CHANGED
|| pref_name
== prefs::kTapToClickEnabled
) {
436 const bool enabled
= tap_to_click_enabled_
.GetValue();
438 touchpad_settings
.SetTapToClick(enabled
);
439 if (reason
== REASON_PREF_CHANGED
)
440 UMA_HISTOGRAM_BOOLEAN("Touchpad.TapToClick.Changed", enabled
);
441 else if (reason
== REASON_INITIALIZATION
)
442 UMA_HISTOGRAM_BOOLEAN("Touchpad.TapToClick.Started", enabled
);
444 // Save owner preference in local state to use on login screen.
446 PrefService
* prefs
= g_browser_process
->local_state();
447 if (prefs
->GetBoolean(prefs::kOwnerTapToClickEnabled
) != enabled
)
448 prefs
->SetBoolean(prefs::kOwnerTapToClickEnabled
, enabled
);
451 if (reason
!= REASON_PREF_CHANGED
||
452 pref_name
== prefs::kTapDraggingEnabled
) {
453 const bool enabled
= tap_dragging_enabled_
.GetValue();
455 touchpad_settings
.SetTapDragging(enabled
);
456 if (reason
== REASON_PREF_CHANGED
)
457 UMA_HISTOGRAM_BOOLEAN("Touchpad.TapDragging.Changed", enabled
);
458 else if (reason
== REASON_INITIALIZATION
)
459 UMA_HISTOGRAM_BOOLEAN("Touchpad.TapDragging.Started", enabled
);
461 if (reason
!= REASON_PREF_CHANGED
||
462 pref_name
== prefs::kEnableTouchpadThreeFingerClick
) {
463 const bool enabled
= three_finger_click_enabled_
.GetValue();
465 touchpad_settings
.SetThreeFingerClick(enabled
);
466 if (reason
== REASON_PREF_CHANGED
)
467 UMA_HISTOGRAM_BOOLEAN("Touchpad.ThreeFingerClick.Changed", enabled
);
468 else if (reason
== REASON_INITIALIZATION
)
469 UMA_HISTOGRAM_BOOLEAN("Touchpad.ThreeFingerClick.Started", enabled
);
471 if (reason
!= REASON_PREF_CHANGED
|| pref_name
== prefs::kNaturalScroll
) {
472 // Force natural scroll default if we've sync'd and if the cmd line arg is
474 ForceNaturalScrollDefault();
476 const bool enabled
= natural_scroll_
.GetValue();
477 DVLOG(1) << "Natural scroll set to " << enabled
;
479 touchpad_settings
.SetNaturalScroll(enabled
);
480 if (reason
== REASON_PREF_CHANGED
)
481 UMA_HISTOGRAM_BOOLEAN("Touchpad.NaturalScroll.Changed", enabled
);
482 else if (reason
== REASON_INITIALIZATION
)
483 UMA_HISTOGRAM_BOOLEAN("Touchpad.NaturalScroll.Started", enabled
);
485 if (reason
!= REASON_PREF_CHANGED
|| pref_name
== prefs::kMouseSensitivity
) {
486 const int sensitivity
= mouse_sensitivity_
.GetValue();
488 mouse_settings
.SetSensitivity(sensitivity
);
489 if (reason
== REASON_PREF_CHANGED
) {
490 UMA_HISTOGRAM_ENUMERATION("Mouse.PointerSensitivity.Changed",
492 system::kMaxPointerSensitivity
+ 1);
493 } else if (reason
== REASON_INITIALIZATION
) {
494 UMA_HISTOGRAM_ENUMERATION("Mouse.PointerSensitivity.Started",
496 system::kMaxPointerSensitivity
+ 1);
499 if (reason
!= REASON_PREF_CHANGED
||
500 pref_name
== prefs::kTouchpadSensitivity
) {
501 const int sensitivity
= touchpad_sensitivity_
.GetValue();
503 touchpad_settings
.SetSensitivity(sensitivity
);
504 if (reason
== REASON_PREF_CHANGED
) {
505 UMA_HISTOGRAM_ENUMERATION("Touchpad.PointerSensitivity.Changed",
507 system::kMaxPointerSensitivity
+ 1);
508 } else if (reason
== REASON_INITIALIZATION
) {
509 UMA_HISTOGRAM_ENUMERATION("Touchpad.PointerSensitivity.Started",
511 system::kMaxPointerSensitivity
+ 1);
514 if (reason
!= REASON_PREF_CHANGED
||
515 pref_name
== prefs::kPrimaryMouseButtonRight
) {
516 const bool right
= primary_mouse_button_right_
.GetValue();
518 mouse_settings
.SetPrimaryButtonRight(right
);
519 if (reason
== REASON_PREF_CHANGED
)
520 UMA_HISTOGRAM_BOOLEAN("Mouse.PrimaryButtonRight.Changed", right
);
521 else if (reason
== REASON_INITIALIZATION
)
522 UMA_HISTOGRAM_BOOLEAN("Mouse.PrimaryButtonRight.Started", right
);
523 // Save owner preference in local state to use on login screen.
525 PrefService
* prefs
= g_browser_process
->local_state();
526 if (prefs
->GetBoolean(prefs::kOwnerPrimaryMouseButtonRight
) != right
)
527 prefs
->SetBoolean(prefs::kOwnerPrimaryMouseButtonRight
, right
);
530 if (reason
!= REASON_PREF_CHANGED
||
531 pref_name
== prefs::kDownloadDefaultDirectory
) {
532 const bool default_download_to_drive
= drive::util::IsUnderDriveMountPoint(
533 download_default_directory_
.GetValue());
534 if (reason
== REASON_PREF_CHANGED
)
535 UMA_HISTOGRAM_BOOLEAN(
536 "FileBrowser.DownloadDestination.IsGoogleDrive.Changed",
537 default_download_to_drive
);
538 else if (reason
== REASON_INITIALIZATION
)
539 UMA_HISTOGRAM_BOOLEAN(
540 "FileBrowser.DownloadDestination.IsGoogleDrive.Started",
541 default_download_to_drive
);
543 if (reason
!= REASON_PREF_CHANGED
||
544 pref_name
== prefs::kTouchHudProjectionEnabled
) {
545 #if !defined(USE_ATHENA)
546 if (user_is_active
) {
547 const bool enabled
= touch_hud_projection_enabled_
.GetValue();
548 ash::Shell::GetInstance()->SetTouchHudProjectionEnabled(enabled
);
553 if (reason
!= REASON_PREF_CHANGED
||
554 pref_name
== prefs::kLanguageXkbAutoRepeatEnabled
) {
555 if (user_is_active
) {
556 const bool enabled
= xkb_auto_repeat_enabled_
.GetValue();
557 input_method::InputMethodManager::Get()
559 ->SetAutoRepeatEnabled(enabled
);
562 if (reason
!= REASON_PREF_CHANGED
||
563 pref_name
== prefs::kLanguageXkbAutoRepeatDelay
||
564 pref_name
== prefs::kLanguageXkbAutoRepeatInterval
) {
566 UpdateAutoRepeatRate();
569 if (user_is_primary_
&& (reason
!= REASON_PREF_CHANGED
||
570 pref_name
== prefs::kWakeOnWiFiEnabled
)) {
571 WakeOnWifiManager::Get()->OnPreferenceChanged(
572 static_cast<WakeOnWifiManager::WakeOnWifiFeature
>(
573 wake_on_wifi_enabled_
.GetValue()));
576 if (reason
== REASON_INITIALIZATION
)
577 SetInputMethodList();
579 if (pref_name
== prefs::kLanguagePreloadEngines
&&
580 reason
== REASON_PREF_CHANGED
) {
581 SetLanguageConfigStringListAsCSV(language_prefs::kGeneralSectionName
,
582 language_prefs::kPreloadEnginesConfigName
,
583 preload_engines_
.GetValue());
586 if ((reason
== REASON_INITIALIZATION
) ||
587 (pref_name
== prefs::kLanguageEnabledExtensionImes
&&
588 reason
== REASON_PREF_CHANGED
)) {
589 std::string
value(enabled_extension_imes_
.GetValue());
591 std::vector
<std::string
> split_values
;
593 base::SplitString(value
, ',', &split_values
);
595 ime_state_
->SetEnabledExtensionImes(&split_values
);
598 if (user_is_active
) {
599 system::InputDeviceSettings::Get()->UpdateTouchpadSettings(
601 system::InputDeviceSettings::Get()->UpdateMouseSettings(mouse_settings
);
605 void Preferences::OnIsSyncingChanged() {
606 DVLOG(1) << "OnIsSyncingChanged";
607 ForceNaturalScrollDefault();
610 void Preferences::ForceNaturalScrollDefault() {
611 DVLOG(1) << "ForceNaturalScrollDefault";
612 if (CommandLine::ForCurrentProcess()->HasSwitch(
613 switches::kNaturalScrollDefault
) &&
614 prefs_
->IsSyncing() &&
615 !prefs_
->GetUserPrefValue(prefs::kNaturalScroll
)) {
616 DVLOG(1) << "Natural scroll forced to true";
617 natural_scroll_
.SetValue(true);
618 UMA_HISTOGRAM_BOOLEAN("Touchpad.NaturalScroll.Forced", true);
622 void Preferences::SetLanguageConfigStringListAsCSV(const char* section
,
624 const std::string
& value
) {
625 VLOG(1) << "Setting " << name
<< " to '" << value
<< "'";
627 std::vector
<std::string
> split_values
;
629 base::SplitString(value
, ',', &split_values
);
631 // Transfers the xkb id to extension-xkb id.
632 if (input_method_manager_
->MigrateInputMethods(&split_values
))
633 preload_engines_
.SetValue(JoinString(split_values
, ','));
635 if (section
== std::string(language_prefs::kGeneralSectionName
) &&
636 name
== std::string(language_prefs::kPreloadEnginesConfigName
)) {
637 ime_state_
->ReplaceEnabledInputMethods(split_values
);
642 void Preferences::SetInputMethodList() {
643 // When |preload_engines_| are set, InputMethodManager::ChangeInputMethod()
644 // might be called to change the current input method to the first one in the
645 // |preload_engines_| list. This also updates previous/current input method
646 // prefs. That's why GetValue() calls are placed before the
647 // SetLanguageConfigStringListAsCSV() call below.
648 const std::string previous_input_method_id
=
649 previous_input_method_
.GetValue();
650 const std::string current_input_method_id
= current_input_method_
.GetValue();
651 SetLanguageConfigStringListAsCSV(language_prefs::kGeneralSectionName
,
652 language_prefs::kPreloadEnginesConfigName
,
653 preload_engines_
.GetValue());
655 // ChangeInputMethod() has to be called AFTER the value of |preload_engines_|
656 // is sent to the InputMethodManager. Otherwise, the ChangeInputMethod request
657 // might be ignored as an invalid input method ID. The ChangeInputMethod()
658 // calls are also necessary to restore the previous/current input method prefs
659 // which could have been modified by the SetLanguageConfigStringListAsCSV call
660 // above to the original state.
661 if (!previous_input_method_id
.empty())
662 ime_state_
->ChangeInputMethod(previous_input_method_id
,
663 false /* show_message */);
664 if (!current_input_method_id
.empty())
665 ime_state_
->ChangeInputMethod(current_input_method_id
,
666 false /* show_message */);
669 void Preferences::UpdateAutoRepeatRate() {
670 input_method::AutoRepeatRate rate
;
671 rate
.initial_delay_in_ms
= xkb_auto_repeat_delay_pref_
.GetValue();
672 rate
.repeat_interval_in_ms
= xkb_auto_repeat_interval_pref_
.GetValue();
673 DCHECK(rate
.initial_delay_in_ms
> 0);
674 DCHECK(rate
.repeat_interval_in_ms
> 0);
675 input_method::InputMethodManager::Get()
677 ->SetAutoRepeatRate(rate
);
680 void Preferences::OnTouchHudProjectionToggled(bool enabled
) {
681 if (touch_hud_projection_enabled_
.GetValue() == enabled
)
683 if (!user_
->is_active())
685 touch_hud_projection_enabled_
.SetValue(enabled
);
688 void Preferences::ActiveUserChanged(const user_manager::User
* active_user
) {
689 if (active_user
!= user_
)
691 ApplyPreferences(REASON_ACTIVE_USER_CHANGED
, "");
694 } // namespace chromeos