Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2276)

Unified Diff: chrome/browser/chromeos/upgrade_detector_chromeos.cc

Issue 7046096: Refactor UpgradeDetector. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync and address finnur's comments in set 2 Created 9 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/chromeos/upgrade_detector_chromeos.h ('k') | chrome/browser/upgrade_detector.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/chromeos/upgrade_detector_chromeos.cc
diff --git a/chrome/browser/chromeos/upgrade_detector_chromeos.cc b/chrome/browser/chromeos/upgrade_detector_chromeos.cc
new file mode 100644
index 0000000000000000000000000000000000000000..45ad77ac523e3764485ec689d124c43f0fc425ef
--- /dev/null
+++ b/chrome/browser/chromeos/upgrade_detector_chromeos.cc
@@ -0,0 +1,78 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/chromeos/upgrade_detector_chromeos.h"
+
+#include "base/memory/singleton.h"
+#include "chrome/browser/chromeos/cros/cros_library.h"
+
+namespace {
+
+// How long to wait (each cycle) before checking which severity level we should
+// be at. Once we reach the highest severity, the timer will stop.
+const int kNotifyCycleTimeMs = 20 * 60 * 1000; // 20 minutes.
+
+} // namespace
+
+UpgradeDetectorChromeos::UpgradeDetectorChromeos() {
+ chromeos::CrosLibrary::Get()->GetUpdateLibrary()->AddObserver(this);
+}
+
+UpgradeDetectorChromeos::~UpgradeDetectorChromeos() {
+ chromeos::CrosLibrary::Get()->GetUpdateLibrary()->RemoveObserver(this);
+}
+
+void UpgradeDetectorChromeos::UpdateStatusChanged(
+ chromeos::UpdateLibrary* library) {
+ if (library->status().status != chromeos::UPDATE_STATUS_UPDATED_NEED_REBOOT)
+ return;
+
+ NotifyUpgradeDetected();
+
+ // ChromeOS shows upgrade arrow once the upgrade becomes available.
+ NotifyOnUpgrade();
+
+ // Setup timer to to move along the upgrade advisory system.
+ upgrade_notification_timer_.Start(
+ 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;
+
+ // These if statements must be sorted (highest interval first).
+ if (time_passed >= kSevereThreshold) {
+ set_upgrade_notification_stage(UPGRADE_ANNOYANCE_SEVERE);
+
+ // We can't get any higher, baby.
+ 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; // Not ready to recommend upgrade.
+ }
+
+ NotifyUpgradeRecommended();
+}
+
+// static
+UpgradeDetectorChromeos* UpgradeDetectorChromeos::GetInstance() {
+ return Singleton<UpgradeDetectorChromeos>::get();
+}
+
+// static
+UpgradeDetector* UpgradeDetector::GetInstance() {
+ return UpgradeDetectorChromeos::GetInstance();
+}
« no previous file with comments | « chrome/browser/chromeos/upgrade_detector_chromeos.h ('k') | chrome/browser/upgrade_detector.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698