| 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/sys_info.h" | 8 #include "base/sys_info.h" |
| 9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/chromeos/input_method/input_method_util.h" | 10 #include "chrome/browser/chromeos/input_method/input_method_util.h" |
| 11 #include "chrome/browser/chromeos/language_preferences.h" | 11 #include "chrome/browser/chromeos/language_preferences.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/profiles/profile_manager.h" | 13 #include "chrome/browser/profiles/profile_manager.h" |
| 14 #include "chrome/common/pref_names.h" | 14 #include "chrome/common/pref_names.h" |
| 15 #include "components/prefs/pref_service.h" | 15 #include "components/prefs/pref_service.h" |
| 16 #include "components/prefs/scoped_user_pref_update.h" | 16 #include "components/prefs/scoped_user_pref_update.h" |
| 17 | 17 |
| 18 namespace chromeos { | 18 namespace chromeos { |
| 19 namespace input_method { | 19 namespace input_method { |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 void PersistSystemInputMethod(const std::string& input_method) { | 22 void PersistSystemInputMethod(const std::string& input_method) { |
| 23 if (!g_browser_process || !g_browser_process->local_state()) | 23 if (!g_browser_process || !g_browser_process->local_state()) |
| 24 return; | 24 return; |
| 25 | 25 |
| 26 g_browser_process->local_state()->SetString( | 26 g_browser_process->local_state()->SetString( |
| 27 language_prefs::kPreferredKeyboardLayout, input_method); | 27 language_prefs::kPreferredKeyboardLayout, input_method); |
| 28 } | 28 } |
| 29 | 29 |
| 30 static void SetUserLRUInputMethodPreference(const std::string& username, | 30 static void SetUserLastInputMethodPreference(const std::string& username, |
| 31 const std::string& input_method, | 31 const std::string& input_method, |
| 32 PrefService* local_state) { | 32 PrefService* local_state) { |
| 33 if (!username.empty() && !local_state->ReadOnly()) { | 33 if (!username.empty() && !local_state->ReadOnly()) { |
| 34 bool update_succeed = false; | 34 bool update_succeed = false; |
| 35 { | 35 { |
| 36 // Updater may have side-effects, therefore we do not replace | 36 // Updater may have side-effects, therefore we do not replace |
| 37 // entry while updater exists. | 37 // entry while updater exists. |
| 38 DictionaryPrefUpdate updater(local_state, prefs::kUsersLRUInputMethod); | 38 DictionaryPrefUpdate updater(local_state, prefs::kUsersLastInputMethod); |
| 39 base::DictionaryValue* const users_lru_input_methods = updater.Get(); | 39 base::DictionaryValue* const users_last_input_methods = updater.Get(); |
| 40 if (users_lru_input_methods) { | 40 if (users_last_input_methods) { |
| 41 users_lru_input_methods->SetStringWithoutPathExpansion(username, | 41 users_last_input_methods->SetStringWithoutPathExpansion(username, |
| 42 input_method); | 42 input_method); |
| 43 update_succeed = true; | 43 update_succeed = true; |
| 44 } | 44 } |
| 45 } | 45 } |
| 46 if (!update_succeed) { | 46 if (!update_succeed) { |
| 47 // Somehow key kUsersLRUInputMethod has value of invalid type. | 47 // Somehow key kUsersLastInputMethod has value of invalid type. |
| 48 // Replace and retry. | 48 // Replace and retry. |
| 49 local_state->Set(prefs::kUsersLRUInputMethod, base::DictionaryValue()); | 49 local_state->Set(prefs::kUsersLastInputMethod, base::DictionaryValue()); |
| 50 | 50 |
| 51 DictionaryPrefUpdate updater(local_state, prefs::kUsersLRUInputMethod); | 51 DictionaryPrefUpdate updater(local_state, prefs::kUsersLastInputMethod); |
| 52 base::DictionaryValue* const users_lru_input_methods = updater.Get(); | 52 base::DictionaryValue* const users_last_input_methods = updater.Get(); |
| 53 if (users_lru_input_methods) { | 53 if (users_last_input_methods) { |
| 54 users_lru_input_methods->SetStringWithoutPathExpansion(username, | 54 users_last_input_methods->SetStringWithoutPathExpansion(username, |
| 55 input_method); | 55 input_method); |
| 56 update_succeed = true; | 56 update_succeed = true; |
| 57 } | 57 } |
| 58 } | 58 } |
| 59 if (!update_succeed) { | 59 if (!update_succeed) { |
| 60 DVLOG(1) << "Failed to replace local_state.kUsersLRUInputMethod: '" | 60 DVLOG(1) << "Failed to replace local_state.kUsersLastInputMethod: '" |
| 61 << prefs::kUsersLRUInputMethod << "' for '" << username << "'"; | 61 << prefs::kUsersLastInputMethod << "' for '" << username << "'"; |
| 62 } | 62 } |
| 63 } | 63 } |
| 64 } | 64 } |
| 65 | 65 |
| 66 // Update user LRU keyboard layout for login screen | 66 // Update user Last keyboard layout for login screen |
| 67 static void SetUserLRUInputMethod( | 67 static void SetUserLastInputMethod( |
| 68 const std::string& input_method, | 68 const std::string& input_method, |
| 69 const chromeos::input_method::InputMethodManager* const manager, | 69 const chromeos::input_method::InputMethodManager* const manager, |
| 70 Profile* profile) { | 70 Profile* profile) { |
| 71 // Skip if it's not a keyboard layout. Drop input methods including | 71 // Skip if it's not a keyboard layout. Drop input methods including |
| 72 // extension ones. | 72 // extension ones. |
| 73 if (!manager->IsLoginKeyboard(input_method)) | 73 if (!manager->IsLoginKeyboard(input_method)) |
| 74 return; | 74 return; |
| 75 | 75 |
| 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 SetUserLastInputMethodPreference(profile->GetProfileUserName(), input_method, |
| 82 profile->GetProfileUserName(), input_method, local_state); | 82 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 Profile* profile) { |
| 88 PrefService* user_prefs = NULL; | 88 PrefService* user_prefs = NULL; |
| 89 // 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 |
| 90 // 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 |
| 91 // 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). |
| 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 SetUserLastInputMethod(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; |
| 102 | 102 |
| 103 user_prefs->SetString(prefs::kLanguagePreviousInputMethod, | 103 user_prefs->SetString(prefs::kLanguagePreviousInputMethod, |
| 104 current_input_method_on_pref); | 104 current_input_method_on_pref); |
| 105 user_prefs->SetString(prefs::kLanguageCurrentInputMethod, | 105 user_prefs->SetString(prefs::kLanguageCurrentInputMethod, |
| 106 input_method); | 106 input_method); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 return; | 146 return; |
| 147 } | 147 } |
| 148 NOTREACHED(); | 148 NOTREACHED(); |
| 149 } | 149 } |
| 150 | 150 |
| 151 void InputMethodPersistence::OnSessionStateChange( | 151 void InputMethodPersistence::OnSessionStateChange( |
| 152 InputMethodManager::UISessionState new_ui_session) { | 152 InputMethodManager::UISessionState new_ui_session) { |
| 153 ui_session_ = new_ui_session; | 153 ui_session_ = new_ui_session; |
| 154 } | 154 } |
| 155 | 155 |
| 156 void SetUserLRUInputMethodPreferenceForTesting(const std::string& username, | 156 void SetUserLastInputMethodPreferenceForTesting( |
| 157 const std::string& input_method, | 157 const std::string& username, |
| 158 PrefService* const local_state) { | 158 const std::string& input_method, |
| 159 SetUserLRUInputMethodPreference(username, input_method, local_state); | 159 PrefService* const local_state) { |
| 160 SetUserLastInputMethodPreference(username, input_method, local_state); |
| 160 } | 161 } |
| 161 | 162 |
| 162 } // namespace input_method | 163 } // namespace input_method |
| 163 } // namespace chromeos | 164 } // namespace chromeos |
| OLD | NEW |