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 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 StartTimerForUpgradeCheck(); | 237 StartTimerForUpgradeCheck(); |
238 } else { | 238 } else { |
239 // Without a valid date, we simulate that we are already outdated... | 239 // Without a valid date, we simulate that we are already outdated... |
240 UpgradeDetected( | 240 UpgradeDetected( |
241 is_auto_update_enabled_ ? UPGRADE_NEEDED_OUTDATED_INSTALL | 241 is_auto_update_enabled_ ? UPGRADE_NEEDED_OUTDATED_INSTALL |
242 : UPGRADE_NEEDED_OUTDATED_INSTALL_NO_AU); | 242 : UPGRADE_NEEDED_OUTDATED_INSTALL_NO_AU); |
243 } | 243 } |
244 return; | 244 return; |
245 } | 245 } |
246 | 246 |
| 247 // Register for experiment notifications. Note that since this class is a |
| 248 // singleton, it does not need to unregister for notifications when destroyed, |
| 249 // since it outlives the VariationsService. |
| 250 chrome_variations::VariationsService* variations_service = |
| 251 g_browser_process->variations_service(); |
| 252 if (variations_service) |
| 253 variations_service->AddObserver(this); |
| 254 |
247 base::Closure start_upgrade_check_timer_task = | 255 base::Closure start_upgrade_check_timer_task = |
248 base::Bind(&UpgradeDetectorImpl::StartTimerForUpgradeCheck, | 256 base::Bind(&UpgradeDetectorImpl::StartTimerForUpgradeCheck, |
249 weak_factory_.GetWeakPtr()); | 257 weak_factory_.GetWeakPtr()); |
250 | 258 |
251 #if defined(OS_WIN) | 259 #if defined(OS_WIN) |
252 // Only enable upgrade notifications for official builds. Chromium has no | 260 // Only enable upgrade notifications for official builds. Chromium has no |
253 // upgrade channel. | 261 // upgrade channel. |
254 #if defined(GOOGLE_CHROME_BUILD) | 262 #if defined(GOOGLE_CHROME_BUILD) |
255 // On Windows, there might be a policy/enterprise environment preventing | 263 // On Windows, there might be a policy/enterprise environment preventing |
256 // updates, so validate updatability, and then call StartTimerForUpgradeCheck | 264 // updates, so validate updatability, and then call StartTimerForUpgradeCheck |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 upgrade_available)); | 347 upgrade_available)); |
340 } | 348 } |
341 } | 349 } |
342 | 350 |
343 void UpgradeDetectorImpl::StartTimerForUpgradeCheck() { | 351 void UpgradeDetectorImpl::StartTimerForUpgradeCheck() { |
344 detect_upgrade_timer_.Start(FROM_HERE, | 352 detect_upgrade_timer_.Start(FROM_HERE, |
345 base::TimeDelta::FromMilliseconds(GetCheckForUpgradeEveryMs()), | 353 base::TimeDelta::FromMilliseconds(GetCheckForUpgradeEveryMs()), |
346 this, &UpgradeDetectorImpl::CheckForUpgrade); | 354 this, &UpgradeDetectorImpl::CheckForUpgrade); |
347 } | 355 } |
348 | 356 |
| 357 void UpgradeDetectorImpl::StartUpgradeNotificationTimer() { |
| 358 // The timer may already be running (e.g. due to both a software upgrade and |
| 359 // experiment updates being available). |
| 360 if (upgrade_notification_timer_.IsRunning()) |
| 361 return; |
| 362 |
| 363 upgrade_detected_time_ = base::Time::Now(); |
| 364 |
| 365 // Start the repeating timer for notifying the user after a certain period. |
| 366 // The called function will eventually figure out that enough time has passed |
| 367 // and stop the timer. |
| 368 const int cycle_time_ms = IsTesting() ? |
| 369 kNotifyCycleTimeForTestingMs : kNotifyCycleTimeMs; |
| 370 upgrade_notification_timer_.Start(FROM_HERE, |
| 371 base::TimeDelta::FromMilliseconds(cycle_time_ms), |
| 372 this, &UpgradeDetectorImpl::NotifyOnUpgrade); |
| 373 } |
| 374 |
349 void UpgradeDetectorImpl::CheckForUpgrade() { | 375 void UpgradeDetectorImpl::CheckForUpgrade() { |
350 // Interrupt any (unlikely) unfinished execution of DetectUpgradeTask, or at | 376 // Interrupt any (unlikely) unfinished execution of DetectUpgradeTask, or at |
351 // least prevent the callback from being executed, because we will potentially | 377 // least prevent the callback from being executed, because we will potentially |
352 // call it from within DetectOutdatedInstall() or will post | 378 // call it from within DetectOutdatedInstall() or will post |
353 // DetectUpgradeTask again below anyway. | 379 // DetectUpgradeTask again below anyway. |
354 weak_factory_.InvalidateWeakPtrs(); | 380 weak_factory_.InvalidateWeakPtrs(); |
355 | 381 |
356 // No need to look for upgrades if the install is outdated. | 382 // No need to look for upgrades if the install is outdated. |
357 if (DetectOutdatedInstall()) | 383 if (DetectOutdatedInstall()) |
358 return; | 384 return; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 UpgradeDetected(is_auto_update_enabled_ ? | 433 UpgradeDetected(is_auto_update_enabled_ ? |
408 UPGRADE_NEEDED_OUTDATED_INSTALL : | 434 UPGRADE_NEEDED_OUTDATED_INSTALL : |
409 UPGRADE_NEEDED_OUTDATED_INSTALL_NO_AU); | 435 UPGRADE_NEEDED_OUTDATED_INSTALL_NO_AU); |
410 return true; | 436 return true; |
411 } | 437 } |
412 // If we simlated an outdated install with a date, we don't want to keep | 438 // 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. | 439 // checking for version upgrades, which happens on non-official builds. |
414 return simulate_outdated; | 440 return simulate_outdated; |
415 } | 441 } |
416 | 442 |
| 443 void UpgradeDetectorImpl::OnExperimentChangesDetected(Severity severity) { |
| 444 set_best_effort_experiment_updates_available(severity == BEST_EFFORT); |
| 445 set_critical_experiment_updates_available(severity == CRITICAL); |
| 446 StartUpgradeNotificationTimer(); |
| 447 } |
| 448 |
417 void UpgradeDetectorImpl::UpgradeDetected(UpgradeAvailable upgrade_available) { | 449 void UpgradeDetectorImpl::UpgradeDetected(UpgradeAvailable upgrade_available) { |
418 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 450 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
419 upgrade_available_ = upgrade_available; | 451 set_upgrade_available(upgrade_available); |
420 | 452 |
421 // Stop the recurring timer (that is checking for changes). | 453 // Stop the recurring timer (that is checking for changes). |
422 detect_upgrade_timer_.Stop(); | 454 detect_upgrade_timer_.Stop(); |
| 455 set_critical_update_acknowledged(false); |
423 | 456 |
424 NotifyUpgradeDetected(); | 457 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 } | 458 } |
435 | 459 |
436 void UpgradeDetectorImpl::NotifyOnUpgrade() { | 460 void UpgradeDetectorImpl::NotifyOnUpgradeWithTimePassed( |
437 const base::TimeDelta time_passed = | 461 base::TimeDelta time_passed) { |
438 base::Time::Now() - upgrade_detected_time(); | 462 const bool is_critical_or_outdated = |
439 | 463 upgrade_available() > UPGRADE_AVAILABLE_REGULAR || |
440 bool is_critical_or_outdated = upgrade_available_ > UPGRADE_AVAILABLE_REGULAR; | 464 critical_experiment_updates_available(); |
441 if (is_unstable_channel_) { | 465 if (is_unstable_channel_) { |
442 // There's only one threat level for unstable channels like dev and | 466 // 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 | 467 // canary, and it hits after one hour. During testing, it hits after one |
444 // second. | 468 // second. |
445 const base::TimeDelta unstable_threshold = IsTesting() ? | 469 const base::TimeDelta unstable_threshold = IsTesting() ? |
446 base::TimeDelta::FromSeconds(1) : base::TimeDelta::FromHours(1); | 470 base::TimeDelta::FromSeconds(1) : base::TimeDelta::FromHours(1); |
447 | 471 |
448 if (is_critical_or_outdated) { | 472 if (is_critical_or_outdated) { |
449 set_upgrade_notification_stage(UPGRADE_ANNOYANCE_CRITICAL); | 473 set_upgrade_notification_stage(UPGRADE_ANNOYANCE_CRITICAL); |
450 } else if (time_passed >= unstable_threshold) { | 474 } else if (time_passed >= unstable_threshold) { |
(...skipping 29 matching lines...) Expand all Loading... |
480 } else if (time_passed >= low_threshold) { | 504 } else if (time_passed >= low_threshold) { |
481 set_upgrade_notification_stage(UPGRADE_ANNOYANCE_LOW); | 505 set_upgrade_notification_stage(UPGRADE_ANNOYANCE_LOW); |
482 } else { | 506 } else { |
483 return; // Not ready to recommend upgrade. | 507 return; // Not ready to recommend upgrade. |
484 } | 508 } |
485 } | 509 } |
486 | 510 |
487 NotifyUpgradeRecommended(); | 511 NotifyUpgradeRecommended(); |
488 } | 512 } |
489 | 513 |
| 514 void UpgradeDetectorImpl::NotifyOnUpgrade() { |
| 515 const base::TimeDelta time_passed = |
| 516 base::Time::Now() - upgrade_detected_time_; |
| 517 NotifyOnUpgradeWithTimePassed(time_passed); |
| 518 } |
| 519 |
490 // static | 520 // static |
491 UpgradeDetectorImpl* UpgradeDetectorImpl::GetInstance() { | 521 UpgradeDetectorImpl* UpgradeDetectorImpl::GetInstance() { |
492 return Singleton<UpgradeDetectorImpl>::get(); | 522 return Singleton<UpgradeDetectorImpl>::get(); |
493 } | 523 } |
494 | 524 |
495 // static | 525 // static |
496 UpgradeDetector* UpgradeDetector::GetInstance() { | 526 UpgradeDetector* UpgradeDetector::GetInstance() { |
497 return UpgradeDetectorImpl::GetInstance(); | 527 return UpgradeDetectorImpl::GetInstance(); |
498 } | 528 } |
OLD | NEW |