1 // Copyright 2013 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_UI_ASH_SYSTEM_TRAY_DELEGATE_CHROMEOS_H_
6 #define CHROME_BROWSER_UI_ASH_SYSTEM_TRAY_DELEGATE_CHROMEOS_H_
8 #include "apps/app_window_registry.h"
9 #include "ash/ime/input_method_menu_manager.h"
10 #include "ash/session/session_state_observer.h"
11 #include "ash/system/tray/system_tray.h"
12 #include "ash/system/tray/system_tray_delegate.h"
13 #include "ash/system/tray/system_tray_notifier.h"
14 #include "base/callback_list.h"
15 #include "base/compiler_specific.h"
16 #include "base/containers/scoped_ptr_hash_map.h"
17 #include "base/memory/ref_counted.h"
18 #include "base/memory/weak_ptr.h"
19 #include "base/prefs/pref_change_registrar.h"
20 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h"
21 #include "chrome/browser/profiles/profile.h"
22 #include "chrome/browser/ui/ash/system_tray_delegate_chromeos.h"
23 #include "chrome/browser/ui/browser_list_observer.h"
24 #include "chromeos/audio/cras_audio_handler.h"
25 #include "chromeos/dbus/session_manager_client.h"
26 #include "chromeos/ime/input_method_manager.h"
27 #include "chromeos/login/login_state.h"
28 #include "components/policy/core/common/cloud/cloud_policy_store.h"
29 #include "content/public/browser/notification_observer.h"
30 #include "content/public/browser/notification_registrar.h"
31 #include "device/bluetooth/bluetooth_adapter.h"
32 #include "device/bluetooth/bluetooth_discovery_session.h"
36 class SystemTrayDelegateChromeOS
37 : public ash::ime::InputMethodMenuManager::Observer,
38 public ash::SystemTrayDelegate,
39 public SessionManagerClient::Observer,
40 public content::NotificationObserver,
41 public input_method::InputMethodManager::Observer,
42 public chromeos::LoginState::Observer,
43 public chromeos::CrasAudioHandler::AudioObserver,
44 public device::BluetoothAdapter::Observer,
45 public policy::CloudPolicyStore::Observer,
46 public ash::SessionStateObserver,
47 public chrome::BrowserListObserver,
48 public apps::AppWindowRegistry::Observer {
50 SystemTrayDelegateChromeOS();
52 virtual ~SystemTrayDelegateChromeOS();
54 void InitializeOnAdapterReady(
55 scoped_refptr<device::BluetoothAdapter> adapter);
57 // Overridden from ash::SystemTrayDelegate:
58 virtual void Initialize() OVERRIDE;
59 virtual void Shutdown() OVERRIDE;
60 virtual bool GetTrayVisibilityOnStartup() OVERRIDE;
61 virtual ash::user::LoginStatus GetUserLoginStatus() const OVERRIDE;
62 virtual void ChangeProfilePicture() OVERRIDE;
63 virtual const std::string GetEnterpriseDomain() const OVERRIDE;
64 virtual const base::string16 GetEnterpriseMessage() const OVERRIDE;
65 virtual const std::string GetSupervisedUserManager() const OVERRIDE;
66 virtual const base::string16 GetSupervisedUserManagerName() const OVERRIDE;
67 virtual const base::string16 GetSupervisedUserMessage() const OVERRIDE;
68 virtual bool SystemShouldUpgrade() const OVERRIDE;
69 virtual base::HourClockType GetHourClockType() const OVERRIDE;
70 virtual void ShowSettings() OVERRIDE;
71 virtual bool ShouldShowSettings() OVERRIDE;
72 virtual void ShowDateSettings() OVERRIDE;
73 virtual void ShowSetTimeDialog() OVERRIDE;
74 virtual void ShowNetworkSettings(const std::string& service_path) OVERRIDE;
75 virtual void ShowBluetoothSettings() OVERRIDE;
76 virtual void ShowDisplaySettings() OVERRIDE;
77 virtual void ShowChromeSlow() OVERRIDE;
78 virtual bool ShouldShowDisplayNotification() OVERRIDE;
79 virtual void ShowIMESettings() OVERRIDE;
80 virtual void ShowHelp() OVERRIDE;
81 virtual void ShowAccessibilityHelp() OVERRIDE;
82 virtual void ShowAccessibilitySettings() OVERRIDE;
83 virtual void ShowPublicAccountInfo() OVERRIDE;
84 virtual void ShowSupervisedUserInfo() OVERRIDE;
85 virtual void ShowEnterpriseInfo() OVERRIDE;
86 virtual void ShowUserLogin() OVERRIDE;
87 virtual bool ShowSpringChargerReplacementDialog() OVERRIDE;
88 virtual bool IsSpringChargerReplacementDialogVisible() OVERRIDE;
89 virtual bool HasUserConfirmedSafeSpringCharger() OVERRIDE;
90 virtual void ShutDown() OVERRIDE;
91 virtual void SignOut() OVERRIDE;
92 virtual void RequestLockScreen() OVERRIDE;
93 virtual void RequestRestartForUpdate() OVERRIDE;
94 virtual void GetAvailableBluetoothDevices(ash::BluetoothDeviceList* list)
96 virtual void BluetoothStartDiscovering() OVERRIDE;
97 virtual void BluetoothStopDiscovering() OVERRIDE;
98 virtual void ConnectToBluetoothDevice(const std::string& address) OVERRIDE;
99 virtual bool IsBluetoothDiscovering() OVERRIDE;
100 virtual void GetCurrentIME(ash::IMEInfo* info) OVERRIDE;
101 virtual void GetAvailableIMEList(ash::IMEInfoList* list) OVERRIDE;
102 virtual void GetCurrentIMEProperties(ash::IMEPropertyInfoList* list) OVERRIDE;
103 virtual void SwitchIME(const std::string& ime_id) OVERRIDE;
104 virtual void ActivateIMEProperty(const std::string& key) OVERRIDE;
105 virtual void ShowNetworkConfigure(const std::string& network_id,
106 gfx::NativeWindow parent_window) OVERRIDE;
107 virtual bool EnrollNetwork(const std::string& network_id,
108 gfx::NativeWindow parent_window) OVERRIDE;
109 virtual void ManageBluetoothDevices() OVERRIDE;
110 virtual void ToggleBluetooth() OVERRIDE;
111 virtual void ShowMobileSimDialog() OVERRIDE;
112 virtual void ShowMobileSetupDialog(const std::string& service_path) OVERRIDE;
113 virtual void ShowOtherNetworkDialog(const std::string& type) OVERRIDE;
114 virtual bool GetBluetoothAvailable() OVERRIDE;
115 virtual bool GetBluetoothEnabled() OVERRIDE;
116 virtual bool GetBluetoothDiscovering() OVERRIDE;
117 virtual void ChangeProxySettings() OVERRIDE;
118 virtual ash::VolumeControlDelegate* GetVolumeControlDelegate() const OVERRIDE;
119 virtual void SetVolumeControlDelegate(
120 scoped_ptr<ash::VolumeControlDelegate> delegate) OVERRIDE;
121 virtual bool GetSessionStartTime(base::TimeTicks* session_start_time)
123 virtual bool GetSessionLengthLimit(base::TimeDelta* session_length_limit)
125 virtual int GetSystemTrayMenuWidth() OVERRIDE;
126 virtual void ActiveUserWasChanged() OVERRIDE;
127 virtual bool IsSearchKeyMappedToCapsLock() OVERRIDE;
128 virtual ash::tray::UserAccountsDelegate* GetUserAccountsDelegate(
129 const std::string& user_id) OVERRIDE;
131 // browser tests need to call ShouldUse24HourClock().
132 bool GetShouldUse24HourClockForTesting() const;
135 // Should be the same as CrosSettings::ObserverSubscription.
136 typedef base::CallbackList<void(void)>::Subscription
137 CrosSettingsObserverSubscription;
139 ash::SystemTray* GetPrimarySystemTray();
141 ash::SystemTrayNotifier* GetSystemTrayNotifier();
143 void SetProfile(Profile* profile);
145 bool UnsetProfile(Profile* profile);
147 bool ShouldUse24HourClock() const;
149 void UpdateClockType();
151 void UpdateShowLogoutButtonInTray();
153 void UpdateLogoutDialogDuration();
155 void UpdateSessionStartTime();
157 void UpdateSessionLengthLimit();
159 void StopObservingAppWindowRegistry();
161 // Notify observers if the current user has no more open browser or app
163 void NotifyIfLastWindowClosed();
165 // LoginState::Observer overrides.
166 virtual void LoggedInStateChanged() OVERRIDE;
168 // Overridden from SessionManagerClient::Observer.
169 virtual void ScreenIsLocked() OVERRIDE;
170 virtual void ScreenIsUnlocked() OVERRIDE;
172 gfx::NativeWindow GetNativeWindow() const;
174 // content::NotificationObserver implementation.
175 virtual void Observe(int type,
176 const content::NotificationSource& source,
177 const content::NotificationDetails& details) OVERRIDE;
179 void OnLanguageRemapSearchKeyToChanged();
181 void OnAccessibilityModeChanged(
182 ash::AccessibilityNotificationVisibility notify);
184 void UpdatePerformanceTracing();
186 // Overridden from InputMethodManager::Observer.
187 virtual void InputMethodChanged(input_method::InputMethodManager* manager,
188 bool show_message) OVERRIDE;
190 // Overridden from InputMethodMenuManager::Observer.
191 virtual void InputMethodMenuItemChanged(
192 ash::ime::InputMethodMenuManager* manager) OVERRIDE;
194 // Overridden from CrasAudioHandler::AudioObserver.
195 virtual void OnOutputVolumeChanged() OVERRIDE;
196 virtual void OnOutputMuteChanged() OVERRIDE;
197 virtual void OnInputGainChanged() OVERRIDE;
198 virtual void OnInputMuteChanged() OVERRIDE;
199 virtual void OnAudioNodesChanged() OVERRIDE;
200 virtual void OnActiveOutputNodeChanged() OVERRIDE;
201 virtual void OnActiveInputNodeChanged() OVERRIDE;
203 // Overridden from BluetoothAdapter::Observer.
204 virtual void AdapterPresentChanged(device::BluetoothAdapter* adapter,
205 bool present) OVERRIDE;
206 virtual void AdapterPoweredChanged(device::BluetoothAdapter* adapter,
207 bool powered) OVERRIDE;
208 virtual void AdapterDiscoveringChanged(device::BluetoothAdapter* adapter,
209 bool discovering) OVERRIDE;
210 virtual void DeviceAdded(device::BluetoothAdapter* adapter,
211 device::BluetoothDevice* device) OVERRIDE;
212 virtual void DeviceChanged(device::BluetoothAdapter* adapter,
213 device::BluetoothDevice* device) OVERRIDE;
214 virtual void DeviceRemoved(device::BluetoothAdapter* adapter,
215 device::BluetoothDevice* device) OVERRIDE;
217 void OnStartBluetoothDiscoverySession(
218 scoped_ptr<device::BluetoothDiscoverySession> discovery_session);
220 void UpdateEnterpriseDomain();
222 // Overridden from CloudPolicyStore::Observer
223 virtual void OnStoreLoaded(policy::CloudPolicyStore* store) OVERRIDE;
224 virtual void OnStoreError(policy::CloudPolicyStore* store) OVERRIDE;
226 // Overridden from ash::SessionStateObserver
227 virtual void UserAddedToSession(const std::string& user_id) OVERRIDE;
229 // Overridden from chrome::BrowserListObserver:
230 virtual void OnBrowserRemoved(Browser* browser) OVERRIDE;
232 // Overridden from apps::AppWindowRegistry::Observer:
233 virtual void OnAppWindowRemoved(apps::AppWindow* app_window) OVERRIDE;
235 void OnAccessibilityStatusChanged(
236 const AccessibilityStatusEventDetails& details);
238 base::WeakPtrFactory<SystemTrayDelegateChromeOS> weak_ptr_factory_;
239 scoped_ptr<content::NotificationRegistrar> registrar_;
240 scoped_ptr<PrefChangeRegistrar> local_state_registrar_;
241 scoped_ptr<PrefChangeRegistrar> user_pref_registrar_;
242 Profile* user_profile_;
243 base::HourClockType clock_type_;
244 int search_key_mapped_to_;
246 bool have_session_start_time_;
247 base::TimeTicks session_start_time_;
248 bool have_session_length_limit_;
249 base::TimeDelta session_length_limit_;
250 std::string enterprise_domain_;
251 bool should_run_bluetooth_discovery_;
253 scoped_refptr<device::BluetoothAdapter> bluetooth_adapter_;
254 scoped_ptr<device::BluetoothDiscoverySession> bluetooth_discovery_session_;
255 scoped_ptr<ash::VolumeControlDelegate> volume_control_delegate_;
256 scoped_ptr<CrosSettingsObserverSubscription> device_settings_observer_;
257 scoped_ptr<AccessibilityStatusSubscription> accessibility_subscription_;
258 base::ScopedPtrHashMap<std::string, ash::tray::UserAccountsDelegate>
261 DISALLOW_COPY_AND_ASSIGN(SystemTrayDelegateChromeOS);
264 ash::SystemTrayDelegate* CreateSystemTrayDelegate();
266 } // namespace chromeos
267 #endif // CHROME_BROWSER_UI_ASH_SYSTEM_TRAY_DELEGATE_CHROMEOS_H_