Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/chromeos/upgrade_detector_chromeos.h" | |
| 6 | |
| 7 #include "base/memory/singleton.h" | |
| 8 #include "chrome/browser/chromeos/cros/cros_library.h" | |
| 9 | |
| 10 namespace { | |
| 11 | |
| 12 // How long to wait (each cycle) before checking which severity level we should | |
| 13 // be at. Once we reach the highest severity, the timer will stop. | |
| 14 const int kNotifyCycleTimeMs = 20 * 60 * 1000; // 20 minutes. | |
| 15 | |
| 16 } // namespace | |
| 17 | |
| 18 UpgradeDetectorChromeos::UpgradeDetectorChromeos() { | |
| 19 chromeos::CrosLibrary::Get()->GetUpdateLibrary()->AddObserver(this); | |
| 20 } | |
| 21 | |
| 22 UpgradeDetectorChromeos::~UpgradeDetectorChromeos() { | |
| 23 chromeos::CrosLibrary::Get()->GetUpdateLibrary()->RemoveObserver(this); | |
| 24 } | |
| 25 | |
| 26 void UpgradeDetectorChromeos::UpdateStatusChanged( | |
| 27 chromeos::UpdateLibrary* library) { | |
| 28 if (library->status().status != chromeos::UPDATE_STATUS_UPDATED_NEED_REBOOT) | |
| 29 return; | |
| 30 | |
| 31 NotifyUpgradeDetected(); | |
| 32 | |
| 33 // ChromeOS shows upgrade arrow once the upgrade becomes available. | |
| 34 NotifyOnUpgrade(); | |
| 35 | |
| 36 // Setup timer to to move along the upgrade advisory system. | |
| 37 upgrade_notification_timer_.Start( | |
| 38 base::TimeDelta::FromMilliseconds(kNotifyCycleTimeMs), | |
| 39 this, &UpgradeDetectorChromeos::NotifyOnUpgrade); | |
| 40 } | |
| 41 | |
| 42 void UpgradeDetectorChromeos::NotifyOnUpgrade() { | |
| 43 base::TimeDelta delta = base::Time::Now() - upgrade_detected_time(); | |
| 44 int64 time_passed = delta.InHours(); | |
| 45 | |
| 46 const int kMultiplier = 24; | |
| 47 const int kSevereThreshold = 7 * kMultiplier; | |
|
Finnur
2011/06/12 12:07:43
kMultiplier was created because on other platforms
xiyuan
2011/06/12 21:02:07
Done. It is left here because I was not sure wheth
| |
| 48 const int kHighThreshold = 4 * kMultiplier; | |
| 49 const int kElevatedThreshold = 2 * kMultiplier; | |
| 50 const int kLowThreshold = 0; | |
| 51 | |
| 52 // These if statements must be sorted (highest interval first). | |
| 53 if (time_passed >= kSevereThreshold) { | |
| 54 set_upgrade_notification_stage(UPGRADE_ANNOYANCE_SEVERE); | |
| 55 | |
| 56 // We can't get any higher, baby. | |
| 57 upgrade_notification_timer_.Stop(); | |
| 58 } else if (time_passed >= kHighThreshold) { | |
| 59 set_upgrade_notification_stage(UPGRADE_ANNOYANCE_HIGH); | |
| 60 } else if (time_passed >= kElevatedThreshold) { | |
| 61 set_upgrade_notification_stage(UPGRADE_ANNOYANCE_ELEVATED); | |
| 62 } else if (time_passed >= kLowThreshold) { | |
| 63 set_upgrade_notification_stage(UPGRADE_ANNOYANCE_LOW); | |
| 64 } else { | |
| 65 return; // Not ready to recommend upgrade. | |
| 66 } | |
| 67 | |
| 68 NotifyUpgradeRecommended(); | |
| 69 } | |
| 70 | |
| 71 // static | |
| 72 UpgradeDetectorChromeos* UpgradeDetectorChromeos::GetInstance() { | |
| 73 return Singleton<UpgradeDetectorChromeos>::get(); | |
| 74 } | |
| 75 | |
| 76 // static | |
| 77 UpgradeDetector* UpgradeDetector::GetInstance() { | |
| 78 return UpgradeDetectorChromeos::GetInstance(); | |
| 79 } | |
| OLD | NEW |