Chromium Code Reviews| Index: chrome/browser/chromeos/input_method/input_method_persistence.cc |
| diff --git a/chrome/browser/chromeos/input_method/input_method_persistence.cc b/chrome/browser/chromeos/input_method/input_method_persistence.cc |
| index 9562b237cc4b21bd9d7e13aeb269dbaa89d8d53f..1afb2dccd3236948cc0a80c9bddd7d1556f435b3 100644 |
| --- a/chrome/browser/chromeos/input_method/input_method_persistence.cc |
| +++ b/chrome/browser/chromeos/input_method/input_method_persistence.cc |
| @@ -4,11 +4,13 @@ |
| #include "chrome/browser/chromeos/input_method/input_method_persistence.h" |
| +#include "base/chromeos/chromeos_version.h" |
| #include "base/logging.h" |
| #include "base/prefs/pref_service.h" |
| #include "chrome/browser/browser_process.h" |
| #include "chrome/browser/chromeos/input_method/input_method_util.h" |
| #include "chrome/browser/chromeos/language_preferences.h" |
| +#include "chrome/browser/prefs/scoped_user_pref_update.h" |
| #include "chrome/browser/profiles/profile.h" |
| #include "chrome/browser/profiles/profile_manager.h" |
| #include "chrome/common/pref_names.h" |
| @@ -25,7 +27,63 @@ void PersistSystemInputMethod(const std::string& input_method) { |
| language_prefs::kPreferredKeyboardLayout, input_method); |
| } |
| -void PersistUserInputMethod(const std::string& input_method) { |
| +// Update user LRU keyboard layout for login screen |
| +static void SetUserLRUInputMethod( |
| + const std::string& input_method, |
| + const chromeos::input_method::InputMethodManager* const manager) { |
| + // Skip if it's not a keyboard layout. Drop input methods including |
| + // extension ones. |
| + if (!InputMethodUtil::IsKeyboardLayout(input_method)) |
| + return; |
| + |
| + PrefService* const local_state = g_browser_process->local_state(); |
| + |
| + Profile* const profile = ProfileManager::GetDefaultProfile(); |
| + |
| + if (profile == NULL) |
| + return; |
| + |
| + if (!manager->IsFullLatinKeyboard(input_method)) |
| + return; |
| + |
| + const std::string username = profile->GetProfileName(); |
| + if (base::chromeos::IsRunningOnChromeOS() && !username.empty() && |
| + !local_state->ReadOnly()) { |
| + bool update_succeed = false; |
| + { |
| + // Updater may have side-effects, therefore we do not replace |
| + // entry while updater exists. |
| + DictionaryPrefUpdate updater(local_state, prefs::kUsersLRUInputMethod); |
| + base::DictionaryValue* const users_lru_input_methods = updater.Get(); |
| + if (users_lru_input_methods) { |
| + users_lru_input_methods->SetStringWithoutPathExpansion(username, |
| + input_method); |
| + update_succeed = true; |
| + } |
| + } |
| + if (!update_succeed) { |
| + // Somehow key kUsersLRUInputMethod has value of invalid type. |
| + // Replace and retry. |
| + local_state->Set(prefs::kUsersLRUInputMethod, base::DictionaryValue()); |
| + |
| + DictionaryPrefUpdate updater(local_state, prefs::kUsersLRUInputMethod); |
| + base::DictionaryValue* const users_lru_input_methods = updater.Get(); |
| + if (users_lru_input_methods) { |
| + users_lru_input_methods->SetStringWithoutPathExpansion(username, |
| + input_method); |
| + update_succeed = true; |
| + } |
| + } |
| + if (!update_succeed) { |
| + DVLOG(1) << "Failed to replace local_state.kUsersLRUInputMethod: '" |
| + << prefs::kUsersLRUInputMethod << "' for '" << username |
|
Seigo Nonaka
2013/07/22 13:17:34
nit: indent?
Alexander Alekseev
2013/07/22 14:24:21
Done.
|
| + << "'"; |
| + } |
| + } |
| +} |
| + |
| +void PersistUserInputMethod(const std::string& input_method, |
| + InputMethodManager* const manager) { |
| PrefService* user_prefs = NULL; |
| Profile* profile = ProfileManager::GetDefaultProfile(); |
| if (profile) |
| @@ -33,6 +91,8 @@ void PersistUserInputMethod(const std::string& input_method) { |
| if (!user_prefs) |
| return; |
| + SetUserLRUInputMethod(input_method, manager); |
| + |
| const std::string current_input_method_on_pref = |
| user_prefs->GetString(prefs::kLanguageCurrentInputMethod); |
| if (current_input_method_on_pref == input_method) |
| @@ -73,7 +133,7 @@ void InputMethodPersistence::InputMethodChanged( |
| PersistSystemInputMethod(current_input_method); |
| return; |
| case InputMethodManager::STATE_BROWSER_SCREEN: |
| - PersistUserInputMethod(current_input_method); |
| + PersistUserInputMethod(current_input_method, manager); |
| return; |
| case InputMethodManager::STATE_LOCK_SCREEN: |
| // We use a special set of input methods on the screen. Do not update. |