blob: 86f2c442babf82150a550d1af5d9d01c08b21f08 [file] [log] [blame]
[email protected]3bed26a2011-04-14 16:05:041// Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]b1b73942010-05-26 20:11:542// 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_UPGRADE_DETECTOR_H_
6#define CHROME_BROWSER_UPGRADE_DETECTOR_H_
[email protected]b1b73942010-05-26 20:11:547
[email protected]b1b73942010-05-26 20:11:548#include "base/timer.h"
[email protected]f1c76b9f2011-10-13 13:43:449#include "chrome/browser/idle.h"
[email protected]f08e0512011-06-13 18:10:4410#include "ui/gfx/image/image.h"
[email protected]b1b73942010-05-26 20:11:5411
[email protected]b1de2c72013-02-06 02:45:4712class PrefRegistrySimple;
[email protected]8fcec3c72010-06-03 00:17:2213
[email protected]b1b73942010-05-26 20:11:5414///////////////////////////////////////////////////////////////////////////////
15// UpgradeDetector
16//
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.
23//
24class UpgradeDetector {
25 public:
[email protected]3bed26a2011-04-14 16:05:0426 // 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.
[email protected]f1c76b9f2011-10-13 13:43:4433 UPGRADE_ANNOYANCE_CRITICAL, // Red exclamation mark.
[email protected]3bed26a2011-04-14 16:05:0434 };
35
[email protected]21788142011-05-03 10:38:3536 // 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.
40 };
41
[email protected]ceff8402011-06-12 23:27:1242 // Returns the singleton implementation instance.
[email protected]fee46a82010-12-09 16:42:1543 static UpgradeDetector* GetInstance();
44
[email protected]ceff8402011-06-12 23:27:1245 virtual ~UpgradeDetector();
[email protected]b1b73942010-05-26 20:11:5446
[email protected]b1de2c72013-02-06 02:45:4747 static void RegisterPrefs(PrefRegistrySimple* registry);
[email protected]8fcec3c72010-06-03 00:17:2248
[email protected]f1c76b9f2011-10-13 13:43:4449 // Whether the user should be notified about an upgrade.
50 bool notify_upgrade() const { return notify_upgrade_; }
51
[email protected]2a54f2d2013-02-15 05:54:3652 // Whether the upgrade recommendation is due to Chrome being outdated.
53 bool is_outdated_install() const {
54 return upgrade_available_ == UPGRADE_NEEDED_OUTDATED_INSTALL;
55 }
[email protected]f1c76b9f2011-10-13 13:43:4456
57 // Notifify this object that the user has acknowledged the critical update
58 // so we don't need to complain about it for now.
59 void acknowledge_critical_update() {
60 critical_update_acknowledged_ = true;
61 }
62
63 // Whether the user has acknowledged the critical update.
64 bool critical_update_acknowledged() const {
65 return critical_update_acknowledged_;
66 }
67
68 // When the last upgrade was detected.
69 const base::Time& upgrade_detected_time() const {
70 return upgrade_detected_time_;
71 }
[email protected]b1b73942010-05-26 20:11:5472
[email protected]21788142011-05-03 10:38:3573 // Retrieves the right icon ID based on the degree of severity (see
74 // UpgradeNotificationAnnoyanceLevel, each level has an an accompanying icon
75 // to go with it). |type| determines which class of icons the caller wants,
76 // either an icon appropriate for badging the wrench menu or one to display
77 // within the wrench menu.
78 int GetIconResourceID(UpgradeNotificationIconType type);
[email protected]3bed26a2011-04-14 16:05:0479
[email protected]9cbc9bf12012-09-12 09:16:4580 UpgradeNotificationAnnoyanceLevel upgrade_notification_stage() const {
81 return upgrade_notification_stage_;
82 }
83
[email protected]ceff8402011-06-12 23:27:1284 protected:
[email protected]fee46a82010-12-09 16:42:1585 UpgradeDetector();
86
[email protected]ceff8402011-06-12 23:27:1287 // Sends out UPGRADE_DETECTED notification and record upgrade_detected_time_.
88 void NotifyUpgradeDetected();
[email protected]b1b73942010-05-26 20:11:5489
[email protected]ceff8402011-06-12 23:27:1290 // Sends out UPGRADE_RECOMMENDED notification and set notify_upgrade_.
91 void NotifyUpgradeRecommended();
[email protected]8fcec3c72010-06-03 00:17:2292
[email protected]ceff8402011-06-12 23:27:1293 void set_upgrade_notification_stage(UpgradeNotificationAnnoyanceLevel stage) {
94 upgrade_notification_stage_ = stage;
95 }
[email protected]b1b73942010-05-26 20:11:5496
[email protected]2a54f2d2013-02-15 05:54:3697 enum UpgradeAvailable {
98 // If no update is available and current install is recent enough.
99 UPGRADE_AVAILABLE_NONE,
100 // If a regular update is available.
101 UPGRADE_AVAILABLE_REGULAR,
102 // If a critical update to Chrome has been installed, such as a zero-day
103 // fix.
104 UPGRADE_AVAILABLE_CRITICAL,
105 // If no update to Chrome has been installed for more than the recommended
106 // time.
107 UPGRADE_NEEDED_OUTDATED_INSTALL,
108 } upgrade_available_;
[email protected]f1c76b9f2011-10-13 13:43:44109
110 // Whether the user has acknowledged the critical update.
111 bool critical_update_acknowledged_;
112
[email protected]ceff8402011-06-12 23:27:12113 private:
[email protected]f1c76b9f2011-10-13 13:43:44114 // Initiates an Idle check. See IdleCallback below.
115 void CheckIdle();
116
117 // The callback for the IdleCheck. Tells us whether Chrome has received any
118 // input events since the specified time.
119 void IdleCallback(IdleState state);
120
[email protected]3bed26a2011-04-14 16:05:04121 // When the upgrade was detected.
122 base::Time upgrade_detected_time_;
123
[email protected]f1c76b9f2011-10-13 13:43:44124 // A timer to check to see if we've been idle for long enough to show the
[email protected]2a54f2d2013-02-15 05:54:36125 // critical warning. Should only be set if |upgrade_available_| is
126 // UPGRADE_AVAILABLE_CRITICAL.
[email protected]f1c76b9f2011-10-13 13:43:44127 base::RepeatingTimer<UpgradeDetector> idle_check_timer_;
128
[email protected]3bed26a2011-04-14 16:05:04129 // The stage at which the annoyance level for upgrade notifications is at.
130 UpgradeNotificationAnnoyanceLevel upgrade_notification_stage_;
131
[email protected]b1b73942010-05-26 20:11:54132 // Whether we have waited long enough after detecting an upgrade (to see
133 // is we should start nagging about upgrading).
134 bool notify_upgrade_;
135
136 DISALLOW_COPY_AND_ASSIGN(UpgradeDetector);
137};
138
139#endif // CHROME_BROWSER_UPGRADE_DETECTOR_H_