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

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

Issue 11466010: Decompose BrowserStateMonitor into two parts, simplifying unit tests and APIs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix gypi ordering. Created 8 years 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 | Annotate | Revision Log
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_delegate_impl.h" 5 #include "chrome/browser/chromeos/input_method/input_method_delegate_impl.h"
6 6
7 #include "base/prefs/public/pref_service_base.h" 7 #include "base/logging.h"
8 #include "chrome/browser/browser_process.h" 8 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/chromeos/language_preferences.h" 9 #include "chrome/browser/prefs/pref_service.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/profiles/profile_manager.h"
12 #include "chrome/common/pref_names.h" 10 #include "chrome/common/pref_names.h"
13 11
14 namespace chromeos { 12 namespace chromeos {
15 namespace input_method { 13 namespace input_method {
16 14
17 InputMethodDelegateImpl::InputMethodDelegateImpl() {} 15 InputMethodDelegateImpl::InputMethodDelegateImpl() {}
18 16
19 void InputMethodDelegateImpl::SetSystemInputMethod(
20 const std::string& input_method) {
21 if (g_browser_process) {
22 PrefServiceBase* local_state = g_browser_process->local_state();
23 if (local_state) {
24 local_state->SetString(language_prefs::kPreferredKeyboardLayout,
25 input_method);
26 return;
27 }
28 }
29
30 NOTREACHED();
31 }
32
33 void InputMethodDelegateImpl::SetUserInputMethod(
34 const std::string& input_method) {
35 PrefServiceBase* user_prefs = NULL;
36 Profile* profile = ProfileManager::GetDefaultProfile();
37 if (profile)
38 user_prefs = profile->GetPrefs();
39 if (!user_prefs)
40 return;
41
42 const std::string current_input_method_on_pref =
43 user_prefs->GetString(prefs::kLanguageCurrentInputMethod);
44 if (current_input_method_on_pref == input_method)
45 return;
46
47 user_prefs->SetString(prefs::kLanguagePreviousInputMethod,
48 current_input_method_on_pref);
49 user_prefs->SetString(prefs::kLanguageCurrentInputMethod,
50 input_method);
51 }
52
53 std::string InputMethodDelegateImpl::GetHardwareKeyboardLayout() const { 17 std::string InputMethodDelegateImpl::GetHardwareKeyboardLayout() const {
54 if (g_browser_process) { 18 if (g_browser_process) {
55 PrefServiceBase* local_state = g_browser_process->local_state(); 19 PrefServiceBase* local_state = g_browser_process->local_state();
56 if (local_state) 20 if (local_state)
57 return local_state->GetString(prefs::kHardwareKeyboardLayout); 21 return local_state->GetString(prefs::kHardwareKeyboardLayout);
58 } 22 }
59 // This shouldn't happen but just in case. 23 // This shouldn't happen but just in case.
60 DVLOG(1) << "Local state is not yet ready."; 24 DVLOG(1) << "Local state is not yet ready.";
61 return std::string(); 25 return std::string();
62 } 26 }
63 27
64 std::string InputMethodDelegateImpl::GetActiveLocale() const { 28 std::string InputMethodDelegateImpl::GetActiveLocale() const {
65 if (g_browser_process) 29 if (g_browser_process)
66 return g_browser_process->GetApplicationLocale(); 30 return g_browser_process->GetApplicationLocale();
67 31
68 NOTREACHED(); 32 NOTREACHED();
69 return std::string(); 33 return std::string();
70 } 34 }
71 35
72 } // namespace input_method 36 } // namespace input_method
73 } // namespace chromeos 37 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698