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.InDays(); |
| 45 |
| 46 const int kSevereThreshold = 7; |
| 47 const int kHighThreshold = 4; |
| 48 const int kElevatedThreshold = 2; |
| 49 const int kLowThreshold = 0; |
| 50 |
| 51 // These if statements must be sorted (highest interval first). |
| 52 if (time_passed >= kSevereThreshold) { |
| 53 set_upgrade_notification_stage(UPGRADE_ANNOYANCE_SEVERE); |
| 54 |
| 55 // We can't get any higher, baby. |
| 56 upgrade_notification_timer_.Stop(); |
| 57 } else if (time_passed >= kHighThreshold) { |
| 58 set_upgrade_notification_stage(UPGRADE_ANNOYANCE_HIGH); |
| 59 } else if (time_passed >= kElevatedThreshold) { |
| 60 set_upgrade_notification_stage(UPGRADE_ANNOYANCE_ELEVATED); |
| 61 } else if (time_passed >= kLowThreshold) { |
| 62 set_upgrade_notification_stage(UPGRADE_ANNOYANCE_LOW); |
| 63 } else { |
| 64 return; // Not ready to recommend upgrade. |
| 65 } |
| 66 |
| 67 NotifyUpgradeRecommended(); |
| 68 } |
| 69 |
| 70 // static |
| 71 UpgradeDetectorChromeos* UpgradeDetectorChromeos::GetInstance() { |
| 72 return Singleton<UpgradeDetectorChromeos>::get(); |
| 73 } |
| 74 |
| 75 // static |
| 76 UpgradeDetector* UpgradeDetector::GetInstance() { |
| 77 return UpgradeDetectorChromeos::GetInstance(); |
| 78 } |
OLD | NEW |