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

Side by Side Diff: chrome/browser/chromeos/input_method/input_method_persistence.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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/chromeos/input_method/input_method_persistence.h"
6
7 #include "base/logging.h"
8 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/chromeos/input_method/input_method_util.h"
10 #include "chrome/browser/chromeos/language_preferences.h"
11 #include "chrome/browser/prefs/pref_service.h"
12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/profiles/profile_manager.h"
14 #include "chrome/common/pref_names.h"
15
16 namespace chromeos {
17 namespace input_method {
18 namespace {
19
20 void PersistSystemInputMethod(const std::string& input_method) {
21 if (!g_browser_process || !g_browser_process->local_state())
22 return;
23
24 g_browser_process->local_state()->SetString(
25 language_prefs::kPreferredKeyboardLayout, input_method);
26 }
27
28 void PersistUserInputMethod(const std::string& input_method) {
29 PrefServiceBase* user_prefs = NULL;
30 Profile* profile = ProfileManager::GetDefaultProfile();
31 if (profile)
32 user_prefs = profile->GetPrefs();
33 if (!user_prefs)
34 return;
35
36 const std::string current_input_method_on_pref =
37 user_prefs->GetString(prefs::kLanguageCurrentInputMethod);
38 if (current_input_method_on_pref == input_method)
39 return;
40
41 user_prefs->SetString(prefs::kLanguagePreviousInputMethod,
42 current_input_method_on_pref);
43 user_prefs->SetString(prefs::kLanguageCurrentInputMethod,
44 input_method);
45 }
46
47 } // namespace
48
49 InputMethodPersistence::InputMethodPersistence(
50 InputMethodManager* input_method_manager)
51 : input_method_manager_(input_method_manager),
52 state_(InputMethodManager::STATE_LOGIN_SCREEN) {
53 input_method_manager_->AddObserver(this);
54 }
55
56 InputMethodPersistence::~InputMethodPersistence() {
57 input_method_manager_->RemoveObserver(this);
58 }
59
60 void InputMethodPersistence::InputMethodChanged(
61 InputMethodManager* manager, bool show_message) {
62 DCHECK_EQ(input_method_manager_, manager);
63 const std::string current_input_method =
64 manager->GetCurrentInputMethod().id();
65 // Save the new input method id depending on the current browser state.
66 switch (state_) {
67 case InputMethodManager::STATE_LOGIN_SCREEN:
68 if (!InputMethodUtil::IsKeyboardLayout(current_input_method)) {
69 DVLOG(1) << "Only keyboard layouts are supported: "
70 << current_input_method;
71 return;
72 }
73 PersistSystemInputMethod(current_input_method);
74 return;
75 case InputMethodManager::STATE_BROWSER_SCREEN:
76 PersistUserInputMethod(current_input_method);
77 return;
78 case InputMethodManager::STATE_LOCK_SCREEN:
79 // We use a special set of input methods on the screen. Do not update.
80 return;
81 case InputMethodManager::STATE_TERMINATING:
82 return;
83 }
84 NOTREACHED();
85 }
86
87 void InputMethodPersistence::InputMethodPropertyChanged(
88 InputMethodManager* manager) {}
89
90 void InputMethodPersistence::OnSessionStateChange(
91 InputMethodManager::State new_state) {
92 state_ = new_state;
93 }
94
95 } // namespace input_method
96 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698