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 |
30 // Update user LRU keyboard layout for login screen | |
31 static void SetUserLRUInputMethod(const std::string& input_method) { | |
32 #if defined(OS_CHROMEOS) | |
Seigo Nonaka
2013/07/11 09:43:56
nit: no need to add OS_CHROMEOS. This class is onl
Alexander Alekseev
2013/07/12 20:10:49
Done.
| |
33 if (g_browser_process != NULL) { | |
34 PrefService* local_state = g_browser_process->local_state(); | |
35 DCHECK(local_state); | |
Mattias Nissler (ping if slow)
2013/07/11 10:05:49
Not needed, local_state != NULL should be guarante
Alexander Alekseev
2013/07/12 20:10:49
Done.
| |
36 | |
37 if (local_state != NULL) { | |
Seigo Nonaka
2013/07/11 09:43:56
If you put DCHECK, please remove this condition, i
Alexander Alekseev
2013/07/12 20:10:49
Done.
| |
38 Profile* profile = ProfileManager::GetDefaultProfile(); | |
39 if (!profile) | |
40 return; | |
41 | |
42 chromeos::input_method::InputMethodManager* manager = | |
43 chromeos::input_method::InputMethodManager::Get(); | |
44 DCHECK(manager); | |
Mattias Nissler (ping if slow)
2013/07/11 10:05:49
Does this singleton getter actually return NULL in
Alexander Alekseev
2013/07/12 20:10:49
Done.
| |
45 | |
46 if (manager == NULL) | |
Seigo Nonaka
2013/07/11 09:43:56
no need to check manager, you already put DCHECK a
Alexander Alekseev
2013/07/12 20:10:49
Done.
| |
47 return; | |
48 | |
49 const chromeos::input_method::InputMethodUtil* ime_util = | |
50 manager->GetInputMethodUtil(); | |
51 DCHECK(ime_util); | |
52 | |
53 if (ime_util == NULL) | |
Seigo Nonaka
2013/07/11 09:43:56
ditto.
Alexander Alekseev
2013/07/12 20:10:49
Done.
| |
54 return; | |
55 | |
56 if (!manager->IsLanguageFullLatinKeyboard( | |
57 ime_util->GetLanguageCodeFromInputMethodId(input_method))) | |
Seigo Nonaka
2013/07/11 09:43:56
Please note that third party input can set any lan
Alexander Alekseev
2013/07/12 20:10:49
Done.
| |
58 return; | |
59 | |
60 const std::string username = profile->GetProfileName(); | |
61 if (base::chromeos::IsRunningOnChromeOS() && !username.empty() && | |
62 !local_state->ReadOnly()) { | |
63 bool update_succeed = false; | |
64 { | |
65 // updater may have side-effects, therefore we do not replace | |
Mattias Nissler (ping if slow)
2013/07/11 10:05:49
*Updater
Alexander Alekseev
2013/07/12 20:10:49
Done.
| |
66 // entry while updater exists. | |
67 DictionaryPrefUpdate updater(local_state, | |
68 prefs::kUsersLRUInputMethod); | |
69 base::DictionaryValue* users_lru_input_methods = updater.Get(); | |
70 if (users_lru_input_methods) { | |
71 users_lru_input_methods->SetStringWithoutPathExpansion( | |
72 username, input_method); | |
73 update_succeed = true; | |
74 } | |
75 } | |
76 if (!update_succeed) { | |
77 // Somehow key kUsersLRUInputMethod has value of invalid type. | |
78 // Replace and retry. | |
79 local_state->Set(prefs::kUsersLRUInputMethod, | |
80 base::DictionaryValue()); | |
81 | |
82 DictionaryPrefUpdate updater(local_state, | |
83 prefs::kUsersLRUInputMethod); | |
84 base::DictionaryValue* users_lru_input_methods = updater.Get(); | |
85 if (users_lru_input_methods) { | |
86 users_lru_input_methods->SetStringWithoutPathExpansion( | |
87 username, input_method); | |
88 update_succeed = true; | |
89 } | |
90 } | |
91 if (!update_succeed) { | |
92 DVLOG(1) << "Failed to replace local_state.kUsersLRUInputMethod: '" | |
93 << prefs::kUsersLRUInputMethod << "' for '" << username | |
94 << "'"; | |
95 } | |
96 } | |
97 } | |
98 } | |
99 #endif | |
100 } | |
101 | |
28 void PersistUserInputMethod(const std::string& input_method) { | 102 void PersistUserInputMethod(const std::string& input_method) { |
29 PrefService* user_prefs = NULL; | 103 PrefService* user_prefs = NULL; |
30 Profile* profile = ProfileManager::GetDefaultProfile(); | 104 Profile* profile = ProfileManager::GetDefaultProfile(); |
31 if (profile) | 105 if (profile) |
32 user_prefs = profile->GetPrefs(); | 106 user_prefs = profile->GetPrefs(); |
33 if (!user_prefs) | 107 if (!user_prefs) |
34 return; | 108 return; |
35 | 109 |
110 SetUserLRUInputMethod(input_method); | |
111 | |
36 const std::string current_input_method_on_pref = | 112 const std::string current_input_method_on_pref = |
37 user_prefs->GetString(prefs::kLanguageCurrentInputMethod); | 113 user_prefs->GetString(prefs::kLanguageCurrentInputMethod); |
38 if (current_input_method_on_pref == input_method) | 114 if (current_input_method_on_pref == input_method) |
39 return; | 115 return; |
40 | 116 |
41 user_prefs->SetString(prefs::kLanguagePreviousInputMethod, | 117 user_prefs->SetString(prefs::kLanguagePreviousInputMethod, |
42 current_input_method_on_pref); | 118 current_input_method_on_pref); |
43 user_prefs->SetString(prefs::kLanguageCurrentInputMethod, | 119 user_prefs->SetString(prefs::kLanguageCurrentInputMethod, |
44 input_method); | 120 input_method); |
45 } | 121 } |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
87 void InputMethodPersistence::InputMethodPropertyChanged( | 163 void InputMethodPersistence::InputMethodPropertyChanged( |
88 InputMethodManager* manager) {} | 164 InputMethodManager* manager) {} |
89 | 165 |
90 void InputMethodPersistence::OnSessionStateChange( | 166 void InputMethodPersistence::OnSessionStateChange( |
91 InputMethodManager::State new_state) { | 167 InputMethodManager::State new_state) { |
92 state_ = new_state; | 168 state_ = new_state; |
93 } | 169 } |
94 | 170 |
95 } // namespace input_method | 171 } // namespace input_method |
96 } // namespace chromeos | 172 } // namespace chromeos |
OLD | NEW |