system_tray_delegate_chromeos.h revision 5c02ac1a9c1b504631c0a3d2b6e737b5d738bae1
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. 4 5#ifndef CHROME_BROWSER_UI_ASH_SYSTEM_TRAY_DELEGATE_CHROMEOS_H_ 6#define CHROME_BROWSER_UI_ASH_SYSTEM_TRAY_DELEGATE_CHROMEOS_H_ 7 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/chromeos/drive/drive_integration_service.h" 22#include "chrome/browser/chromeos/drive/job_list.h" 23#include "chrome/browser/profiles/profile.h" 24#include "chrome/browser/ui/ash/system_tray_delegate_chromeos.h" 25#include "chrome/browser/ui/browser_list_observer.h" 26#include "chromeos/audio/cras_audio_handler.h" 27#include "chromeos/dbus/session_manager_client.h" 28#include "chromeos/ime/input_method_manager.h" 29#include "chromeos/login/login_state.h" 30#include "components/policy/core/common/cloud/cloud_policy_store.h" 31#include "content/public/browser/notification_observer.h" 32#include "content/public/browser/notification_registrar.h" 33#include "device/bluetooth/bluetooth_adapter.h" 34#include "device/bluetooth/bluetooth_discovery_session.h" 35 36namespace chromeos { 37 38class SystemTrayDelegateChromeOS 39 : public ash::ime::InputMethodMenuManager::Observer, 40 public ash::SystemTrayDelegate, 41 public SessionManagerClient::Observer, 42 public drive::JobListObserver, 43 public content::NotificationObserver, 44 public input_method::InputMethodManager::Observer, 45 public chromeos::LoginState::Observer, 46 public chromeos::CrasAudioHandler::AudioObserver, 47 public device::BluetoothAdapter::Observer, 48 public policy::CloudPolicyStore::Observer, 49 public ash::SessionStateObserver, 50 public chrome::BrowserListObserver, 51 public apps::AppWindowRegistry::Observer { 52 public: 53 SystemTrayDelegateChromeOS(); 54 55 virtual ~SystemTrayDelegateChromeOS(); 56 57 void InitializeOnAdapterReady( 58 scoped_refptr<device::BluetoothAdapter> adapter); 59 60 // Overridden from ash::SystemTrayDelegate: 61 virtual void Initialize() OVERRIDE; 62 virtual void Shutdown() OVERRIDE; 63 virtual bool GetTrayVisibilityOnStartup() OVERRIDE; 64 virtual ash::user::LoginStatus GetUserLoginStatus() const OVERRIDE; 65 virtual void ChangeProfilePicture() OVERRIDE; 66 virtual const std::string GetEnterpriseDomain() const OVERRIDE; 67 virtual const base::string16 GetEnterpriseMessage() const OVERRIDE; 68 virtual const std::string GetLocallyManagedUserManager() const OVERRIDE; 69 virtual const base::string16 GetLocallyManagedUserManagerName() 70 const OVERRIDE; 71 virtual const base::string16 GetLocallyManagedUserMessage() const OVERRIDE; 72 virtual bool SystemShouldUpgrade() const OVERRIDE; 73 virtual base::HourClockType GetHourClockType() const OVERRIDE; 74 virtual void ShowSettings() OVERRIDE; 75 virtual bool ShouldShowSettings() OVERRIDE; 76 virtual void ShowDateSettings() OVERRIDE; 77 virtual void ShowSetTimeDialog() OVERRIDE; 78 virtual void ShowNetworkSettings(const std::string& service_path) OVERRIDE; 79 virtual void ShowBluetoothSettings() OVERRIDE; 80 virtual void ShowDisplaySettings() OVERRIDE; 81 virtual void ShowChromeSlow() OVERRIDE; 82 virtual bool ShouldShowDisplayNotification() OVERRIDE; 83 virtual void ShowDriveSettings() OVERRIDE; 84 virtual void ShowIMESettings() OVERRIDE; 85 virtual void ShowHelp() OVERRIDE; 86 virtual void ShowAccessibilityHelp() OVERRIDE; 87 virtual void ShowAccessibilitySettings() OVERRIDE; 88 virtual void ShowPublicAccountInfo() OVERRIDE; 89 virtual void ShowLocallyManagedUserInfo() OVERRIDE; 90 virtual void ShowEnterpriseInfo() OVERRIDE; 91 virtual void ShowUserLogin() OVERRIDE; 92 virtual bool ShowSpringChargerReplacementDialog() OVERRIDE; 93 virtual bool IsSpringChargerReplacementDialogVisible() OVERRIDE; 94 virtual bool HasUserConfirmedSafeSpringCharger() OVERRIDE; 95 virtual void ShutDown() OVERRIDE; 96 virtual void SignOut() OVERRIDE; 97 virtual void RequestLockScreen() OVERRIDE; 98 virtual void RequestRestartForUpdate() OVERRIDE; 99 virtual void GetAvailableBluetoothDevices(ash::BluetoothDeviceList* list) 100 OVERRIDE; 101 virtual void BluetoothStartDiscovering() OVERRIDE; 102 virtual void BluetoothStopDiscovering() OVERRIDE; 103 virtual void ConnectToBluetoothDevice(const std::string& address) OVERRIDE; 104 virtual bool IsBluetoothDiscovering() OVERRIDE; 105 virtual void GetCurrentIME(ash::IMEInfo* info) OVERRIDE; 106 virtual void GetAvailableIMEList(ash::IMEInfoList* list) OVERRIDE; 107 virtual void GetCurrentIMEProperties(ash::IMEPropertyInfoList* list) OVERRIDE; 108 virtual void SwitchIME(const std::string& ime_id) OVERRIDE; 109 virtual void ActivateIMEProperty(const std::string& key) OVERRIDE; 110 virtual void CancelDriveOperation(int32 operation_id) OVERRIDE; 111 virtual void GetDriveOperationStatusList(ash::DriveOperationStatusList* list) 112 OVERRIDE; 113 virtual void ShowNetworkConfigure(const std::string& network_id, 114 gfx::NativeWindow parent_window) OVERRIDE; 115 virtual bool EnrollNetwork(const std::string& network_id, 116 gfx::NativeWindow parent_window) OVERRIDE; 117 virtual void ManageBluetoothDevices() OVERRIDE; 118 virtual void ToggleBluetooth() OVERRIDE; 119 virtual void ShowMobileSimDialog() OVERRIDE; 120 virtual void ShowMobileSetupDialog(const std::string& service_path) OVERRIDE; 121 virtual void ShowOtherNetworkDialog(const std::string& type) OVERRIDE; 122 virtual bool GetBluetoothAvailable() OVERRIDE; 123 virtual bool GetBluetoothEnabled() OVERRIDE; 124 virtual bool GetBluetoothDiscovering() OVERRIDE; 125 virtual void ChangeProxySettings() OVERRIDE; 126 virtual ash::VolumeControlDelegate* GetVolumeControlDelegate() const OVERRIDE; 127 virtual void SetVolumeControlDelegate( 128 scoped_ptr<ash::VolumeControlDelegate> delegate) OVERRIDE; 129 virtual bool GetSessionStartTime(base::TimeTicks* session_start_time) 130 OVERRIDE; 131 virtual bool GetSessionLengthLimit(base::TimeDelta* session_length_limit) 132 OVERRIDE; 133 virtual int GetSystemTrayMenuWidth() OVERRIDE; 134 virtual void ActiveUserWasChanged() OVERRIDE; 135 virtual bool IsNetworkBehindCaptivePortal( 136 const std::string& service_path) const OVERRIDE; 137 virtual bool IsSearchKeyMappedToCapsLock() OVERRIDE; 138 virtual ash::tray::UserAccountsDelegate* GetUserAccountsDelegate( 139 const std::string& user_id) OVERRIDE; 140 141 // browser tests need to call ShouldUse24HourClock(). 142 bool GetShouldUse24HourClockForTesting() const; 143 144 private: 145 // Should be the same as CrosSettings::ObserverSubscription. 146 typedef base::CallbackList<void(void)>::Subscription 147 CrosSettingsObserverSubscription; 148 149 ash::SystemTray* GetPrimarySystemTray(); 150 151 ash::SystemTrayNotifier* GetSystemTrayNotifier(); 152 153 void SetProfile(Profile* profile); 154 155 bool UnsetProfile(Profile* profile); 156 157 void ObserveDriveUpdates(); 158 159 void UnobserveDriveUpdates(); 160 161 bool ShouldUse24HourClock() const; 162 163 void UpdateClockType(); 164 165 void UpdateShowLogoutButtonInTray(); 166 167 void UpdateLogoutDialogDuration(); 168 169 void UpdateSessionStartTime(); 170 171 void UpdateSessionLengthLimit(); 172 173 void StopObservingAppWindowRegistry(); 174 175 // Notify observers if the current user has no more open browser or app 176 // windows. 177 void NotifyIfLastWindowClosed(); 178 179 // LoginState::Observer overrides. 180 virtual void LoggedInStateChanged() OVERRIDE; 181 182 // Overridden from SessionManagerClient::Observer. 183 virtual void ScreenIsLocked() OVERRIDE; 184 virtual void ScreenIsUnlocked() OVERRIDE; 185 186 gfx::NativeWindow GetNativeWindow() const; 187 188 // content::NotificationObserver implementation. 189 virtual void Observe(int type, 190 const content::NotificationSource& source, 191 const content::NotificationDetails& details) OVERRIDE; 192 193 void OnLanguageRemapSearchKeyToChanged(); 194 195 void OnAccessibilityModeChanged( 196 ash::AccessibilityNotificationVisibility notify); 197 198 void UpdatePerformanceTracing(); 199 200 // Overridden from InputMethodManager::Observer. 201 virtual void InputMethodChanged(input_method::InputMethodManager* manager, 202 bool show_message) OVERRIDE; 203 204 // Overridden from InputMethodMenuManager::Observer. 205 virtual void InputMethodMenuItemChanged( 206 ash::ime::InputMethodMenuManager* manager) OVERRIDE; 207 208 // Overridden from CrasAudioHandler::AudioObserver. 209 virtual void OnOutputVolumeChanged() OVERRIDE; 210 virtual void OnOutputMuteChanged() OVERRIDE; 211 virtual void OnInputGainChanged() OVERRIDE; 212 virtual void OnInputMuteChanged() OVERRIDE; 213 virtual void OnAudioNodesChanged() OVERRIDE; 214 virtual void OnActiveOutputNodeChanged() OVERRIDE; 215 virtual void OnActiveInputNodeChanged() OVERRIDE; 216 217 // drive::JobListObserver overrides. 218 virtual void OnJobAdded(const drive::JobInfo& job_info) OVERRIDE; 219 220 virtual void OnJobDone(const drive::JobInfo& job_info, 221 drive::FileError error) OVERRIDE; 222 223 virtual void OnJobUpdated(const drive::JobInfo& job_info) OVERRIDE; 224 225 drive::DriveIntegrationService* FindDriveIntegrationService(); 226 227 // Overridden from BluetoothAdapter::Observer. 228 virtual void AdapterPresentChanged(device::BluetoothAdapter* adapter, 229 bool present) OVERRIDE; 230 virtual void AdapterPoweredChanged(device::BluetoothAdapter* adapter, 231 bool powered) OVERRIDE; 232 virtual void AdapterDiscoveringChanged(device::BluetoothAdapter* adapter, 233 bool discovering) OVERRIDE; 234 virtual void DeviceAdded(device::BluetoothAdapter* adapter, 235 device::BluetoothDevice* device) OVERRIDE; 236 virtual void DeviceChanged(device::BluetoothAdapter* adapter, 237 device::BluetoothDevice* device) OVERRIDE; 238 virtual void DeviceRemoved(device::BluetoothAdapter* adapter, 239 device::BluetoothDevice* device) OVERRIDE; 240 241 void OnStartBluetoothDiscoverySession( 242 scoped_ptr<device::BluetoothDiscoverySession> discovery_session); 243 244 void UpdateEnterpriseDomain(); 245 246 // Overridden from CloudPolicyStore::Observer 247 virtual void OnStoreLoaded(policy::CloudPolicyStore* store) OVERRIDE; 248 virtual void OnStoreError(policy::CloudPolicyStore* store) OVERRIDE; 249 250 // Overridden from ash::SessionStateObserver 251 virtual void UserAddedToSession(const std::string& user_id) OVERRIDE; 252 253 // Overridden from chrome::BrowserListObserver: 254 virtual void OnBrowserRemoved(Browser* browser) OVERRIDE; 255 256 // Overridden from apps::AppWindowRegistry::Observer: 257 virtual void OnAppWindowAdded(apps::AppWindow* app_window) OVERRIDE; 258 virtual void OnAppWindowIconChanged(apps::AppWindow* app_window) OVERRIDE; 259 virtual void OnAppWindowRemoved(apps::AppWindow* app_window) OVERRIDE; 260 261 void OnAccessibilityStatusChanged( 262 const AccessibilityStatusEventDetails& details); 263 264 base::WeakPtrFactory<SystemTrayDelegateChromeOS> weak_ptr_factory_; 265 scoped_ptr<content::NotificationRegistrar> registrar_; 266 scoped_ptr<PrefChangeRegistrar> local_state_registrar_; 267 scoped_ptr<PrefChangeRegistrar> user_pref_registrar_; 268 Profile* user_profile_; 269 base::HourClockType clock_type_; 270 int search_key_mapped_to_; 271 bool screen_locked_; 272 bool have_session_start_time_; 273 base::TimeTicks session_start_time_; 274 bool have_session_length_limit_; 275 base::TimeDelta session_length_limit_; 276 std::string enterprise_domain_; 277 bool should_run_bluetooth_discovery_; 278 279 scoped_refptr<device::BluetoothAdapter> bluetooth_adapter_; 280 scoped_ptr<device::BluetoothDiscoverySession> bluetooth_discovery_session_; 281 scoped_ptr<ash::VolumeControlDelegate> volume_control_delegate_; 282 scoped_ptr<CrosSettingsObserverSubscription> device_settings_observer_; 283 scoped_ptr<AccessibilityStatusSubscription> accessibility_subscription_; 284 base::ScopedPtrHashMap<std::string, ash::tray::UserAccountsDelegate> 285 accounts_delegates_; 286 287 DISALLOW_COPY_AND_ASSIGN(SystemTrayDelegateChromeOS); 288}; 289 290ash::SystemTrayDelegate* CreateSystemTrayDelegate(); 291 292} // namespace chromeos 293#endif // CHROME_BROWSER_UI_ASH_SYSTEM_TRAY_DELEGATE_CHROMEOS_H_ 294