[email protected] | 3bed26a | 2011-04-14 16:05:04 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | b1b7394 | 2010-05-26 20:11:54 | [diff] [blame] | 2 | // 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] | b1b7394 | 2010-05-26 20:11:54 | [diff] [blame] | 7 | |
[email protected] | b1b7394 | 2010-05-26 20:11:54 | [diff] [blame] | 8 | #include "base/timer.h" |
[email protected] | f1c76b9f | 2011-10-13 13:43:44 | [diff] [blame] | 9 | #include "chrome/browser/idle.h" |
[email protected] | f08e051 | 2011-06-13 18:10:44 | [diff] [blame] | 10 | #include "ui/gfx/image/image.h" |
[email protected] | b1b7394 | 2010-05-26 20:11:54 | [diff] [blame] | 11 | |
[email protected] | 8fcec3c7 | 2010-06-03 00:17:22 | [diff] [blame] | 12 | class PrefService; |
| 13 | |
[email protected] | b1b7394 | 2010-05-26 20:11:54 | [diff] [blame] | 14 | /////////////////////////////////////////////////////////////////////////////// |
| 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 | // |
| 24 | class UpgradeDetector { |
| 25 | public: |
[email protected] | 3bed26a | 2011-04-14 16:05:04 | [diff] [blame] | 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. |
[email protected] | f1c76b9f | 2011-10-13 13:43:44 | [diff] [blame] | 33 | UPGRADE_ANNOYANCE_CRITICAL, // Red exclamation mark. |
[email protected] | 3bed26a | 2011-04-14 16:05:04 | [diff] [blame] | 34 | }; |
| 35 | |
[email protected] | 2178814 | 2011-05-03 10:38:35 | [diff] [blame] | 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. |
| 40 | }; |
| 41 | |
[email protected] | ceff840 | 2011-06-12 23:27:12 | [diff] [blame] | 42 | // Returns the singleton implementation instance. |
[email protected] | fee46a8 | 2010-12-09 16:42:15 | [diff] [blame] | 43 | static UpgradeDetector* GetInstance(); |
| 44 | |
[email protected] | ceff840 | 2011-06-12 23:27:12 | [diff] [blame] | 45 | virtual ~UpgradeDetector(); |
[email protected] | b1b7394 | 2010-05-26 20:11:54 | [diff] [blame] | 46 | |
[email protected] | 8fcec3c7 | 2010-06-03 00:17:22 | [diff] [blame] | 47 | static void RegisterPrefs(PrefService* prefs); |
| 48 | |
[email protected] | f1c76b9f | 2011-10-13 13:43:44 | [diff] [blame] | 49 | // Whether the user should be notified about an upgrade. |
| 50 | bool notify_upgrade() const { return notify_upgrade_; } |
| 51 | |
| 52 | // Whether the upgrade is a critical upgrade (such as a zero-day update). |
| 53 | bool is_critical_update() const { return is_critical_upgrade_; } |
| 54 | |
| 55 | // Notifify this object that the user has acknowledged the critical update |
| 56 | // so we don't need to complain about it for now. |
| 57 | void acknowledge_critical_update() { |
| 58 | critical_update_acknowledged_ = true; |
| 59 | } |
| 60 | |
| 61 | // Whether the user has acknowledged the critical update. |
| 62 | bool critical_update_acknowledged() const { |
| 63 | return critical_update_acknowledged_; |
| 64 | } |
| 65 | |
| 66 | // When the last upgrade was detected. |
| 67 | const base::Time& upgrade_detected_time() const { |
| 68 | return upgrade_detected_time_; |
| 69 | } |
[email protected] | b1b7394 | 2010-05-26 20:11:54 | [diff] [blame] | 70 | |
[email protected] | 2178814 | 2011-05-03 10:38:35 | [diff] [blame] | 71 | // Retrieves the right icon ID based on the degree of severity (see |
| 72 | // UpgradeNotificationAnnoyanceLevel, each level has an an accompanying icon |
| 73 | // to go with it). |type| determines which class of icons the caller wants, |
| 74 | // either an icon appropriate for badging the wrench menu or one to display |
| 75 | // within the wrench menu. |
| 76 | int GetIconResourceID(UpgradeNotificationIconType type); |
[email protected] | 3bed26a | 2011-04-14 16:05:04 | [diff] [blame] | 77 | |
[email protected] | 9cbc9bf1 | 2012-09-12 09:16:45 | [diff] [blame^] | 78 | UpgradeNotificationAnnoyanceLevel upgrade_notification_stage() const { |
| 79 | return upgrade_notification_stage_; |
| 80 | } |
| 81 | |
[email protected] | ceff840 | 2011-06-12 23:27:12 | [diff] [blame] | 82 | protected: |
[email protected] | fee46a8 | 2010-12-09 16:42:15 | [diff] [blame] | 83 | UpgradeDetector(); |
| 84 | |
[email protected] | ceff840 | 2011-06-12 23:27:12 | [diff] [blame] | 85 | // Sends out UPGRADE_DETECTED notification and record upgrade_detected_time_. |
| 86 | void NotifyUpgradeDetected(); |
[email protected] | b1b7394 | 2010-05-26 20:11:54 | [diff] [blame] | 87 | |
[email protected] | ceff840 | 2011-06-12 23:27:12 | [diff] [blame] | 88 | // Sends out UPGRADE_RECOMMENDED notification and set notify_upgrade_. |
| 89 | void NotifyUpgradeRecommended(); |
[email protected] | 8fcec3c7 | 2010-06-03 00:17:22 | [diff] [blame] | 90 | |
[email protected] | ceff840 | 2011-06-12 23:27:12 | [diff] [blame] | 91 | void set_upgrade_notification_stage(UpgradeNotificationAnnoyanceLevel stage) { |
| 92 | upgrade_notification_stage_ = stage; |
| 93 | } |
[email protected] | b1b7394 | 2010-05-26 20:11:54 | [diff] [blame] | 94 | |
[email protected] | f1c76b9f | 2011-10-13 13:43:44 | [diff] [blame] | 95 | // True if a critical update to Chrome has been installed, such as a zero-day |
| 96 | // fix. |
| 97 | bool is_critical_upgrade_; |
| 98 | |
| 99 | // Whether the user has acknowledged the critical update. |
| 100 | bool critical_update_acknowledged_; |
| 101 | |
[email protected] | ceff840 | 2011-06-12 23:27:12 | [diff] [blame] | 102 | private: |
[email protected] | f1c76b9f | 2011-10-13 13:43:44 | [diff] [blame] | 103 | // Initiates an Idle check. See IdleCallback below. |
| 104 | void CheckIdle(); |
| 105 | |
| 106 | // The callback for the IdleCheck. Tells us whether Chrome has received any |
| 107 | // input events since the specified time. |
| 108 | void IdleCallback(IdleState state); |
| 109 | |
[email protected] | 3bed26a | 2011-04-14 16:05:04 | [diff] [blame] | 110 | // When the upgrade was detected. |
| 111 | base::Time upgrade_detected_time_; |
| 112 | |
[email protected] | f1c76b9f | 2011-10-13 13:43:44 | [diff] [blame] | 113 | // A timer to check to see if we've been idle for long enough to show the |
| 114 | // critical warning. Should only be set if |is_critical_upgrade_| is true. |
| 115 | base::RepeatingTimer<UpgradeDetector> idle_check_timer_; |
| 116 | |
[email protected] | 3bed26a | 2011-04-14 16:05:04 | [diff] [blame] | 117 | // The stage at which the annoyance level for upgrade notifications is at. |
| 118 | UpgradeNotificationAnnoyanceLevel upgrade_notification_stage_; |
| 119 | |
[email protected] | b1b7394 | 2010-05-26 20:11:54 | [diff] [blame] | 120 | // Whether we have waited long enough after detecting an upgrade (to see |
| 121 | // is we should start nagging about upgrading). |
| 122 | bool notify_upgrade_; |
| 123 | |
| 124 | DISALLOW_COPY_AND_ASSIGN(UpgradeDetector); |
| 125 | }; |
| 126 | |
| 127 | #endif // CHROME_BROWSER_UPGRADE_DETECTOR_H_ |