Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(348)

Side by Side Diff: chrome/browser/chromeos/preferences.cc

Issue 419293002: IME refactoring: ChromeOS introduce input methods State. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Unit test fixed. Re-sorted methods of StateImpl and IMM. Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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_ = 358 user_is_primary_ =
357 user_manager::UserManager::Get()->GetPrimaryUser() == user_; 359 user_manager::UserManager::Get()->GetPrimaryUser() == user_;
358 InitUserPrefs(prefs); 360 InitUserPrefs(prefs);
359 361
360 user_manager::UserManager::Get()->AddSessionStateObserver(this); 362 user_manager::UserManager::Get()->AddSessionStateObserver(this);
361 363
362 // This causes OnIsSyncingChanged to be called when the value of 364 // This causes OnIsSyncingChanged to be called when the value of
363 // PrefService::IsSyncing() changes. 365 // PrefService::IsSyncing() changes.
364 prefs->AddObserver(this); 366 prefs->AddObserver(this);
365 367
368 UserSessionManager* session_manager = UserSessionManager::GetInstance();
369 DCHECK(session_manager);
370 ime_state_ = session_manager->GetDefaultIMEState(
371 ProfileHelper::Get()->GetProfileByUser(user_));
372 input_method_manager_->SetState(ime_state_);
373
366 // Initialize preferences to currently saved state. 374 // Initialize preferences to currently saved state.
367 ApplyPreferences(REASON_INITIALIZATION, ""); 375 ApplyPreferences(REASON_INITIALIZATION, "");
368 376
369 // If a guest is logged in, initialize the prefs as if this is the first 377 // If a guest is logged in, initialize the prefs as if this is the first
370 // login. For a regular user this is done in 378 // login. For a regular user this is done in
371 // UserSessionManager::InitProfilePreferences(). 379 // UserSessionManager::InitProfilePreferences().
372 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kGuestSession)) 380 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kGuestSession))
373 UserSessionManager::SetFirstLoginPrefs(prefs, std::string(), std::string()); 381 session_manager->SetFirstLoginPrefs(profile, std::string(), std::string());
374 } 382 }
375 383
376 void Preferences::InitUserPrefsForTesting(PrefServiceSyncable* prefs, 384 void Preferences::InitUserPrefsForTesting(
377 const user_manager::User* user) { 385 PrefServiceSyncable* prefs,
386 const user_manager::User* user,
387 scoped_refptr<input_method::InputMethodManager::State> ime_state) {
378 user_ = user; 388 user_ = user;
389 ime_state_ = ime_state;
390
391 if (ime_state)
392 input_method_manager_->SetState(ime_state);
393
379 InitUserPrefs(prefs); 394 InitUserPrefs(prefs);
380 } 395 }
381 396
382 void Preferences::SetInputMethodListForTesting() { 397 void Preferences::SetInputMethodListForTesting() {
383 SetInputMethodList(); 398 SetInputMethodList();
384 } 399 }
385 400
386 void Preferences::OnPreferenceChanged(const std::string& pref_name) { 401 void Preferences::OnPreferenceChanged(const std::string& pref_name) {
387 ApplyPreferences(REASON_PREF_CHANGED, pref_name); 402 ApplyPreferences(REASON_PREF_CHANGED, pref_name);
388 } 403 }
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 ->SetAutoRepeatEnabled(enabled); 545 ->SetAutoRepeatEnabled(enabled);
531 } 546 }
532 } 547 }
533 if (reason != REASON_PREF_CHANGED || 548 if (reason != REASON_PREF_CHANGED ||
534 pref_name == prefs::kLanguageXkbAutoRepeatDelay || 549 pref_name == prefs::kLanguageXkbAutoRepeatDelay ||
535 pref_name == prefs::kLanguageXkbAutoRepeatInterval) { 550 pref_name == prefs::kLanguageXkbAutoRepeatInterval) {
536 if (user_is_active) 551 if (user_is_active)
537 UpdateAutoRepeatRate(); 552 UpdateAutoRepeatRate();
538 } 553 }
539 554
540 if (reason != REASON_PREF_CHANGED && user_is_active) { 555 if (reason == REASON_INITIALIZATION)
541 SetInputMethodList(); 556 SetInputMethodList();
542 } else if (pref_name == prefs::kLanguagePreloadEngines && user_is_active) { 557
558 if (pref_name == prefs::kLanguagePreloadEngines &&
559 reason == REASON_PREF_CHANGED) {
543 SetLanguageConfigStringListAsCSV(language_prefs::kGeneralSectionName, 560 SetLanguageConfigStringListAsCSV(language_prefs::kGeneralSectionName,
544 language_prefs::kPreloadEnginesConfigName, 561 language_prefs::kPreloadEnginesConfigName,
545 preload_engines_.GetValue()); 562 preload_engines_.GetValue());
546 } 563 }
547 564
548 if (reason != REASON_PREF_CHANGED || 565 if ((reason == REASON_INITIALIZATION) ||
549 pref_name == prefs::kLanguageEnabledExtensionImes) { 566 (pref_name == prefs::kLanguageEnabledExtensionImes &&
550 if (user_is_active) { 567 reason == REASON_PREF_CHANGED)) {
551 std::string value(enabled_extension_imes_.GetValue()); 568 std::string value(enabled_extension_imes_.GetValue());
552 569
553 std::vector<std::string> split_values; 570 std::vector<std::string> split_values;
554 if (!value.empty()) 571 if (!value.empty())
555 base::SplitString(value, ',', &split_values); 572 base::SplitString(value, ',', &split_values);
556 573
557 input_method_manager_->SetEnabledExtensionImes(&split_values); 574 ime_state_->SetEnabledExtensionImes(&split_values);
558 }
559 } 575 }
560 576
561 if (user_is_active) { 577 if (user_is_active) {
562 system::InputDeviceSettings::Get()->UpdateTouchpadSettings( 578 system::InputDeviceSettings::Get()->UpdateTouchpadSettings(
563 touchpad_settings); 579 touchpad_settings);
564 system::InputDeviceSettings::Get()->UpdateMouseSettings(mouse_settings); 580 system::InputDeviceSettings::Get()->UpdateMouseSettings(mouse_settings);
565 } 581 }
566 } 582 }
567 583
568 void Preferences::OnIsSyncingChanged() { 584 void Preferences::OnIsSyncingChanged() {
(...skipping 21 matching lines...) Expand all
590 std::vector<std::string> split_values; 606 std::vector<std::string> split_values;
591 if (!value.empty()) 607 if (!value.empty())
592 base::SplitString(value, ',', &split_values); 608 base::SplitString(value, ',', &split_values);
593 609
594 // Transfers the xkb id to extension-xkb id. 610 // Transfers the xkb id to extension-xkb id.
595 if (input_method_manager_->MigrateInputMethods(&split_values)) 611 if (input_method_manager_->MigrateInputMethods(&split_values))
596 preload_engines_.SetValue(JoinString(split_values, ',')); 612 preload_engines_.SetValue(JoinString(split_values, ','));
597 613
598 if (section == std::string(language_prefs::kGeneralSectionName) && 614 if (section == std::string(language_prefs::kGeneralSectionName) &&
599 name == std::string(language_prefs::kPreloadEnginesConfigName)) { 615 name == std::string(language_prefs::kPreloadEnginesConfigName)) {
600 input_method_manager_->ReplaceEnabledInputMethods(split_values); 616 ime_state_->ReplaceEnabledInputMethods(split_values);
601 return; 617 return;
602 } 618 }
603 } 619 }
604 620
605 void Preferences::SetInputMethodList() { 621 void Preferences::SetInputMethodList() {
606 // When |preload_engines_| are set, InputMethodManager::ChangeInputMethod() 622 // When |preload_engines_| are set, InputMethodManager::ChangeInputMethod()
607 // might be called to change the current input method to the first one in the 623 // might be called to change the current input method to the first one in the
608 // |preload_engines_| list. This also updates previous/current input method 624 // |preload_engines_| list. This also updates previous/current input method
609 // prefs. That's why GetValue() calls are placed before the 625 // prefs. That's why GetValue() calls are placed before the
610 // SetLanguageConfigStringListAsCSV() call below. 626 // SetLanguageConfigStringListAsCSV() call below.
611 const std::string previous_input_method_id = 627 const std::string previous_input_method_id =
612 previous_input_method_.GetValue(); 628 previous_input_method_.GetValue();
613 const std::string current_input_method_id = current_input_method_.GetValue(); 629 const std::string current_input_method_id = current_input_method_.GetValue();
614 SetLanguageConfigStringListAsCSV(language_prefs::kGeneralSectionName, 630 SetLanguageConfigStringListAsCSV(language_prefs::kGeneralSectionName,
615 language_prefs::kPreloadEnginesConfigName, 631 language_prefs::kPreloadEnginesConfigName,
616 preload_engines_.GetValue()); 632 preload_engines_.GetValue());
617 633
618 // ChangeInputMethod() has to be called AFTER the value of |preload_engines_| 634 // ChangeInputMethod() has to be called AFTER the value of |preload_engines_|
619 // is sent to the InputMethodManager. Otherwise, the ChangeInputMethod request 635 // is sent to the InputMethodManager. Otherwise, the ChangeInputMethod request
620 // might be ignored as an invalid input method ID. The ChangeInputMethod() 636 // might be ignored as an invalid input method ID. The ChangeInputMethod()
621 // calls are also necessary to restore the previous/current input method prefs 637 // calls are also necessary to restore the previous/current input method prefs
622 // which could have been modified by the SetLanguageConfigStringListAsCSV call 638 // which could have been modified by the SetLanguageConfigStringListAsCSV call
623 // above to the original state. 639 // above to the original state.
624 if (!previous_input_method_id.empty()) 640 if (!previous_input_method_id.empty())
625 input_method_manager_->ChangeInputMethod(previous_input_method_id); 641 ime_state_->ChangeInputMethod(previous_input_method_id,
642 false /* show_message */);
626 if (!current_input_method_id.empty()) 643 if (!current_input_method_id.empty())
627 input_method_manager_->ChangeInputMethod(current_input_method_id); 644 ime_state_->ChangeInputMethod(current_input_method_id,
645 false /* show_message */);
628 } 646 }
629 647
630 void Preferences::UpdateAutoRepeatRate() { 648 void Preferences::UpdateAutoRepeatRate() {
631 input_method::AutoRepeatRate rate; 649 input_method::AutoRepeatRate rate;
632 rate.initial_delay_in_ms = xkb_auto_repeat_delay_pref_.GetValue(); 650 rate.initial_delay_in_ms = xkb_auto_repeat_delay_pref_.GetValue();
633 rate.repeat_interval_in_ms = xkb_auto_repeat_interval_pref_.GetValue(); 651 rate.repeat_interval_in_ms = xkb_auto_repeat_interval_pref_.GetValue();
634 DCHECK(rate.initial_delay_in_ms > 0); 652 DCHECK(rate.initial_delay_in_ms > 0);
635 DCHECK(rate.repeat_interval_in_ms > 0); 653 DCHECK(rate.repeat_interval_in_ms > 0);
636 input_method::InputMethodManager::Get() 654 input_method::InputMethodManager::Get()
637 ->GetImeKeyboard() 655 ->GetImeKeyboard()
638 ->SetAutoRepeatRate(rate); 656 ->SetAutoRepeatRate(rate);
639 } 657 }
640 658
641 void Preferences::OnTouchHudProjectionToggled(bool enabled) { 659 void Preferences::OnTouchHudProjectionToggled(bool enabled) {
642 if (touch_hud_projection_enabled_.GetValue() == enabled) 660 if (touch_hud_projection_enabled_.GetValue() == enabled)
643 return; 661 return;
644 if (!user_->is_active()) 662 if (!user_->is_active())
645 return; 663 return;
646 touch_hud_projection_enabled_.SetValue(enabled); 664 touch_hud_projection_enabled_.SetValue(enabled);
647 } 665 }
648 666
649 void Preferences::ActiveUserChanged(const user_manager::User* active_user) { 667 void Preferences::ActiveUserChanged(const user_manager::User* active_user) {
650 if (active_user != user_) 668 if (active_user != user_)
651 return; 669 return;
652 ApplyPreferences(REASON_ACTIVE_USER_CHANGED, ""); 670 ApplyPreferences(REASON_ACTIVE_USER_CHANGED, "");
653 } 671 }
654 672
655 } // namespace chromeos 673 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/preferences.h ('k') | chrome/browser/chromeos/preferences_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698