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/build_time.h" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/cpu.h" | 12 #include "base/cpu.h" |
13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "base/memory/singleton.h" | 15 #include "base/memory/singleton.h" |
16 #include "base/path_service.h" | 16 #include "base/path_service.h" |
17 #include "base/prefs/pref_service.h" | 17 #include "base/prefs/pref_service.h" |
18 #include "base/process/launch.h" | 18 #include "base/process/launch.h" |
19 #include "base/strings/string_number_conversions.h" | 19 #include "base/strings/string_number_conversions.h" |
20 #include "base/strings/string_util.h" | 20 #include "base/strings/string_util.h" |
21 #include "base/strings/utf_string_conversions.h" | 21 #include "base/strings/utf_string_conversions.h" |
22 #include "base/time/time.h" | 22 #include "base/time/time.h" |
23 #include "base/version.h" | |
24 #include "chrome/browser/browser_process.h" | 23 #include "chrome/browser/browser_process.h" |
25 #include "chrome/browser/google/google_brand.h" | 24 #include "chrome/browser/google/google_brand.h" |
26 #include "chrome/common/chrome_switches.h" | 25 #include "chrome/common/chrome_switches.h" |
27 #include "chrome/common/chrome_version_info.h" | 26 #include "chrome/common/chrome_version_info.h" |
28 #include "chrome/common/pref_names.h" | 27 #include "chrome/common/pref_names.h" |
29 #include "components/network_time/network_time_tracker.h" | 28 #include "components/network_time/network_time_tracker.h" |
30 #include "content/public/browser/browser_thread.h" | 29 #include "content/public/browser/browser_thread.h" |
31 #include "ui/base/resource/resource_bundle.h" | 30 #include "ui/base/resource/resource_bundle.h" |
32 | 31 |
33 #if defined(OS_WIN) | 32 #if defined(OS_WIN) |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 // Don't try to turn on autoupdate when we failed previously. | 141 // Don't try to turn on autoupdate when we failed previously. |
143 if (is_auto_update_enabled) { | 142 if (is_auto_update_enabled) { |
144 *is_auto_update_enabled = | 143 *is_auto_update_enabled = |
145 GoogleUpdateSettings::AreAutoupdatesEnabled(app_guid); | 144 GoogleUpdateSettings::AreAutoupdatesEnabled(app_guid); |
146 } | 145 } |
147 *is_unstable_channel = IsUnstableChannel(); | 146 *is_unstable_channel = IsUnstableChannel(); |
148 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, callback_task); | 147 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, callback_task); |
149 } | 148 } |
150 #endif // defined(OS_WIN) | 149 #endif // defined(OS_WIN) |
151 | 150 |
| 151 // Gets the currently installed version. On Windows, if |critical_update| is not |
| 152 // NULL, also retrieves the critical update version info if available. |
| 153 base::Version GetCurrentlyInstalledVersionImpl(Version* critical_update) { |
| 154 base::ThreadRestrictions::AssertIOAllowed(); |
| 155 |
| 156 Version installed_version; |
| 157 #if defined(OS_WIN) |
| 158 // Get the version of the currently *installed* instance of Chrome, |
| 159 // which might be newer than the *running* instance if we have been |
| 160 // upgraded in the background. |
| 161 bool system_install = IsSystemInstall(); |
| 162 |
| 163 // TODO(tommi): Check if using the default distribution is always the right |
| 164 // thing to do. |
| 165 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
| 166 InstallUtil::GetChromeVersion(dist, system_install, &installed_version); |
| 167 if (critical_update && installed_version.IsValid()) { |
| 168 InstallUtil::GetCriticalUpdateVersion(dist, system_install, |
| 169 critical_update); |
| 170 } |
| 171 #elif defined(OS_MACOSX) |
| 172 installed_version = |
| 173 Version(base::UTF16ToASCII(keystone_glue::CurrentlyInstalledVersion())); |
| 174 #elif defined(OS_POSIX) |
| 175 // POSIX but not Mac OS X: Linux, etc. |
| 176 CommandLine command_line(*CommandLine::ForCurrentProcess()); |
| 177 command_line.AppendSwitch(switches::kProductVersion); |
| 178 std::string reply; |
| 179 if (!base::GetAppOutput(command_line, &reply)) { |
| 180 DLOG(ERROR) << "Failed to get current file version"; |
| 181 return installed_version; |
| 182 } |
| 183 |
| 184 installed_version = Version(reply); |
| 185 #endif |
| 186 return installed_version; |
| 187 } |
| 188 |
152 } // namespace | 189 } // namespace |
153 | 190 |
154 UpgradeDetectorImpl::UpgradeDetectorImpl() | 191 UpgradeDetectorImpl::UpgradeDetectorImpl() |
155 : weak_factory_(this), | 192 : weak_factory_(this), |
156 is_unstable_channel_(false), | 193 is_unstable_channel_(false), |
157 is_auto_update_enabled_(true), | 194 is_auto_update_enabled_(true), |
158 build_date_(base::GetBuildTime()) { | 195 build_date_(base::GetBuildTime()) { |
159 CommandLine command_line(*CommandLine::ForCurrentProcess()); | 196 CommandLine command_line(*CommandLine::ForCurrentProcess()); |
160 // The different command line switches that affect testing can't be used | 197 // The different command line switches that affect testing can't be used |
161 // simultaneously, if they do, here's the precedence order, based on the order | 198 // simultaneously, if they do, here's the precedence order, based on the order |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 282 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
246 base::Bind(&CheckForUnstableChannel, | 283 base::Bind(&CheckForUnstableChannel, |
247 start_upgrade_check_timer_task, | 284 start_upgrade_check_timer_task, |
248 &is_unstable_channel_)); | 285 &is_unstable_channel_)); |
249 #endif | 286 #endif |
250 } | 287 } |
251 | 288 |
252 UpgradeDetectorImpl::~UpgradeDetectorImpl() { | 289 UpgradeDetectorImpl::~UpgradeDetectorImpl() { |
253 } | 290 } |
254 | 291 |
255 // Static | 292 // static |
| 293 base::Version UpgradeDetectorImpl::GetCurrentlyInstalledVersion() { |
| 294 return GetCurrentlyInstalledVersionImpl(NULL); |
| 295 } |
| 296 |
| 297 // static |
256 // This task checks the currently running version of Chrome against the | 298 // This task checks the currently running version of Chrome against the |
257 // installed version. If the installed version is newer, it calls back | 299 // installed version. If the installed version is newer, it calls back |
258 // UpgradeDetectorImpl::UpgradeDetected using a weak pointer so that it can | 300 // UpgradeDetectorImpl::UpgradeDetected using a weak pointer so that it can |
259 // be interrupted from the UI thread. | 301 // be interrupted from the UI thread. |
260 void UpgradeDetectorImpl::DetectUpgradeTask( | 302 void UpgradeDetectorImpl::DetectUpgradeTask( |
261 base::WeakPtr<UpgradeDetectorImpl> upgrade_detector) { | 303 base::WeakPtr<UpgradeDetectorImpl> upgrade_detector) { |
262 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 304 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
263 | 305 |
264 Version installed_version; | |
265 Version critical_update; | 306 Version critical_update; |
266 | 307 Version installed_version = |
267 #if defined(OS_WIN) | 308 GetCurrentlyInstalledVersionImpl(&critical_update); |
268 // Get the version of the currently *installed* instance of Chrome, | |
269 // which might be newer than the *running* instance if we have been | |
270 // upgraded in the background. | |
271 bool system_install = IsSystemInstall(); | |
272 | |
273 // TODO(tommi): Check if using the default distribution is always the right | |
274 // thing to do. | |
275 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | |
276 InstallUtil::GetChromeVersion(dist, system_install, &installed_version); | |
277 | |
278 if (installed_version.IsValid()) { | |
279 InstallUtil::GetCriticalUpdateVersion(dist, system_install, | |
280 &critical_update); | |
281 } | |
282 #elif defined(OS_MACOSX) | |
283 installed_version = | |
284 Version(base::UTF16ToASCII(keystone_glue::CurrentlyInstalledVersion())); | |
285 #elif defined(OS_POSIX) | |
286 // POSIX but not Mac OS X: Linux, etc. | |
287 CommandLine command_line(*CommandLine::ForCurrentProcess()); | |
288 command_line.AppendSwitch(switches::kProductVersion); | |
289 std::string reply; | |
290 if (!base::GetAppOutput(command_line, &reply)) { | |
291 DLOG(ERROR) << "Failed to get current file version"; | |
292 return; | |
293 } | |
294 | |
295 installed_version = Version(reply); | |
296 #endif | |
297 | 309 |
298 // Get the version of the currently *running* instance of Chrome. | 310 // Get the version of the currently *running* instance of Chrome. |
299 chrome::VersionInfo version_info; | 311 chrome::VersionInfo version_info; |
300 if (!version_info.is_valid()) { | 312 if (!version_info.is_valid()) { |
301 NOTREACHED() << "Failed to get current file version"; | 313 NOTREACHED() << "Failed to get current file version"; |
302 return; | 314 return; |
303 } | 315 } |
304 Version running_version(version_info.Version()); | 316 Version running_version(version_info.Version()); |
305 if (!running_version.IsValid()) { | 317 if (!running_version.IsValid()) { |
306 NOTREACHED(); | 318 NOTREACHED(); |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
429 bool is_testing = IsTesting(); | 441 bool is_testing = IsTesting(); |
430 int64 time_passed = is_testing ? delta.InSeconds() : delta.InHours(); | 442 int64 time_passed = is_testing ? delta.InSeconds() : delta.InHours(); |
431 | 443 |
432 bool is_critical_or_outdated = upgrade_available_ > UPGRADE_AVAILABLE_REGULAR; | 444 bool is_critical_or_outdated = upgrade_available_ > UPGRADE_AVAILABLE_REGULAR; |
433 if (is_unstable_channel_) { | 445 if (is_unstable_channel_) { |
434 // There's only one threat level for unstable channels like dev and | 446 // There's only one threat level for unstable channels like dev and |
435 // canary, and it hits after one hour. During testing, it hits after one | 447 // canary, and it hits after one hour. During testing, it hits after one |
436 // second. | 448 // second. |
437 const int kUnstableThreshold = 1; | 449 const int kUnstableThreshold = 1; |
438 | 450 |
439 if (is_critical_or_outdated) | 451 if (is_critical_or_outdated) { |
440 set_upgrade_notification_stage(UPGRADE_ANNOYANCE_CRITICAL); | 452 set_upgrade_notification_stage(UPGRADE_ANNOYANCE_CRITICAL); |
441 else if (time_passed >= kUnstableThreshold) { | 453 } else if (time_passed >= kUnstableThreshold) { |
442 set_upgrade_notification_stage(UPGRADE_ANNOYANCE_LOW); | 454 set_upgrade_notification_stage(UPGRADE_ANNOYANCE_LOW); |
443 | 455 |
444 // That's as high as it goes. | 456 // That's as high as it goes. |
445 upgrade_notification_timer_.Stop(); | 457 upgrade_notification_timer_.Stop(); |
446 } else { | 458 } else { |
447 return; // Not ready to recommend upgrade. | 459 return; // Not ready to recommend upgrade. |
448 } | 460 } |
449 } else { | 461 } else { |
450 const int kMultiplier = is_testing ? 10 : 24; | 462 const int kMultiplier = is_testing ? 10 : 24; |
451 // 14 days when not testing, otherwise 14 seconds. | 463 // 14 days when not testing, otherwise 14 seconds. |
(...skipping 26 matching lines...) Expand all Loading... |
478 | 490 |
479 // static | 491 // static |
480 UpgradeDetectorImpl* UpgradeDetectorImpl::GetInstance() { | 492 UpgradeDetectorImpl* UpgradeDetectorImpl::GetInstance() { |
481 return Singleton<UpgradeDetectorImpl>::get(); | 493 return Singleton<UpgradeDetectorImpl>::get(); |
482 } | 494 } |
483 | 495 |
484 // static | 496 // static |
485 UpgradeDetector* UpgradeDetector::GetInstance() { | 497 UpgradeDetector* UpgradeDetector::GetInstance() { |
486 return UpgradeDetectorImpl::GetInstance(); | 498 return UpgradeDetectorImpl::GetInstance(); |
487 } | 499 } |
OLD | NEW |