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

Unified Diff: chrome/browser/chromeos/input_method/input_method_persistence.cc

Issue 18856014: We should switch the keyboard layout to the layout the user set according to (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Diff versus master. Created 7 years, 5 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 side-by-side diff with in-line comments
Download patch
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..49809fe1aa04807a5bf99efaafe701af5356f4d4 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,62 @@ 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 << "'";
+ }
+ }
+}
+
+void PersistUserInputMethod(const std::string& input_method,
+ InputMethodManager* const manager) {
PrefService* user_prefs = NULL;
Profile* profile = ProfileManager::GetDefaultProfile();
if (profile)
@@ -33,6 +90,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 +132,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.

Powered by Google App Engine
This is Rietveld 408576698