OLD | NEW |
| (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 #ifndef CHROME_BROWSER_CHROMEOS_INPUT_METHOD_BROWSER_STATE_MONITOR_H_ | |
6 #define CHROME_BROWSER_CHROMEOS_INPUT_METHOD_BROWSER_STATE_MONITOR_H_ | |
7 #pragma once | |
8 | |
9 #include <string> | |
10 | |
11 #include "chrome/browser/chromeos/input_method/input_method_manager.h" | |
12 #include "chrome/browser/prefs/pref_member.h" | |
13 #include "content/public/browser/notification_observer.h" | |
14 #include "content/public/browser/notification_registrar.h" | |
15 #include "content/public/browser/notification_types.h" | |
16 | |
17 namespace chromeos { | |
18 namespace input_method { | |
19 | |
20 // A class which monitors a notification from the browser to keep track of the | |
21 // browser state (not logged in, logged in, etc.) and notify the current state | |
22 // to the input method manager. The class also updates the appropriate Chrome | |
23 // prefs (~/Local\ State or ~/Preferences) depending on the current browser | |
24 // state. | |
25 class BrowserStateMonitor | |
26 : public content::NotificationObserver, | |
27 public input_method::InputMethodManager::PreferenceObserver { | |
28 public: | |
29 explicit BrowserStateMonitor(InputMethodManager* manager); | |
30 virtual ~BrowserStateMonitor(); | |
31 | |
32 protected: | |
33 // Updates ~/Local\ State file. protected: for testing. | |
34 virtual void UpdateLocalState(const std::string& current_input_method); | |
35 // Updates ~/Preferences file. protected: for testing. | |
36 virtual void UpdateUserPreferences(const std::string& current_input_method); | |
37 | |
38 private: | |
39 // InputMethodManager::PreferenceObserver implementation. | |
40 // TODO(yusukes): On R20, use input_method::InputMethodManager::Observer and | |
41 // remove the PreferenceObserver interface from InputMethodManager. | |
42 virtual void PreferenceUpdateNeeded( | |
43 input_method::InputMethodManager* manager, | |
44 const input_method::InputMethodDescriptor& previous_input_method, | |
45 const input_method::InputMethodDescriptor& current_input_method) OVERRIDE; | |
46 virtual void FirstObserverIsAdded( | |
47 input_method::InputMethodManager* manager) OVERRIDE {} | |
48 | |
49 // content::NotificationObserver overrides: | |
50 virtual void Observe(int type, | |
51 const content::NotificationSource& source, | |
52 const content::NotificationDetails& details) OVERRIDE; | |
53 | |
54 void SetState(InputMethodManager::State new_state); | |
55 void InitializePrefMembers(); | |
56 | |
57 InputMethodManager* manager_; | |
58 InputMethodManager::State state_; | |
59 | |
60 // Objects for updating the Chrome prefs. | |
61 StringPrefMember previous_input_method_pref_; | |
62 StringPrefMember current_input_method_pref_; | |
63 bool initialized_; | |
64 | |
65 // This is used to register this object to some browser notifications. | |
66 content::NotificationRegistrar notification_registrar_; | |
67 | |
68 DISALLOW_COPY_AND_ASSIGN(BrowserStateMonitor); | |
69 }; | |
70 | |
71 } // namespace input_method | |
72 } // namespace chromeos | |
73 | |
74 #endif // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_BROWSER_STATE_MONITOR_H_ | |
OLD | NEW |