OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/ash/system_tray_delegate_linux.h" | 5 #include "chrome/browser/ui/ash/system_tray_delegate_linux.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
10 #include "ash/shell_delegate.h" | 10 #include "ash/shell_delegate.h" |
11 #include "ash/system/tray/system_tray.h" | 11 #include "ash/system/tray/system_tray.h" |
12 #include "ash/system/tray/system_tray_delegate.h" | 12 #include "ash/system/tray/system_tray_delegate.h" |
13 #include "ash/system/tray/system_tray_notifier.h" | 13 #include "ash/system/tray/system_tray_notifier.h" |
14 #include "ash/volume_control_delegate.h" | 14 #include "ash/volume_control_delegate.h" |
15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
16 #include "chrome/browser/chrome_notification_types.h" | 16 #include "chrome/browser/chrome_notification_types.h" |
17 #include "chrome/browser/lifetime/application_lifetime.h" | 17 #include "chrome/browser/lifetime/application_lifetime.h" |
18 #include "chrome/browser/profiles/profile_manager.h" | 18 #include "chrome/browser/profiles/profile_manager.h" |
19 #include "chrome/browser/ui/chrome_pages.h" | 19 #include "chrome/browser/ui/chrome_pages.h" |
20 #include "chrome/browser/ui/host_desktop.h" | 20 #include "chrome/browser/ui/host_desktop.h" |
21 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" | 21 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" |
22 #include "chrome/browser/upgrade_detector.h" | 22 #include "chrome/browser/upgrade_detector.h" |
23 #include "chrome/grit/locale_settings.h" | 23 #include "chrome/grit/locale_settings.h" |
24 #include "content/public/browser/notification_observer.h" | 24 #include "content/public/browser/notification_observer.h" |
25 #include "content/public/browser/notification_service.h" | 25 #include "content/public/browser/notification_service.h" |
26 #include "ui/base/l10n/l10n_util.h" | 26 #include "ui/base/l10n/l10n_util.h" |
27 | 27 |
28 namespace { | 28 namespace { |
29 | 29 |
| 30 void GetUpdateInfo(const UpgradeDetector* detector, ash::UpdateInfo* info) { |
| 31 if (!detector || !info) |
| 32 return; |
| 33 ash::UpdateInfo::UpdateSeverity severity = ash::UpdateInfo::UPDATE_NORMAL; |
| 34 switch (detector->upgrade_notification_stage()) { |
| 35 case UpgradeDetector::UPGRADE_ANNOYANCE_CRITICAL: |
| 36 case UpgradeDetector::UPGRADE_ANNOYANCE_SEVERE: |
| 37 severity = ash::UpdateInfo::UPDATE_SEVERE_RED; |
| 38 break; |
| 39 case UpgradeDetector::UPGRADE_ANNOYANCE_HIGH: |
| 40 severity = ash::UpdateInfo::UPDATE_HIGH_ORANGE; |
| 41 break; |
| 42 case UpgradeDetector::UPGRADE_ANNOYANCE_ELEVATED: |
| 43 severity = ash::UpdateInfo::UPDATE_LOW_GREEN; |
| 44 break; |
| 45 case UpgradeDetector::UPGRADE_ANNOYANCE_LOW: |
| 46 case UpgradeDetector::UPGRADE_ANNOYANCE_NONE: |
| 47 severity = ash::UpdateInfo::UPDATE_NORMAL; |
| 48 break; |
| 49 } |
| 50 info->severity = severity; |
| 51 info->update_required = detector->notify_upgrade(); |
| 52 info->factory_reset_required = detector->is_factory_reset_required(); |
| 53 } |
| 54 |
30 class SystemTrayDelegateLinux : public ash::SystemTrayDelegate, | 55 class SystemTrayDelegateLinux : public ash::SystemTrayDelegate, |
31 public content::NotificationObserver { | 56 public content::NotificationObserver { |
32 public: | 57 public: |
33 SystemTrayDelegateLinux() | 58 SystemTrayDelegateLinux() |
34 : clock_type_(base::GetHourClockType()) { | 59 : clock_type_(base::GetHourClockType()) { |
35 // Register notifications on construction so that events such as | 60 // Register notifications on construction so that events such as |
36 // PROFILE_CREATED do not get missed if they happen before Initialize(). | 61 // PROFILE_CREATED do not get missed if they happen before Initialize(). |
37 registrar_.reset(new content::NotificationRegistrar); | 62 registrar_.reset(new content::NotificationRegistrar); |
38 registrar_->Add(this, | 63 registrar_->Add(this, |
39 chrome::NOTIFICATION_UPGRADE_RECOMMENDED, | 64 chrome::NOTIFICATION_UPGRADE_RECOMMENDED, |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 } | 105 } |
81 | 106 |
82 virtual const base::string16 GetSupervisedUserMessage() const OVERRIDE { | 107 virtual const base::string16 GetSupervisedUserMessage() const OVERRIDE { |
83 return base::string16(); | 108 return base::string16(); |
84 } | 109 } |
85 | 110 |
86 virtual bool IsUserSupervised() const OVERRIDE { | 111 virtual bool IsUserSupervised() const OVERRIDE { |
87 return false; | 112 return false; |
88 } | 113 } |
89 | 114 |
90 virtual bool SystemShouldUpgrade() const OVERRIDE { | 115 virtual void GetSystemUpdateInfo(ash::UpdateInfo* info) const OVERRIDE { |
91 return UpgradeDetector::GetInstance()->notify_upgrade(); | 116 GetUpdateInfo(UpgradeDetector::GetInstance(), info); |
92 } | 117 } |
93 | 118 |
94 virtual base::HourClockType GetHourClockType() const OVERRIDE { | 119 virtual base::HourClockType GetHourClockType() const OVERRIDE { |
95 return clock_type_; | 120 return clock_type_; |
96 } | 121 } |
97 | 122 |
98 virtual void ShowSettings() OVERRIDE { | 123 virtual void ShowSettings() OVERRIDE { |
99 } | 124 } |
100 | 125 |
101 virtual bool ShouldShowSettings() OVERRIDE { | 126 virtual bool ShouldShowSettings() OVERRIDE { |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 clock_type_ = (base::GetHourClockType() == base::k24HourClock) ? | 320 clock_type_ = (base::GetHourClockType() == base::k24HourClock) ? |
296 base::k24HourClock : base::k12HourClock; | 321 base::k24HourClock : base::k12HourClock; |
297 GetSystemTrayNotifier()->NotifyDateFormatChanged(); | 322 GetSystemTrayNotifier()->NotifyDateFormatChanged(); |
298 } | 323 } |
299 | 324 |
300 // content::NotificationObserver implementation. | 325 // content::NotificationObserver implementation. |
301 virtual void Observe(int type, | 326 virtual void Observe(int type, |
302 const content::NotificationSource& source, | 327 const content::NotificationSource& source, |
303 const content::NotificationDetails& details) OVERRIDE { | 328 const content::NotificationDetails& details) OVERRIDE { |
304 if (type == chrome::NOTIFICATION_UPGRADE_RECOMMENDED) { | 329 if (type == chrome::NOTIFICATION_UPGRADE_RECOMMENDED) { |
305 UpgradeDetector* detector = | 330 ash::UpdateInfo info; |
306 content::Source<UpgradeDetector>(source).ptr(); | 331 GetUpdateInfo(content::Source<UpgradeDetector>(source).ptr(), &info); |
307 ash::UpdateObserver::UpdateSeverity severity = | 332 GetSystemTrayNotifier()->NotifyUpdateRecommended(info); |
308 ash::UpdateObserver::UPDATE_NORMAL; | |
309 switch (detector->upgrade_notification_stage()) { | |
310 case UpgradeDetector::UPGRADE_ANNOYANCE_CRITICAL: | |
311 case UpgradeDetector::UPGRADE_ANNOYANCE_SEVERE: | |
312 severity = ash::UpdateObserver::UPDATE_SEVERE_RED; | |
313 break; | |
314 case UpgradeDetector::UPGRADE_ANNOYANCE_HIGH: | |
315 severity = ash::UpdateObserver::UPDATE_HIGH_ORANGE; | |
316 break; | |
317 case UpgradeDetector::UPGRADE_ANNOYANCE_ELEVATED: | |
318 severity = ash::UpdateObserver::UPDATE_LOW_GREEN; | |
319 break; | |
320 case UpgradeDetector::UPGRADE_ANNOYANCE_LOW: | |
321 case UpgradeDetector::UPGRADE_ANNOYANCE_NONE: | |
322 severity = ash::UpdateObserver::UPDATE_NORMAL; | |
323 break; | |
324 } | |
325 GetSystemTrayNotifier()->NotifyUpdateRecommended(severity); | |
326 } else { | 333 } else { |
327 NOTREACHED(); | 334 NOTREACHED(); |
328 } | 335 } |
329 } | 336 } |
330 | 337 |
331 scoped_ptr<content::NotificationRegistrar> registrar_; | 338 scoped_ptr<content::NotificationRegistrar> registrar_; |
332 base::HourClockType clock_type_; | 339 base::HourClockType clock_type_; |
333 | 340 |
334 DISALLOW_COPY_AND_ASSIGN(SystemTrayDelegateLinux); | 341 DISALLOW_COPY_AND_ASSIGN(SystemTrayDelegateLinux); |
335 }; | 342 }; |
336 | 343 |
337 } // namespace | 344 } // namespace |
338 | 345 |
339 | 346 |
340 ash::SystemTrayDelegate* CreateLinuxSystemTrayDelegate() { | 347 ash::SystemTrayDelegate* CreateLinuxSystemTrayDelegate() { |
341 return new SystemTrayDelegateLinux(); | 348 return new SystemTrayDelegateLinux(); |
342 } | 349 } |
OLD | NEW |