OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/chromeos/preferences.h" | 5 #include "chrome/browser/chromeos/preferences.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "ash/autoclick/autoclick_controller.h" | 9 #include "ash/autoclick/autoclick_controller.h" |
10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/i18n/time_formatting.h" | 12 #include "base/i18n/time_formatting.h" |
13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
14 #include "base/prefs/pref_member.h" | 14 #include "base/prefs/pref_member.h" |
15 #include "base/prefs/pref_registry_simple.h" | 15 #include "base/prefs/pref_registry_simple.h" |
16 #include "base/prefs/scoped_user_pref_update.h" | 16 #include "base/prefs/scoped_user_pref_update.h" |
17 #include "base/strings/string_split.h" | 17 #include "base/strings/string_split.h" |
18 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
19 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
20 #include "base/sys_info.h" | 20 #include "base/sys_info.h" |
21 #include "chrome/browser/browser_process.h" | 21 #include "chrome/browser/browser_process.h" |
22 #include "chrome/browser/chrome_notification_types.h" | 22 #include "chrome/browser/chrome_notification_types.h" |
23 #include "chrome/browser/chromeos/accessibility/magnification_manager.h" | 23 #include "chrome/browser/chromeos/accessibility/magnification_manager.h" |
24 #include "chrome/browser/chromeos/drive/file_system_util.h" | 24 #include "chrome/browser/chromeos/drive/file_system_util.h" |
25 #include "chrome/browser/chromeos/input_method/input_method_syncer.h" | 25 #include "chrome/browser/chromeos/input_method/input_method_syncer.h" |
26 #include "chrome/browser/chromeos/login/session/user_session_manager.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" | 27 #include "chrome/browser/chromeos/system/input_device_settings.h" |
29 #include "chrome/browser/download/download_prefs.h" | 28 #include "chrome/browser/download/download_prefs.h" |
30 #include "chrome/browser/prefs/pref_service_syncable.h" | 29 #include "chrome/browser/prefs/pref_service_syncable.h" |
31 #include "chrome/common/chrome_switches.h" | 30 #include "chrome/common/chrome_switches.h" |
32 #include "chrome/common/pref_names.h" | 31 #include "chrome/common/pref_names.h" |
33 #include "chromeos/chromeos_switches.h" | 32 #include "chromeos/chromeos_switches.h" |
34 #include "chromeos/system/statistics_provider.h" | 33 #include "chromeos/system/statistics_provider.h" |
35 #include "components/feedback/tracing_manager.h" | 34 #include "components/feedback/tracing_manager.h" |
36 #include "components/pref_registry/pref_registry_syncable.h" | 35 #include "components/pref_registry/pref_registry_syncable.h" |
37 #include "components/user_manager/user.h" | 36 #include "components/user_manager/user.h" |
38 #include "content/public/browser/browser_thread.h" | 37 #include "content/public/browser/browser_thread.h" |
39 #include "third_party/icu/source/i18n/unicode/timezone.h" | 38 #include "third_party/icu/source/i18n/unicode/timezone.h" |
40 #include "ui/base/ime/chromeos/extension_ime_util.h" | 39 #include "ui/base/ime/chromeos/extension_ime_util.h" |
41 #include "ui/base/ime/chromeos/ime_keyboard.h" | 40 #include "ui/base/ime/chromeos/ime_keyboard.h" |
42 #include "ui/base/ime/chromeos/input_method_manager.h" | 41 #include "ui/base/ime/chromeos/input_method_manager.h" |
43 #include "ui/chromeos/accessibility_types.h" | 42 #include "ui/chromeos/accessibility_types.h" |
44 #include "ui/events/event_constants.h" | 43 #include "ui/events/event_constants.h" |
45 #include "ui/events/event_utils.h" | 44 #include "ui/events/event_utils.h" |
46 #include "url/gurl.h" | 45 #include "url/gurl.h" |
47 | 46 |
47 #if !defined(DISABLE_WAKE_ON_WIFI) | |
48 #include "chrome/browser/chromeos/net/wake_on_wifi_manager.h" | |
49 #endif | |
50 | |
48 namespace chromeos { | 51 namespace chromeos { |
49 | 52 |
50 static const char kFallbackInputMethodLocale[] = "en-US"; | 53 static const char kFallbackInputMethodLocale[] = "en-US"; |
51 | 54 |
52 Preferences::Preferences() | 55 Preferences::Preferences() |
53 : prefs_(NULL), | 56 : prefs_(NULL), |
54 input_method_manager_(input_method::InputMethodManager::Get()), | 57 input_method_manager_(input_method::InputMethodManager::Get()), |
55 user_(NULL), | 58 user_(NULL), |
56 user_is_primary_(false) { | 59 user_is_primary_(false) { |
57 // Do not observe shell, if there is no shell instance; e.g., in some unit | 60 // Do not observe shell, if there is no shell instance; e.g., in some unit |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
266 registry->RegisterIntegerPref( | 269 registry->RegisterIntegerPref( |
267 prefs::kLanguageXkbAutoRepeatDelay, | 270 prefs::kLanguageXkbAutoRepeatDelay, |
268 language_prefs::kXkbAutoRepeatDelayInMs, | 271 language_prefs::kXkbAutoRepeatDelayInMs, |
269 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); | 272 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); |
270 registry->RegisterIntegerPref( | 273 registry->RegisterIntegerPref( |
271 prefs::kLanguageXkbAutoRepeatInterval, | 274 prefs::kLanguageXkbAutoRepeatInterval, |
272 language_prefs::kXkbAutoRepeatIntervalInMs, | 275 language_prefs::kXkbAutoRepeatIntervalInMs, |
273 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); | 276 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); |
274 | 277 |
275 // We don't sync wake-on-wifi related prefs because they are device specific. | 278 // We don't sync wake-on-wifi related prefs because they are device specific. |
276 // TODO(chirantan): Default this to on when we are ready to launch. | 279 registry->RegisterBooleanPref( |
277 registry->RegisterIntegerPref( | 280 prefs::kWakeOnWifiSsid, |
278 prefs::kWakeOnWiFiEnabled, | 281 true, |
279 base::CommandLine::ForCurrentProcess()->HasSwitch( | |
280 switches::kWakeOnPackets) | |
281 ? WakeOnWifiManager::WAKE_ON_PACKET_AND_SSID | |
282 : WakeOnWifiManager::WAKE_ON_NONE, | |
283 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 282 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
284 | 283 |
285 // Mobile plan notifications default to on. | 284 // Mobile plan notifications default to on. |
286 registry->RegisterBooleanPref( | 285 registry->RegisterBooleanPref( |
287 prefs::kShowPlanNotifications, | 286 prefs::kShowPlanNotifications, |
288 true, | 287 true, |
289 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); | 288 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); |
290 | 289 |
291 // 3G first-time usage promo will be shown at least once. | 290 // 3G first-time usage promo will be shown at least once. |
292 registry->RegisterBooleanPref( | 291 registry->RegisterBooleanPref( |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
352 previous_input_method_.Init(prefs::kLanguagePreviousInputMethod, | 351 previous_input_method_.Init(prefs::kLanguagePreviousInputMethod, |
353 prefs, callback); | 352 prefs, callback); |
354 | 353 |
355 xkb_auto_repeat_enabled_.Init( | 354 xkb_auto_repeat_enabled_.Init( |
356 prefs::kLanguageXkbAutoRepeatEnabled, prefs, callback); | 355 prefs::kLanguageXkbAutoRepeatEnabled, prefs, callback); |
357 xkb_auto_repeat_delay_pref_.Init( | 356 xkb_auto_repeat_delay_pref_.Init( |
358 prefs::kLanguageXkbAutoRepeatDelay, prefs, callback); | 357 prefs::kLanguageXkbAutoRepeatDelay, prefs, callback); |
359 xkb_auto_repeat_interval_pref_.Init( | 358 xkb_auto_repeat_interval_pref_.Init( |
360 prefs::kLanguageXkbAutoRepeatInterval, prefs, callback); | 359 prefs::kLanguageXkbAutoRepeatInterval, prefs, callback); |
361 | 360 |
362 wake_on_wifi_enabled_.Init(prefs::kWakeOnWiFiEnabled, prefs, callback); | 361 #if !defined(DISABLE_WAKE_ON_WIFI) |
362 wake_on_wifi_ssid_.Init(prefs::kWakeOnWifiSsid, prefs, callback); | |
363 #endif | |
363 } | 364 } |
364 | 365 |
365 void Preferences::Init(Profile* profile, const user_manager::User* user) { | 366 void Preferences::Init(Profile* profile, const user_manager::User* user) { |
366 DCHECK(profile); | 367 DCHECK(profile); |
367 DCHECK(user); | 368 DCHECK(user); |
368 PrefServiceSyncable* prefs = PrefServiceSyncable::FromProfile(profile); | 369 PrefServiceSyncable* prefs = PrefServiceSyncable::FromProfile(profile); |
369 // This causes OnIsSyncingChanged to be called when the value of | 370 // This causes OnIsSyncingChanged to be called when the value of |
370 // PrefService::IsSyncing() changes. | 371 // PrefService::IsSyncing() changes. |
371 prefs->AddObserver(this); | 372 prefs->AddObserver(this); |
372 user_ = user; | 373 user_ = user; |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
566 ->SetAutoRepeatEnabled(enabled); | 567 ->SetAutoRepeatEnabled(enabled); |
567 } | 568 } |
568 } | 569 } |
569 if (reason != REASON_PREF_CHANGED || | 570 if (reason != REASON_PREF_CHANGED || |
570 pref_name == prefs::kLanguageXkbAutoRepeatDelay || | 571 pref_name == prefs::kLanguageXkbAutoRepeatDelay || |
571 pref_name == prefs::kLanguageXkbAutoRepeatInterval) { | 572 pref_name == prefs::kLanguageXkbAutoRepeatInterval) { |
572 if (user_is_active) | 573 if (user_is_active) |
573 UpdateAutoRepeatRate(); | 574 UpdateAutoRepeatRate(); |
574 } | 575 } |
575 | 576 |
576 if (user_is_primary_ && (reason != REASON_PREF_CHANGED || | |
577 pref_name == prefs::kWakeOnWiFiEnabled)) { | |
578 WakeOnWifiManager::Get()->OnPreferenceChanged( | |
579 static_cast<WakeOnWifiManager::WakeOnWifiFeature>( | |
580 wake_on_wifi_enabled_.GetValue())); | |
581 } | |
582 | |
583 if (reason == REASON_INITIALIZATION) | 577 if (reason == REASON_INITIALIZATION) |
584 SetInputMethodList(); | 578 SetInputMethodList(); |
585 | 579 |
586 if (pref_name == prefs::kLanguagePreloadEngines && | 580 if (pref_name == prefs::kLanguagePreloadEngines && |
587 reason == REASON_PREF_CHANGED) { | 581 reason == REASON_PREF_CHANGED) { |
588 SetLanguageConfigStringListAsCSV(language_prefs::kGeneralSectionName, | 582 SetLanguageConfigStringListAsCSV(language_prefs::kGeneralSectionName, |
589 language_prefs::kPreloadEnginesConfigName, | 583 language_prefs::kPreloadEnginesConfigName, |
590 preload_engines_.GetValue()); | 584 preload_engines_.GetValue()); |
591 } | 585 } |
592 | 586 |
593 if ((reason == REASON_INITIALIZATION) || | 587 if ((reason == REASON_INITIALIZATION) || |
594 (pref_name == prefs::kLanguageEnabledExtensionImes && | 588 (pref_name == prefs::kLanguageEnabledExtensionImes && |
595 reason == REASON_PREF_CHANGED)) { | 589 reason == REASON_PREF_CHANGED)) { |
596 std::string value(enabled_extension_imes_.GetValue()); | 590 std::string value(enabled_extension_imes_.GetValue()); |
597 | 591 |
598 std::vector<std::string> split_values; | 592 std::vector<std::string> split_values; |
599 if (!value.empty()) | 593 if (!value.empty()) |
600 base::SplitString(value, ',', &split_values); | 594 base::SplitString(value, ',', &split_values); |
601 | 595 |
602 ime_state_->SetEnabledExtensionImes(&split_values); | 596 ime_state_->SetEnabledExtensionImes(&split_values); |
603 } | 597 } |
604 | 598 |
605 if (user_is_active) { | 599 if (user_is_active) { |
606 system::InputDeviceSettings::Get()->UpdateTouchpadSettings( | 600 system::InputDeviceSettings::Get()->UpdateTouchpadSettings( |
607 touchpad_settings); | 601 touchpad_settings); |
608 system::InputDeviceSettings::Get()->UpdateMouseSettings(mouse_settings); | 602 system::InputDeviceSettings::Get()->UpdateMouseSettings(mouse_settings); |
609 } | 603 } |
604 | |
605 #if !defined(DISABLE_WAKE_ON_WIFI) | |
606 if (user_is_primary_ && (reason != REASON_PREF_CHANGED || | |
607 pref_name == prefs::kWakeOnWifiSsid)) { | |
608 int features = wake_on_wifi_ssid_.GetValue() ? | |
609 WakeOnWifiManager::WAKE_ON_SSID : WakeOnWifiManager::WAKE_ON_NONE; | |
610 // The flag enables wake on packets but doesn't update a preference. | |
611 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kWakeOnPackets)) | |
612 features |= WakeOnWifiManager::WAKE_ON_PACKET; | |
michaelpg
2014/12/17 02:30:54
bitwise operations make life easier and will conti
| |
613 WakeOnWifiManager::Get()->OnPreferenceChanged( | |
614 static_cast<WakeOnWifiManager::WakeOnWifiFeature>(features)); | |
615 } | |
616 #endif // !defined(DISABLE_WAKE_ON_WIFI) | |
610 } | 617 } |
611 | 618 |
612 void Preferences::OnIsSyncingChanged() { | 619 void Preferences::OnIsSyncingChanged() { |
613 DVLOG(1) << "OnIsSyncingChanged"; | 620 DVLOG(1) << "OnIsSyncingChanged"; |
614 ForceNaturalScrollDefault(); | 621 ForceNaturalScrollDefault(); |
615 } | 622 } |
616 | 623 |
617 void Preferences::ForceNaturalScrollDefault() { | 624 void Preferences::ForceNaturalScrollDefault() { |
618 DVLOG(1) << "ForceNaturalScrollDefault"; | 625 DVLOG(1) << "ForceNaturalScrollDefault"; |
619 if (CommandLine::ForCurrentProcess()->HasSwitch( | 626 if (CommandLine::ForCurrentProcess()->HasSwitch( |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
692 touch_hud_projection_enabled_.SetValue(enabled); | 699 touch_hud_projection_enabled_.SetValue(enabled); |
693 } | 700 } |
694 | 701 |
695 void Preferences::ActiveUserChanged(const user_manager::User* active_user) { | 702 void Preferences::ActiveUserChanged(const user_manager::User* active_user) { |
696 if (active_user != user_) | 703 if (active_user != user_) |
697 return; | 704 return; |
698 ApplyPreferences(REASON_ACTIVE_USER_CHANGED, ""); | 705 ApplyPreferences(REASON_ACTIVE_USER_CHANGED, ""); |
699 } | 706 } |
700 | 707 |
701 } // namespace chromeos | 708 } // namespace chromeos |
OLD | NEW |