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/magnifier/magnifier_constants.h" | 10 #include "ash/magnifier/magnifier_constants.h" |
11 #include "ash/shell.h" | 11 #include "ash/shell.h" |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/i18n/time_formatting.h" | 13 #include "base/i18n/time_formatting.h" |
14 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
15 #include "base/prefs/pref_member.h" | 15 #include "base/prefs/pref_member.h" |
16 #include "base/prefs/pref_registry_simple.h" | 16 #include "base/prefs/pref_registry_simple.h" |
17 #include "base/prefs/scoped_user_pref_update.h" | 17 #include "base/prefs/scoped_user_pref_update.h" |
18 #include "base/strings/string_split.h" | 18 #include "base/strings/string_split.h" |
19 #include "base/strings/string_util.h" | 19 #include "base/strings/string_util.h" |
20 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
21 #include "base/sys_info.h" | 21 #include "base/sys_info.h" |
22 #include "chrome/browser/browser_process.h" | 22 #include "chrome/browser/browser_process.h" |
23 #include "chrome/browser/chrome_notification_types.h" | 23 #include "chrome/browser/chrome_notification_types.h" |
24 #include "chrome/browser/chromeos/accessibility/magnification_manager.h" | 24 #include "chrome/browser/chromeos/accessibility/magnification_manager.h" |
25 #include "chrome/browser/chromeos/drive/file_system_util.h" | 25 #include "chrome/browser/chromeos/drive/file_system_util.h" |
26 #include "chrome/browser/chromeos/input_method/input_method_util.h" | 26 #include "chrome/browser/chromeos/input_method/input_method_util.h" |
27 #include "chrome/browser/chromeos/login/session/user_session_manager.h" | 27 #include "chrome/browser/chromeos/login/session/user_session_manager.h" |
28 #include "chrome/browser/chromeos/profiles/profile_helper.h" | |
28 #include "chrome/browser/chromeos/system/input_device_settings.h" | 29 #include "chrome/browser/chromeos/system/input_device_settings.h" |
29 #include "chrome/browser/download/download_prefs.h" | 30 #include "chrome/browser/download/download_prefs.h" |
30 #include "chrome/browser/prefs/pref_service_syncable.h" | 31 #include "chrome/browser/prefs/pref_service_syncable.h" |
31 #include "chrome/common/chrome_switches.h" | 32 #include "chrome/common/chrome_switches.h" |
32 #include "chrome/common/pref_names.h" | 33 #include "chrome/common/pref_names.h" |
33 #include "chromeos/chromeos_switches.h" | 34 #include "chromeos/chromeos_switches.h" |
34 #include "chromeos/ime/extension_ime_util.h" | 35 #include "chromeos/ime/extension_ime_util.h" |
35 #include "chromeos/ime/ime_keyboard.h" | 36 #include "chromeos/ime/ime_keyboard.h" |
36 #include "chromeos/ime/input_method_manager.h" | 37 #include "chromeos/ime/input_method_manager.h" |
37 #include "chromeos/system/statistics_provider.h" | 38 #include "chromeos/system/statistics_provider.h" |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
342 prefs, callback); | 343 prefs, callback); |
343 | 344 |
344 xkb_auto_repeat_enabled_.Init( | 345 xkb_auto_repeat_enabled_.Init( |
345 prefs::kLanguageXkbAutoRepeatEnabled, prefs, callback); | 346 prefs::kLanguageXkbAutoRepeatEnabled, prefs, callback); |
346 xkb_auto_repeat_delay_pref_.Init( | 347 xkb_auto_repeat_delay_pref_.Init( |
347 prefs::kLanguageXkbAutoRepeatDelay, prefs, callback); | 348 prefs::kLanguageXkbAutoRepeatDelay, prefs, callback); |
348 xkb_auto_repeat_interval_pref_.Init( | 349 xkb_auto_repeat_interval_pref_.Init( |
349 prefs::kLanguageXkbAutoRepeatInterval, prefs, callback); | 350 prefs::kLanguageXkbAutoRepeatInterval, prefs, callback); |
350 } | 351 } |
351 | 352 |
352 void Preferences::Init(PrefServiceSyncable* prefs, | 353 void Preferences::Init(Profile* profile, const user_manager::User* user) { |
353 const user_manager::User* user) { | 354 DCHECK(profile); |
354 DCHECK(user); | 355 DCHECK(user); |
356 PrefServiceSyncable* prefs = PrefServiceSyncable::FromProfile(profile); | |
355 user_ = user; | 357 user_ = user; |
356 user_is_primary_ = UserManager::Get()->GetPrimaryUser() == user_; | 358 user_is_primary_ = UserManager::Get()->GetPrimaryUser() == user_; |
357 InitUserPrefs(prefs); | 359 InitUserPrefs(prefs); |
358 | 360 |
359 UserManager::Get()->AddSessionStateObserver(this); | 361 UserManager::Get()->AddSessionStateObserver(this); |
360 | 362 |
361 // This causes OnIsSyncingChanged to be called when the value of | 363 // This causes OnIsSyncingChanged to be called when the value of |
362 // PrefService::IsSyncing() changes. | 364 // PrefService::IsSyncing() changes. |
363 prefs->AddObserver(this); | 365 prefs->AddObserver(this); |
364 | 366 |
367 ime_state_ = input_method_manager_->GetDefaultState( | |
368 ProfileHelper::Get()->GetProfileByUser(user_)); | |
369 input_method_manager_->SetState(ime_state_); | |
370 | |
365 // Initialize preferences to currently saved state. | 371 // Initialize preferences to currently saved state. |
366 ApplyPreferences(REASON_INITIALIZATION, ""); | 372 ApplyPreferences(REASON_INITIALIZATION, ""); |
367 | 373 |
368 // If a guest is logged in, initialize the prefs as if this is the first | 374 // If a guest is logged in, initialize the prefs as if this is the first |
369 // login. For a regular user this is done in | 375 // login. For a regular user this is done in |
370 // UserSessionManager::InitProfilePreferences(). | 376 // UserSessionManager::InitProfilePreferences(). |
371 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kGuestSession)) | 377 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kGuestSession)) |
372 UserSessionManager::SetFirstLoginPrefs(prefs, std::string(), std::string()); | 378 UserSessionManager::SetFirstLoginPrefs( |
379 profile, std::string(), std::string()); | |
373 } | 380 } |
374 | 381 |
375 void Preferences::InitUserPrefsForTesting(PrefServiceSyncable* prefs, | 382 void Preferences::InitUserPrefsForTesting(PrefServiceSyncable* prefs, |
376 const user_manager::User* user) { | 383 const user_manager::User* user) { |
377 user_ = user; | 384 user_ = user; |
378 InitUserPrefs(prefs); | 385 InitUserPrefs(prefs); |
379 } | 386 } |
380 | 387 |
381 void Preferences::SetInputMethodListForTesting() { | 388 void Preferences::SetInputMethodListForTesting() { |
382 SetInputMethodList(); | 389 SetInputMethodList(); |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
529 ->SetAutoRepeatEnabled(enabled); | 536 ->SetAutoRepeatEnabled(enabled); |
530 } | 537 } |
531 } | 538 } |
532 if (reason != REASON_PREF_CHANGED || | 539 if (reason != REASON_PREF_CHANGED || |
533 pref_name == prefs::kLanguageXkbAutoRepeatDelay || | 540 pref_name == prefs::kLanguageXkbAutoRepeatDelay || |
534 pref_name == prefs::kLanguageXkbAutoRepeatInterval) { | 541 pref_name == prefs::kLanguageXkbAutoRepeatInterval) { |
535 if (user_is_active) | 542 if (user_is_active) |
536 UpdateAutoRepeatRate(); | 543 UpdateAutoRepeatRate(); |
537 } | 544 } |
538 | 545 |
539 if (reason != REASON_PREF_CHANGED && user_is_active) { | 546 if (reason == REASON_INITIALIZATION) { |
540 SetInputMethodList(); | 547 SetInputMethodList(); |
541 } else if (pref_name == prefs::kLanguagePreloadEngines && user_is_active) { | 548 } |
Nikita (slow)
2014/08/13 10:56:41
nit: drop {}
Alexander Alekseev
2014/08/13 23:29:32
Done.
| |
549 | |
550 if (pref_name == prefs::kLanguagePreloadEngines && | |
551 reason == REASON_PREF_CHANGED) { | |
542 SetLanguageConfigStringListAsCSV(language_prefs::kGeneralSectionName, | 552 SetLanguageConfigStringListAsCSV(language_prefs::kGeneralSectionName, |
543 language_prefs::kPreloadEnginesConfigName, | 553 language_prefs::kPreloadEnginesConfigName, |
544 preload_engines_.GetValue()); | 554 preload_engines_.GetValue()); |
545 } | 555 } |
546 | 556 |
547 if (reason != REASON_PREF_CHANGED || | 557 if ((reason == REASON_INITIALIZATION) || |
548 pref_name == prefs::kLanguageEnabledExtensionImes) { | 558 (pref_name == prefs::kLanguageEnabledExtensionImes && |
549 if (user_is_active) { | 559 reason == REASON_PREF_CHANGED)) { |
550 std::string value(enabled_extension_imes_.GetValue()); | 560 std::string value(enabled_extension_imes_.GetValue()); |
551 | 561 |
552 std::vector<std::string> split_values; | 562 std::vector<std::string> split_values; |
553 if (!value.empty()) | 563 if (!value.empty()) |
554 base::SplitString(value, ',', &split_values); | 564 base::SplitString(value, ',', &split_values); |
555 | 565 |
556 input_method_manager_->SetEnabledExtensionImes(&split_values); | 566 ime_state_->SetEnabledExtensionImes(&split_values); |
557 } | |
558 } | 567 } |
559 | 568 |
560 if (user_is_active) { | 569 if (user_is_active) { |
561 system::InputDeviceSettings::Get()->UpdateTouchpadSettings( | 570 system::InputDeviceSettings::Get()->UpdateTouchpadSettings( |
562 touchpad_settings); | 571 touchpad_settings); |
563 system::InputDeviceSettings::Get()->UpdateMouseSettings(mouse_settings); | 572 system::InputDeviceSettings::Get()->UpdateMouseSettings(mouse_settings); |
564 } | 573 } |
565 } | 574 } |
566 | 575 |
567 void Preferences::OnIsSyncingChanged() { | 576 void Preferences::OnIsSyncingChanged() { |
(...skipping 21 matching lines...) Expand all Loading... | |
589 std::vector<std::string> split_values; | 598 std::vector<std::string> split_values; |
590 if (!value.empty()) | 599 if (!value.empty()) |
591 base::SplitString(value, ',', &split_values); | 600 base::SplitString(value, ',', &split_values); |
592 | 601 |
593 // Transfers the xkb id to extension-xkb id. | 602 // Transfers the xkb id to extension-xkb id. |
594 if (input_method_manager_->MigrateInputMethods(&split_values)) | 603 if (input_method_manager_->MigrateInputMethods(&split_values)) |
595 preload_engines_.SetValue(JoinString(split_values, ',')); | 604 preload_engines_.SetValue(JoinString(split_values, ',')); |
596 | 605 |
597 if (section == std::string(language_prefs::kGeneralSectionName) && | 606 if (section == std::string(language_prefs::kGeneralSectionName) && |
598 name == std::string(language_prefs::kPreloadEnginesConfigName)) { | 607 name == std::string(language_prefs::kPreloadEnginesConfigName)) { |
599 input_method_manager_->ReplaceEnabledInputMethods(split_values); | 608 ime_state_->ReplaceEnabledInputMethods(split_values); |
600 return; | 609 return; |
601 } | 610 } |
602 } | 611 } |
603 | 612 |
604 void Preferences::SetInputMethodList() { | 613 void Preferences::SetInputMethodList() { |
605 // When |preload_engines_| are set, InputMethodManager::ChangeInputMethod() | 614 // When |preload_engines_| are set, InputMethodManager::ChangeInputMethod() |
606 // might be called to change the current input method to the first one in the | 615 // might be called to change the current input method to the first one in the |
607 // |preload_engines_| list. This also updates previous/current input method | 616 // |preload_engines_| list. This also updates previous/current input method |
608 // prefs. That's why GetValue() calls are placed before the | 617 // prefs. That's why GetValue() calls are placed before the |
609 // SetLanguageConfigStringListAsCSV() call below. | 618 // SetLanguageConfigStringListAsCSV() call below. |
610 const std::string previous_input_method_id = | 619 const std::string previous_input_method_id = |
611 previous_input_method_.GetValue(); | 620 previous_input_method_.GetValue(); |
612 const std::string current_input_method_id = current_input_method_.GetValue(); | 621 const std::string current_input_method_id = current_input_method_.GetValue(); |
613 SetLanguageConfigStringListAsCSV(language_prefs::kGeneralSectionName, | 622 SetLanguageConfigStringListAsCSV(language_prefs::kGeneralSectionName, |
614 language_prefs::kPreloadEnginesConfigName, | 623 language_prefs::kPreloadEnginesConfigName, |
615 preload_engines_.GetValue()); | 624 preload_engines_.GetValue()); |
616 | 625 |
617 // ChangeInputMethod() has to be called AFTER the value of |preload_engines_| | 626 // ChangeInputMethod() has to be called AFTER the value of |preload_engines_| |
618 // is sent to the InputMethodManager. Otherwise, the ChangeInputMethod request | 627 // is sent to the InputMethodManager. Otherwise, the ChangeInputMethod request |
619 // might be ignored as an invalid input method ID. The ChangeInputMethod() | 628 // might be ignored as an invalid input method ID. The ChangeInputMethod() |
620 // calls are also necessary to restore the previous/current input method prefs | 629 // calls are also necessary to restore the previous/current input method prefs |
621 // which could have been modified by the SetLanguageConfigStringListAsCSV call | 630 // which could have been modified by the SetLanguageConfigStringListAsCSV call |
622 // above to the original state. | 631 // above to the original state. |
623 if (!previous_input_method_id.empty()) | 632 if (!previous_input_method_id.empty()) |
624 input_method_manager_->ChangeInputMethod(previous_input_method_id); | 633 ime_state_->ChangeInputMethod(previous_input_method_id, |
634 false /* show_message */); | |
625 if (!current_input_method_id.empty()) | 635 if (!current_input_method_id.empty()) |
626 input_method_manager_->ChangeInputMethod(current_input_method_id); | 636 ime_state_->ChangeInputMethod(current_input_method_id, |
637 false /* show_message */); | |
627 } | 638 } |
628 | 639 |
629 void Preferences::UpdateAutoRepeatRate() { | 640 void Preferences::UpdateAutoRepeatRate() { |
630 input_method::AutoRepeatRate rate; | 641 input_method::AutoRepeatRate rate; |
631 rate.initial_delay_in_ms = xkb_auto_repeat_delay_pref_.GetValue(); | 642 rate.initial_delay_in_ms = xkb_auto_repeat_delay_pref_.GetValue(); |
632 rate.repeat_interval_in_ms = xkb_auto_repeat_interval_pref_.GetValue(); | 643 rate.repeat_interval_in_ms = xkb_auto_repeat_interval_pref_.GetValue(); |
633 DCHECK(rate.initial_delay_in_ms > 0); | 644 DCHECK(rate.initial_delay_in_ms > 0); |
634 DCHECK(rate.repeat_interval_in_ms > 0); | 645 DCHECK(rate.repeat_interval_in_ms > 0); |
635 input_method::InputMethodManager::Get() | 646 input_method::InputMethodManager::Get() |
636 ->GetImeKeyboard() | 647 ->GetImeKeyboard() |
637 ->SetAutoRepeatRate(rate); | 648 ->SetAutoRepeatRate(rate); |
638 } | 649 } |
639 | 650 |
640 void Preferences::OnTouchHudProjectionToggled(bool enabled) { | 651 void Preferences::OnTouchHudProjectionToggled(bool enabled) { |
641 if (touch_hud_projection_enabled_.GetValue() == enabled) | 652 if (touch_hud_projection_enabled_.GetValue() == enabled) |
642 return; | 653 return; |
643 if (!user_->is_active()) | 654 if (!user_->is_active()) |
644 return; | 655 return; |
645 touch_hud_projection_enabled_.SetValue(enabled); | 656 touch_hud_projection_enabled_.SetValue(enabled); |
646 } | 657 } |
647 | 658 |
648 void Preferences::ActiveUserChanged(const user_manager::User* active_user) { | 659 void Preferences::ActiveUserChanged(const user_manager::User* active_user) { |
649 if (active_user != user_) | 660 if (active_user != user_) |
650 return; | 661 return; |
651 ApplyPreferences(REASON_ACTIVE_USER_CHANGED, ""); | 662 ApplyPreferences(REASON_ACTIVE_USER_CHANGED, ""); |
652 } | 663 } |
653 | 664 |
654 } // namespace chromeos | 665 } // namespace chromeos |
OLD | NEW |