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" |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
277 // Always enable upgrade notifications regardless of branding. | 277 // Always enable upgrade notifications regardless of branding. |
278 #else | 278 #else |
279 return; | 279 return; |
280 #endif | 280 #endif |
281 // Check whether the build is an unstable channel before starting the timer. | 281 // Check whether the build is an unstable channel before starting the timer. |
282 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 282 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
283 base::Bind(&CheckForUnstableChannel, | 283 base::Bind(&CheckForUnstableChannel, |
284 start_upgrade_check_timer_task, | 284 start_upgrade_check_timer_task, |
285 &is_unstable_channel_)); | 285 &is_unstable_channel_)); |
286 #endif | 286 #endif |
287 | |
288 // Register for experiment notifications. Note that since this class is a | |
289 // singleton, it does not need to unregister for notifications when destroyed, | |
290 // since it outlines the VariationsService. | |
MAD
2014/08/01 17:41:30
outlines -> outlives
Alexei Svitkine (slow)
2014/08/04 19:43:10
Done.
| |
291 g_browser_process->variations_service()->AddObserver(this); | |
287 } | 292 } |
288 | 293 |
289 UpgradeDetectorImpl::~UpgradeDetectorImpl() { | 294 UpgradeDetectorImpl::~UpgradeDetectorImpl() { |
290 } | 295 } |
291 | 296 |
292 // static | 297 // static |
293 base::Version UpgradeDetectorImpl::GetCurrentlyInstalledVersion() { | 298 base::Version UpgradeDetectorImpl::GetCurrentlyInstalledVersion() { |
294 return GetCurrentlyInstalledVersionImpl(NULL); | 299 return GetCurrentlyInstalledVersionImpl(NULL); |
295 } | 300 } |
296 | 301 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
339 upgrade_available)); | 344 upgrade_available)); |
340 } | 345 } |
341 } | 346 } |
342 | 347 |
343 void UpgradeDetectorImpl::StartTimerForUpgradeCheck() { | 348 void UpgradeDetectorImpl::StartTimerForUpgradeCheck() { |
344 detect_upgrade_timer_.Start(FROM_HERE, | 349 detect_upgrade_timer_.Start(FROM_HERE, |
345 base::TimeDelta::FromMilliseconds(GetCheckForUpgradeEveryMs()), | 350 base::TimeDelta::FromMilliseconds(GetCheckForUpgradeEveryMs()), |
346 this, &UpgradeDetectorImpl::CheckForUpgrade); | 351 this, &UpgradeDetectorImpl::CheckForUpgrade); |
347 } | 352 } |
348 | 353 |
354 void UpgradeDetectorImpl::StartUpgradeNotificationTimer() { | |
355 // The timer may already be running (e.g. due to both a software upgrade and | |
356 // experiment updates being available). | |
357 if (upgrade_notification_timer_.IsRunning()) | |
358 return; | |
359 | |
360 upgrade_detected_time_ = base::Time::Now(); | |
361 | |
362 // Start the repeating timer for notifying the user after a certain period. | |
363 // The called function will eventually figure out that enough time has passed | |
364 // and stop the timer. | |
365 const int cycle_time_ms = IsTesting() ? | |
366 kNotifyCycleTimeForTestingMs : kNotifyCycleTimeMs; | |
367 upgrade_notification_timer_.Start(FROM_HERE, | |
368 base::TimeDelta::FromMilliseconds(cycle_time_ms), | |
369 this, &UpgradeDetectorImpl::NotifyOnUpgrade); | |
370 } | |
371 | |
349 void UpgradeDetectorImpl::CheckForUpgrade() { | 372 void UpgradeDetectorImpl::CheckForUpgrade() { |
350 // Interrupt any (unlikely) unfinished execution of DetectUpgradeTask, or at | 373 // Interrupt any (unlikely) unfinished execution of DetectUpgradeTask, or at |
351 // least prevent the callback from being executed, because we will potentially | 374 // least prevent the callback from being executed, because we will potentially |
352 // call it from within DetectOutdatedInstall() or will post | 375 // call it from within DetectOutdatedInstall() or will post |
353 // DetectUpgradeTask again below anyway. | 376 // DetectUpgradeTask again below anyway. |
354 weak_factory_.InvalidateWeakPtrs(); | 377 weak_factory_.InvalidateWeakPtrs(); |
355 | 378 |
356 // No need to look for upgrades if the install is outdated. | 379 // No need to look for upgrades if the install is outdated. |
357 if (DetectOutdatedInstall()) | 380 if (DetectOutdatedInstall()) |
358 return; | 381 return; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
407 UpgradeDetected(is_auto_update_enabled_ ? | 430 UpgradeDetected(is_auto_update_enabled_ ? |
408 UPGRADE_NEEDED_OUTDATED_INSTALL : | 431 UPGRADE_NEEDED_OUTDATED_INSTALL : |
409 UPGRADE_NEEDED_OUTDATED_INSTALL_NO_AU); | 432 UPGRADE_NEEDED_OUTDATED_INSTALL_NO_AU); |
410 return true; | 433 return true; |
411 } | 434 } |
412 // If we simlated an outdated install with a date, we don't want to keep | 435 // If we simlated an outdated install with a date, we don't want to keep |
413 // checking for version upgrades, which happens on non-official builds. | 436 // checking for version upgrades, which happens on non-official builds. |
414 return simulate_outdated; | 437 return simulate_outdated; |
415 } | 438 } |
416 | 439 |
440 void UpgradeDetectorImpl::OnExperimentChangesDetected(Severity severity) { | |
441 best_effort_experiment_updates_available_ = (severity == BEST_EFFORT); | |
442 critical_experiment_updates_available_ = (severity == CRITICAL); | |
443 StartUpgradeNotificationTimer(); | |
444 } | |
445 | |
417 void UpgradeDetectorImpl::UpgradeDetected(UpgradeAvailable upgrade_available) { | 446 void UpgradeDetectorImpl::UpgradeDetected(UpgradeAvailable upgrade_available) { |
418 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 447 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
419 upgrade_available_ = upgrade_available; | 448 upgrade_available_ = upgrade_available; |
420 | 449 |
421 // Stop the recurring timer (that is checking for changes). | 450 // Stop the recurring timer (that is checking for changes). |
422 detect_upgrade_timer_.Stop(); | 451 detect_upgrade_timer_.Stop(); |
452 critical_update_acknowledged_ = false; | |
423 | 453 |
424 NotifyUpgradeDetected(); | 454 StartUpgradeNotificationTimer(); |
425 | |
426 // Start the repeating timer for notifying the user after a certain period. | |
427 // The called function will eventually figure out that enough time has passed | |
428 // and stop the timer. | |
429 int cycle_time = IsTesting() ? | |
430 kNotifyCycleTimeForTestingMs : kNotifyCycleTimeMs; | |
431 upgrade_notification_timer_.Start(FROM_HERE, | |
432 base::TimeDelta::FromMilliseconds(cycle_time), | |
433 this, &UpgradeDetectorImpl::NotifyOnUpgrade); | |
434 } | 455 } |
435 | 456 |
436 void UpgradeDetectorImpl::NotifyOnUpgrade() { | 457 void UpgradeDetectorImpl::NotifyOnUpgradeWithTimePassed( |
437 const base::TimeDelta time_passed = | 458 base::TimeDelta time_passed) { |
438 base::Time::Now() - upgrade_detected_time(); | 459 const bool is_critical_or_outdated = |
439 | 460 upgrade_available_ > UPGRADE_AVAILABLE_REGULAR || |
440 bool is_critical_or_outdated = upgrade_available_ > UPGRADE_AVAILABLE_REGULAR; | 461 critical_experiment_updates_available_; |
441 if (is_unstable_channel_) { | 462 if (is_unstable_channel_) { |
442 // There's only one threat level for unstable channels like dev and | 463 // There's only one threat level for unstable channels like dev and |
443 // canary, and it hits after one hour. During testing, it hits after one | 464 // canary, and it hits after one hour. During testing, it hits after one |
444 // second. | 465 // second. |
445 const base::TimeDelta unstable_threshold = IsTesting() ? | 466 const base::TimeDelta unstable_threshold = IsTesting() ? |
446 base::TimeDelta::FromSeconds(1) : base::TimeDelta::FromHours(1); | 467 base::TimeDelta::FromSeconds(1) : base::TimeDelta::FromHours(1); |
447 | 468 |
448 if (is_critical_or_outdated) { | 469 if (is_critical_or_outdated) { |
449 set_upgrade_notification_stage(UPGRADE_ANNOYANCE_CRITICAL); | 470 set_upgrade_notification_stage(UPGRADE_ANNOYANCE_CRITICAL); |
450 } else if (time_passed >= unstable_threshold) { | 471 } else if (time_passed >= unstable_threshold) { |
(...skipping 29 matching lines...) Expand all Loading... | |
480 } else if (time_passed >= low_threshold) { | 501 } else if (time_passed >= low_threshold) { |
481 set_upgrade_notification_stage(UPGRADE_ANNOYANCE_LOW); | 502 set_upgrade_notification_stage(UPGRADE_ANNOYANCE_LOW); |
482 } else { | 503 } else { |
483 return; // Not ready to recommend upgrade. | 504 return; // Not ready to recommend upgrade. |
484 } | 505 } |
485 } | 506 } |
486 | 507 |
487 NotifyUpgradeRecommended(); | 508 NotifyUpgradeRecommended(); |
488 } | 509 } |
489 | 510 |
511 void UpgradeDetectorImpl::NotifyOnUpgrade() { | |
512 const base::TimeDelta time_passed = | |
513 base::Time::Now() - upgrade_detected_time_; | |
sky
2014/08/04 18:24:07
Don't you want timeticks?
Alexei Svitkine (slow)
2014/08/04 19:43:11
This CL doesn't actually change the logic around t
| |
514 NotifyOnUpgradeWithTimePassed(time_passed); | |
515 } | |
516 | |
490 // static | 517 // static |
491 UpgradeDetectorImpl* UpgradeDetectorImpl::GetInstance() { | 518 UpgradeDetectorImpl* UpgradeDetectorImpl::GetInstance() { |
492 return Singleton<UpgradeDetectorImpl>::get(); | 519 return Singleton<UpgradeDetectorImpl>::get(); |
493 } | 520 } |
494 | 521 |
495 // static | 522 // static |
496 UpgradeDetector* UpgradeDetector::GetInstance() { | 523 UpgradeDetector* UpgradeDetector::GetInstance() { |
497 return UpgradeDetectorImpl::GetInstance(); | 524 return UpgradeDetectorImpl::GetInstance(); |
498 } | 525 } |
OLD | NEW |