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 "ash/magnifier/magnifier_constants.h" | 7 #include "ash/magnifier/magnifier_constants.h" |
8 #include "base/chromeos/chromeos_version.h" | 8 #include "base/chromeos/chromeos_version.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/i18n/time_formatting.h" | 10 #include "base/i18n/time_formatting.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
42 namespace chromeos { | 42 namespace chromeos { |
43 | 43 |
44 static const char kFallbackInputMethodLocale[] = "en-US"; | 44 static const char kFallbackInputMethodLocale[] = "en-US"; |
45 | 45 |
46 Preferences::Preferences() | 46 Preferences::Preferences() |
47 : prefs_(NULL), | 47 : prefs_(NULL), |
48 input_method_manager_(input_method::InputMethodManager::Get()) { | 48 input_method_manager_(input_method::InputMethodManager::Get()) { |
49 } | 49 } |
50 | 50 |
51 Preferences::Preferences(input_method::InputMethodManager* input_method_manager) | 51 Preferences::Preferences(input_method::InputMethodManager* input_method_manager) |
52 : input_method_manager_(input_method_manager) { | 52 : prefs_(NULL), |
xiyuan
2013/05/21 02:01:44
Good catch.
| |
53 input_method_manager_(input_method_manager) { | |
53 } | 54 } |
54 | 55 |
55 Preferences::~Preferences() { | 56 Preferences::~Preferences() { |
56 prefs_->RemoveObserver(this); | 57 prefs_->RemoveObserver(this); |
57 } | 58 } |
58 | 59 |
59 // static | 60 // static |
60 void Preferences::RegisterPrefs(PrefRegistrySimple* registry) { | 61 void Preferences::RegisterPrefs(PrefRegistrySimple* registry) { |
61 registry->RegisterBooleanPref(prefs::kHighContrastEnabled, false); | 62 registry->RegisterBooleanPref(prefs::kHighContrastEnabled, false); |
62 registry->RegisterBooleanPref(prefs::kOwnerPrimaryMouseButtonRight, false); | 63 registry->RegisterBooleanPref(prefs::kOwnerPrimaryMouseButtonRight, false); |
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
518 void Preferences::Init(PrefServiceSyncable* prefs) { | 519 void Preferences::Init(PrefServiceSyncable* prefs) { |
519 InitUserPrefs(prefs); | 520 InitUserPrefs(prefs); |
520 | 521 |
521 // This causes OnIsSyncingChanged to be called when the value of | 522 // This causes OnIsSyncingChanged to be called when the value of |
522 // PrefService::IsSyncing() changes. | 523 // PrefService::IsSyncing() changes. |
523 prefs->AddObserver(this); | 524 prefs->AddObserver(this); |
524 | 525 |
525 // Initialize preferences to currently saved state. | 526 // Initialize preferences to currently saved state. |
526 NotifyPrefChanged(NULL); | 527 NotifyPrefChanged(NULL); |
527 | 528 |
529 // Listen to changes in device hierarchy. | |
530 pointer_device_observer_.reset(new system::PointerDeviceObserver()); | |
531 pointer_device_observer_->AddObserver(this); | |
532 pointer_device_observer_->Init(); | |
533 | |
528 // If a guest is logged in, initialize the prefs as if this is the first | 534 // If a guest is logged in, initialize the prefs as if this is the first |
529 // login. | 535 // login. |
530 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kGuestSession)) { | 536 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kGuestSession)) { |
531 LoginUtils::Get()->SetFirstLoginPrefs(prefs); | 537 LoginUtils::Get()->SetFirstLoginPrefs(prefs); |
532 } | 538 } |
533 } | 539 } |
534 | 540 |
535 void Preferences::InitUserPrefsForTesting(PrefServiceSyncable* prefs) { | 541 void Preferences::InitUserPrefsForTesting(PrefServiceSyncable* prefs) { |
536 InitUserPrefs(prefs); | 542 InitUserPrefs(prefs); |
537 } | 543 } |
538 | 544 |
539 void Preferences::SetInputMethodListForTesting() { | 545 void Preferences::SetInputMethodListForTesting() { |
540 SetInputMethodList(); | 546 SetInputMethodList(); |
541 } | 547 } |
542 | 548 |
543 void Preferences::OnPreferenceChanged(const std::string& pref_name) { | 549 void Preferences::OnPreferenceChanged(const std::string& pref_name) { |
544 NotifyPrefChanged(&pref_name); | 550 NotifyPrefChanged(&pref_name); |
545 } | 551 } |
546 | 552 |
547 void Preferences::NotifyPrefChanged(const std::string* pref_name) { | 553 void Preferences::SetTouchpadPrefs(const std::string* pref_name) { |
548 if (!pref_name || *pref_name == prefs::kTapToClickEnabled) { | 554 if (!pref_name || *pref_name == prefs::kTapToClickEnabled) { |
549 const bool enabled = tap_to_click_enabled_.GetValue(); | 555 const bool enabled = tap_to_click_enabled_.GetValue(); |
550 system::touchpad_settings::SetTapToClick(enabled); | 556 system::touchpad_settings::SetTapToClick(enabled); |
551 if (pref_name) | 557 if (pref_name) |
552 UMA_HISTOGRAM_BOOLEAN("Touchpad.TapToClick.Changed", enabled); | 558 UMA_HISTOGRAM_BOOLEAN("Touchpad.TapToClick.Changed", enabled); |
553 else | 559 else |
554 UMA_HISTOGRAM_BOOLEAN("Touchpad.TapToClick.Started", enabled); | 560 UMA_HISTOGRAM_BOOLEAN("Touchpad.TapToClick.Started", enabled); |
555 | 561 |
556 // Save owner preference in local state to use on login screen. | 562 // Save owner preference in local state to use on login screen. |
557 if (chromeos::UserManager::Get()->IsCurrentUserOwner()) { | 563 if (chromeos::UserManager::Get()->IsCurrentUserOwner()) { |
(...skipping 19 matching lines...) Expand all Loading... | |
577 UMA_HISTOGRAM_BOOLEAN("Touchpad.ThreeFingerClick.Started", enabled); | 583 UMA_HISTOGRAM_BOOLEAN("Touchpad.ThreeFingerClick.Started", enabled); |
578 } | 584 } |
579 if (!pref_name || *pref_name == prefs::kEnableTouchpadThreeFingerSwipe) { | 585 if (!pref_name || *pref_name == prefs::kEnableTouchpadThreeFingerSwipe) { |
580 const bool enabled = three_finger_swipe_enabled_.GetValue(); | 586 const bool enabled = three_finger_swipe_enabled_.GetValue(); |
581 system::touchpad_settings::SetThreeFingerSwipe(enabled); | 587 system::touchpad_settings::SetThreeFingerSwipe(enabled); |
582 if (pref_name) | 588 if (pref_name) |
583 UMA_HISTOGRAM_BOOLEAN("Touchpad.ThreeFingerSwipe.Changed", enabled); | 589 UMA_HISTOGRAM_BOOLEAN("Touchpad.ThreeFingerSwipe.Changed", enabled); |
584 else | 590 else |
585 UMA_HISTOGRAM_BOOLEAN("Touchpad.ThreeFingerSwipe.Started", enabled); | 591 UMA_HISTOGRAM_BOOLEAN("Touchpad.ThreeFingerSwipe.Started", enabled); |
586 } | 592 } |
587 if (!pref_name || *pref_name == prefs::kNaturalScroll) { | 593 if (!pref_name || *pref_name == prefs::kTouchpadSensitivity) { |
588 // Force natural scroll default if we've sync'd and if the cmd line arg is | 594 const int sensitivity = touchpad_sensitivity_.GetValue(); |
589 // set. | 595 system::touchpad_settings::SetSensitivity(sensitivity); |
590 ForceNaturalScrollDefault(); | 596 if (pref_name) { |
597 UMA_HISTOGRAM_CUSTOM_COUNTS( | |
598 "Touchpad.Sensitivity.Changed", sensitivity, 1, 5, 5); | |
599 } else { | |
600 UMA_HISTOGRAM_CUSTOM_COUNTS( | |
601 "Touchpad.Sensitivity.Started", sensitivity, 1, 5, 5); | |
602 } | |
603 } | |
604 } | |
591 | 605 |
592 const bool enabled = natural_scroll_.GetValue(); | 606 void Preferences::SetMousePrefs(const std::string* pref_name) { |
593 DVLOG(1) << "Natural scroll set to " << enabled; | |
594 ui::SetNaturalScroll(enabled); | |
595 if (pref_name) | |
596 UMA_HISTOGRAM_BOOLEAN("Touchpad.NaturalScroll.Changed", enabled); | |
597 else | |
598 UMA_HISTOGRAM_BOOLEAN("Touchpad.NaturalScroll.Started", enabled); | |
599 } | |
600 if (!pref_name || *pref_name == prefs::kMouseSensitivity) { | 607 if (!pref_name || *pref_name == prefs::kMouseSensitivity) { |
601 const int sensitivity = mouse_sensitivity_.GetValue(); | 608 const int sensitivity = mouse_sensitivity_.GetValue(); |
602 system::mouse_settings::SetSensitivity(sensitivity); | 609 system::mouse_settings::SetSensitivity(sensitivity); |
603 if (pref_name) { | 610 if (pref_name) { |
604 UMA_HISTOGRAM_CUSTOM_COUNTS( | 611 UMA_HISTOGRAM_CUSTOM_COUNTS( |
605 "Mouse.Sensitivity.Changed", sensitivity, 1, 5, 5); | 612 "Mouse.Sensitivity.Changed", sensitivity, 1, 5, 5); |
606 } else { | 613 } else { |
607 UMA_HISTOGRAM_CUSTOM_COUNTS( | 614 UMA_HISTOGRAM_CUSTOM_COUNTS( |
608 "Mouse.Sensitivity.Started", sensitivity, 1, 5, 5); | 615 "Mouse.Sensitivity.Started", sensitivity, 1, 5, 5); |
609 } | 616 } |
610 } | 617 } |
611 if (!pref_name || *pref_name == prefs::kTouchpadSensitivity) { | |
612 const int sensitivity = touchpad_sensitivity_.GetValue(); | |
613 system::touchpad_settings::SetSensitivity(sensitivity); | |
614 if (pref_name) { | |
615 UMA_HISTOGRAM_CUSTOM_COUNTS( | |
616 "Touchpad.Sensitivity.Changed", sensitivity, 1, 5, 5); | |
617 } else { | |
618 UMA_HISTOGRAM_CUSTOM_COUNTS( | |
619 "Touchpad.Sensitivity.Started", sensitivity, 1, 5, 5); | |
620 } | |
621 } | |
622 if (!pref_name || *pref_name == prefs::kPrimaryMouseButtonRight) { | 618 if (!pref_name || *pref_name == prefs::kPrimaryMouseButtonRight) { |
623 const bool right = primary_mouse_button_right_.GetValue(); | 619 const bool right = primary_mouse_button_right_.GetValue(); |
624 system::mouse_settings::SetPrimaryButtonRight(right); | 620 system::mouse_settings::SetPrimaryButtonRight(right); |
625 if (pref_name) | 621 if (pref_name) |
626 UMA_HISTOGRAM_BOOLEAN("Mouse.PrimaryButtonRight.Changed", right); | 622 UMA_HISTOGRAM_BOOLEAN("Mouse.PrimaryButtonRight.Changed", right); |
627 else | 623 else |
628 UMA_HISTOGRAM_BOOLEAN("Mouse.PrimaryButtonRight.Started", right); | 624 UMA_HISTOGRAM_BOOLEAN("Mouse.PrimaryButtonRight.Started", right); |
629 | 625 |
630 // Save owner preference in local state to use on login screen. | 626 // Save owner preference in local state to use on login screen. |
631 if (chromeos::UserManager::Get()->IsCurrentUserOwner()) { | 627 if (chromeos::UserManager::Get()->IsCurrentUserOwner()) { |
632 PrefService* prefs = g_browser_process->local_state(); | 628 PrefService* prefs = g_browser_process->local_state(); |
633 if (prefs->GetBoolean(prefs::kOwnerPrimaryMouseButtonRight) != right) | 629 if (prefs->GetBoolean(prefs::kOwnerPrimaryMouseButtonRight) != right) |
634 prefs->SetBoolean(prefs::kOwnerPrimaryMouseButtonRight, right); | 630 prefs->SetBoolean(prefs::kOwnerPrimaryMouseButtonRight, right); |
635 } | 631 } |
636 } | 632 } |
633 } | |
634 | |
635 void Preferences::NotifyPrefChanged(const std::string* pref_name) { | |
636 SetTouchpadPrefs(pref_name); | |
637 SetMousePrefs(pref_name); | |
638 | |
639 if (!pref_name || *pref_name == prefs::kNaturalScroll) { | |
640 // Force natural scroll default if we've sync'd and if the cmd line arg is | |
641 // set. | |
642 ForceNaturalScrollDefault(); | |
643 | |
644 const bool enabled = natural_scroll_.GetValue(); | |
645 DVLOG(1) << "Natural scroll set to " << enabled; | |
646 ui::SetNaturalScroll(enabled); | |
647 if (pref_name) | |
648 UMA_HISTOGRAM_BOOLEAN("Touchpad.NaturalScroll.Changed", enabled); | |
649 else | |
650 UMA_HISTOGRAM_BOOLEAN("Touchpad.NaturalScroll.Started", enabled); | |
651 } | |
637 if (!pref_name || *pref_name == prefs::kDownloadDefaultDirectory) { | 652 if (!pref_name || *pref_name == prefs::kDownloadDefaultDirectory) { |
638 const base::FilePath pref_path = download_default_directory_.GetValue(); | 653 const base::FilePath pref_path = download_default_directory_.GetValue(); |
639 // TODO(haruki): Remove this when migration completes. crbug.com/229304. | 654 // TODO(haruki): Remove this when migration completes. crbug.com/229304. |
640 if (drive::util::NeedsNamespaceMigration(pref_path)) { | 655 if (drive::util::NeedsNamespaceMigration(pref_path)) { |
641 prefs_->SetFilePath(prefs::kDownloadDefaultDirectory, | 656 prefs_->SetFilePath(prefs::kDownloadDefaultDirectory, |
642 drive::util::ConvertToMyDriveNamespace(pref_path)); | 657 drive::util::ConvertToMyDriveNamespace(pref_path)); |
643 } | 658 } |
644 | 659 |
645 const bool default_download_to_drive = drive::util::IsUnderDriveMountPoint( | 660 const bool default_download_to_drive = drive::util::IsUnderDriveMountPoint( |
646 download_default_directory_.GetValue()); | 661 download_default_directory_.GetValue()); |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
882 if (CommandLine::ForCurrentProcess()->HasSwitch( | 897 if (CommandLine::ForCurrentProcess()->HasSwitch( |
883 switches::kNaturalScrollDefault) && | 898 switches::kNaturalScrollDefault) && |
884 prefs_->IsSyncing() && | 899 prefs_->IsSyncing() && |
885 !prefs_->GetUserPrefValue(prefs::kNaturalScroll)) { | 900 !prefs_->GetUserPrefValue(prefs::kNaturalScroll)) { |
886 DVLOG(1) << "Natural scroll forced to true"; | 901 DVLOG(1) << "Natural scroll forced to true"; |
887 natural_scroll_.SetValue(true); | 902 natural_scroll_.SetValue(true); |
888 UMA_HISTOGRAM_BOOLEAN("Touchpad.NaturalScroll.Forced", true); | 903 UMA_HISTOGRAM_BOOLEAN("Touchpad.NaturalScroll.Forced", true); |
889 } | 904 } |
890 } | 905 } |
891 | 906 |
907 void Preferences::TouchpadExists(bool exists) { | |
908 SetTouchpadPrefs(NULL); | |
909 } | |
910 | |
911 void Preferences::MouseExists(bool exists) { | |
912 SetMousePrefs(NULL); | |
913 } | |
914 | |
892 void Preferences::SetLanguageConfigBoolean(const char* section, | 915 void Preferences::SetLanguageConfigBoolean(const char* section, |
893 const char* name, | 916 const char* name, |
894 bool value) { | 917 bool value) { |
895 input_method::InputMethodConfigValue config; | 918 input_method::InputMethodConfigValue config; |
896 config.type = input_method::InputMethodConfigValue::kValueTypeBool; | 919 config.type = input_method::InputMethodConfigValue::kValueTypeBool; |
897 config.bool_value = value; | 920 config.bool_value = value; |
898 input_method_manager_->SetInputMethodConfig(section, name, config); | 921 input_method_manager_->SetInputMethodConfig(section, name, config); |
899 } | 922 } |
900 | 923 |
901 void Preferences::SetLanguageConfigInteger(const char* section, | 924 void Preferences::SetLanguageConfigInteger(const char* section, |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
984 | 1007 |
985 input_method::AutoRepeatRate rate; | 1008 input_method::AutoRepeatRate rate; |
986 rate.initial_delay_in_ms = xkb_auto_repeat_delay_pref_.GetValue(); | 1009 rate.initial_delay_in_ms = xkb_auto_repeat_delay_pref_.GetValue(); |
987 rate.repeat_interval_in_ms = xkb_auto_repeat_interval_pref_.GetValue(); | 1010 rate.repeat_interval_in_ms = xkb_auto_repeat_interval_pref_.GetValue(); |
988 DCHECK(rate.initial_delay_in_ms > 0); | 1011 DCHECK(rate.initial_delay_in_ms > 0); |
989 DCHECK(rate.repeat_interval_in_ms > 0); | 1012 DCHECK(rate.repeat_interval_in_ms > 0); |
990 input_method::XKeyboard::SetAutoRepeatRate(rate); | 1013 input_method::XKeyboard::SetAutoRepeatRate(rate); |
991 } | 1014 } |
992 | 1015 |
993 } // namespace chromeos | 1016 } // namespace chromeos |
OLD | NEW |