OLD | NEW |
---|---|
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_number_conversions.h" | 17 #include "base/string_number_conversions.h" |
16 #include "base/string_util.h" | 18 #include "base/string_util.h" |
17 #include "base/time.h" | |
18 #include "base/utf_string_conversions.h" | 19 #include "base/utf_string_conversions.h" |
20 #include "base/version.h" | |
21 #include "chrome/browser/browser_process.h" | |
19 #include "chrome/common/chrome_switches.h" | 22 #include "chrome/common/chrome_switches.h" |
20 #include "chrome/common/chrome_version_info.h" | 23 #include "chrome/common/chrome_version_info.h" |
21 #include "chrome/installer/util/browser_distribution.h" | |
22 #include "content/public/browser/browser_thread.h" | 24 #include "content/public/browser/browser_thread.h" |
25 #include "googleurl/src/gurl.h" | |
26 #include "net/base/load_flags.h" | |
27 #include "net/http/http_response_headers.h" | |
28 #include "net/url_request/url_fetcher.h" | |
29 #include "net/url_request/url_request_status.h" | |
23 #include "ui/base/resource/resource_bundle.h" | 30 #include "ui/base/resource/resource_bundle.h" |
24 | 31 |
25 #if defined(OS_WIN) | 32 #if defined(OS_WIN) |
33 #include "chrome/installer/util/browser_distribution.h" | |
34 #include "chrome/installer/util/google_update_settings.h" | |
35 #include "chrome/installer/util/helper.h" | |
26 #include "chrome/installer/util/install_util.h" | 36 #include "chrome/installer/util/install_util.h" |
27 #elif defined(OS_MACOSX) | 37 #elif defined(OS_MACOSX) |
28 #include "chrome/browser/mac/keystone_glue.h" | 38 #include "chrome/browser/mac/keystone_glue.h" |
29 #elif defined(OS_POSIX) | 39 #elif defined(OS_POSIX) |
30 #include "base/process_util.h" | 40 #include "base/process_util.h" |
31 #include "base/version.h" | |
32 #endif | 41 #endif |
33 | 42 |
34 using content::BrowserThread; | 43 using content::BrowserThread; |
35 | 44 |
36 namespace { | 45 namespace { |
37 | 46 |
38 // How long (in milliseconds) to wait (each cycle) before checking whether | 47 // How long (in milliseconds) to wait (each cycle) before checking whether |
39 // Chrome's been upgraded behind our back. | 48 // Chrome's been upgraded behind our back. |
40 const int kCheckForUpgradeMs = 2 * 60 * 60 * 1000; // 2 hours. | 49 const int kCheckForUpgradeMs = 2 * 60 * 60 * 1000; // 2 hours. |
41 | 50 |
42 // How long to wait (each cycle) before checking which severity level we should | 51 // 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. | 52 // be at. Once we reach the highest severity, the timer will stop. |
44 const int kNotifyCycleTimeMs = 20 * 60 * 1000; // 20 minutes. | 53 const int kNotifyCycleTimeMs = 20 * 60 * 1000; // 20 minutes. |
45 | 54 |
46 // Same as kNotifyCycleTimeMs but only used during testing. | 55 // Same as kNotifyCycleTimeMs but only used during testing. |
47 const int kNotifyCycleTimeForTestingMs = 500; // Half a second. | 56 const int kNotifyCycleTimeForTestingMs = 500; // Half a second. |
48 | 57 |
58 // Default server of Variations seed info. | |
Finnur
2013/01/30 15:50:48
Here is the 'Variations' comment also. Is that int
MAD
2013/01/31 21:31:42
Damn... Really sorry about that, I should have bee
| |
59 const char kTimeServerURL[] = "https://www.google.com"; | |
60 const int kMaxRetryTimeFetch = 5; | |
61 | |
62 const char kOutadedInstallCheckTrialName[] = "OutadedInstallCheck"; | |
63 const char kOutadedInstallCheck12WeeksGroupName[] = "12WeeksOutdatedIntalls"; | |
Finnur
2013/01/30 15:50:48
There are three cases of Outdaded misspellings her
MAD
2013/01/31 21:31:42
Copy/Paste from hell!!! :-)
| |
64 | |
49 std::string CmdLineInterval() { | 65 std::string CmdLineInterval() { |
50 const CommandLine& cmd_line = *CommandLine::ForCurrentProcess(); | 66 const CommandLine& cmd_line = *CommandLine::ForCurrentProcess(); |
51 return cmd_line.GetSwitchValueASCII(switches::kCheckForUpdateIntervalSec); | 67 return cmd_line.GetSwitchValueASCII(switches::kCheckForUpdateIntervalSec); |
52 } | 68 } |
53 | 69 |
54 bool IsTesting() { | 70 bool IsTesting() { |
55 const CommandLine& cmd_line = *CommandLine::ForCurrentProcess(); | 71 const CommandLine& cmd_line = *CommandLine::ForCurrentProcess(); |
56 return cmd_line.HasSwitch(switches::kSimulateUpgrade) || | 72 return cmd_line.HasSwitch(switches::kSimulateUpgrade) || |
57 cmd_line.HasSwitch(switches::kCheckForUpdateIntervalSec); | 73 cmd_line.HasSwitch(switches::kCheckForUpdateIntervalSec) || |
74 cmd_line.HasSwitch(switches::kSimulateCriticalUpdate) || | |
75 cmd_line.HasSwitch(switches::kSimulateOutdated); | |
58 } | 76 } |
59 | 77 |
60 // How often to check for an upgrade. | 78 // How often to check for an upgrade. |
61 int GetCheckForUpgradeEveryMs() { | 79 int GetCheckForUpgradeEveryMs() { |
62 // Check for a value passed via the command line. | 80 // Check for a value passed via the command line. |
63 int interval_ms; | 81 int interval_ms; |
64 std::string interval = CmdLineInterval(); | 82 std::string interval = CmdLineInterval(); |
65 if (!interval.empty() && base::StringToInt(interval, &interval_ms)) | 83 if (!interval.empty() && base::StringToInt(interval, &interval_ms)) |
66 return interval_ms * 1000; // Command line value is in seconds. | 84 return interval_ms * 1000; // Command line value is in seconds. |
67 | 85 |
68 return kCheckForUpgradeMs; | 86 return kCheckForUpgradeMs; |
69 } | 87 } |
70 | 88 |
89 #if defined(OS_WIN) | |
90 bool IsSystemInstall() { | |
91 FilePath exe_path; | |
92 if (!PathService::Get(base::DIR_EXE, &exe_path)) { | |
93 NOTREACHED() << "Failed to find executable path"; | |
94 return false; | |
95 } | |
96 | |
97 return !InstallUtil::IsPerUserInstall(exe_path.value().c_str()); | |
98 } | |
99 #endif | |
100 | |
71 // This task checks the currently running version of Chrome against the | 101 // This task checks the currently running version of Chrome against the |
72 // installed version. If the installed version is newer, it runs the passed | 102 // installed version. If the installed version is newer, it runs the passed |
73 // callback task. Otherwise it just deletes the task. | 103 // callback task. Otherwise it just deletes the task. |
74 void DetectUpgradeTask(const base::Closure& upgrade_detected_task, | 104 void DetectUpgradeTask(const base::Closure& upgrade_detected_task, |
75 bool* is_unstable_channel, | 105 bool* is_unstable_channel, |
76 bool* is_critical_upgrade) { | 106 bool* is_critical_upgrade) { |
77 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 107 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
78 | 108 |
79 Version installed_version; | 109 Version installed_version; |
80 Version critical_update; | 110 Version critical_update; |
81 | 111 |
82 #if defined(OS_WIN) | 112 #if defined(OS_WIN) |
83 // Get the version of the currently *installed* instance of Chrome, | 113 // Get the version of the currently *installed* instance of Chrome, |
84 // which might be newer than the *running* instance if we have been | 114 // which might be newer than the *running* instance if we have been |
85 // upgraded in the background. | 115 // upgraded in the background. |
86 FilePath exe_path; | 116 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 | 117 |
95 // TODO(tommi): Check if using the default distribution is always the right | 118 // TODO(tommi): Check if using the default distribution is always the right |
96 // thing to do. | 119 // thing to do. |
97 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | 120 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
98 InstallUtil::GetChromeVersion(dist, system_install, &installed_version); | 121 InstallUtil::GetChromeVersion(dist, system_install, &installed_version); |
99 | 122 |
100 if (installed_version.IsValid()) { | 123 if (installed_version.IsValid()) { |
101 InstallUtil::GetCriticalUpdateVersion(dist, system_install, | 124 InstallUtil::GetCriticalUpdateVersion(dist, system_install, |
102 &critical_update); | 125 &critical_update); |
103 } | 126 } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
143 *is_critical_upgrade = | 166 *is_critical_upgrade = |
144 critical_update.IsValid() && | 167 critical_update.IsValid() && |
145 (critical_update.CompareTo(running_version) > 0); | 168 (critical_update.CompareTo(running_version) > 0); |
146 | 169 |
147 // Fire off the upgrade detected task. | 170 // Fire off the upgrade detected task. |
148 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 171 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
149 upgrade_detected_task); | 172 upgrade_detected_task); |
150 } | 173 } |
151 } | 174 } |
152 | 175 |
176 #if defined(OS_WIN) | |
177 // This task checks the update policy and calls back the task only if automatic | |
178 // updates are allowed. | |
179 void DetectUpdatability(bool* is_auto_update_allowed) { | |
180 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | |
181 | |
182 string16 app_guid = installer::GetAppGuidForUpdates(IsSystemInstall()); | |
183 DCHECK(!app_guid.empty()); | |
184 *is_auto_update_allowed = GoogleUpdateSettings::AUTOMATIC_UPDATES == | |
185 GoogleUpdateSettings::GetAppUpdatePolicy(app_guid, NULL); | |
186 } | |
187 #endif // defined(OS_WIN) | |
188 | |
153 } // namespace | 189 } // namespace |
154 | 190 |
155 UpgradeDetectorImpl::UpgradeDetectorImpl() | 191 UpgradeDetectorImpl::UpgradeDetectorImpl() |
156 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), | 192 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), |
157 is_unstable_channel_(false) { | 193 is_unstable_channel_(false), |
194 is_outdated_reinstall_allowed_(false), | |
195 build_date_(base::GetBuildTime()) { | |
158 CommandLine command_line(*CommandLine::ForCurrentProcess()); | 196 CommandLine command_line(*CommandLine::ForCurrentProcess()); |
159 if (command_line.HasSwitch(switches::kDisableBackgroundNetworking)) | 197 if (command_line.HasSwitch(switches::kDisableBackgroundNetworking)) |
160 return; | 198 return; |
161 if (command_line.HasSwitch(switches::kSimulateUpgrade)) { | 199 if (command_line.HasSwitch(switches::kSimulateUpgrade)) { |
162 UpgradeDetected(); | 200 UpgradeDetected(); |
163 return; | 201 return; |
164 } | 202 } |
203 if (command_line.HasSwitch(switches::kSimulateCriticalUpdate)) { | |
204 is_critical_upgrade_ = true; | |
205 UpgradeDetected(); | |
206 return; | |
207 } | |
208 if (command_line.HasSwitch(switches::kSimulateOutdated)) { | |
209 // The outdated simulation can work without a value, which means outdated | |
210 // now, or with a value that must be a well formed date/time string that | |
211 // overrides the build date. | |
212 is_outdated_reinstall_allowed_ = true; | |
213 std::string build_date = command_line.GetSwitchValueASCII( | |
214 switches::kSimulateOutdated); | |
215 base::Time maybe_build_time; | |
216 bool result = base::Time::FromString(build_date.c_str(), &maybe_build_time); | |
217 if (result && !maybe_build_time.is_null()) { | |
218 // We got a valid build date simulation so use it and check for upgrades. | |
219 build_date_ = maybe_build_time; | |
220 detect_upgrade_timer_.Start(FROM_HERE, | |
221 base::TimeDelta::FromMilliseconds(GetCheckForUpgradeEveryMs()), | |
222 this, &UpgradeDetectorImpl::CheckForUpgrade); | |
223 } else { | |
224 // Without a valid date, we simulate that we are already outdated... | |
225 is_outdated_install_ = true; | |
226 UpgradeDetected(); | |
227 } | |
228 return; | |
229 } | |
165 // Windows: only enable upgrade notifications for official builds. | 230 // Windows: only enable upgrade notifications for official builds. |
166 // Mac: only enable them if the updater (Keystone) is present. | 231 // Mac: only enable them if the updater (Keystone) is present. |
167 // Linux (and other POSIX): always enable regardless of branding. | 232 // Linux (and other POSIX): always enable regardless of branding. |
168 #if (defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD)) || defined(OS_POSIX) | 233 #if (defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD)) || defined(OS_POSIX) |
169 #if defined(OS_MACOSX) | 234 #if defined(OS_MACOSX) |
170 if (keystone_glue::KeystoneEnabled()) | 235 is_outdated_reinstall_allowed_ = keystone_glue::KeystoneEnabled(); |
236 if (is_outdated_reinstall_allowed_) | |
171 #endif | 237 #endif |
172 { | 238 { |
173 detect_upgrade_timer_.Start(FROM_HERE, | 239 detect_upgrade_timer_.Start(FROM_HERE, |
174 base::TimeDelta::FromMilliseconds(GetCheckForUpgradeEveryMs()), | 240 base::TimeDelta::FromMilliseconds(GetCheckForUpgradeEveryMs()), |
175 this, &UpgradeDetectorImpl::CheckForUpgrade); | 241 this, &UpgradeDetectorImpl::CheckForUpgrade); |
176 } | 242 } |
177 #endif | 243 #endif |
244 | |
245 // Only enable the outdated install check if we are running the trial for it. | |
246 if (base::FieldTrialList::FindFullName(kOutadedInstallCheckTrialName) != | |
247 kOutadedInstallCheck12WeeksGroupName) { | |
248 is_outdated_reinstall_allowed_ = false; | |
249 return; | |
250 } | |
251 | |
252 // On Windows, there might be a policy preventing updates, | |
253 // so validate updatability to set |is_outdated_reinstall_allowed_|. | |
Finnur
2013/01/30 15:50:48
I don't understand the second line of this comment
MAD
2013/01/31 21:31:42
Done.
| |
254 #if defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD) | |
255 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | |
256 base::Bind(&DetectUpdatability, | |
257 &is_outdated_reinstall_allowed_)); | |
258 #elif !(defined(OS_MACOSX) || defined(OS_CHROME)) | |
259 // All other devices are always allowed, except OS_MACOSX which sets it above, | |
260 // and Chrome OS which doesn't support the reinstall bubble. | |
261 is_outdated_reinstall_allowed_ = true; | |
Finnur
2013/01/30 15:50:48
If we ever remove the field trial guard, then this
MAD
2013/01/31 21:31:42
D'Ho!
Added && defined(OS_POSIX) which is || to
| |
262 #endif | |
178 } | 263 } |
179 | 264 |
180 UpgradeDetectorImpl::~UpgradeDetectorImpl() { | 265 UpgradeDetectorImpl::~UpgradeDetectorImpl() { |
181 } | 266 } |
182 | 267 |
183 void UpgradeDetectorImpl::CheckForUpgrade() { | 268 void UpgradeDetectorImpl::CheckForUpgrade() { |
269 if (is_outdated_reinstall_allowed_ && !is_outdated_install_) | |
270 CompareBuildTimeToSaneTime(); | |
271 | |
272 // If we are simulating an outdated install, no need to detect an upgrade. | |
273 // Since upgrade has precedence over outdated installs, it would prevent | |
274 // testing. | |
275 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSimulateOutdated)) | |
276 return; | |
Finnur
2013/01/30 15:50:48
Can we DCHECK or something if tricky combinations
MAD
2013/01/31 21:31:42
Done.
| |
277 | |
184 weak_factory_.InvalidateWeakPtrs(); | 278 weak_factory_.InvalidateWeakPtrs(); |
185 base::Closure callback_task = | 279 base::Closure callback_task = |
186 base::Bind(&UpgradeDetectorImpl::UpgradeDetected, | 280 base::Bind(&UpgradeDetectorImpl::UpgradeDetected, |
187 weak_factory_.GetWeakPtr()); | 281 weak_factory_.GetWeakPtr()); |
188 // We use FILE as the thread to run the upgrade detection code on all | 282 // 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 | 283 // 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 | 284 // while launching a background process and reading its output; on the Mac and |
191 // on Windows checking for an upgrade requires reading a file. | 285 // on Windows checking for an upgrade requires reading a file. |
192 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 286 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
193 base::Bind(&DetectUpgradeTask, | 287 base::Bind(&DetectUpgradeTask, |
194 callback_task, | 288 callback_task, |
195 &is_unstable_channel_, | 289 &is_unstable_channel_, |
196 &is_critical_upgrade_)); | 290 &is_critical_upgrade_)); |
197 } | 291 } |
198 | 292 |
293 void UpgradeDetectorImpl::CompareBuildTimeToSaneTime() { | |
Finnur
2013/01/30 15:50:48
Check the design doc for a proposal that does not
MAD
2013/01/31 21:31:42
Done.
| |
294 DCHECK(is_outdated_reinstall_allowed_); | |
295 // Check again, in case we got posted more than once by CheckForUpgrade. | |
296 if (is_outdated_install_) | |
297 return; | |
298 // Only fetch time from server when it has not been done already. | |
299 if (server_time_.is_null()) { | |
300 if (!pending_time_request_.get()) { | |
301 pending_time_request_.reset(net::URLFetcher::Create( | |
302 GURL(kTimeServerURL), net::URLFetcher::GET, this)); | |
303 pending_time_request_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | | |
304 net::LOAD_DO_NOT_SAVE_COOKIES); | |
305 pending_time_request_->SetRequestContext( | |
306 g_browser_process->system_request_context()); | |
307 pending_time_request_->SetMaxRetriesOn5xx(kMaxRetryTimeFetch); | |
Finnur
2013/01/30 15:50:48
I don't think we should be retry-ing on 500 errors
MAD
2013/01/31 21:31:42
Done.
| |
308 pending_time_request_->Start(); | |
309 } | |
310 } else { | |
311 // The current sane time is the server time offset by elasped ticks. | |
312 base::Time sane_time = server_time_ + (base::TimeTicks::Now() - | |
313 server_time_ticks_); | |
314 // TODO(mad): Add server side control of the time delta. | |
Finnur
2013/01/30 15:50:48
What does this mean?
MAD
2013/01/31 21:31:42
It was about a discussion we had about changing th
| |
315 if (sane_time - build_date_ > base::TimeDelta::FromDays(12 * 7)) { | |
Finnur
2013/01/30 15:50:48
nit: Add constant kOutdatedInDays, or something, a
MAD
2013/01/31 21:31:42
Done.
| |
316 is_outdated_install_ = true; | |
317 UpgradeDetected(); | |
318 } | |
319 } | |
320 } | |
321 | |
199 void UpgradeDetectorImpl::UpgradeDetected() { | 322 void UpgradeDetectorImpl::UpgradeDetected() { |
200 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 323 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
201 | 324 |
202 // Stop the recurring timer (that is checking for changes). | 325 // Stop the recurring timer (that is checking for changes). |
203 detect_upgrade_timer_.Stop(); | 326 detect_upgrade_timer_.Stop(); |
204 | 327 |
205 NotifyUpgradeDetected(); | 328 NotifyUpgradeDetected(); |
206 | 329 |
207 // Start the repeating timer for notifying the user after a certain period. | 330 // 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 | 331 // The called function will eventually figure out that enough time has passed |
209 // and stop the timer. | 332 // and stop the timer. |
210 int cycle_time = IsTesting() ? | 333 int cycle_time = IsTesting() ? |
211 kNotifyCycleTimeForTestingMs : kNotifyCycleTimeMs; | 334 kNotifyCycleTimeForTestingMs : kNotifyCycleTimeMs; |
212 upgrade_notification_timer_.Start(FROM_HERE, | 335 upgrade_notification_timer_.Start(FROM_HERE, |
213 base::TimeDelta::FromMilliseconds(cycle_time), | 336 base::TimeDelta::FromMilliseconds(cycle_time), |
214 this, &UpgradeDetectorImpl::NotifyOnUpgrade); | 337 this, &UpgradeDetectorImpl::NotifyOnUpgrade); |
215 } | 338 } |
216 | 339 |
217 void UpgradeDetectorImpl::NotifyOnUpgrade() { | 340 void UpgradeDetectorImpl::NotifyOnUpgrade() { |
218 base::TimeDelta delta = base::Time::Now() - upgrade_detected_time(); | 341 base::TimeDelta delta = base::Time::Now() - upgrade_detected_time(); |
219 | 342 |
220 // We'll make testing more convenient by switching to seconds of waiting | 343 // We'll make testing more convenient by switching to seconds of waiting |
221 // instead of days between flipping severity. | 344 // instead of days between flipping severity. |
222 bool is_testing = IsTesting(); | 345 bool is_testing = IsTesting(); |
223 int64 time_passed = is_testing ? delta.InSeconds() : delta.InHours(); | 346 int64 time_passed = is_testing ? delta.InSeconds() : delta.InHours(); |
224 | 347 |
348 bool is_critical_or_oudated = is_critical_upgrade_ || is_outdated_install_; | |
225 if (is_unstable_channel_) { | 349 if (is_unstable_channel_) { |
226 // There's only one threat level for unstable channels like dev and | 350 // 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 | 351 // canary, and it hits after one hour. During testing, it hits after one |
228 // minute. | 352 // minute. |
229 const int kUnstableThreshold = 1; | 353 const int kUnstableThreshold = 1; |
230 | 354 |
231 if (is_critical_upgrade_) | 355 if (is_critical_or_oudated) |
232 set_upgrade_notification_stage(UPGRADE_ANNOYANCE_CRITICAL); | 356 set_upgrade_notification_stage(UPGRADE_ANNOYANCE_CRITICAL); |
233 else if (time_passed >= kUnstableThreshold) { | 357 else if (time_passed >= kUnstableThreshold) { |
234 set_upgrade_notification_stage(UPGRADE_ANNOYANCE_LOW); | 358 set_upgrade_notification_stage(UPGRADE_ANNOYANCE_LOW); |
235 | 359 |
236 // That's as high as it goes. | 360 // That's as high as it goes. |
237 upgrade_notification_timer_.Stop(); | 361 upgrade_notification_timer_.Stop(); |
238 } else { | 362 } else { |
239 return; // Not ready to recommend upgrade. | 363 return; // Not ready to recommend upgrade. |
240 } | 364 } |
241 } else { | 365 } else { |
242 const int kMultiplier = is_testing ? 1 : 24; | 366 const int kMultiplier = is_testing ? 1 : 24; |
243 // 14 days when not testing, otherwise 14 seconds. | 367 // 14 days when not testing, otherwise 14 seconds. |
244 const int kSevereThreshold = 14 * kMultiplier; | 368 const int kSevereThreshold = 14 * kMultiplier; |
245 const int kHighThreshold = 7 * kMultiplier; | 369 const int kHighThreshold = 7 * kMultiplier; |
246 const int kElevatedThreshold = 4 * kMultiplier; | 370 const int kElevatedThreshold = 4 * kMultiplier; |
247 const int kLowThreshold = 2 * kMultiplier; | 371 const int kLowThreshold = 2 * kMultiplier; |
248 | 372 |
249 // These if statements must be sorted (highest interval first). | 373 // These if statements must be sorted (highest interval first). |
250 if (time_passed >= kSevereThreshold || is_critical_upgrade_) { | 374 if (time_passed >= kSevereThreshold || is_critical_or_oudated) { |
251 set_upgrade_notification_stage( | 375 set_upgrade_notification_stage( |
252 is_critical_upgrade_ ? UPGRADE_ANNOYANCE_CRITICAL : | 376 is_critical_or_oudated ? UPGRADE_ANNOYANCE_CRITICAL : |
253 UPGRADE_ANNOYANCE_SEVERE); | 377 UPGRADE_ANNOYANCE_SEVERE); |
254 | 378 |
255 // We can't get any higher, baby. | 379 // We can't get any higher, baby. |
256 upgrade_notification_timer_.Stop(); | 380 upgrade_notification_timer_.Stop(); |
257 } else if (time_passed >= kHighThreshold) { | 381 } else if (time_passed >= kHighThreshold) { |
258 set_upgrade_notification_stage(UPGRADE_ANNOYANCE_HIGH); | 382 set_upgrade_notification_stage(UPGRADE_ANNOYANCE_HIGH); |
259 } else if (time_passed >= kElevatedThreshold) { | 383 } else if (time_passed >= kElevatedThreshold) { |
260 set_upgrade_notification_stage(UPGRADE_ANNOYANCE_ELEVATED); | 384 set_upgrade_notification_stage(UPGRADE_ANNOYANCE_ELEVATED); |
261 } else if (time_passed >= kLowThreshold) { | 385 } else if (time_passed >= kLowThreshold) { |
262 set_upgrade_notification_stage(UPGRADE_ANNOYANCE_LOW); | 386 set_upgrade_notification_stage(UPGRADE_ANNOYANCE_LOW); |
263 } else { | 387 } else { |
264 return; // Not ready to recommend upgrade. | 388 return; // Not ready to recommend upgrade. |
265 } | 389 } |
266 } | 390 } |
267 | 391 |
268 NotifyUpgradeRecommended(); | 392 NotifyUpgradeRecommended(); |
269 } | 393 } |
270 | 394 |
395 void UpgradeDetectorImpl::OnURLFetchComplete(const net::URLFetcher* source) { | |
396 // The fetcher will be deleted when the request is handled. | |
397 scoped_ptr<const net::URLFetcher> request(pending_time_request_.release()); | |
398 if (request->GetStatus().status() == net::URLRequestStatus::SUCCESS) { | |
399 base::Time response_date; | |
400 if (request->GetResponseHeaders()->GetDateValue(&response_date)) { | |
401 DCHECK(!response_date.is_null() && response_date >= build_date_); | |
402 server_time_ = response_date; | |
403 server_time_ticks_ = base::TimeTicks::Now(); | |
404 } | |
405 } | |
406 // If |server_time_| was successfully set, this will compare it to | |
407 // |build_time_|, otherwise, it will try again. | |
408 CompareBuildTimeToSaneTime(); | |
Finnur
2013/01/30 15:50:48
Wow! Holy Duncan Ferguson! Stop the press! :)
Thi
MAD
2013/01/31 21:31:42
Triple D'Ho!... I often feel stupid when I write b
Finnur
2013/02/01 17:09:15
No worries. We've all been there. :)
On 2013/01/3
| |
409 } | |
410 | |
271 // static | 411 // static |
272 UpgradeDetectorImpl* UpgradeDetectorImpl::GetInstance() { | 412 UpgradeDetectorImpl* UpgradeDetectorImpl::GetInstance() { |
273 return Singleton<UpgradeDetectorImpl>::get(); | 413 return Singleton<UpgradeDetectorImpl>::get(); |
274 } | 414 } |
275 | 415 |
276 // static | 416 // static |
277 UpgradeDetector* UpgradeDetector::GetInstance() { | 417 UpgradeDetector* UpgradeDetector::GetInstance() { |
278 return UpgradeDetectorImpl::GetInstance(); | 418 return UpgradeDetectorImpl::GetInstance(); |
279 } | 419 } |
OLD | NEW |