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

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

Issue 333313003: Simulate variation seeds using installed version string. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 6 years, 6 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
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/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 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 244 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
246 base::Bind(&CheckForUnstableChannel, 245 base::Bind(&CheckForUnstableChannel,
247 start_upgrade_check_timer_task, 246 start_upgrade_check_timer_task,
248 &is_unstable_channel_)); 247 &is_unstable_channel_));
249 #endif 248 #endif
250 } 249 }
251 250
252 UpgradeDetectorImpl::~UpgradeDetectorImpl() { 251 UpgradeDetectorImpl::~UpgradeDetectorImpl() {
253 } 252 }
254 253
255 // Static 254 // static
256 // This task checks the currently running version of Chrome against the 255 base::Version UpgradeDetectorImpl::GetCurrentlyInstalledVersion() {
257 // installed version. If the installed version is newer, it calls back 256 base::ThreadRestrictions::AssertIOAllowed();
258 // UpgradeDetectorImpl::UpgradeDetected using a weak pointer so that it can
259 // be interrupted from the UI thread.
260 void UpgradeDetectorImpl::DetectUpgradeTask(
261 base::WeakPtr<UpgradeDetectorImpl> upgrade_detector) {
262 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
263 257
264 Version installed_version; 258 Version installed_version;
265 Version critical_update;
266
267 #if defined(OS_WIN) 259 #if defined(OS_WIN)
268 // Get the version of the currently *installed* instance of Chrome, 260 // Get the version of the currently *installed* instance of Chrome,
269 // which might be newer than the *running* instance if we have been 261 // which might be newer than the *running* instance if we have been
270 // upgraded in the background. 262 // upgraded in the background.
271 bool system_install = IsSystemInstall(); 263 bool system_install = IsSystemInstall();
272 264
273 // TODO(tommi): Check if using the default distribution is always the right 265 // TODO(tommi): Check if using the default distribution is always the right
274 // thing to do. 266 // thing to do.
275 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); 267 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
276 InstallUtil::GetChromeVersion(dist, system_install, &installed_version); 268 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) 269 #elif defined(OS_MACOSX)
283 installed_version = 270 installed_version =
284 Version(base::UTF16ToASCII(keystone_glue::CurrentlyInstalledVersion())); 271 Version(base::UTF16ToASCII(keystone_glue::CurrentlyInstalledVersion()));
285 #elif defined(OS_POSIX) 272 #elif defined(OS_POSIX)
286 // POSIX but not Mac OS X: Linux, etc. 273 // POSIX but not Mac OS X: Linux, etc.
287 CommandLine command_line(*CommandLine::ForCurrentProcess()); 274 CommandLine command_line(*CommandLine::ForCurrentProcess());
288 command_line.AppendSwitch(switches::kProductVersion); 275 command_line.AppendSwitch(switches::kProductVersion);
289 std::string reply; 276 std::string reply;
290 if (!base::GetAppOutput(command_line, &reply)) { 277 if (!base::GetAppOutput(command_line, &reply)) {
291 DLOG(ERROR) << "Failed to get current file version"; 278 DLOG(ERROR) << "Failed to get current file version";
292 return; 279 return;
293 } 280 }
294 281
295 installed_version = Version(reply); 282 installed_version = Version(reply);
296 #endif 283 #endif
284 return installed_version;
285 }
286
287 // static
288 // This task checks the currently running version of Chrome against the
289 // installed version. If the installed version is newer, it calls back
290 // UpgradeDetectorImpl::UpgradeDetected using a weak pointer so that it can
291 // be interrupted from the UI thread.
292 void UpgradeDetectorImpl::DetectUpgradeTask(
293 base::WeakPtr<UpgradeDetectorImpl> upgrade_detector) {
294 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
295
296 Version installed_version = GetCurrentlyInstalledVersion();
297 Version critical_update;
298 #if defined(OS_WIN)
299 if (installed_version.IsValid()) {
300 InstallUtil::GetCriticalUpdateVersion(dist, system_install,
301 &critical_update);
302 }
303 #endif
297 304
298 // Get the version of the currently *running* instance of Chrome. 305 // Get the version of the currently *running* instance of Chrome.
299 chrome::VersionInfo version_info; 306 chrome::VersionInfo version_info;
300 if (!version_info.is_valid()) { 307 if (!version_info.is_valid()) {
301 NOTREACHED() << "Failed to get current file version"; 308 NOTREACHED() << "Failed to get current file version";
302 return; 309 return;
303 } 310 }
304 Version running_version(version_info.Version()); 311 Version running_version(version_info.Version());
305 if (!running_version.IsValid()) { 312 if (!running_version.IsValid()) {
306 NOTREACHED(); 313 NOTREACHED();
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 bool is_testing = IsTesting(); 436 bool is_testing = IsTesting();
430 int64 time_passed = is_testing ? delta.InSeconds() : delta.InHours(); 437 int64 time_passed = is_testing ? delta.InSeconds() : delta.InHours();
431 438
432 bool is_critical_or_outdated = upgrade_available_ > UPGRADE_AVAILABLE_REGULAR; 439 bool is_critical_or_outdated = upgrade_available_ > UPGRADE_AVAILABLE_REGULAR;
433 if (is_unstable_channel_) { 440 if (is_unstable_channel_) {
434 // There's only one threat level for unstable channels like dev and 441 // 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 442 // canary, and it hits after one hour. During testing, it hits after one
436 // second. 443 // second.
437 const int kUnstableThreshold = 1; 444 const int kUnstableThreshold = 1;
438 445
439 if (is_critical_or_outdated) 446 if (is_critical_or_outdated) {
440 set_upgrade_notification_stage(UPGRADE_ANNOYANCE_CRITICAL); 447 set_upgrade_notification_stage(UPGRADE_ANNOYANCE_CRITICAL);
441 else if (time_passed >= kUnstableThreshold) { 448 } else if (time_passed >= kUnstableThreshold) {
442 set_upgrade_notification_stage(UPGRADE_ANNOYANCE_LOW); 449 set_upgrade_notification_stage(UPGRADE_ANNOYANCE_LOW);
443 450
444 // That's as high as it goes. 451 // That's as high as it goes.
445 upgrade_notification_timer_.Stop(); 452 upgrade_notification_timer_.Stop();
446 } else { 453 } else {
447 return; // Not ready to recommend upgrade. 454 return; // Not ready to recommend upgrade.
448 } 455 }
449 } else { 456 } else {
450 const int kMultiplier = is_testing ? 10 : 24; 457 const int kMultiplier = is_testing ? 10 : 24;
451 // 14 days when not testing, otherwise 14 seconds. 458 // 14 days when not testing, otherwise 14 seconds.
(...skipping 26 matching lines...) Expand all
478 485
479 // static 486 // static
480 UpgradeDetectorImpl* UpgradeDetectorImpl::GetInstance() { 487 UpgradeDetectorImpl* UpgradeDetectorImpl::GetInstance() {
481 return Singleton<UpgradeDetectorImpl>::get(); 488 return Singleton<UpgradeDetectorImpl>::get();
482 } 489 }
483 490
484 // static 491 // static
485 UpgradeDetector* UpgradeDetector::GetInstance() { 492 UpgradeDetector* UpgradeDetector::GetInstance() {
486 return UpgradeDetectorImpl::GetInstance(); 493 return UpgradeDetectorImpl::GetInstance();
487 } 494 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698