| 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/input_method/input_method_persistence.h" | 5 #include "chrome/browser/chromeos/input_method/input_method_persistence.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
| 9 #include "base/prefs/scoped_user_pref_update.h" | 9 #include "base/prefs/scoped_user_pref_update.h" |
| 10 #include "base/sys_info.h" | 10 #include "base/sys_info.h" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 if (profile == NULL) | 76 if (profile == NULL) |
| 77 return; | 77 return; |
| 78 | 78 |
| 79 PrefService* const local_state = g_browser_process->local_state(); | 79 PrefService* const local_state = g_browser_process->local_state(); |
| 80 | 80 |
| 81 SetUserLRUInputMethodPreference( | 81 SetUserLRUInputMethodPreference( |
| 82 profile->GetProfileUserName(), input_method, local_state); | 82 profile->GetProfileUserName(), input_method, local_state); |
| 83 } | 83 } |
| 84 | 84 |
| 85 void PersistUserInputMethod(const std::string& input_method, | 85 void PersistUserInputMethod(const std::string& input_method, |
| 86 InputMethodManager* const manager) { | 86 InputMethodManager* const manager, |
| 87 Profile* profile) { |
| 87 PrefService* user_prefs = NULL; | 88 PrefService* user_prefs = NULL; |
| 88 // Persist the method on a per user basis. Note that the keyboard settings are | 89 // Persist the method on a per user basis. Note that the keyboard settings are |
| 89 // stored per user desktop and a visiting window will use the same input | 90 // stored per user desktop and a visiting window will use the same input |
| 90 // method as the desktop it is on (and not of the owner of the window). | 91 // method as the desktop it is on (and not of the owner of the window). |
| 91 Profile* profile = ProfileManager::GetActiveUserProfile(); | |
| 92 if (profile) | 92 if (profile) |
| 93 user_prefs = profile->GetPrefs(); | 93 user_prefs = profile->GetPrefs(); |
| 94 if (!user_prefs) | 94 if (!user_prefs) |
| 95 return; | 95 return; |
| 96 SetUserLRUInputMethod(input_method, manager, profile); | 96 SetUserLRUInputMethod(input_method, manager, profile); |
| 97 | 97 |
| 98 const std::string current_input_method_on_pref = | 98 const std::string current_input_method_on_pref = |
| 99 user_prefs->GetString(prefs::kLanguageCurrentInputMethod); | 99 user_prefs->GetString(prefs::kLanguageCurrentInputMethod); |
| 100 if (current_input_method_on_pref == input_method) | 100 if (current_input_method_on_pref == input_method) |
| 101 return; | 101 return; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 112 InputMethodManager* input_method_manager) | 112 InputMethodManager* input_method_manager) |
| 113 : input_method_manager_(input_method_manager), | 113 : input_method_manager_(input_method_manager), |
| 114 ui_session_(InputMethodManager::STATE_LOGIN_SCREEN) { | 114 ui_session_(InputMethodManager::STATE_LOGIN_SCREEN) { |
| 115 input_method_manager_->AddObserver(this); | 115 input_method_manager_->AddObserver(this); |
| 116 } | 116 } |
| 117 | 117 |
| 118 InputMethodPersistence::~InputMethodPersistence() { | 118 InputMethodPersistence::~InputMethodPersistence() { |
| 119 input_method_manager_->RemoveObserver(this); | 119 input_method_manager_->RemoveObserver(this); |
| 120 } | 120 } |
| 121 | 121 |
| 122 void InputMethodPersistence::InputMethodChanged( | 122 void InputMethodPersistence::InputMethodChanged(InputMethodManager* manager, |
| 123 InputMethodManager* manager, bool show_message) { | 123 Profile* profile, |
| 124 bool show_message) { |
| 124 DCHECK_EQ(input_method_manager_, manager); | 125 DCHECK_EQ(input_method_manager_, manager); |
| 125 const std::string current_input_method = | 126 const std::string current_input_method = |
| 126 manager->GetActiveIMEState()->GetCurrentInputMethod().id(); | 127 manager->GetActiveIMEState()->GetCurrentInputMethod().id(); |
| 127 // Save the new input method id depending on the current browser state. | 128 // Save the new input method id depending on the current browser state. |
| 128 switch (ui_session_) { | 129 switch (ui_session_) { |
| 129 case InputMethodManager::STATE_LOGIN_SCREEN: | 130 case InputMethodManager::STATE_LOGIN_SCREEN: |
| 130 if (!manager->IsLoginKeyboard(current_input_method)) { | 131 if (!manager->IsLoginKeyboard(current_input_method)) { |
| 131 DVLOG(1) << "Only keyboard layouts are supported: " | 132 DVLOG(1) << "Only keyboard layouts are supported: " |
| 132 << current_input_method; | 133 << current_input_method; |
| 133 return; | 134 return; |
| 134 } | 135 } |
| 135 PersistSystemInputMethod(current_input_method); | 136 PersistSystemInputMethod(current_input_method); |
| 136 return; | 137 return; |
| 137 case InputMethodManager::STATE_BROWSER_SCREEN: | 138 case InputMethodManager::STATE_BROWSER_SCREEN: |
| 138 PersistUserInputMethod(current_input_method, manager); | 139 PersistUserInputMethod(current_input_method, manager, profile); |
| 139 return; | 140 return; |
| 140 case InputMethodManager::STATE_LOCK_SCREEN: | 141 case InputMethodManager::STATE_LOCK_SCREEN: |
| 141 // We use a special set of input methods on the screen. Do not update. | 142 // We use a special set of input methods on the screen. Do not update. |
| 142 return; | 143 return; |
| 143 case InputMethodManager::STATE_TERMINATING: | 144 case InputMethodManager::STATE_TERMINATING: |
| 144 return; | 145 return; |
| 145 } | 146 } |
| 146 NOTREACHED(); | 147 NOTREACHED(); |
| 147 } | 148 } |
| 148 | 149 |
| 149 void InputMethodPersistence::OnSessionStateChange( | 150 void InputMethodPersistence::OnSessionStateChange( |
| 150 InputMethodManager::UISessionState new_ui_session) { | 151 InputMethodManager::UISessionState new_ui_session) { |
| 151 ui_session_ = new_ui_session; | 152 ui_session_ = new_ui_session; |
| 152 } | 153 } |
| 153 | 154 |
| 154 void SetUserLRUInputMethodPreferenceForTesting(const std::string& username, | 155 void SetUserLRUInputMethodPreferenceForTesting(const std::string& username, |
| 155 const std::string& input_method, | 156 const std::string& input_method, |
| 156 PrefService* const local_state) { | 157 PrefService* const local_state) { |
| 157 SetUserLRUInputMethodPreference(username, input_method, local_state); | 158 SetUserLRUInputMethodPreference(username, input_method, local_state); |
| 158 } | 159 } |
| 159 | 160 |
| 160 } // namespace input_method | 161 } // namespace input_method |
| 161 } // namespace chromeos | 162 } // namespace chromeos |
| OLD | NEW |