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