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

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

Issue 8347016: chromeos: Simplify power supply info in PowerLibrary (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: support unit testing, added power supply status struct Created 9 years, 2 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
Index: chrome/browser/chromeos/low_battery_observer.cc
diff --git a/chrome/browser/chromeos/low_battery_observer.cc b/chrome/browser/chromeos/low_battery_observer.cc
index fea2d0d60b0533f4613e1151064a50e358b213e2..10134c59bf2290ee0c3e0a936379fad43b64540d 100644
--- a/chrome/browser/chromeos/low_battery_observer.cc
+++ b/chrome/browser/chromeos/low_battery_observer.cc
@@ -8,6 +8,7 @@
#include "chrome/common/time_format.h"
#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
+#include "third_party/cros/chromeos_power.h"
satorux1 2011/10/20 04:32:40 I thought we don't need this?
Simon Que 2011/10/20 21:18:53 Done.
#include "ui/base/l10n/l10n_util.h"
namespace chromeos {
@@ -22,7 +23,7 @@ LowBatteryObserver::~LowBatteryObserver() {
Hide();
}
-void LowBatteryObserver::PowerChanged(PowerLibrary* power_lib) {
+void LowBatteryObserver::PowerChanged(const PowerSupplyStatus& power_status) {
const int limit_min = 15; // Notification will show when remaining number
// of minutes is <= limit.
const int limit_max = 30; // Notification will hid when remaining number
@@ -30,21 +31,19 @@ void LowBatteryObserver::PowerChanged(PowerLibrary* power_lib) {
const int critical = 5; // Notification will be forced visible if hidden
// by user when time remaining <= critical.
- base::TimeDelta remaining = power_lib->GetBatteryTimeToEmpty();
- int remaining_minutes = remaining.InMinutes();
+ int remaining = power_status.battery_time_to_empty;
satorux1 2011/10/20 04:32:40 What happend to |remaining_minutes| in the orignal
Simon Que 2011/10/20 21:18:53 Fixed. Everything is a TimeDelta now.
// To simplify the logic - we handle the case of calculating the remaining
// time as if we were on line power.
// remaining time of zero means still calculating, this is denoted by
// base::TimeDelta().
- bool line_power = power_lib->IsLinePowerOn() ||
- remaining == base::TimeDelta();
+ bool line_power = power_status.line_power_on || remaining == 0;
// The urgent flag is used to re-notify the user if the power level
// goes critical. We only want to do this once even if the time remaining
// goes back up (so long as it doesn't go above limit_max.
bool urgent = !line_power &&
- (notification_.urgent() || remaining_minutes <= critical);
+ (notification_.urgent() || remaining <= critical);
satorux1 2011/10/20 04:32:40 This looks wrong. The orignal code was using remai
Simon Que 2011/10/20 21:18:53 Done.
// This is a simple state machine with two states and three edges:
// States: visible_, !visible_
@@ -59,14 +58,14 @@ void LowBatteryObserver::PowerChanged(PowerLibrary* power_lib) {
// we know the remaining time, and that time is less than limit.
if (notification_.visible()) {
- if (line_power || remaining_minutes > limit_max) {
+ if (line_power || remaining > limit_max) {
Hide();
- } else if (remaining_minutes != remaining_) {
- Show(remaining, urgent);
+ } else if (remaining != remaining_) {
+ Show(base::TimeDelta::FromSeconds(remaining), urgent);
}
} else {
- if (!line_power && remaining_minutes <= limit_min) {
- Show(remaining, urgent);
+ if (!line_power && remaining <= limit_min) {
+ Show(base::TimeDelta::FromSeconds(remaining), urgent);
}
}
}

Powered by Google App Engine
This is Rietveld 408576698