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
3 // found in the LICENSE file.
5 #include "chrome/browser/chromeos/upgrade_detector_chromeos.h"
7 #include "base/memory/singleton.h"
8 #include "chromeos/dbus/dbus_thread_manager.h"
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.
18 using chromeos::DBusThreadManager
;
19 using chromeos::UpdateEngineClient
;
21 UpgradeDetectorChromeos::UpgradeDetectorChromeos() : initialized_(false) {
24 UpgradeDetectorChromeos::~UpgradeDetectorChromeos() {
27 void UpgradeDetectorChromeos::Init() {
28 DBusThreadManager::Get()->GetUpdateEngineClient()->AddObserver(this);
32 void UpgradeDetectorChromeos::Shutdown() {
33 // Init() may not be called from tests.
36 DBusThreadManager::Get()->GetUpdateEngineClient()->RemoveObserver(this);
39 void UpgradeDetectorChromeos::UpdateStatusChanged(
40 const UpdateEngineClient::Status
& status
) {
41 if (status
.status
!= UpdateEngineClient::UPDATE_STATUS_UPDATED_NEED_REBOOT
)
44 NotifyUpgradeDetected();
46 // ChromeOS shows upgrade arrow once the upgrade becomes available.
49 // Setup timer to to move along the upgrade advisory system.
50 upgrade_notification_timer_
.Start(
51 FROM_HERE
, base::TimeDelta::FromMilliseconds(kNotifyCycleTimeMs
),
52 this, &UpgradeDetectorChromeos::NotifyOnUpgrade
);
55 void UpgradeDetectorChromeos::NotifyOnUpgrade() {
56 base::TimeDelta delta
= base::Time::Now() - upgrade_detected_time();
57 int64 time_passed
= delta
.InDays();
59 const int kSevereThreshold
= 7;
60 const int kHighThreshold
= 4;
61 const int kElevatedThreshold
= 2;
62 const int kLowThreshold
= 0;
64 // These if statements must be sorted (highest interval first).
65 if (time_passed
>= kSevereThreshold
) {
66 set_upgrade_notification_stage(UPGRADE_ANNOYANCE_SEVERE
);
68 // We can't get any higher, baby.
69 upgrade_notification_timer_
.Stop();
70 } else if (time_passed
>= kHighThreshold
) {
71 set_upgrade_notification_stage(UPGRADE_ANNOYANCE_HIGH
);
72 } else if (time_passed
>= kElevatedThreshold
) {
73 set_upgrade_notification_stage(UPGRADE_ANNOYANCE_ELEVATED
);
74 } else if (time_passed
>= kLowThreshold
) {
75 set_upgrade_notification_stage(UPGRADE_ANNOYANCE_LOW
);
77 return; // Not ready to recommend upgrade.
80 NotifyUpgradeRecommended();
84 UpgradeDetectorChromeos
* UpgradeDetectorChromeos::GetInstance() {
85 return Singleton
<UpgradeDetectorChromeos
>::get();
89 UpgradeDetector
* UpgradeDetector::GetInstance() {
90 return UpgradeDetectorChromeos::GetInstance();