Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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. | |
| 4 | |
| 5 #include "chrome/browser/chromeos/input_method/input_method_persistence.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "chrome/browser/browser_process.h" | |
| 9 #include "chrome/browser/chromeos/input_method/input_method_util.h" | |
| 10 #include "chrome/browser/chromeos/language_preferences.h" | |
| 11 #include "chrome/browser/prefs/pref_service.h" | |
| 12 #include "chrome/browser/profiles/profile.h" | |
| 13 #include "chrome/browser/profiles/profile_manager.h" | |
| 14 #include "chrome/common/pref_names.h" | |
| 15 | |
| 16 namespace chromeos { | |
| 17 namespace input_method { | |
| 18 namespace { | |
| 19 | |
| 20 void PersistSystemInputMethod(const std::string& input_method) { | |
| 21 PrefServiceBase* local_state = NULL; | |
| 22 if (g_browser_process) | |
| 23 local_state = g_browser_process->local_state(); | |
| 24 DCHECK(local_state); | |
| 25 | |
| 26 if (local_state) { | |
|
Seigo Nonaka
2012/12/11 04:33:04
You check the |local_state| just above.
Plz remov
erikwright (departed)
2012/12/11 16:39:44
Done. Note that the original code did DCHECK in th
| |
| 27 local_state->SetString( | |
| 28 language_prefs::kPreferredKeyboardLayout, input_method); | |
| 29 } | |
| 30 } | |
| 31 | |
| 32 void PersistUserInputMethod(const std::string& input_method) { | |
| 33 PrefServiceBase* user_prefs = NULL; | |
| 34 Profile* profile = ProfileManager::GetDefaultProfile(); | |
| 35 if (profile) | |
| 36 user_prefs = profile->GetPrefs(); | |
| 37 if (!user_prefs) | |
| 38 return; | |
| 39 | |
| 40 const std::string current_input_method_on_pref = | |
| 41 user_prefs->GetString(prefs::kLanguageCurrentInputMethod); | |
| 42 if (current_input_method_on_pref == input_method) | |
| 43 return; | |
| 44 | |
| 45 user_prefs->SetString(prefs::kLanguagePreviousInputMethod, | |
| 46 current_input_method_on_pref); | |
| 47 user_prefs->SetString(prefs::kLanguageCurrentInputMethod, | |
| 48 input_method); | |
| 49 } | |
| 50 | |
| 51 } // namespace | |
| 52 | |
| 53 InputMethodPersistence::InputMethodPersistence( | |
| 54 InputMethodManager* input_method_manager) | |
| 55 : input_method_manager_(input_method_manager), | |
| 56 state_(InputMethodManager::STATE_LOGIN_SCREEN) { | |
| 57 input_method_manager_->AddObserver(this); | |
| 58 } | |
| 59 | |
| 60 InputMethodPersistence::~InputMethodPersistence() { | |
| 61 input_method_manager_->RemoveObserver(this); | |
| 62 } | |
| 63 | |
| 64 void InputMethodPersistence::InputMethodChanged( | |
| 65 InputMethodManager* manager, bool show_message) { | |
| 66 DCHECK_EQ(input_method_manager_, manager); | |
| 67 const std::string current_input_method = | |
| 68 manager->GetCurrentInputMethod().id(); | |
| 69 // Save the new input method id depending on the current browser state. | |
| 70 switch (state_) { | |
| 71 case InputMethodManager::STATE_LOGIN_SCREEN: | |
| 72 if (!InputMethodUtil::IsKeyboardLayout(current_input_method)) { | |
| 73 DVLOG(1) << "Only keyboard layouts are supported: " | |
| 74 << current_input_method; | |
| 75 return; | |
| 76 } | |
| 77 PersistSystemInputMethod(current_input_method); | |
| 78 return; | |
| 79 case InputMethodManager::STATE_BROWSER_SCREEN: | |
| 80 PersistUserInputMethod(current_input_method); | |
| 81 return; | |
| 82 case InputMethodManager::STATE_LOCK_SCREEN: | |
| 83 // We use a special set of input methods on the screen. Do not update. | |
| 84 return; | |
| 85 case InputMethodManager::STATE_TERMINATING: | |
| 86 return; | |
| 87 } | |
| 88 NOTREACHED(); | |
| 89 } | |
| 90 | |
| 91 void InputMethodPersistence::InputMethodPropertyChanged( | |
| 92 InputMethodManager* manager) {} | |
| 93 | |
| 94 void InputMethodPersistence::OnSessionStateChange( | |
| 95 InputMethodManager::State new_state) { | |
| 96 state_ = new_state; | |
| 97 } | |
| 98 | |
| 99 } // namespace input_method | |
| 100 } // namespace chromeos | |
| OLD | NEW |