| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef CHROME_BROWSER_UPGRADE_DETECTOR_H_ | 5 #ifndef CHROME_BROWSER_UPGRADE_DETECTOR_H_ |
| 6 #define CHROME_BROWSER_UPGRADE_DETECTOR_H_ | 6 #define CHROME_BROWSER_UPGRADE_DETECTOR_H_ |
| 7 | 7 |
| 8 #include "base/timer/timer.h" | 8 #include "base/timer/timer.h" |
| 9 #include "chrome/browser/chrome_notification_types.h" |
| 9 #include "chrome/browser/idle.h" | 10 #include "chrome/browser/idle.h" |
| 10 #include "ui/gfx/image/image.h" | 11 #include "ui/gfx/image/image.h" |
| 11 | 12 |
| 12 class PrefRegistrySimple; | 13 class PrefRegistrySimple; |
| 13 | 14 |
| 14 /////////////////////////////////////////////////////////////////////////////// | 15 /////////////////////////////////////////////////////////////////////////////// |
| 15 // UpgradeDetector | 16 // UpgradeDetector |
| 16 // | 17 // |
| 17 // This class is a singleton class that monitors when an upgrade happens in the | 18 // 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 // background. We basically ask Omaha what it thinks the latest version is and |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 // so we don't need to complain about it for now. | 59 // so we don't need to complain about it for now. |
| 59 void acknowledge_critical_update() { | 60 void acknowledge_critical_update() { |
| 60 critical_update_acknowledged_ = true; | 61 critical_update_acknowledged_ = true; |
| 61 } | 62 } |
| 62 | 63 |
| 63 // Whether the user has acknowledged the critical update. | 64 // Whether the user has acknowledged the critical update. |
| 64 bool critical_update_acknowledged() const { | 65 bool critical_update_acknowledged() const { |
| 65 return critical_update_acknowledged_; | 66 return critical_update_acknowledged_; |
| 66 } | 67 } |
| 67 | 68 |
| 68 // When the last upgrade was detected. | |
| 69 const base::Time& upgrade_detected_time() const { | |
| 70 return upgrade_detected_time_; | |
| 71 } | |
| 72 | |
| 73 // Retrieves the right icon ID based on the degree of severity (see | 69 // Retrieves the right icon ID based on the degree of severity (see |
| 74 // UpgradeNotificationAnnoyanceLevel, each level has an an accompanying icon | 70 // UpgradeNotificationAnnoyanceLevel, each level has an an accompanying icon |
| 75 // to go with it) to display within the wrench menu. | 71 // to go with it) to display within the wrench menu. |
| 76 int GetIconResourceID(); | 72 int GetIconResourceID(); |
| 77 | 73 |
| 78 UpgradeNotificationAnnoyanceLevel upgrade_notification_stage() const { | 74 UpgradeNotificationAnnoyanceLevel upgrade_notification_stage() const { |
| 79 return upgrade_notification_stage_; | 75 return upgrade_notification_stage_; |
| 80 } | 76 } |
| 81 | 77 |
| 82 protected: | 78 protected: |
| 83 UpgradeDetector(); | |
| 84 | |
| 85 // Sends out UPGRADE_DETECTED notification and record upgrade_detected_time_. | |
| 86 void NotifyUpgradeDetected(); | |
| 87 | |
| 88 // Sends out UPGRADE_RECOMMENDED notification and set notify_upgrade_. | |
| 89 void NotifyUpgradeRecommended(); | |
| 90 | |
| 91 void set_upgrade_notification_stage(UpgradeNotificationAnnoyanceLevel stage) { | |
| 92 upgrade_notification_stage_ = stage; | |
| 93 } | |
| 94 | |
| 95 enum UpgradeAvailable { | 79 enum UpgradeAvailable { |
| 96 // If no update is available and current install is recent enough. | 80 // If no update is available and current install is recent enough. |
| 97 UPGRADE_AVAILABLE_NONE, | 81 UPGRADE_AVAILABLE_NONE, |
| 98 // If a regular update is available. | 82 // If a regular update is available. |
| 99 UPGRADE_AVAILABLE_REGULAR, | 83 UPGRADE_AVAILABLE_REGULAR, |
| 100 // If a critical update to Chrome has been installed, such as a zero-day | 84 // If a critical update to Chrome has been installed, such as a zero-day |
| 101 // fix. | 85 // fix. |
| 102 UPGRADE_AVAILABLE_CRITICAL, | 86 UPGRADE_AVAILABLE_CRITICAL, |
| 103 // If no update to Chrome has been installed for more than the recommended | 87 // If no update to Chrome has been installed for more than the recommended |
| 104 // time. | 88 // time. |
| 105 UPGRADE_NEEDED_OUTDATED_INSTALL, | 89 UPGRADE_NEEDED_OUTDATED_INSTALL, |
| 106 // If no update to Chrome has been installed for more than the recommended | 90 // If no update to Chrome has been installed for more than the recommended |
| 107 // time AND auto-update is turned off. | 91 // time AND auto-update is turned off. |
| 108 UPGRADE_NEEDED_OUTDATED_INSTALL_NO_AU, | 92 UPGRADE_NEEDED_OUTDATED_INSTALL_NO_AU, |
| 109 } upgrade_available_; | 93 }; |
| 110 | 94 |
| 111 // Whether the user has acknowledged the critical update. | 95 UpgradeDetector(); |
| 112 bool critical_update_acknowledged_; | 96 |
| 97 // Sends out UPGRADE_RECOMMENDED notification and set notify_upgrade_. |
| 98 void NotifyUpgradeRecommended(); |
| 99 |
| 100 // Triggers a critical update, which starts a timer that checks the machine |
| 101 // idle state. Protected and virtual so that it could be overridden by tests. |
| 102 virtual void TriggerCriticalUpdate(); |
| 103 |
| 104 UpgradeAvailable upgrade_available() const { return upgrade_available_; } |
| 105 void set_upgrade_available(UpgradeAvailable available) { |
| 106 upgrade_available_ = available; |
| 107 } |
| 108 |
| 109 void set_best_effort_experiment_updates_available(bool available) { |
| 110 best_effort_experiment_updates_available_ = available; |
| 111 } |
| 112 |
| 113 bool critical_experiment_updates_available() const { |
| 114 return critical_experiment_updates_available_; |
| 115 } |
| 116 void set_critical_experiment_updates_available(bool available) { |
| 117 critical_experiment_updates_available_ = available; |
| 118 } |
| 119 |
| 120 void set_critical_update_acknowledged(bool acknowledged) { |
| 121 critical_update_acknowledged_ = acknowledged; |
| 122 } |
| 123 |
| 124 void set_upgrade_notification_stage(UpgradeNotificationAnnoyanceLevel stage) { |
| 125 upgrade_notification_stage_ = stage; |
| 126 } |
| 113 | 127 |
| 114 private: | 128 private: |
| 115 // Initiates an Idle check. See IdleCallback below. | 129 // Initiates an Idle check. See IdleCallback below. |
| 116 void CheckIdle(); | 130 void CheckIdle(); |
| 117 | 131 |
| 118 // The callback for the IdleCheck. Tells us whether Chrome has received any | 132 // The callback for the IdleCheck. Tells us whether Chrome has received any |
| 119 // input events since the specified time. | 133 // input events since the specified time. |
| 120 void IdleCallback(IdleState state); | 134 void IdleCallback(IdleState state); |
| 121 | 135 |
| 122 // When the upgrade was detected. | 136 // Triggers a global notification of the specified |type|. |
| 123 base::Time upgrade_detected_time_; | 137 void TriggerNotification(chrome::NotificationType type); |
| 138 |
| 139 // Whether any software updates are available (experiment updates are tracked |
| 140 // separately via additional member variables below). |
| 141 UpgradeAvailable upgrade_available_; |
| 142 |
| 143 // Whether "best effort" experiment updates are available. |
| 144 bool best_effort_experiment_updates_available_; |
| 145 |
| 146 // Whether "critical" experiment updates are available. |
| 147 bool critical_experiment_updates_available_; |
| 148 |
| 149 // Whether the user has acknowledged the critical update. |
| 150 bool critical_update_acknowledged_; |
| 124 | 151 |
| 125 // A timer to check to see if we've been idle for long enough to show the | 152 // A timer to check to see if we've been idle for long enough to show the |
| 126 // critical warning. Should only be set if |upgrade_available_| is | 153 // critical warning. Should only be set if |upgrade_available_| is |
| 127 // UPGRADE_AVAILABLE_CRITICAL. | 154 // UPGRADE_AVAILABLE_CRITICAL. |
| 128 base::RepeatingTimer<UpgradeDetector> idle_check_timer_; | 155 base::RepeatingTimer<UpgradeDetector> idle_check_timer_; |
| 129 | 156 |
| 130 // The stage at which the annoyance level for upgrade notifications is at. | 157 // The stage at which the annoyance level for upgrade notifications is at. |
| 131 UpgradeNotificationAnnoyanceLevel upgrade_notification_stage_; | 158 UpgradeNotificationAnnoyanceLevel upgrade_notification_stage_; |
| 132 | 159 |
| 133 // Whether we have waited long enough after detecting an upgrade (to see | 160 // Whether we have waited long enough after detecting an upgrade (to see |
| 134 // is we should start nagging about upgrading). | 161 // is we should start nagging about upgrading). |
| 135 bool notify_upgrade_; | 162 bool notify_upgrade_; |
| 136 | 163 |
| 137 DISALLOW_COPY_AND_ASSIGN(UpgradeDetector); | 164 DISALLOW_COPY_AND_ASSIGN(UpgradeDetector); |
| 138 }; | 165 }; |
| 139 | 166 |
| 140 #endif // CHROME_BROWSER_UPGRADE_DETECTOR_H_ | 167 #endif // CHROME_BROWSER_UPGRADE_DETECTOR_H_ |
| OLD | NEW |