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/logging.h" | 8 #include "base/logging.h" |
8 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
9 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
10 #include "chrome/browser/chromeos/input_method/input_method_util.h" | 11 #include "chrome/browser/chromeos/input_method/input_method_util.h" |
11 #include "chrome/browser/chromeos/language_preferences.h" | 12 #include "chrome/browser/chromeos/language_preferences.h" |
13 #include "chrome/browser/prefs/scoped_user_pref_update.h" | |
12 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
13 #include "chrome/browser/profiles/profile_manager.h" | 15 #include "chrome/browser/profiles/profile_manager.h" |
14 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
15 | 17 |
16 namespace chromeos { | 18 namespace chromeos { |
17 namespace input_method { | 19 namespace input_method { |
18 namespace { | 20 namespace { |
19 | 21 |
20 void PersistSystemInputMethod(const std::string& input_method) { | 22 void PersistSystemInputMethod(const std::string& input_method) { |
21 if (!g_browser_process || !g_browser_process->local_state()) | 23 if (!g_browser_process || !g_browser_process->local_state()) |
22 return; | 24 return; |
23 | 25 |
24 g_browser_process->local_state()->SetString( | 26 g_browser_process->local_state()->SetString( |
25 language_prefs::kPreferredKeyboardLayout, input_method); | 27 language_prefs::kPreferredKeyboardLayout, input_method); |
26 } | 28 } |
27 | 29 |
28 void PersistUserInputMethod(const std::string& input_method) { | 30 // Update user LRU keyboard layout for login screen |
31 static void SetUserLRUInputMethod( | |
32 const std::string& input_method, | |
33 const chromeos::input_method::InputMethodManager* const manager) { | |
34 // Skip if it's not a keyboard layout. Drop input methods including | |
35 // extension ones. | |
36 if (!InputMethodUtil::IsKeyboardLayout(input_method)) | |
37 return; | |
38 | |
39 PrefService* const local_state = g_browser_process->local_state(); | |
40 | |
41 Profile* const profile = ProfileManager::GetDefaultProfile(); | |
42 | |
43 if (profile == NULL) | |
44 return; | |
45 | |
46 if (!manager->IsFullLatinKeyboard(input_method)) | |
47 return; | |
48 | |
49 const std::string username = profile->GetProfileName(); | |
50 if (base::chromeos::IsRunningOnChromeOS() && !username.empty() && | |
51 !local_state->ReadOnly()) { | |
52 bool update_succeed = false; | |
53 { | |
54 // Updater may have side-effects, therefore we do not replace | |
55 // entry while updater exists. | |
56 DictionaryPrefUpdate updater(local_state, prefs::kUsersLRUInputMethod); | |
57 base::DictionaryValue* const users_lru_input_methods = updater.Get(); | |
58 if (users_lru_input_methods) { | |
59 users_lru_input_methods->SetStringWithoutPathExpansion(username, | |
60 input_method); | |
61 update_succeed = true; | |
62 } | |
63 } | |
64 if (!update_succeed) { | |
65 // Somehow key kUsersLRUInputMethod has value of invalid type. | |
66 // Replace and retry. | |
67 local_state->Set(prefs::kUsersLRUInputMethod, base::DictionaryValue()); | |
68 | |
69 DictionaryPrefUpdate updater(local_state, prefs::kUsersLRUInputMethod); | |
70 base::DictionaryValue* const users_lru_input_methods = updater.Get(); | |
71 if (users_lru_input_methods) { | |
72 users_lru_input_methods->SetStringWithoutPathExpansion(username, | |
73 input_method); | |
74 update_succeed = true; | |
75 } | |
76 } | |
77 if (!update_succeed) { | |
78 DVLOG(1) << "Failed to replace local_state.kUsersLRUInputMethod: '" | |
79 << prefs::kUsersLRUInputMethod << "' for '" << username | |
Seigo Nonaka
2013/07/22 13:17:34
nit: indent?
Alexander Alekseev
2013/07/22 14:24:21
Done.
| |
80 << "'"; | |
81 } | |
82 } | |
83 } | |
84 | |
85 void PersistUserInputMethod(const std::string& input_method, | |
86 InputMethodManager* const manager) { | |
29 PrefService* user_prefs = NULL; | 87 PrefService* user_prefs = NULL; |
30 Profile* profile = ProfileManager::GetDefaultProfile(); | 88 Profile* profile = ProfileManager::GetDefaultProfile(); |
31 if (profile) | 89 if (profile) |
32 user_prefs = profile->GetPrefs(); | 90 user_prefs = profile->GetPrefs(); |
33 if (!user_prefs) | 91 if (!user_prefs) |
34 return; | 92 return; |
35 | 93 |
94 SetUserLRUInputMethod(input_method, manager); | |
95 | |
36 const std::string current_input_method_on_pref = | 96 const std::string current_input_method_on_pref = |
37 user_prefs->GetString(prefs::kLanguageCurrentInputMethod); | 97 user_prefs->GetString(prefs::kLanguageCurrentInputMethod); |
38 if (current_input_method_on_pref == input_method) | 98 if (current_input_method_on_pref == input_method) |
39 return; | 99 return; |
40 | 100 |
41 user_prefs->SetString(prefs::kLanguagePreviousInputMethod, | 101 user_prefs->SetString(prefs::kLanguagePreviousInputMethod, |
42 current_input_method_on_pref); | 102 current_input_method_on_pref); |
43 user_prefs->SetString(prefs::kLanguageCurrentInputMethod, | 103 user_prefs->SetString(prefs::kLanguageCurrentInputMethod, |
44 input_method); | 104 input_method); |
45 } | 105 } |
(...skipping 20 matching lines...) Expand all Loading... | |
66 switch (state_) { | 126 switch (state_) { |
67 case InputMethodManager::STATE_LOGIN_SCREEN: | 127 case InputMethodManager::STATE_LOGIN_SCREEN: |
68 if (!InputMethodUtil::IsKeyboardLayout(current_input_method)) { | 128 if (!InputMethodUtil::IsKeyboardLayout(current_input_method)) { |
69 DVLOG(1) << "Only keyboard layouts are supported: " | 129 DVLOG(1) << "Only keyboard layouts are supported: " |
70 << current_input_method; | 130 << current_input_method; |
71 return; | 131 return; |
72 } | 132 } |
73 PersistSystemInputMethod(current_input_method); | 133 PersistSystemInputMethod(current_input_method); |
74 return; | 134 return; |
75 case InputMethodManager::STATE_BROWSER_SCREEN: | 135 case InputMethodManager::STATE_BROWSER_SCREEN: |
76 PersistUserInputMethod(current_input_method); | 136 PersistUserInputMethod(current_input_method, manager); |
77 return; | 137 return; |
78 case InputMethodManager::STATE_LOCK_SCREEN: | 138 case InputMethodManager::STATE_LOCK_SCREEN: |
79 // We use a special set of input methods on the screen. Do not update. | 139 // We use a special set of input methods on the screen. Do not update. |
80 return; | 140 return; |
81 case InputMethodManager::STATE_TERMINATING: | 141 case InputMethodManager::STATE_TERMINATING: |
82 return; | 142 return; |
83 } | 143 } |
84 NOTREACHED(); | 144 NOTREACHED(); |
85 } | 145 } |
86 | 146 |
87 void InputMethodPersistence::InputMethodPropertyChanged( | 147 void InputMethodPersistence::InputMethodPropertyChanged( |
88 InputMethodManager* manager) {} | 148 InputMethodManager* manager) {} |
89 | 149 |
90 void InputMethodPersistence::OnSessionStateChange( | 150 void InputMethodPersistence::OnSessionStateChange( |
91 InputMethodManager::State new_state) { | 151 InputMethodManager::State new_state) { |
92 state_ = new_state; | 152 state_ = new_state; |
93 } | 153 } |
94 | 154 |
95 } // namespace input_method | 155 } // namespace input_method |
96 } // namespace chromeos | 156 } // namespace chromeos |
OLD | NEW |