blob: 0e73ebc151a550b137d9a6c9d1fe56a034dc55e6 [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_
7
thestiga0e18cd2015-09-25 04:58:368#include "base/gtest_prod_util.h"
avi664c07b2015-12-26 02:18:319#include "base/macros.h"
weidonggef06a6f42017-05-22 17:47:1110#include "base/observer_list.h"
[email protected]b22b27a2013-06-28 05:37:5711#include "base/timer/timer.h"
weidonggef06a6f42017-05-22 17:47:1112#include "chrome/browser/upgrade_observer.h"
derat49b2fd52015-01-16 15:32:1213#include "ui/base/idle/idle.h"
[email protected]f08e0512011-06-13 18:10:4414#include "ui/gfx/image/image.h"
[email protected]b1b73942010-05-26 20:11:5415
[email protected]b1de2c72013-02-06 02:45:4716class PrefRegistrySimple;
weidonggef06a6f42017-05-22 17:47:1117class UpgradeObserver;
[email protected]8fcec3c72010-06-03 00:17:2218
[email protected]b1b73942010-05-26 20:11:5419///////////////////////////////////////////////////////////////////////////////
20// UpgradeDetector
21//
22// This class is a singleton class that monitors when an upgrade happens in the
23// background. We basically ask Omaha what it thinks the latest version is and
24// if our version is lower we send out a notification upon:
25// a) Detecting an upgrade and...
26// b) When we think the user should be notified about the upgrade.
27// The latter happens much later, since we don't want to be too annoying.
28//
29class UpgradeDetector {
30 public:
[email protected]3bed26a2011-04-14 16:05:0431 // The Homeland Security Upgrade Advisory System.
32 enum UpgradeNotificationAnnoyanceLevel {
33 UPGRADE_ANNOYANCE_NONE = 0, // What? Me worry?
34 UPGRADE_ANNOYANCE_LOW, // Green.
35 UPGRADE_ANNOYANCE_ELEVATED, // Yellow.
36 UPGRADE_ANNOYANCE_HIGH, // Red.
37 UPGRADE_ANNOYANCE_SEVERE, // Orange.
[email protected]f1c76b9f2011-10-13 13:43:4438 UPGRADE_ANNOYANCE_CRITICAL, // Red exclamation mark.
[email protected]3bed26a2011-04-14 16:05:0439 };
40
[email protected]ceff8402011-06-12 23:27:1241 // Returns the singleton implementation instance.
[email protected]fee46a82010-12-09 16:42:1542 static UpgradeDetector* GetInstance();
43
[email protected]ceff8402011-06-12 23:27:1244 virtual ~UpgradeDetector();
[email protected]b1b73942010-05-26 20:11:5445
[email protected]b1de2c72013-02-06 02:45:4746 static void RegisterPrefs(PrefRegistrySimple* registry);
[email protected]8fcec3c72010-06-03 00:17:2247
[email protected]f1c76b9f2011-10-13 13:43:4448 // Whether the user should be notified about an upgrade.
49 bool notify_upgrade() const { return notify_upgrade_; }
50
[email protected]2a54f2d2013-02-15 05:54:3651 // Whether the upgrade recommendation is due to Chrome being outdated.
52 bool is_outdated_install() const {
53 return upgrade_available_ == UPGRADE_NEEDED_OUTDATED_INSTALL;
54 }
[email protected]f1c76b9f2011-10-13 13:43:4455
[email protected]d50dd9d2014-03-28 21:46:2456 // Whether the upgrade recommendation is due to Chrome being outdated AND
57 // auto-update is turned off.
58 bool is_outdated_install_no_au() const {
59 return upgrade_available_ == UPGRADE_NEEDED_OUTDATED_INSTALL_NO_AU;
60 }
61
[email protected]f1c76b9f2011-10-13 13:43:4462 // Notifify this object that the user has acknowledged the critical update
63 // so we don't need to complain about it for now.
64 void acknowledge_critical_update() {
65 critical_update_acknowledged_ = true;
66 }
67
68 // Whether the user has acknowledged the critical update.
69 bool critical_update_acknowledged() const {
70 return critical_update_acknowledged_;
71 }
72
ygorshenin9903cf42014-10-07 06:47:1173 bool is_factory_reset_required() const { return is_factory_reset_required_; }
74
estade1e949edc2016-02-08 21:19:4675 // Retrieves the right icon based on the degree of severity (see
[email protected]21788142011-05-03 10:38:3576 // UpgradeNotificationAnnoyanceLevel, each level has an an accompanying icon
tfarina917cff5e2015-10-31 01:16:3877 // to go with it) to display within the app menu.
estade1e949edc2016-02-08 21:19:4678 gfx::Image GetIcon();
[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
weidonggef06a6f42017-05-22 17:47:1184 void AddObserver(UpgradeObserver* observer);
85
86 void RemoveObserver(UpgradeObserver* observer);
87
weidongg04695232017-06-09 00:01:0588 // Notifies that the current install is outdated. No details are expected.
89 void NotifyOutdatedInstall();
90
91 // Notifies that the current install is outdated and auto-update (AU) is
92 // disabled. No details are expected.
93 void NotifyOutdatedInstallNoAutoUpdate();
94
[email protected]ceff8402011-06-12 23:27:1295 protected:
[email protected]2a54f2d2013-02-15 05:54:3696 enum UpgradeAvailable {
97 // If no update is available and current install is recent enough.
98 UPGRADE_AVAILABLE_NONE,
99 // If a regular update is available.
100 UPGRADE_AVAILABLE_REGULAR,
101 // If a critical update to Chrome has been installed, such as a zero-day
102 // fix.
103 UPGRADE_AVAILABLE_CRITICAL,
104 // If no update to Chrome has been installed for more than the recommended
105 // time.
106 UPGRADE_NEEDED_OUTDATED_INSTALL,
[email protected]d50dd9d2014-03-28 21:46:24107 // If no update to Chrome has been installed for more than the recommended
108 // time AND auto-update is turned off.
109 UPGRADE_NEEDED_OUTDATED_INSTALL_NO_AU,
[email protected]dd46dd52014-08-07 21:57:14110 };
[email protected]f1c76b9f2011-10-13 13:43:44111
[email protected]dd46dd52014-08-07 21:57:14112 UpgradeDetector();
113
weidongg04695232017-06-09 00:01:05114 // Notifies that update is recommended and triggers different actions based
115 // on the update availability.
116 void NotifyUpgrade();
117
118 // Notifies that update is recommended.
[email protected]dd46dd52014-08-07 21:57:14119 void NotifyUpgradeRecommended();
120
weidongg04695232017-06-09 00:01:05121 // Notifies that a critical update has been installed. No details are
122 // expected.
123 void NotifyCriticalUpgradeInstalled();
124
weidonggef06a6f42017-05-22 17:47:11125 // The function that sends out a notification that lets the rest of the UI
126 // know we should notify the user that a new update is available to download
127 // over cellular connection.
128 void NotifyUpdateOverCellularAvailable();
129
Weidong Guo8f8b700162017-07-28 19:37:02130 // Notifies that the user's one time permission on update over cellular
131 // connection has been granted.
132 void NotifyUpdateOverCellularOneTimePermissionGranted();
133
[email protected]dd46dd52014-08-07 21:57:14134 // Triggers a critical update, which starts a timer that checks the machine
135 // idle state. Protected and virtual so that it could be overridden by tests.
136 virtual void TriggerCriticalUpdate();
137
138 UpgradeAvailable upgrade_available() const { return upgrade_available_; }
139 void set_upgrade_available(UpgradeAvailable available) {
140 upgrade_available_ = available;
141 }
142
143 void set_best_effort_experiment_updates_available(bool available) {
144 best_effort_experiment_updates_available_ = available;
145 }
146
147 bool critical_experiment_updates_available() const {
148 return critical_experiment_updates_available_;
149 }
150 void set_critical_experiment_updates_available(bool available) {
151 critical_experiment_updates_available_ = available;
152 }
153
154 void set_critical_update_acknowledged(bool acknowledged) {
155 critical_update_acknowledged_ = acknowledged;
156 }
157
158 void set_upgrade_notification_stage(UpgradeNotificationAnnoyanceLevel stage) {
159 upgrade_notification_stage_ = stage;
160 }
[email protected]f1c76b9f2011-10-13 13:43:44161
ygorshenin9903cf42014-10-07 06:47:11162 void set_is_factory_reset_required(bool is_factory_reset_required) {
163 is_factory_reset_required_ = is_factory_reset_required;
164 }
165
[email protected]ceff8402011-06-12 23:27:12166 private:
tfarinaa10d43152015-10-26 20:11:30167 FRIEND_TEST_ALL_PREFIXES(AppMenuModelTest, Basics);
jamescook80547782016-12-13 18:35:29168 FRIEND_TEST_ALL_PREFIXES(SystemTrayClientTest, UpdateTrayIcon);
abodenha44babbe2015-04-27 18:30:48169
[email protected]f1c76b9f2011-10-13 13:43:44170 // Initiates an Idle check. See IdleCallback below.
171 void CheckIdle();
172
173 // The callback for the IdleCheck. Tells us whether Chrome has received any
174 // input events since the specified time.
derat49b2fd52015-01-16 15:32:12175 void IdleCallback(ui::IdleState state);
[email protected]f1c76b9f2011-10-13 13:43:44176
[email protected]dd46dd52014-08-07 21:57:14177 // Whether any software updates are available (experiment updates are tracked
178 // separately via additional member variables below).
179 UpgradeAvailable upgrade_available_;
180
181 // Whether "best effort" experiment updates are available.
182 bool best_effort_experiment_updates_available_;
183
184 // Whether "critical" experiment updates are available.
185 bool critical_experiment_updates_available_;
186
187 // Whether the user has acknowledged the critical update.
188 bool critical_update_acknowledged_;
[email protected]3bed26a2011-04-14 16:05:04189
ygorshenin9903cf42014-10-07 06:47:11190 // Whether a factory reset is needed to complete an update.
191 bool is_factory_reset_required_;
192
[email protected]f1c76b9f2011-10-13 13:43:44193 // A timer to check to see if we've been idle for long enough to show the
[email protected]2a54f2d2013-02-15 05:54:36194 // critical warning. Should only be set if |upgrade_available_| is
195 // UPGRADE_AVAILABLE_CRITICAL.
danakj8c3eb802015-09-24 07:53:00196 base::RepeatingTimer idle_check_timer_;
[email protected]f1c76b9f2011-10-13 13:43:44197
[email protected]3bed26a2011-04-14 16:05:04198 // The stage at which the annoyance level for upgrade notifications is at.
199 UpgradeNotificationAnnoyanceLevel upgrade_notification_stage_;
200
[email protected]b1b73942010-05-26 20:11:54201 // Whether we have waited long enough after detecting an upgrade (to see
202 // is we should start nagging about upgrading).
203 bool notify_upgrade_;
204
weidonggef06a6f42017-05-22 17:47:11205 base::ObserverList<UpgradeObserver> observer_list_;
206
[email protected]b1b73942010-05-26 20:11:54207 DISALLOW_COPY_AND_ASSIGN(UpgradeDetector);
208};
209
210#endif // CHROME_BROWSER_UPGRADE_DETECTOR_H_