| 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/chromeos/chromeos_version.h" | 7 #include "base/chromeos/chromeos_version.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 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 // Update user LRU keyboard layout for login screen | 30 // Update user LRU keyboard layout for login screen |
| 31 static void SetUserLRUInputMethod( | 31 static void SetUserLRUInputMethod( |
| 32 const std::string& input_method, | 32 const std::string& input_method, |
| 33 const chromeos::input_method::InputMethodManager* const manager) { | 33 const chromeos::input_method::InputMethodManager* const manager) { |
| 34 // Skip if it's not a keyboard layout. Drop input methods including | 34 // Skip if it's not a keyboard layout. Drop input methods including |
| 35 // extension ones. | 35 // extension ones. |
| 36 if (!InputMethodUtil::IsKeyboardLayout(input_method)) | 36 if (!manager->IsLoginKeyboard(input_method)) |
| 37 return; | 37 return; |
| 38 | 38 |
| 39 PrefService* const local_state = g_browser_process->local_state(); | 39 PrefService* const local_state = g_browser_process->local_state(); |
| 40 | 40 |
| 41 Profile* const profile = ProfileManager::GetDefaultProfile(); | 41 Profile* const profile = ProfileManager::GetDefaultProfile(); |
| 42 | 42 |
| 43 if (profile == NULL) | 43 if (profile == NULL) |
| 44 return; | 44 return; |
| 45 | 45 |
| 46 if (!manager->IsFullLatinKeyboard(input_method)) | 46 if (!manager->IsLoginKeyboard(input_method)) |
| 47 return; | 47 return; |
| 48 | 48 |
| 49 const std::string username = profile->GetProfileName(); | 49 const std::string username = profile->GetProfileName(); |
| 50 if (base::chromeos::IsRunningOnChromeOS() && !username.empty() && | 50 if (base::chromeos::IsRunningOnChromeOS() && !username.empty() && |
| 51 !local_state->ReadOnly()) { | 51 !local_state->ReadOnly()) { |
| 52 bool update_succeed = false; | 52 bool update_succeed = false; |
| 53 { | 53 { |
| 54 // Updater may have side-effects, therefore we do not replace | 54 // Updater may have side-effects, therefore we do not replace |
| 55 // entry while updater exists. | 55 // entry while updater exists. |
| 56 DictionaryPrefUpdate updater(local_state, prefs::kUsersLRUInputMethod); | 56 DictionaryPrefUpdate updater(local_state, prefs::kUsersLRUInputMethod); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 } | 117 } |
| 118 | 118 |
| 119 void InputMethodPersistence::InputMethodChanged( | 119 void InputMethodPersistence::InputMethodChanged( |
| 120 InputMethodManager* manager, bool show_message) { | 120 InputMethodManager* manager, bool show_message) { |
| 121 DCHECK_EQ(input_method_manager_, manager); | 121 DCHECK_EQ(input_method_manager_, manager); |
| 122 const std::string current_input_method = | 122 const std::string current_input_method = |
| 123 manager->GetCurrentInputMethod().id(); | 123 manager->GetCurrentInputMethod().id(); |
| 124 // Save the new input method id depending on the current browser state. | 124 // Save the new input method id depending on the current browser state. |
| 125 switch (state_) { | 125 switch (state_) { |
| 126 case InputMethodManager::STATE_LOGIN_SCREEN: | 126 case InputMethodManager::STATE_LOGIN_SCREEN: |
| 127 if (!InputMethodUtil::IsKeyboardLayout(current_input_method)) { | 127 if (!manager->IsLoginKeyboard(current_input_method)) { |
| 128 DVLOG(1) << "Only keyboard layouts are supported: " | 128 DVLOG(1) << "Only keyboard layouts are supported: " |
| 129 << current_input_method; | 129 << current_input_method; |
| 130 return; | 130 return; |
| 131 } | 131 } |
| 132 PersistSystemInputMethod(current_input_method); | 132 PersistSystemInputMethod(current_input_method); |
| 133 return; | 133 return; |
| 134 case InputMethodManager::STATE_BROWSER_SCREEN: | 134 case InputMethodManager::STATE_BROWSER_SCREEN: |
| 135 PersistUserInputMethod(current_input_method, manager); | 135 PersistUserInputMethod(current_input_method, manager); |
| 136 return; | 136 return; |
| 137 case InputMethodManager::STATE_LOCK_SCREEN: | 137 case InputMethodManager::STATE_LOCK_SCREEN: |
| 138 // We use a special set of input methods on the screen. Do not update. | 138 // We use a special set of input methods on the screen. Do not update. |
| 139 return; | 139 return; |
| 140 case InputMethodManager::STATE_TERMINATING: | 140 case InputMethodManager::STATE_TERMINATING: |
| 141 return; | 141 return; |
| 142 } | 142 } |
| 143 NOTREACHED(); | 143 NOTREACHED(); |
| 144 } | 144 } |
| 145 | 145 |
| 146 void InputMethodPersistence::InputMethodPropertyChanged( | 146 void InputMethodPersistence::InputMethodPropertyChanged( |
| 147 InputMethodManager* manager) {} | 147 InputMethodManager* manager) {} |
| 148 | 148 |
| 149 void InputMethodPersistence::OnSessionStateChange( | 149 void InputMethodPersistence::OnSessionStateChange( |
| 150 InputMethodManager::State new_state) { | 150 InputMethodManager::State new_state) { |
| 151 state_ = new_state; | 151 state_ = new_state; |
| 152 } | 152 } |
| 153 | 153 |
| 154 } // namespace input_method | 154 } // namespace input_method |
| 155 } // namespace chromeos | 155 } // namespace chromeos |
| OLD | NEW |