Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / upgrade_detector.h
blobe117a67c48d3bbadc8ac1a31caafac1d492f24de
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/chrome_notification_types.h"
10 #include "ui/base/idle/idle.h"
11 #include "ui/gfx/image/image.h"
13 class PrefRegistrySimple;
15 ///////////////////////////////////////////////////////////////////////////////
16 // UpgradeDetector
18 // This class is a singleton class that monitors when an upgrade happens in the
19 // background. We basically ask Omaha what it thinks the latest version is and
20 // if our version is lower we send out a notification upon:
21 // a) Detecting an upgrade and...
22 // b) When we think the user should be notified about the upgrade.
23 // The latter happens much later, since we don't want to be too annoying.
25 class UpgradeDetector {
26 public:
27 // The Homeland Security Upgrade Advisory System.
28 enum UpgradeNotificationAnnoyanceLevel {
29 UPGRADE_ANNOYANCE_NONE = 0, // What? Me worry?
30 UPGRADE_ANNOYANCE_LOW, // Green.
31 UPGRADE_ANNOYANCE_ELEVATED, // Yellow.
32 UPGRADE_ANNOYANCE_HIGH, // Red.
33 UPGRADE_ANNOYANCE_SEVERE, // Orange.
34 UPGRADE_ANNOYANCE_CRITICAL, // Red exclamation mark.
37 // Returns the singleton implementation instance.
38 static UpgradeDetector* GetInstance();
40 virtual ~UpgradeDetector();
42 static void RegisterPrefs(PrefRegistrySimple* registry);
44 // Whether the user should be notified about an upgrade.
45 bool notify_upgrade() const { return notify_upgrade_; }
47 // Whether the upgrade recommendation is due to Chrome being outdated.
48 bool is_outdated_install() const {
49 return upgrade_available_ == UPGRADE_NEEDED_OUTDATED_INSTALL;
52 // Whether the upgrade recommendation is due to Chrome being outdated AND
53 // auto-update is turned off.
54 bool is_outdated_install_no_au() const {
55 return upgrade_available_ == UPGRADE_NEEDED_OUTDATED_INSTALL_NO_AU;
58 // Notifify this object that the user has acknowledged the critical update
59 // so we don't need to complain about it for now.
60 void acknowledge_critical_update() {
61 critical_update_acknowledged_ = true;
64 // Whether the user has acknowledged the critical update.
65 bool critical_update_acknowledged() const {
66 return critical_update_acknowledged_;
69 bool is_factory_reset_required() const { return is_factory_reset_required_; }
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) to display within the wrench menu.
74 int GetIconResourceID();
76 UpgradeNotificationAnnoyanceLevel upgrade_notification_stage() const {
77 return upgrade_notification_stage_;
80 protected:
81 enum UpgradeAvailable {
82 // If no update is available and current install is recent enough.
83 UPGRADE_AVAILABLE_NONE,
84 // If a regular update is available.
85 UPGRADE_AVAILABLE_REGULAR,
86 // If a critical update to Chrome has been installed, such as a zero-day
87 // fix.
88 UPGRADE_AVAILABLE_CRITICAL,
89 // If no update to Chrome has been installed for more than the recommended
90 // time.
91 UPGRADE_NEEDED_OUTDATED_INSTALL,
92 // If no update to Chrome has been installed for more than the recommended
93 // time AND auto-update is turned off.
94 UPGRADE_NEEDED_OUTDATED_INSTALL_NO_AU,
97 UpgradeDetector();
99 // Sends out UPGRADE_RECOMMENDED notification and set notify_upgrade_.
100 void NotifyUpgradeRecommended();
102 // Triggers a critical update, which starts a timer that checks the machine
103 // idle state. Protected and virtual so that it could be overridden by tests.
104 virtual void TriggerCriticalUpdate();
106 UpgradeAvailable upgrade_available() const { return upgrade_available_; }
107 void set_upgrade_available(UpgradeAvailable available) {
108 upgrade_available_ = available;
111 void set_best_effort_experiment_updates_available(bool available) {
112 best_effort_experiment_updates_available_ = available;
115 bool critical_experiment_updates_available() const {
116 return critical_experiment_updates_available_;
118 void set_critical_experiment_updates_available(bool available) {
119 critical_experiment_updates_available_ = available;
122 void set_critical_update_acknowledged(bool acknowledged) {
123 critical_update_acknowledged_ = acknowledged;
126 void set_upgrade_notification_stage(UpgradeNotificationAnnoyanceLevel stage) {
127 upgrade_notification_stage_ = stage;
130 void set_is_factory_reset_required(bool is_factory_reset_required) {
131 is_factory_reset_required_ = is_factory_reset_required;
134 private:
135 FRIEND_TEST_ALL_PREFIXES(WrenchMenuModelTest, Basics);
137 // Initiates an Idle check. See IdleCallback below.
138 void CheckIdle();
140 // The callback for the IdleCheck. Tells us whether Chrome has received any
141 // input events since the specified time.
142 void IdleCallback(ui::IdleState state);
144 // Triggers a global notification of the specified |type|.
145 void TriggerNotification(chrome::NotificationType type);
147 // Whether any software updates are available (experiment updates are tracked
148 // separately via additional member variables below).
149 UpgradeAvailable upgrade_available_;
151 // Whether "best effort" experiment updates are available.
152 bool best_effort_experiment_updates_available_;
154 // Whether "critical" experiment updates are available.
155 bool critical_experiment_updates_available_;
157 // Whether the user has acknowledged the critical update.
158 bool critical_update_acknowledged_;
160 // Whether a factory reset is needed to complete an update.
161 bool is_factory_reset_required_;
163 // A timer to check to see if we've been idle for long enough to show the
164 // critical warning. Should only be set if |upgrade_available_| is
165 // UPGRADE_AVAILABLE_CRITICAL.
166 base::RepeatingTimer<UpgradeDetector> idle_check_timer_;
168 // The stage at which the annoyance level for upgrade notifications is at.
169 UpgradeNotificationAnnoyanceLevel upgrade_notification_stage_;
171 // Whether we have waited long enough after detecting an upgrade (to see
172 // is we should start nagging about upgrading).
173 bool notify_upgrade_;
175 DISALLOW_COPY_AND_ASSIGN(UpgradeDetector);
178 #endif // CHROME_BROWSER_UPGRADE_DETECTOR_H_