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

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

Issue 2067016: Added support for critical notification on low battery. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: Minor comment tweaks. Created 10 years, 7 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 400c0248bed62f7a19c0f8bdd9ee599aab803beb..071b6ffd99451f5bbf2fc061748fdfc80654c171 100644
--- a/chrome/browser/chromeos/low_battery_observer.cc
+++ b/chrome/browser/chromeos/low_battery_observer.cc
@@ -8,11 +8,13 @@
#include "base/utf_string_conversions.h"
#include "chrome/common/time_format.h"
#include "grit/generated_resources.h"
+#include "grit/theme_resources.h"
namespace chromeos {
LowBatteryObserver::LowBatteryObserver(Profile* profile)
: notification_(profile, "battery.chromeos",
+ IDR_NOTIFICATION_LOW_BATTERY,
l10n_util::GetStringUTF16(IDS_LOW_BATTERY_TITLE)),
remaining_(0) {}
@@ -21,11 +23,25 @@ LowBatteryObserver::~LowBatteryObserver() {
}
void LowBatteryObserver::PowerChanged(PowerLibrary* object) {
- const int limit = 15; // Notification will show when remaining number
- // of minutes is <= limit
+ 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
+ // of minutes is > limit_max.
+ const int critical = 5; // Notification will be forced visible if hidden
+ // by user when time remaining <= critical.
base::TimeDelta remaining = object->battery_time_to_empty();
- bool line_power = object->line_power_on();
+ int remaining_minutes = remaining.InMinutes();
+
+ // To simplify the logic - we handle the case of calculating the remaining
+ // time as if we were on line power.
+ bool line_power = object->line_power_on() || remaining == base::TimeDelta();
oshima 2010/05/19 19:23:51 I'm guessing that remaining == 0 mean we're calcul
+
+ // 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);
// remaining time of zero means still calculating, this is denoted by
// TimeDelta().
@@ -35,31 +51,29 @@ void LowBatteryObserver::PowerChanged(PowerLibrary* object) {
// Edges: hide: is visible_ to !visible_ triggered if we transition
// to line_power, we're calculating our time remaining,
// or our time remaining has climbed higher than
- // limit (either by reduced useor an undected transition to/from
- // line_power).
+ // limit_max (either by reduced user an undetected transition
+ // to/from line_power).
// update: is visible_ to _visible triggered when we didn't hide
// and the minutes remaining changed from what's shown.
// show: is !visible_ to visible_ triggered when we're on battery,
// we know the remaining time, and that time is less than limit.
if (notification_.visible()) {
- if (line_power || remaining == base::TimeDelta()
- || remaining.InMinutes() > limit) {
+ if (line_power || remaining_minutes > limit_max) {
Hide();
- } else if (remaining.InMinutes() != remaining_) {
- Show(remaining);
+ } else if (remaining_minutes != remaining_) {
+ Show(remaining, urgent);
}
} else {
- if (!line_power && remaining != base::TimeDelta()
- && remaining.InMinutes() <= limit) {
- Show(remaining);
+ if (!line_power && remaining_minutes <= limit_min) {
+ Show(remaining, urgent);
}
}
}
-void LowBatteryObserver::Show(base::TimeDelta remaining) {
+void LowBatteryObserver::Show(base::TimeDelta remaining, bool urgent) {
notification_.Show(l10n_util::GetStringFUTF16(IDS_LOW_BATTERY_MESSAGE,
- WideToUTF16(TimeFormat::TimeRemaining(remaining))));
+ WideToUTF16(TimeFormat::TimeRemaining(remaining))), urgent);
remaining_ = remaining.InMinutes();
}
« no previous file with comments | « chrome/browser/chromeos/low_battery_observer.h ('k') | chrome/browser/chromeos/notifications/system_notification.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698