Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(693)

Side by Side Diff: chrome/browser/chromeos/input_method/input_method_persistence.cc

Issue 484353005: ChromeOS: "Add New User" screen should enable all hardware keyboards. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix tests. Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 // Update user LRU keyboard layout for login screen 30 static void SetUserLRUInputMethodPreference(const std::string& username,
31 static void SetUserLRUInputMethod( 31 const std::string& input_method,
32 const std::string& input_method, 32 PrefService* local_state) {
33 const chromeos::input_method::InputMethodManager* const manager, 33 if (!username.empty() && !local_state->ReadOnly()) {
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()) {
48 bool update_succeed = false; 34 bool update_succeed = false;
49 { 35 {
50 // Updater may have side-effects, therefore we do not replace 36 // Updater may have side-effects, therefore we do not replace
51 // entry while updater exists. 37 // entry while updater exists.
52 DictionaryPrefUpdate updater(local_state, prefs::kUsersLRUInputMethod); 38 DictionaryPrefUpdate updater(local_state, prefs::kUsersLRUInputMethod);
53 base::DictionaryValue* const users_lru_input_methods = updater.Get(); 39 base::DictionaryValue* const users_lru_input_methods = updater.Get();
54 if (users_lru_input_methods) { 40 if (users_lru_input_methods) {
55 users_lru_input_methods->SetStringWithoutPathExpansion(username, 41 users_lru_input_methods->SetStringWithoutPathExpansion(username,
56 input_method); 42 input_method);
57 update_succeed = true; 43 update_succeed = true;
(...skipping 12 matching lines...) Expand all
70 update_succeed = true; 56 update_succeed = true;
71 } 57 }
72 } 58 }
73 if (!update_succeed) { 59 if (!update_succeed) {
74 DVLOG(1) << "Failed to replace local_state.kUsersLRUInputMethod: '" 60 DVLOG(1) << "Failed to replace local_state.kUsersLRUInputMethod: '"
75 << prefs::kUsersLRUInputMethod << "' for '" << username << "'"; 61 << prefs::kUsersLRUInputMethod << "' for '" << username << "'";
76 } 62 }
77 } 63 }
78 } 64 }
79 65
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
80 void PersistUserInputMethod(const std::string& input_method, 85 void PersistUserInputMethod(const std::string& input_method,
81 InputMethodManager* const manager) { 86 InputMethodManager* const manager) {
82 PrefService* user_prefs = NULL; 87 PrefService* user_prefs = NULL;
83 // Persist the method on a per user basis. Note that the keyboard settings are 88 // Persist the method on a per user basis. Note that the keyboard settings are
84 // stored per user desktop and a visiting window will use the same input 89 // stored per user desktop and a visiting window will use the same input
85 // method as the desktop it is on (and not of the owner of the window). 90 // method as the desktop it is on (and not of the owner of the window).
86 Profile* profile = ProfileManager::GetActiveUserProfile(); 91 Profile* profile = ProfileManager::GetActiveUserProfile();
87 if (profile) 92 if (profile)
88 user_prefs = profile->GetPrefs(); 93 user_prefs = profile->GetPrefs();
89 if (!user_prefs) 94 if (!user_prefs)
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 return; 144 return;
140 } 145 }
141 NOTREACHED(); 146 NOTREACHED();
142 } 147 }
143 148
144 void InputMethodPersistence::OnSessionStateChange( 149 void InputMethodPersistence::OnSessionStateChange(
145 InputMethodManager::UISessionState new_ui_session) { 150 InputMethodManager::UISessionState new_ui_session) {
146 ui_session_ = new_ui_session; 151 ui_session_ = new_ui_session;
147 } 152 }
148 153
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
149 } // namespace input_method 160 } // namespace input_method
150 } // namespace chromeos 161 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/input_method/input_method_persistence.h ('k') | chrome/browser/chromeos/login/login_manager_test.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698