1 // Copyright (c) 2011 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 #ifndef CHROME_BROWSER_UPGRADE_DETECTOR_H_
6 #define CHROME_BROWSER_UPGRADE_DETECTOR_H_
8 #include "base/timer/timer.h"
9 #include "chrome/browser/idle.h"
10 #include "ui/gfx/image/image.h"
12 class PrefRegistrySimple
;
14 ///////////////////////////////////////////////////////////////////////////////
17 // This class is a singleton class that monitors when an upgrade happens in the
18 // background. We basically ask Omaha what it thinks the latest version is and
19 // if our version is lower we send out a notification upon:
20 // a) Detecting an upgrade and...
21 // b) When we think the user should be notified about the upgrade.
22 // The latter happens much later, since we don't want to be too annoying.
24 class UpgradeDetector
{
26 // The Homeland Security Upgrade Advisory System.
27 enum UpgradeNotificationAnnoyanceLevel
{
28 UPGRADE_ANNOYANCE_NONE
= 0, // What? Me worry?
29 UPGRADE_ANNOYANCE_LOW
, // Green.
30 UPGRADE_ANNOYANCE_ELEVATED
, // Yellow.
31 UPGRADE_ANNOYANCE_HIGH
, // Red.
32 UPGRADE_ANNOYANCE_SEVERE
, // Orange.
33 UPGRADE_ANNOYANCE_CRITICAL
, // Red exclamation mark.
36 // The two types of icons we know about.
37 enum UpgradeNotificationIconType
{
38 UPGRADE_ICON_TYPE_BADGE
= 0, // For overlay badging of the wrench menu.
39 UPGRADE_ICON_TYPE_MENU_ICON
, // For showing in the wrench menu.
42 // Returns the singleton implementation instance.
43 static UpgradeDetector
* GetInstance();
45 virtual ~UpgradeDetector();
47 static void RegisterPrefs(PrefRegistrySimple
* registry
);
49 // Whether the user should be notified about an upgrade.
50 bool notify_upgrade() const { return notify_upgrade_
; }
52 // Whether the upgrade recommendation is due to Chrome being outdated.
53 bool is_outdated_install() const {
54 return upgrade_available_
== UPGRADE_NEEDED_OUTDATED_INSTALL
;
57 // Whether the upgrade recommendation is due to Chrome being outdated AND
58 // auto-update is turned off.
59 bool is_outdated_install_no_au() const {
60 return upgrade_available_
== UPGRADE_NEEDED_OUTDATED_INSTALL_NO_AU
;
63 // Notifify this object that the user has acknowledged the critical update
64 // so we don't need to complain about it for now.
65 void acknowledge_critical_update() {
66 critical_update_acknowledged_
= true;
69 // Whether the user has acknowledged the critical update.
70 bool critical_update_acknowledged() const {
71 return critical_update_acknowledged_
;
74 // When the last upgrade was detected.
75 const base::Time
& upgrade_detected_time() const {
76 return upgrade_detected_time_
;
79 // Retrieves the right icon ID based on the degree of severity (see
80 // UpgradeNotificationAnnoyanceLevel, each level has an an accompanying icon
81 // to go with it). |type| determines which class of icons the caller wants,
82 // either an icon appropriate for badging the wrench menu or one to display
83 // within the wrench menu.
84 int GetIconResourceID(UpgradeNotificationIconType type
);
86 UpgradeNotificationAnnoyanceLevel
upgrade_notification_stage() const {
87 return upgrade_notification_stage_
;
93 // Sends out UPGRADE_DETECTED notification and record upgrade_detected_time_.
94 void NotifyUpgradeDetected();
96 // Sends out UPGRADE_RECOMMENDED notification and set notify_upgrade_.
97 void NotifyUpgradeRecommended();
99 void set_upgrade_notification_stage(UpgradeNotificationAnnoyanceLevel stage
) {
100 upgrade_notification_stage_
= stage
;
103 enum UpgradeAvailable
{
104 // If no update is available and current install is recent enough.
105 UPGRADE_AVAILABLE_NONE
,
106 // If a regular update is available.
107 UPGRADE_AVAILABLE_REGULAR
,
108 // If a critical update to Chrome has been installed, such as a zero-day
110 UPGRADE_AVAILABLE_CRITICAL
,
111 // If no update to Chrome has been installed for more than the recommended
113 UPGRADE_NEEDED_OUTDATED_INSTALL
,
114 // If no update to Chrome has been installed for more than the recommended
115 // time AND auto-update is turned off.
116 UPGRADE_NEEDED_OUTDATED_INSTALL_NO_AU
,
117 } upgrade_available_
;
119 // Whether the user has acknowledged the critical update.
120 bool critical_update_acknowledged_
;
123 // Initiates an Idle check. See IdleCallback below.
126 // The callback for the IdleCheck. Tells us whether Chrome has received any
127 // input events since the specified time.
128 void IdleCallback(IdleState state
);
130 // When the upgrade was detected.
131 base::Time upgrade_detected_time_
;
133 // A timer to check to see if we've been idle for long enough to show the
134 // critical warning. Should only be set if |upgrade_available_| is
135 // UPGRADE_AVAILABLE_CRITICAL.
136 base::RepeatingTimer
<UpgradeDetector
> idle_check_timer_
;
138 // The stage at which the annoyance level for upgrade notifications is at.
139 UpgradeNotificationAnnoyanceLevel upgrade_notification_stage_
;
141 // Whether we have waited long enough after detecting an upgrade (to see
142 // is we should start nagging about upgrading).
143 bool notify_upgrade_
;
145 DISALLOW_COPY_AND_ASSIGN(UpgradeDetector
);
148 #endif // CHROME_BROWSER_UPGRADE_DETECTOR_H_