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.
5 #ifndef CHROME_BROWSER_CHROMEOS_INPUT_METHOD_BROWSER_STATE_MONITOR_H_
6 #define CHROME_BROWSER_CHROMEOS_INPUT_METHOD_BROWSER_STATE_MONITOR_H_
10 #include "chrome/browser/api/prefs/pref_member.h"
11 #include "chrome/browser/chromeos/input_method/input_method_manager.h"
12 #include "content/public/browser/notification_observer.h"
13 #include "content/public/browser/notification_registrar.h"
14 #include "content/public/browser/notification_types.h"
19 namespace input_method
{
21 // A class which monitors a notification from the browser to keep track of the
22 // browser state (not logged in, logged in, etc.) and notify the current state
23 // to the input method manager. The class also updates the appropriate Chrome
24 // prefs (~/Local\ State or ~/Preferences) depending on the current browser
26 class BrowserStateMonitor
: public content::NotificationObserver
,
27 public InputMethodManager::Observer
{
29 explicit BrowserStateMonitor(InputMethodManager
* manager
);
30 virtual ~BrowserStateMonitor();
32 InputMethodManager::State
state() const { return state_
; }
34 void SetPrefServiceForTesting(PrefService
* pref_service
);
37 // Updates ~/Local\ State file. protected: for testing.
38 virtual void UpdateLocalState(const std::string
& current_input_method
);
39 // Updates ~/Preferences file. protected: for testing.
40 virtual void UpdateUserPreferences(const std::string
& current_input_method
);
42 // InputMethodManager::Observer overrides:
43 virtual void InputMethodChanged(InputMethodManager
* manager
,
44 bool show_message
) OVERRIDE
;
45 virtual void InputMethodPropertyChanged(InputMethodManager
* manager
) OVERRIDE
;
47 // content::NotificationObserver overrides:
48 virtual void Observe(int type
,
49 const content::NotificationSource
& source
,
50 const content::NotificationDetails
& details
) OVERRIDE
;
53 void SetState(InputMethodManager::State new_state
);
54 void InitializePrefMembers();
56 InputMethodManager
* manager_
;
57 InputMethodManager::State state_
;
59 // This is used to register this object to some browser notifications.
60 content::NotificationRegistrar notification_registrar_
;
63 PrefService
* pref_service_
;
65 DISALLOW_COPY_AND_ASSIGN(BrowserStateMonitor
);
68 } // namespace input_method
69 } // namespace chromeos
71 #endif // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_BROWSER_STATE_MONITOR_H_