system_tray_delegate_win.cc revision a1401311d1ab56c4ed0a474bd38c108f75cb0cd9
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#include "chrome/browser/ui/ash/system_tray_delegate_win.h" 6 7#include <string> 8 9#include "ash/shell.h" 10#include "ash/shell_delegate.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 "ash/volume_control_delegate.h" 15#include "base/logging.h" 16#include "base/time/time.h" 17#include "chrome/browser/chrome_notification_types.h" 18#include "chrome/browser/lifetime/application_lifetime.h" 19#include "chrome/browser/profiles/profile_manager.h" 20#include "chrome/browser/ui/chrome_pages.h" 21#include "chrome/browser/ui/host_desktop.h" 22#include "chrome/browser/upgrade_detector.h" 23#include "content/public/browser/notification_observer.h" 24#include "content/public/browser/notification_service.h" 25 26#include "grit/locale_settings.h" 27#include "ui/base/l10n/l10n_util.h" 28 29namespace { 30 31class SystemTrayDelegateWin : public ash::SystemTrayDelegate, 32 public content::NotificationObserver { 33 public: 34 SystemTrayDelegateWin() 35 : clock_type_(base::GetHourClockType()) { 36 // Register notifications on construction so that events such as 37 // PROFILE_CREATED do not get missed if they happen before Initialize(). 38 registrar_.reset(new content::NotificationRegistrar); 39 registrar_->Add(this, 40 chrome::NOTIFICATION_UPGRADE_RECOMMENDED, 41 content::NotificationService::AllSources()); 42 } 43 44 virtual ~SystemTrayDelegateWin() { 45 registrar_.reset(); 46 } 47 48 // Overridden from ash::SystemTrayDelegate: 49 virtual void Initialize() OVERRIDE { 50 UpdateClockType(); 51 } 52 53 virtual void Shutdown() OVERRIDE { 54 } 55 56 virtual bool GetTrayVisibilityOnStartup() OVERRIDE { 57 return true; 58 } 59 60 virtual ash::user::LoginStatus GetUserLoginStatus() const OVERRIDE { 61 return ash::user::LOGGED_IN_OWNER; 62 } 63 64 virtual bool IsOobeCompleted() const OVERRIDE { 65 return true; 66 } 67 68 virtual void ChangeProfilePicture() OVERRIDE { 69 } 70 71 virtual const std::string GetEnterpriseDomain() const OVERRIDE { 72 return std::string(); 73 } 74 75 virtual const base::string16 GetEnterpriseMessage() const OVERRIDE { 76 return base::string16(); 77 } 78 79 virtual const std::string GetLocallyManagedUserManager() const OVERRIDE { 80 return std::string(); 81 } 82 83 virtual const base::string16 GetLocallyManagedUserManagerName() const 84 OVERRIDE { 85 return base::string16(); 86 } 87 88 virtual const base::string16 GetLocallyManagedUserMessage() const OVERRIDE { 89 return base::string16(); 90 } 91 92 virtual bool SystemShouldUpgrade() const OVERRIDE { 93 return UpgradeDetector::GetInstance()->notify_upgrade(); 94 } 95 96 virtual base::HourClockType GetHourClockType() const OVERRIDE { 97 return clock_type_; 98 } 99 100 virtual void ShowSettings() OVERRIDE { 101 } 102 103 virtual bool ShouldShowSettings() OVERRIDE { 104 return true; 105 } 106 107 virtual void ShowDateSettings() OVERRIDE { 108 } 109 110 virtual void ShowNetworkSettings(const std::string& service_path) OVERRIDE { 111 } 112 113 virtual void ShowBluetoothSettings() OVERRIDE { 114 } 115 116 virtual void ShowDisplaySettings() OVERRIDE { 117 } 118 119 virtual void ShowChromeSlow() OVERRIDE { 120 } 121 122 virtual bool ShouldShowDisplayNotification() OVERRIDE { 123 return false; 124 } 125 126 virtual void ShowDriveSettings() OVERRIDE { 127 } 128 129 virtual void ShowIMESettings() OVERRIDE { 130 } 131 132 virtual void ShowHelp() OVERRIDE { 133 chrome::ShowHelpForProfile( 134 ProfileManager::GetLastUsedProfile(), 135 chrome::HOST_DESKTOP_TYPE_ASH, 136 chrome::HELP_SOURCE_MENU); 137 } 138 139 virtual void ShowAccessibilityHelp() OVERRIDE { 140 } 141 142 virtual void ShowAccessibilitySettings() OVERRIDE { 143 } 144 145 virtual void ShowPublicAccountInfo() OVERRIDE { 146 } 147 148 virtual void ShowLocallyManagedUserInfo() OVERRIDE { 149 } 150 151 virtual void ShowEnterpriseInfo() OVERRIDE { 152 } 153 154 virtual void ShowUserLogin() OVERRIDE { 155 } 156 157 virtual bool ShowSpringChargerReplacementDialog() OVERRIDE { 158 return false; 159 } 160 161 virtual bool IsSpringChargerReplacementDialogVisible() OVERRIDE { 162 return false; 163 } 164 165 virtual bool HasUserConfirmedSafeSpringCharger() OVERRIDE { 166 return false; 167 } 168 169 virtual void ShutDown() OVERRIDE { 170 } 171 172 virtual void SignOut() OVERRIDE { 173 } 174 175 virtual void RequestLockScreen() OVERRIDE { 176 } 177 178 virtual void RequestRestartForUpdate() OVERRIDE { 179 chrome::AttemptRestart(); 180 } 181 182 virtual void GetAvailableBluetoothDevices( 183 ash::BluetoothDeviceList* list) OVERRIDE { 184 } 185 186 virtual void BluetoothStartDiscovering() OVERRIDE { 187 } 188 189 virtual void BluetoothStopDiscovering() OVERRIDE { 190 } 191 192 virtual void ConnectToBluetoothDevice(const std::string& address) OVERRIDE { 193 } 194 195 virtual bool IsBluetoothDiscovering() OVERRIDE { 196 return false; 197 } 198 199 virtual void GetCurrentIME(ash::IMEInfo* info) OVERRIDE { 200 } 201 202 virtual void GetAvailableIMEList(ash::IMEInfoList* list) OVERRIDE { 203 } 204 205 virtual void GetCurrentIMEProperties( 206 ash::IMEPropertyInfoList* list) OVERRIDE { 207 } 208 209 virtual void SwitchIME(const std::string& ime_id) OVERRIDE { 210 } 211 212 virtual void ActivateIMEProperty(const std::string& key) OVERRIDE { 213 } 214 215 virtual void CancelDriveOperation(int32 operation_id) OVERRIDE { 216 } 217 218 virtual void GetDriveOperationStatusList( 219 ash::DriveOperationStatusList* list) OVERRIDE { 220 } 221 222 virtual void ShowNetworkConfigure(const std::string& network_id, 223 gfx::NativeWindow parent_window) OVERRIDE { 224 } 225 226 virtual bool EnrollNetwork(const std::string& network_id, 227 gfx::NativeWindow parent_window) OVERRIDE { 228 return true; 229 } 230 231 virtual void ManageBluetoothDevices() OVERRIDE { 232 } 233 234 virtual void ToggleBluetooth() OVERRIDE { 235 } 236 237 virtual void ShowMobileSimDialog() OVERRIDE { 238 } 239 240 virtual void ShowMobileSetupDialog(const std::string& service_path) OVERRIDE { 241 } 242 243 virtual void ShowOtherNetworkDialog(const std::string& type) OVERRIDE { 244 } 245 246 virtual bool GetBluetoothAvailable() OVERRIDE { 247 return false; 248 } 249 250 virtual bool GetBluetoothEnabled() OVERRIDE { 251 return false; 252 } 253 254 virtual void ChangeProxySettings() OVERRIDE { 255 } 256 257 virtual ash::VolumeControlDelegate* 258 GetVolumeControlDelegate() const OVERRIDE { 259 return NULL; 260 } 261 262 virtual void SetVolumeControlDelegate( 263 scoped_ptr<ash::VolumeControlDelegate> delegate) OVERRIDE { 264 } 265 266 virtual bool GetSessionStartTime( 267 base::TimeTicks* session_start_time) OVERRIDE { 268 return false; 269 } 270 271 virtual bool GetSessionLengthLimit( 272 base::TimeDelta* session_length_limit) OVERRIDE { 273 return false; 274 } 275 276 virtual int GetSystemTrayMenuWidth() OVERRIDE { 277 return l10n_util::GetLocalizedContentsWidthInPixels( 278 IDS_SYSTEM_TRAY_MENU_BUBBLE_WIDTH_PIXELS); 279 } 280 281 virtual void ActiveUserWasChanged() OVERRIDE { 282 } 283 284 virtual bool IsNetworkBehindCaptivePortal( 285 const std::string& service_path) const OVERRIDE { 286 return false; 287 } 288 289 virtual bool IsSearchKeyMappedToCapsLock() OVERRIDE { 290 return false; 291 } 292 293 private: 294 ash::SystemTrayNotifier* GetSystemTrayNotifier() { 295 return ash::Shell::GetInstance()->system_tray_notifier(); 296 } 297 298 void UpdateClockType() { 299 clock_type_ = (base::GetHourClockType() == base::k24HourClock) ? 300 base::k24HourClock : base::k12HourClock; 301 GetSystemTrayNotifier()->NotifyDateFormatChanged(); 302 } 303 304 // content::NotificationObserver implementation. 305 virtual void Observe(int type, 306 const content::NotificationSource& source, 307 const content::NotificationDetails& details) OVERRIDE { 308 if (type == chrome::NOTIFICATION_UPGRADE_RECOMMENDED) { 309 UpgradeDetector* detector = 310 content::Source<UpgradeDetector>(source).ptr(); 311 ash::UpdateObserver::UpdateSeverity severity = 312 ash::UpdateObserver::UPDATE_NORMAL; 313 switch (detector->upgrade_notification_stage()) { 314 case UpgradeDetector::UPGRADE_ANNOYANCE_SEVERE: 315 severity = ash::UpdateObserver::UPDATE_SEVERE_RED; 316 break; 317 case UpgradeDetector::UPGRADE_ANNOYANCE_HIGH: 318 severity = ash::UpdateObserver::UPDATE_HIGH_ORANGE; 319 break; 320 case UpgradeDetector::UPGRADE_ANNOYANCE_ELEVATED: 321 severity = ash::UpdateObserver::UPDATE_LOW_GREEN; 322 break; 323 case UpgradeDetector::UPGRADE_ANNOYANCE_LOW: 324 severity = ash::UpdateObserver::UPDATE_NORMAL; 325 break; 326 } 327 GetSystemTrayNotifier()->NotifyUpdateRecommended(severity); 328 } else { 329 NOTREACHED(); 330 } 331 } 332 333 scoped_ptr<content::NotificationRegistrar> registrar_; 334 base::HourClockType clock_type_; 335 336 DISALLOW_COPY_AND_ASSIGN(SystemTrayDelegateWin); 337}; 338 339} // namespace 340 341 342ash::SystemTrayDelegate* CreateWindowsSystemTrayDelegate() { 343 return new SystemTrayDelegateWin(); 344} 345