Split gdata_file_system_interface.h from gdata_file_system.h
[chromium-blink-merge.git] / chrome / browser / chromeos / upgrade_detector_chromeos.cc
blobe66dbdf0bb2a0f2b0b748d049289165a73efb33a
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"
10 namespace {
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.
16 } // namespace
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);
29 initialized_ = true;
32 void UpgradeDetectorChromeos::Shutdown() {
33 // Init() may not be called from tests.
34 if (!initialized_)
35 return;
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)
42 return;
44 NotifyUpgradeDetected();
46 // ChromeOS shows upgrade arrow once the upgrade becomes available.
47 NotifyOnUpgrade();
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);
76 } else {
77 return; // Not ready to recommend upgrade.
80 NotifyUpgradeRecommended();
83 // static
84 UpgradeDetectorChromeos* UpgradeDetectorChromeos::GetInstance() {
85 return Singleton<UpgradeDetectorChromeos>::get();
88 // static
89 UpgradeDetector* UpgradeDetector::GetInstance() {
90 return UpgradeDetectorChromeos::GetInstance();