| 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" |
| 11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
| 12 #include "chrome/browser/chromeos/input_method/input_method_util.h" | 12 #include "chrome/browser/chromeos/input_method/input_method_util.h" |
| 13 #include "chrome/browser/chromeos/language_preferences.h" | 13 #include "chrome/browser/chromeos/language_preferences.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/profiles/profile_manager.h" | 15 #include "chrome/browser/profiles/profile_manager.h" |
| 16 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.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 // Update user LRU keyboard layout for login screen |
| 31 const std::string& input_method, | 31 static void SetUserLRUInputMethod( |
| 32 PrefService* local_state) { | 32 const std::string& input_method, |
| 33 if (!username.empty() && !local_state->ReadOnly()) { | 33 const chromeos::input_method::InputMethodManager* const manager, |
| 34 Profile* profile) { |
| 35 // Skip if it's not a keyboard layout. Drop input methods including |
| 36 // extension ones. |
| 37 if (!manager->IsLoginKeyboard(input_method)) |
| 38 return; |
| 39 |
| 40 PrefService* const local_state = g_browser_process->local_state(); |
| 41 |
| 42 if (profile == NULL) |
| 43 return; |
| 44 |
| 45 const std::string username = profile->GetProfileName(); |
| 46 if (base::SysInfo::IsRunningOnChromeOS() && !username.empty() && |
| 47 !local_state->ReadOnly()) { |
| 34 bool update_succeed = false; | 48 bool update_succeed = false; |
| 35 { | 49 { |
| 36 // Updater may have side-effects, therefore we do not replace | 50 // Updater may have side-effects, therefore we do not replace |
| 37 // entry while updater exists. | 51 // entry while updater exists. |
| 38 DictionaryPrefUpdate updater(local_state, prefs::kUsersLRUInputMethod); | 52 DictionaryPrefUpdate updater(local_state, prefs::kUsersLRUInputMethod); |
| 39 base::DictionaryValue* const users_lru_input_methods = updater.Get(); | 53 base::DictionaryValue* const users_lru_input_methods = updater.Get(); |
| 40 if (users_lru_input_methods) { | 54 if (users_lru_input_methods) { |
| 41 users_lru_input_methods->SetStringWithoutPathExpansion(username, | 55 users_lru_input_methods->SetStringWithoutPathExpansion(username, |
| 42 input_method); | 56 input_method); |
| 43 update_succeed = true; | 57 update_succeed = true; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 56 update_succeed = true; | 70 update_succeed = true; |
| 57 } | 71 } |
| 58 } | 72 } |
| 59 if (!update_succeed) { | 73 if (!update_succeed) { |
| 60 DVLOG(1) << "Failed to replace local_state.kUsersLRUInputMethod: '" | 74 DVLOG(1) << "Failed to replace local_state.kUsersLRUInputMethod: '" |
| 61 << prefs::kUsersLRUInputMethod << "' for '" << username << "'"; | 75 << prefs::kUsersLRUInputMethod << "' for '" << username << "'"; |
| 62 } | 76 } |
| 63 } | 77 } |
| 64 } | 78 } |
| 65 | 79 |
| 66 // Update user LRU keyboard layout for login screen | |
| 67 static void SetUserLRUInputMethod( | |
| 68 const std::string& input_method, | |
| 69 const chromeos::input_method::InputMethodManager* const manager, | |
| 70 Profile* profile) { | |
| 71 // Skip if it's not a keyboard layout. Drop input methods including | |
| 72 // extension ones. | |
| 73 if (!manager->IsLoginKeyboard(input_method)) | |
| 74 return; | |
| 75 | |
| 76 if (profile == NULL) | |
| 77 return; | |
| 78 | |
| 79 PrefService* const local_state = g_browser_process->local_state(); | |
| 80 | |
| 81 SetUserLRUInputMethodPreference( | |
| 82 profile->GetProfileName(), input_method, local_state); | |
| 83 } | |
| 84 | |
| 85 void PersistUserInputMethod(const std::string& input_method, | 80 void PersistUserInputMethod(const std::string& input_method, |
| 86 InputMethodManager* const manager) { | 81 InputMethodManager* const manager) { |
| 87 PrefService* user_prefs = NULL; | 82 PrefService* user_prefs = NULL; |
| 88 // Persist the method on a per user basis. Note that the keyboard settings are | 83 // 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 | 84 // 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). | 85 // method as the desktop it is on (and not of the owner of the window). |
| 91 Profile* profile = ProfileManager::GetActiveUserProfile(); | 86 Profile* profile = ProfileManager::GetActiveUserProfile(); |
| 92 if (profile) | 87 if (profile) |
| 93 user_prefs = profile->GetPrefs(); | 88 user_prefs = profile->GetPrefs(); |
| 94 if (!user_prefs) | 89 if (!user_prefs) |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 return; | 139 return; |
| 145 } | 140 } |
| 146 NOTREACHED(); | 141 NOTREACHED(); |
| 147 } | 142 } |
| 148 | 143 |
| 149 void InputMethodPersistence::OnSessionStateChange( | 144 void InputMethodPersistence::OnSessionStateChange( |
| 150 InputMethodManager::UISessionState new_ui_session) { | 145 InputMethodManager::UISessionState new_ui_session) { |
| 151 ui_session_ = new_ui_session; | 146 ui_session_ = new_ui_session; |
| 152 } | 147 } |
| 153 | 148 |
| 154 void SetUserLRUInputMethodPreferenceForTesting(const std::string& username, | |
| 155 const std::string& input_method, | |
| 156 PrefService* const local_state) { | |
| 157 SetUserLRUInputMethodPreference(username, input_method, local_state); | |
| 158 } | |
| 159 | |
| 160 } // namespace input_method | 149 } // namespace input_method |
| 161 } // namespace chromeos | 150 } // namespace chromeos |
| OLD | NEW |