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..e0a79ccdefa4fc48856dab20eabe40ec236e2db7 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,6 +27,78 @@ void PersistSystemInputMethod(const std::string& input_method) { |
language_prefs::kPreferredKeyboardLayout, input_method); |
} |
+// Update user LRU keyboard layout for login screen |
+static void SetUserLRUInputMethod(const std::string& input_method) { |
+#if defined(OS_CHROMEOS) |
Seigo Nonaka
2013/07/11 09:43:56
nit: no need to add OS_CHROMEOS. This class is onl
Alexander Alekseev
2013/07/12 20:10:49
Done.
|
+ if (g_browser_process != NULL) { |
+ PrefService* local_state = g_browser_process->local_state(); |
+ DCHECK(local_state); |
Mattias Nissler (ping if slow)
2013/07/11 10:05:49
Not needed, local_state != NULL should be guarante
Alexander Alekseev
2013/07/12 20:10:49
Done.
|
+ |
+ if (local_state != NULL) { |
Seigo Nonaka
2013/07/11 09:43:56
If you put DCHECK, please remove this condition, i
Alexander Alekseev
2013/07/12 20:10:49
Done.
|
+ Profile* profile = ProfileManager::GetDefaultProfile(); |
+ if (!profile) |
+ return; |
+ |
+ chromeos::input_method::InputMethodManager* manager = |
+ chromeos::input_method::InputMethodManager::Get(); |
+ DCHECK(manager); |
Mattias Nissler (ping if slow)
2013/07/11 10:05:49
Does this singleton getter actually return NULL in
Alexander Alekseev
2013/07/12 20:10:49
Done.
|
+ |
+ if (manager == NULL) |
Seigo Nonaka
2013/07/11 09:43:56
no need to check manager, you already put DCHECK a
Alexander Alekseev
2013/07/12 20:10:49
Done.
|
+ return; |
+ |
+ const chromeos::input_method::InputMethodUtil* ime_util = |
+ manager->GetInputMethodUtil(); |
+ DCHECK(ime_util); |
+ |
+ if (ime_util == NULL) |
Seigo Nonaka
2013/07/11 09:43:56
ditto.
Alexander Alekseev
2013/07/12 20:10:49
Done.
|
+ return; |
+ |
+ if (!manager->IsLanguageFullLatinKeyboard( |
+ ime_util->GetLanguageCodeFromInputMethodId(input_method))) |
Seigo Nonaka
2013/07/11 09:43:56
Please note that third party input can set any lan
Alexander Alekseev
2013/07/12 20:10:49
Done.
|
+ 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 |
Mattias Nissler (ping if slow)
2013/07/11 10:05:49
*Updater
Alexander Alekseev
2013/07/12 20:10:49
Done.
|
+ // entry while updater exists. |
+ DictionaryPrefUpdate updater(local_state, |
+ prefs::kUsersLRUInputMethod); |
+ base::DictionaryValue* 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* 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 |
+ << "'"; |
+ } |
+ } |
+ } |
+ } |
+#endif |
+} |
+ |
void PersistUserInputMethod(const std::string& input_method) { |
PrefService* user_prefs = NULL; |
Profile* profile = ProfileManager::GetDefaultProfile(); |
@@ -33,6 +107,8 @@ void PersistUserInputMethod(const std::string& input_method) { |
if (!user_prefs) |
return; |
+ SetUserLRUInputMethod(input_method); |
+ |
const std::string current_input_method_on_pref = |
user_prefs->GetString(prefs::kLanguageCurrentInputMethod); |
if (current_input_method_on_pref == input_method) |