This source file includes following definitions.
- Init
- Shutdown
- UpdateStatusChanged
- NotifyOnUpgrade
- GetInstance
- GetInstance
#include "chrome/browser/chromeos/upgrade_detector_chromeos.h"
#include "base/memory/singleton.h"
#include "chromeos/dbus/dbus_thread_manager.h"
namespace {
const int kNotifyCycleTimeMs = 20 * 60 * 1000;
}
using chromeos::DBusThreadManager;
using chromeos::UpdateEngineClient;
UpgradeDetectorChromeos::UpgradeDetectorChromeos() : initialized_(false) {
}
UpgradeDetectorChromeos::~UpgradeDetectorChromeos() {
}
void UpgradeDetectorChromeos::Init() {
DBusThreadManager::Get()->GetUpdateEngineClient()->AddObserver(this);
initialized_ = true;
}
void UpgradeDetectorChromeos::Shutdown() {
if (!initialized_)
return;
DBusThreadManager::Get()->GetUpdateEngineClient()->RemoveObserver(this);
}
void UpgradeDetectorChromeos::UpdateStatusChanged(
const UpdateEngineClient::Status& status) {
if (status.status != UpdateEngineClient::UPDATE_STATUS_UPDATED_NEED_REBOOT)
return;
NotifyUpgradeDetected();
NotifyOnUpgrade();
upgrade_notification_timer_.Start(
FROM_HERE, base::TimeDelta::FromMilliseconds(kNotifyCycleTimeMs),
this, &UpgradeDetectorChromeos::NotifyOnUpgrade);
}
void UpgradeDetectorChromeos::NotifyOnUpgrade() {
base::TimeDelta delta = base::Time::Now() - upgrade_detected_time();
int64 time_passed = delta.InDays();
const int kSevereThreshold = 7;
const int kHighThreshold = 4;
const int kElevatedThreshold = 2;
const int kLowThreshold = 0;
if (time_passed >= kSevereThreshold) {
set_upgrade_notification_stage(UPGRADE_ANNOYANCE_SEVERE);
upgrade_notification_timer_.Stop();
} else if (time_passed >= kHighThreshold) {
set_upgrade_notification_stage(UPGRADE_ANNOYANCE_HIGH);
} else if (time_passed >= kElevatedThreshold) {
set_upgrade_notification_stage(UPGRADE_ANNOYANCE_ELEVATED);
} else if (time_passed >= kLowThreshold) {
set_upgrade_notification_stage(UPGRADE_ANNOYANCE_LOW);
} else {
return;
}
NotifyUpgradeRecommended();
}
UpgradeDetectorChromeos* UpgradeDetectorChromeos::GetInstance() {
return Singleton<UpgradeDetectorChromeos>::get();
}
UpgradeDetector* UpgradeDetector::GetInstance() {
return UpgradeDetectorChromeos::GetInstance();
}