Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1201)

Side by Side Diff: chrome/browser/upgrade_detector_impl.cc

Issue 11440020: Add an outdated upgrade bubble view. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed OWNERS comments... Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/upgrade_detector_impl.h ('k') | chrome/chrome_browser_ui.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include "chrome/browser/upgrade_detector_impl.h" 5 #include "chrome/browser/upgrade_detector_impl.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/build_time.h"
10 #include "base/command_line.h" 11 #include "base/command_line.h"
11 #include "base/file_path.h" 12 #include "base/file_path.h"
12 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/singleton.h" 14 #include "base/memory/singleton.h"
15 #include "base/metrics/field_trial.h"
14 #include "base/path_service.h" 16 #include "base/path_service.h"
15 #include "base/string_util.h" 17 #include "base/string_util.h"
16 #include "base/strings/string_number_conversions.h" 18 #include "base/strings/string_number_conversions.h"
17 #include "base/time.h" 19 #include "base/time.h"
18 #include "base/utf_string_conversions.h" 20 #include "base/utf_string_conversions.h"
21 #include "base/version.h"
22 #include "chrome/browser/browser_process.h"
23 #include "chrome/browser/metrics/variations/variations_service.h"
19 #include "chrome/common/chrome_switches.h" 24 #include "chrome/common/chrome_switches.h"
20 #include "chrome/common/chrome_version_info.h" 25 #include "chrome/common/chrome_version_info.h"
21 #include "chrome/installer/util/browser_distribution.h"
22 #include "content/public/browser/browser_thread.h" 26 #include "content/public/browser/browser_thread.h"
23 #include "ui/base/resource/resource_bundle.h" 27 #include "ui/base/resource/resource_bundle.h"
24 28
25 #if defined(OS_WIN) 29 #if defined(OS_WIN)
30 #include "chrome/installer/util/browser_distribution.h"
31 #include "chrome/installer/util/google_update_settings.h"
32 #include "chrome/installer/util/helper.h"
26 #include "chrome/installer/util/install_util.h" 33 #include "chrome/installer/util/install_util.h"
27 #elif defined(OS_MACOSX) 34 #elif defined(OS_MACOSX)
28 #include "chrome/browser/mac/keystone_glue.h" 35 #include "chrome/browser/mac/keystone_glue.h"
29 #elif defined(OS_POSIX) 36 #elif defined(OS_POSIX)
30 #include "base/process_util.h" 37 #include "base/process_util.h"
31 #include "base/version.h"
32 #endif 38 #endif
33 39
34 using content::BrowserThread; 40 using content::BrowserThread;
35 41
36 namespace { 42 namespace {
37 43
38 // How long (in milliseconds) to wait (each cycle) before checking whether 44 // How long (in milliseconds) to wait (each cycle) before checking whether
39 // Chrome's been upgraded behind our back. 45 // Chrome's been upgraded behind our back.
40 const int kCheckForUpgradeMs = 2 * 60 * 60 * 1000; // 2 hours. 46 const int kCheckForUpgradeMs = 2 * 60 * 60 * 1000; // 2 hours.
41 47
42 // How long to wait (each cycle) before checking which severity level we should 48 // How long to wait (each cycle) before checking which severity level we should
43 // be at. Once we reach the highest severity, the timer will stop. 49 // be at. Once we reach the highest severity, the timer will stop.
44 const int kNotifyCycleTimeMs = 20 * 60 * 1000; // 20 minutes. 50 const int kNotifyCycleTimeMs = 20 * 60 * 1000; // 20 minutes.
45 51
46 // Same as kNotifyCycleTimeMs but only used during testing. 52 // Same as kNotifyCycleTimeMs but only used during testing.
47 const int kNotifyCycleTimeForTestingMs = 500; // Half a second. 53 const int kNotifyCycleTimeForTestingMs = 500; // Half a second.
48 54
55 // The number of days after which we identify a build/install as outdated.
56 const uint64 kOutdatedBuildAgeInDays = 12 * 7;
57
58 // Finch Experiment strings to identify if we should check for outdated install.
59 const char kOutdatedInstallCheckTrialName[] = "OutdatedInstallCheck";
60 const char kOutdatedInstallCheck12WeeksGroupName[] = "12WeeksOutdatedIntalls";
61
49 std::string CmdLineInterval() { 62 std::string CmdLineInterval() {
50 const CommandLine& cmd_line = *CommandLine::ForCurrentProcess(); 63 const CommandLine& cmd_line = *CommandLine::ForCurrentProcess();
51 return cmd_line.GetSwitchValueASCII(switches::kCheckForUpdateIntervalSec); 64 return cmd_line.GetSwitchValueASCII(switches::kCheckForUpdateIntervalSec);
52 } 65 }
53 66
54 bool IsTesting() { 67 bool IsTesting() {
55 const CommandLine& cmd_line = *CommandLine::ForCurrentProcess(); 68 const CommandLine& cmd_line = *CommandLine::ForCurrentProcess();
56 return cmd_line.HasSwitch(switches::kSimulateUpgrade) || 69 return cmd_line.HasSwitch(switches::kSimulateUpgrade) ||
57 cmd_line.HasSwitch(switches::kCheckForUpdateIntervalSec); 70 cmd_line.HasSwitch(switches::kCheckForUpdateIntervalSec) ||
71 cmd_line.HasSwitch(switches::kSimulateCriticalUpdate) ||
72 cmd_line.HasSwitch(switches::kSimulateOutdated);
58 } 73 }
59 74
60 // How often to check for an upgrade. 75 // How often to check for an upgrade.
61 int GetCheckForUpgradeEveryMs() { 76 int GetCheckForUpgradeEveryMs() {
62 // Check for a value passed via the command line. 77 // Check for a value passed via the command line.
63 int interval_ms; 78 int interval_ms;
64 std::string interval = CmdLineInterval(); 79 std::string interval = CmdLineInterval();
65 if (!interval.empty() && base::StringToInt(interval, &interval_ms)) 80 if (!interval.empty() && base::StringToInt(interval, &interval_ms))
66 return interval_ms * 1000; // Command line value is in seconds. 81 return interval_ms * 1000; // Command line value is in seconds.
67 82
68 return kCheckForUpgradeMs; 83 return kCheckForUpgradeMs;
69 } 84 }
70 85
86 bool IsUnstableChannel() {
87 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
88 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel();
89 return channel == chrome::VersionInfo::CHANNEL_DEV ||
90 channel == chrome::VersionInfo::CHANNEL_CANARY;
91 }
92
93 // This task identifies whether we are running an unstable version. And then
94 // it unconditionally calls back the provided task.
95 void CheckForUnstableChannel(const base::Closure& callback_task,
96 bool* is_unstable_channel) {
97 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
98 *is_unstable_channel = IsUnstableChannel();
99 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, callback_task);
100 }
101
102 #if defined(OS_WIN)
103 bool IsSystemInstall() {
104 // Get the version of the currently *installed* instance of Chrome,
105 // which might be newer than the *running* instance if we have been
106 // upgraded in the background.
107 base::FilePath exe_path;
108 if (!PathService::Get(base::DIR_EXE, &exe_path)) {
109 NOTREACHED() << "Failed to find executable path";
110 return false;
111 }
112
113 return !InstallUtil::IsPerUserInstall(exe_path.value().c_str());
114 }
115
116 // This task checks the update policy and calls back the task only if automatic
117 // updates are allowed. It also identifies whether we are running an unstable
118 // channel.
119 void DetectUpdatability(const base::Closure& callback_task,
120 bool* is_unstable_channel) {
121 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
122
123 string16 app_guid = installer::GetAppGuidForUpdates(IsSystemInstall());
124 DCHECK(!app_guid.empty());
125 if (GoogleUpdateSettings::AUTOMATIC_UPDATES ==
126 GoogleUpdateSettings::GetAppUpdatePolicy(app_guid, NULL)) {
127 CheckForUnstableChannel(callback_task, is_unstable_channel);
128 }
129 }
130 #endif // defined(OS_WIN)
131
132 } // namespace
133
134 UpgradeDetectorImpl::UpgradeDetectorImpl()
135 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)),
136 is_unstable_channel_(false),
137 build_date_(base::GetBuildTime()) {
138 CommandLine command_line(*CommandLine::ForCurrentProcess());
139 // The different command line switches that affect testing can't be used
140 // simultaneously, if they do, here's the precedence order, based on the order
141 // of the if statements below:
142 // - kDisableBackgroundNetworking prevents any of the other command line
143 // switch from being taken into account.
144 // - kSimulateUpgrade supersedes critical or outdated upgrade switches.
145 // - kSimulateCriticalUpdate has precedence over kSimulateOutdated.
146 // - kSimulateOutdated can work on its own, or with a specified date.
147 if (command_line.HasSwitch(switches::kDisableBackgroundNetworking))
148 return;
149 if (command_line.HasSwitch(switches::kSimulateUpgrade)) {
150 UpgradeDetected(UPGRADE_AVAILABLE_REGULAR);
151 return;
152 }
153 if (command_line.HasSwitch(switches::kSimulateCriticalUpdate)) {
154 UpgradeDetected(UPGRADE_AVAILABLE_CRITICAL);
155 return;
156 }
157 if (command_line.HasSwitch(switches::kSimulateOutdated)) {
158 // The outdated simulation can work without a value, which means outdated
159 // now, or with a value that must be a well formed date/time string that
160 // overrides the build date.
161 // Also note that to test with a given time/date, until the network time
162 // tracking moves off of the VariationsService, the "variations-server-url"
163 // command line switch must also be specified for the service to be
164 // available on non GOOGLE_CHROME_BUILD.
165 std::string build_date = command_line.GetSwitchValueASCII(
166 switches::kSimulateOutdated);
167 base::Time maybe_build_time;
168 bool result = base::Time::FromString(build_date.c_str(), &maybe_build_time);
169 if (result && !maybe_build_time.is_null()) {
170 // We got a valid build date simulation so use it and check for upgrades.
171 build_date_ = maybe_build_time;
172 StartTimerForUpgradeCheck();
173 } else {
174 // Without a valid date, we simulate that we are already outdated...
175 UpgradeDetected(UPGRADE_NEEDED_OUTDATED_INSTALL);
176 }
177 return;
178 }
179
180 // Windows: only enable upgrade notifications for official builds.
181 // Mac: only enable them if the updater (Keystone) is present.
182 // Linux (and other POSIX): always enable regardless of branding.
183 base::Closure start_upgrade_check_timer_task =
184 base::Bind(&UpgradeDetectorImpl::StartTimerForUpgradeCheck,
185 weak_factory_.GetWeakPtr());
186 #if defined(OS_WINDOW) && defined(GOOGLE_CHROME_BUILD)
187 // On Windows, there might be a policy preventing updates, so validate
188 // updatability, and then call StartTimerForUpgradeCheck appropriately.
189 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
190 base::Bind(&DetectUpdatability,
191 start_upgrade_check_timer_task,
192 &is_unstable_channel_));
193 return;
194 #elif defined(OS_WINDOW) && !defined(GOOGLE_CHROME_BUILD)
195 return; // Chromium has no upgrade channel.
196 #elif defined(OS_MACOSX)
197 if (!keystone_glue::KeystoneEnabled())
198 return; // Keystone updater not enabled.
199 #elif !defined(OS_POSIX)
200 return;
201 #endif
202
203 // Check whether the build is an unstable channel before starting the timer.
204 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
205 base::Bind(&CheckForUnstableChannel,
206 start_upgrade_check_timer_task,
207 &is_unstable_channel_));
208 }
209
210 UpgradeDetectorImpl::~UpgradeDetectorImpl() {
211 }
212
213 // Static
71 // This task checks the currently running version of Chrome against the 214 // This task checks the currently running version of Chrome against the
72 // installed version. If the installed version is newer, it runs the passed 215 // installed version. If the installed version is newer, it calls back
73 // callback task. Otherwise it just deletes the task. 216 // UpgradeDetectorImpl::UpgradeDetected using a weak pointer so that it can
74 void DetectUpgradeTask(const base::Closure& upgrade_detected_task, 217 // be interrupted from the UI thread.
75 bool* is_unstable_channel, 218 void UpgradeDetectorImpl::DetectUpgradeTask(
76 bool* is_critical_upgrade) { 219 base::WeakPtr<UpgradeDetectorImpl> upgrade_detector) {
77 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 220 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
78 221
79 Version installed_version; 222 Version installed_version;
80 Version critical_update; 223 Version critical_update;
81 224
82 #if defined(OS_WIN) 225 #if defined(OS_WIN)
83 // Get the version of the currently *installed* instance of Chrome, 226 // Get the version of the currently *installed* instance of Chrome,
84 // which might be newer than the *running* instance if we have been 227 // which might be newer than the *running* instance if we have been
85 // upgraded in the background. 228 // upgraded in the background.
86 base::FilePath exe_path; 229 bool system_install = IsSystemInstall();
87 if (!PathService::Get(base::DIR_EXE, &exe_path)) {
88 NOTREACHED() << "Failed to find executable path";
89 return;
90 }
91
92 bool system_install =
93 !InstallUtil::IsPerUserInstall(exe_path.value().c_str());
94 230
95 // TODO(tommi): Check if using the default distribution is always the right 231 // TODO(tommi): Check if using the default distribution is always the right
96 // thing to do. 232 // thing to do.
97 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); 233 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
98 InstallUtil::GetChromeVersion(dist, system_install, &installed_version); 234 InstallUtil::GetChromeVersion(dist, system_install, &installed_version);
99 235
100 if (installed_version.IsValid()) { 236 if (installed_version.IsValid()) {
101 InstallUtil::GetCriticalUpdateVersion(dist, system_install, 237 InstallUtil::GetCriticalUpdateVersion(dist, system_install,
102 &critical_update); 238 &critical_update);
103 } 239 }
104 #elif defined(OS_MACOSX) 240 #elif defined(OS_MACOSX)
105 installed_version = 241 installed_version =
106 Version(UTF16ToASCII(keystone_glue::CurrentlyInstalledVersion())); 242 Version(UTF16ToASCII(keystone_glue::CurrentlyInstalledVersion()));
107 #elif defined(OS_POSIX) 243 #elif defined(OS_POSIX)
108 // POSIX but not Mac OS X: Linux, etc. 244 // POSIX but not Mac OS X: Linux, etc.
109 CommandLine command_line(*CommandLine::ForCurrentProcess()); 245 CommandLine command_line(*CommandLine::ForCurrentProcess());
110 command_line.AppendSwitch(switches::kProductVersion); 246 command_line.AppendSwitch(switches::kProductVersion);
111 std::string reply; 247 std::string reply;
112 if (!base::GetAppOutput(command_line, &reply)) { 248 if (!base::GetAppOutput(command_line, &reply)) {
113 DLOG(ERROR) << "Failed to get current file version"; 249 DLOG(ERROR) << "Failed to get current file version";
114 return; 250 return;
115 } 251 }
116 252
117 installed_version = Version(reply); 253 installed_version = Version(reply);
118 #endif 254 #endif
119 255
120 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel();
121 *is_unstable_channel = channel == chrome::VersionInfo::CHANNEL_DEV ||
122 channel == chrome::VersionInfo::CHANNEL_CANARY;
123
124 // Get the version of the currently *running* instance of Chrome. 256 // Get the version of the currently *running* instance of Chrome.
125 chrome::VersionInfo version_info; 257 chrome::VersionInfo version_info;
126 if (!version_info.is_valid()) { 258 if (!version_info.is_valid()) {
127 NOTREACHED() << "Failed to get current file version"; 259 NOTREACHED() << "Failed to get current file version";
128 return; 260 return;
129 } 261 }
130 Version running_version(version_info.Version()); 262 Version running_version(version_info.Version());
131 if (!running_version.IsValid()) { 263 if (!running_version.IsValid()) {
132 NOTREACHED(); 264 NOTREACHED();
133 return; 265 return;
134 } 266 }
135 267
136 // |installed_version| may be NULL when the user downgrades on Linux (by 268 // |installed_version| may be NULL when the user downgrades on Linux (by
137 // switching from dev to beta channel, for example). The user needs a 269 // switching from dev to beta channel, for example). The user needs a
138 // restart in this case as well. See http://crbug.com/46547 270 // restart in this case as well. See http://crbug.com/46547
139 if (!installed_version.IsValid() || 271 if (!installed_version.IsValid() ||
140 (installed_version.CompareTo(running_version) > 0)) { 272 (installed_version.CompareTo(running_version) > 0)) {
141 // If a more recent version is available, it might be that we are lacking 273 // If a more recent version is available, it might be that we are lacking
142 // a critical update, such as a zero-day fix. 274 // a critical update, such as a zero-day fix.
143 *is_critical_upgrade = 275 UpgradeAvailable upgrade_available = UPGRADE_AVAILABLE_REGULAR;
144 critical_update.IsValid() && 276 if (critical_update.IsValid() &&
145 (critical_update.CompareTo(running_version) > 0); 277 critical_update.CompareTo(running_version) > 0) {
278 upgrade_available = UPGRADE_AVAILABLE_CRITICAL;
279 }
146 280
147 // Fire off the upgrade detected task. 281 // Fire off the upgrade detected task.
148 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 282 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
149 upgrade_detected_task); 283 base::Bind(&UpgradeDetectorImpl::UpgradeDetected,
284 upgrade_detector,
285 upgrade_available));
150 } 286 }
151 } 287 }
152 288
153 } // namespace 289 void UpgradeDetectorImpl::StartTimerForUpgradeCheck() {
154 290 detect_upgrade_timer_.Start(FROM_HERE,
155 UpgradeDetectorImpl::UpgradeDetectorImpl() 291 base::TimeDelta::FromMilliseconds(GetCheckForUpgradeEveryMs()),
156 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), 292 this, &UpgradeDetectorImpl::CheckForUpgrade);
157 is_unstable_channel_(false) {
158 CommandLine command_line(*CommandLine::ForCurrentProcess());
159 if (command_line.HasSwitch(switches::kDisableBackgroundNetworking))
160 return;
161 if (command_line.HasSwitch(switches::kSimulateUpgrade)) {
162 UpgradeDetected();
163 return;
164 }
165 // Windows: only enable upgrade notifications for official builds.
166 // Mac: only enable them if the updater (Keystone) is present.
167 // Linux (and other POSIX): always enable regardless of branding.
168 #if (defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD)) || defined(OS_POSIX)
169 #if defined(OS_MACOSX)
170 if (keystone_glue::KeystoneEnabled())
171 #endif
172 {
173 detect_upgrade_timer_.Start(FROM_HERE,
174 base::TimeDelta::FromMilliseconds(GetCheckForUpgradeEveryMs()),
175 this, &UpgradeDetectorImpl::CheckForUpgrade);
176 }
177 #endif
178 }
179
180 UpgradeDetectorImpl::~UpgradeDetectorImpl() {
181 } 293 }
182 294
183 void UpgradeDetectorImpl::CheckForUpgrade() { 295 void UpgradeDetectorImpl::CheckForUpgrade() {
296 // Interrupt any (unlikely) unfinished execution of DetectUpgradeTask, or at
297 // least prevent the callback from being executed, because we will potentially
298 // call it from within DetectOutdatedInstall() or will post
299 // DetectUpgradeTask again below anyway.
184 weak_factory_.InvalidateWeakPtrs(); 300 weak_factory_.InvalidateWeakPtrs();
185 base::Closure callback_task = 301
186 base::Bind(&UpgradeDetectorImpl::UpgradeDetected, 302 // No need to look for upgrades if the install is outdated.
187 weak_factory_.GetWeakPtr()); 303 if (DetectOutdatedInstall())
304 return;
305
188 // We use FILE as the thread to run the upgrade detection code on all 306 // We use FILE as the thread to run the upgrade detection code on all
189 // platforms. For Linux, this is because we don't want to block the UI thread 307 // platforms. For Linux, this is because we don't want to block the UI thread
190 // while launching a background process and reading its output; on the Mac and 308 // while launching a background process and reading its output; on the Mac and
191 // on Windows checking for an upgrade requires reading a file. 309 // on Windows checking for an upgrade requires reading a file.
192 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 310 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
193 base::Bind(&DetectUpgradeTask, 311 base::Bind(&UpgradeDetectorImpl::DetectUpgradeTask,
194 callback_task, 312 weak_factory_.GetWeakPtr()));
195 &is_unstable_channel_,
196 &is_critical_upgrade_));
197 } 313 }
198 314
199 void UpgradeDetectorImpl::UpgradeDetected() { 315 bool UpgradeDetectorImpl::DetectOutdatedInstall() {
316 // Only enable the outdated install check if we are running the trial for it,
317 // unless we are simulating an outdated isntall.
318 static bool simulate_outdated = CommandLine::ForCurrentProcess()->HasSwitch(
319 switches::kSimulateOutdated);
320 if (base::FieldTrialList::FindFullName(kOutdatedInstallCheckTrialName) !=
321 kOutdatedInstallCheck12WeeksGroupName && !simulate_outdated) {
322 return false;
323 }
324
325 base::Time network_time;
326 base::TimeDelta uncertainty;
327 if (!g_browser_process->variations_service() ||
328 !g_browser_process->variations_service()->GetNetworkTime(&network_time,
329 &uncertainty)) {
330 return false;
331 }
332
333 if (network_time.is_null() || build_date_.is_null() ||
334 build_date_ > network_time) {
335 NOTREACHED();
336 return false;
337 }
338
339 if (network_time - build_date_ >
340 base::TimeDelta::FromDays(kOutdatedBuildAgeInDays)) {
341 UpgradeDetected(UPGRADE_NEEDED_OUTDATED_INSTALL);
342 return true;
343 }
344 // If we simlated an outdated install with a date, we don't want to keep
345 // checking for version upgrades, which happens on non-official builds.
346 return simulate_outdated;
347 }
348
349 void UpgradeDetectorImpl::UpgradeDetected(UpgradeAvailable upgrade_available) {
200 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 350 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
351 upgrade_available_ = upgrade_available;
201 352
202 // Stop the recurring timer (that is checking for changes). 353 // Stop the recurring timer (that is checking for changes).
203 detect_upgrade_timer_.Stop(); 354 detect_upgrade_timer_.Stop();
204 355
205 NotifyUpgradeDetected(); 356 NotifyUpgradeDetected();
206 357
207 // Start the repeating timer for notifying the user after a certain period. 358 // Start the repeating timer for notifying the user after a certain period.
208 // The called function will eventually figure out that enough time has passed 359 // The called function will eventually figure out that enough time has passed
209 // and stop the timer. 360 // and stop the timer.
210 int cycle_time = IsTesting() ? 361 int cycle_time = IsTesting() ?
211 kNotifyCycleTimeForTestingMs : kNotifyCycleTimeMs; 362 kNotifyCycleTimeForTestingMs : kNotifyCycleTimeMs;
212 upgrade_notification_timer_.Start(FROM_HERE, 363 upgrade_notification_timer_.Start(FROM_HERE,
213 base::TimeDelta::FromMilliseconds(cycle_time), 364 base::TimeDelta::FromMilliseconds(cycle_time),
214 this, &UpgradeDetectorImpl::NotifyOnUpgrade); 365 this, &UpgradeDetectorImpl::NotifyOnUpgrade);
215 } 366 }
216 367
217 void UpgradeDetectorImpl::NotifyOnUpgrade() { 368 void UpgradeDetectorImpl::NotifyOnUpgrade() {
218 base::TimeDelta delta = base::Time::Now() - upgrade_detected_time(); 369 base::TimeDelta delta = base::Time::Now() - upgrade_detected_time();
219 370
220 // We'll make testing more convenient by switching to seconds of waiting 371 // We'll make testing more convenient by switching to seconds of waiting
221 // instead of days between flipping severity. 372 // instead of days between flipping severity.
222 bool is_testing = IsTesting(); 373 bool is_testing = IsTesting();
223 int64 time_passed = is_testing ? delta.InSeconds() : delta.InHours(); 374 int64 time_passed = is_testing ? delta.InSeconds() : delta.InHours();
224 375
376 bool is_critical_or_outdated = upgrade_available_ > UPGRADE_AVAILABLE_REGULAR;
225 if (is_unstable_channel_) { 377 if (is_unstable_channel_) {
226 // There's only one threat level for unstable channels like dev and 378 // There's only one threat level for unstable channels like dev and
227 // canary, and it hits after one hour. During testing, it hits after one 379 // canary, and it hits after one hour. During testing, it hits after one
228 // minute. 380 // minute.
229 const int kUnstableThreshold = 1; 381 const int kUnstableThreshold = 1;
230 382
231 if (is_critical_upgrade_) 383 if (is_critical_or_outdated)
232 set_upgrade_notification_stage(UPGRADE_ANNOYANCE_CRITICAL); 384 set_upgrade_notification_stage(UPGRADE_ANNOYANCE_CRITICAL);
233 else if (time_passed >= kUnstableThreshold) { 385 else if (time_passed >= kUnstableThreshold) {
234 set_upgrade_notification_stage(UPGRADE_ANNOYANCE_LOW); 386 set_upgrade_notification_stage(UPGRADE_ANNOYANCE_LOW);
235 387
236 // That's as high as it goes. 388 // That's as high as it goes.
237 upgrade_notification_timer_.Stop(); 389 upgrade_notification_timer_.Stop();
238 } else { 390 } else {
239 return; // Not ready to recommend upgrade. 391 return; // Not ready to recommend upgrade.
240 } 392 }
241 } else { 393 } else {
242 const int kMultiplier = is_testing ? 1 : 24; 394 const int kMultiplier = is_testing ? 1 : 24;
243 // 14 days when not testing, otherwise 14 seconds. 395 // 14 days when not testing, otherwise 14 seconds.
244 const int kSevereThreshold = 14 * kMultiplier; 396 const int kSevereThreshold = 14 * kMultiplier;
245 const int kHighThreshold = 7 * kMultiplier; 397 const int kHighThreshold = 7 * kMultiplier;
246 const int kElevatedThreshold = 4 * kMultiplier; 398 const int kElevatedThreshold = 4 * kMultiplier;
247 const int kLowThreshold = 2 * kMultiplier; 399 const int kLowThreshold = 2 * kMultiplier;
248 400
249 // These if statements must be sorted (highest interval first). 401 // These if statements must be sorted (highest interval first).
250 if (time_passed >= kSevereThreshold || is_critical_upgrade_) { 402 if (time_passed >= kSevereThreshold || is_critical_or_outdated) {
251 set_upgrade_notification_stage( 403 set_upgrade_notification_stage(
252 is_critical_upgrade_ ? UPGRADE_ANNOYANCE_CRITICAL : 404 is_critical_or_outdated ? UPGRADE_ANNOYANCE_CRITICAL :
253 UPGRADE_ANNOYANCE_SEVERE); 405 UPGRADE_ANNOYANCE_SEVERE);
254 406
255 // We can't get any higher, baby. 407 // We can't get any higher, baby.
256 upgrade_notification_timer_.Stop(); 408 upgrade_notification_timer_.Stop();
257 } else if (time_passed >= kHighThreshold) { 409 } else if (time_passed >= kHighThreshold) {
258 set_upgrade_notification_stage(UPGRADE_ANNOYANCE_HIGH); 410 set_upgrade_notification_stage(UPGRADE_ANNOYANCE_HIGH);
259 } else if (time_passed >= kElevatedThreshold) { 411 } else if (time_passed >= kElevatedThreshold) {
260 set_upgrade_notification_stage(UPGRADE_ANNOYANCE_ELEVATED); 412 set_upgrade_notification_stage(UPGRADE_ANNOYANCE_ELEVATED);
261 } else if (time_passed >= kLowThreshold) { 413 } else if (time_passed >= kLowThreshold) {
262 set_upgrade_notification_stage(UPGRADE_ANNOYANCE_LOW); 414 set_upgrade_notification_stage(UPGRADE_ANNOYANCE_LOW);
263 } else { 415 } else {
264 return; // Not ready to recommend upgrade. 416 return; // Not ready to recommend upgrade.
265 } 417 }
266 } 418 }
267 419
268 NotifyUpgradeRecommended(); 420 NotifyUpgradeRecommended();
269 } 421 }
270 422
271 // static 423 // static
272 UpgradeDetectorImpl* UpgradeDetectorImpl::GetInstance() { 424 UpgradeDetectorImpl* UpgradeDetectorImpl::GetInstance() {
273 return Singleton<UpgradeDetectorImpl>::get(); 425 return Singleton<UpgradeDetectorImpl>::get();
274 } 426 }
275 427
276 // static 428 // static
277 UpgradeDetector* UpgradeDetector::GetInstance() { 429 UpgradeDetector* UpgradeDetector::GetInstance() {
278 return UpgradeDetectorImpl::GetInstance(); 430 return UpgradeDetectorImpl::GetInstance();
279 } 431 }
OLDNEW
« no previous file with comments | « chrome/browser/upgrade_detector_impl.h ('k') | chrome/chrome_browser_ui.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698