Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / ash / system_tray_delegate_win.cc
blobeba5603c4bc60f968d01a9a41e7dd0de133f99ec
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 #include "chrome/browser/ui/ash/system_tray_delegate_win.h"
7 #include <string>
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"
26 #include "grit/locale_settings.h"
27 #include "ui/base/l10n/l10n_util.h"
29 namespace {
31 class 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());
44 virtual ~SystemTrayDelegateWin() {
45 registrar_.reset();
48 // Overridden from ash::SystemTrayDelegate:
49 virtual void Initialize() OVERRIDE {
50 UpdateClockType();
53 virtual void Shutdown() OVERRIDE {
56 virtual bool GetTrayVisibilityOnStartup() OVERRIDE {
57 return true;
60 virtual ash::user::LoginStatus GetUserLoginStatus() const OVERRIDE {
61 return ash::user::LOGGED_IN_OWNER;
64 virtual bool IsOobeCompleted() const OVERRIDE {
65 return true;
68 virtual void ChangeProfilePicture() OVERRIDE {
71 virtual const std::string GetEnterpriseDomain() const OVERRIDE {
72 return std::string();
75 virtual const base::string16 GetEnterpriseMessage() const OVERRIDE {
76 return base::string16();
79 virtual const std::string GetLocallyManagedUserManager() const OVERRIDE {
80 return std::string();
83 virtual const base::string16 GetLocallyManagedUserManagerName() const
84 OVERRIDE {
85 return base::string16();
88 virtual const base::string16 GetLocallyManagedUserMessage() const OVERRIDE {
89 return base::string16();
92 virtual bool SystemShouldUpgrade() const OVERRIDE {
93 return UpgradeDetector::GetInstance()->notify_upgrade();
96 virtual base::HourClockType GetHourClockType() const OVERRIDE {
97 return clock_type_;
100 virtual void ShowSettings() OVERRIDE {
103 virtual bool ShouldShowSettings() OVERRIDE {
104 return true;
107 virtual void ShowDateSettings() OVERRIDE {
110 virtual void ShowNetworkSettings(const std::string& service_path) OVERRIDE {
113 virtual void ShowBluetoothSettings() OVERRIDE {
116 virtual void ShowDisplaySettings() OVERRIDE {
119 virtual void ShowChromeSlow() OVERRIDE {
122 virtual bool ShouldShowDisplayNotification() OVERRIDE {
123 return false;
126 virtual void ShowDriveSettings() OVERRIDE {
129 virtual void ShowIMESettings() OVERRIDE {
132 virtual void ShowHelp() OVERRIDE {
133 chrome::ShowHelpForProfile(
134 ProfileManager::GetLastUsedProfile(),
135 chrome::HOST_DESKTOP_TYPE_ASH,
136 chrome::HELP_SOURCE_MENU);
139 virtual void ShowAccessibilityHelp() OVERRIDE {
142 virtual void ShowAccessibilitySettings() OVERRIDE {
145 virtual void ShowPublicAccountInfo() OVERRIDE {
148 virtual void ShowLocallyManagedUserInfo() OVERRIDE {
151 virtual void ShowEnterpriseInfo() OVERRIDE {
154 virtual void ShowUserLogin() OVERRIDE {
157 virtual void ShowSpringChargerReplacementDialog() OVERRIDE {
160 virtual bool HasUserConfirmedSafeSpringCharger() OVERRIDE {
161 return false;
164 virtual void ShutDown() OVERRIDE {
167 virtual void SignOut() OVERRIDE {
170 virtual void RequestLockScreen() OVERRIDE {
173 virtual void RequestRestartForUpdate() OVERRIDE {
174 chrome::AttemptRestart();
177 virtual void GetAvailableBluetoothDevices(
178 ash::BluetoothDeviceList* list) OVERRIDE {
181 virtual void BluetoothStartDiscovering() OVERRIDE {
184 virtual void BluetoothStopDiscovering() OVERRIDE {
187 virtual void ConnectToBluetoothDevice(const std::string& address) OVERRIDE {
190 virtual bool IsBluetoothDiscovering() OVERRIDE {
191 return false;
194 virtual void GetCurrentIME(ash::IMEInfo* info) OVERRIDE {
197 virtual void GetAvailableIMEList(ash::IMEInfoList* list) OVERRIDE {
200 virtual void GetCurrentIMEProperties(
201 ash::IMEPropertyInfoList* list) OVERRIDE {
204 virtual void SwitchIME(const std::string& ime_id) OVERRIDE {
207 virtual void ActivateIMEProperty(const std::string& key) OVERRIDE {
210 virtual void CancelDriveOperation(int32 operation_id) OVERRIDE {
213 virtual void GetDriveOperationStatusList(
214 ash::DriveOperationStatusList* list) OVERRIDE {
217 virtual void ShowNetworkConfigure(const std::string& network_id,
218 gfx::NativeWindow parent_window) OVERRIDE {
221 virtual bool EnrollNetwork(const std::string& network_id,
222 gfx::NativeWindow parent_window) OVERRIDE {
223 return true;
226 virtual void ManageBluetoothDevices() OVERRIDE {
229 virtual void ToggleBluetooth() OVERRIDE {
232 virtual void ShowMobileSimDialog() OVERRIDE {
235 virtual void ShowMobileSetupDialog(const std::string& service_path) OVERRIDE {
238 virtual void ShowOtherNetworkDialog(const std::string& type) OVERRIDE {
241 virtual bool GetBluetoothAvailable() OVERRIDE {
242 return false;
245 virtual bool GetBluetoothEnabled() OVERRIDE {
246 return false;
249 virtual void ChangeProxySettings() OVERRIDE {
252 virtual ash::VolumeControlDelegate*
253 GetVolumeControlDelegate() const OVERRIDE {
254 return NULL;
257 virtual void SetVolumeControlDelegate(
258 scoped_ptr<ash::VolumeControlDelegate> delegate) OVERRIDE {
261 virtual bool GetSessionStartTime(
262 base::TimeTicks* session_start_time) OVERRIDE {
263 return false;
266 virtual bool GetSessionLengthLimit(
267 base::TimeDelta* session_length_limit) OVERRIDE {
268 return false;
271 virtual int GetSystemTrayMenuWidth() OVERRIDE {
272 return l10n_util::GetLocalizedContentsWidthInPixels(
273 IDS_SYSTEM_TRAY_MENU_BUBBLE_WIDTH_PIXELS);
276 private:
277 ash::SystemTrayNotifier* GetSystemTrayNotifier() {
278 return ash::Shell::GetInstance()->system_tray_notifier();
281 void UpdateClockType() {
282 clock_type_ = (base::GetHourClockType() == base::k24HourClock) ?
283 base::k24HourClock : base::k12HourClock;
284 GetSystemTrayNotifier()->NotifyDateFormatChanged();
287 // content::NotificationObserver implementation.
288 virtual void Observe(int type,
289 const content::NotificationSource& source,
290 const content::NotificationDetails& details) OVERRIDE {
291 if (type == chrome::NOTIFICATION_UPGRADE_RECOMMENDED) {
292 UpgradeDetector* detector =
293 content::Source<UpgradeDetector>(source).ptr();
294 ash::UpdateObserver::UpdateSeverity severity =
295 ash::UpdateObserver::UPDATE_NORMAL;
296 switch (detector->upgrade_notification_stage()) {
297 case UpgradeDetector::UPGRADE_ANNOYANCE_SEVERE:
298 severity = ash::UpdateObserver::UPDATE_SEVERE_RED;
299 break;
300 case UpgradeDetector::UPGRADE_ANNOYANCE_HIGH:
301 severity = ash::UpdateObserver::UPDATE_HIGH_ORANGE;
302 break;
303 case UpgradeDetector::UPGRADE_ANNOYANCE_ELEVATED:
304 severity = ash::UpdateObserver::UPDATE_LOW_GREEN;
305 break;
306 case UpgradeDetector::UPGRADE_ANNOYANCE_LOW:
307 severity = ash::UpdateObserver::UPDATE_NORMAL;
308 break;
310 GetSystemTrayNotifier()->NotifyUpdateRecommended(severity);
311 } else {
312 NOTREACHED();
316 scoped_ptr<content::NotificationRegistrar> registrar_;
317 base::HourClockType clock_type_;
319 DISALLOW_COPY_AND_ASSIGN(SystemTrayDelegateWin);
322 } // namespace
325 ash::SystemTrayDelegate* CreateWindowsSystemTrayDelegate() {
326 return new SystemTrayDelegateWin();