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

Side by Side Diff: chrome/browser/chromeos/low_battery_observer.cc

Issue 8263003: cros: PowerLibrary virtual functions should be named using CamelCase. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix browser_tests 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chromeos/low_battery_observer.h" 5 #include "chrome/browser/chromeos/low_battery_observer.h"
6 6
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "chrome/common/time_format.h" 8 #include "chrome/common/time_format.h"
9 #include "grit/generated_resources.h" 9 #include "grit/generated_resources.h"
10 #include "grit/theme_resources.h" 10 #include "grit/theme_resources.h"
11 #include "ui/base/l10n/l10n_util.h" 11 #include "ui/base/l10n/l10n_util.h"
12 12
13 namespace chromeos { 13 namespace chromeos {
14 14
15 LowBatteryObserver::LowBatteryObserver(Profile* profile) 15 LowBatteryObserver::LowBatteryObserver(Profile* profile)
16 : notification_(profile, "battery.chromeos", 16 : notification_(profile, "battery.chromeos",
17 IDR_NOTIFICATION_LOW_BATTERY, 17 IDR_NOTIFICATION_LOW_BATTERY,
18 l10n_util::GetStringUTF16(IDS_LOW_BATTERY_TITLE)), 18 l10n_util::GetStringUTF16(IDS_LOW_BATTERY_TITLE)),
19 remaining_(0) {} 19 remaining_(0) {}
20 20
21 LowBatteryObserver::~LowBatteryObserver() { 21 LowBatteryObserver::~LowBatteryObserver() {
22 Hide(); 22 Hide();
23 } 23 }
24 24
25 void LowBatteryObserver::PowerChanged(PowerLibrary* object) { 25 void LowBatteryObserver::PowerChanged(PowerLibrary* power_lib) {
26 const int limit_min = 15; // Notification will show when remaining number 26 const int limit_min = 15; // Notification will show when remaining number
27 // of minutes is <= limit. 27 // of minutes is <= limit.
28 const int limit_max = 30; // Notification will hid when remaining number 28 const int limit_max = 30; // Notification will hid when remaining number
29 // of minutes is > limit_max. 29 // of minutes is > limit_max.
30 const int critical = 5; // Notification will be forced visible if hidden 30 const int critical = 5; // Notification will be forced visible if hidden
31 // by user when time remaining <= critical. 31 // by user when time remaining <= critical.
32 32
33 base::TimeDelta remaining = object->battery_time_to_empty(); 33 base::TimeDelta remaining = power_lib->GetBatteryTimeToEmpty();
34 int remaining_minutes = remaining.InMinutes(); 34 int remaining_minutes = remaining.InMinutes();
35 35
36 // To simplify the logic - we handle the case of calculating the remaining 36 // To simplify the logic - we handle the case of calculating the remaining
37 // time as if we were on line power. 37 // time as if we were on line power.
38 // remaining time of zero means still calculating, this is denoted by 38 // remaining time of zero means still calculating, this is denoted by
39 // base::TimeDelta(). 39 // base::TimeDelta().
40 bool line_power = object->line_power_on() || remaining == base::TimeDelta(); 40 bool line_power = power_lib->IsLinePowerOn() ||
41 remaining == base::TimeDelta();
41 42
42 // The urgent flag is used to re-notify the user if the power level 43 // The urgent flag is used to re-notify the user if the power level
43 // goes critical. We only want to do this once even if the time remaining 44 // goes critical. We only want to do this once even if the time remaining
44 // goes back up (so long as it doesn't go above limit_max. 45 // goes back up (so long as it doesn't go above limit_max.
45 bool urgent = !line_power && 46 bool urgent = !line_power &&
46 (notification_.urgent() || remaining_minutes <= critical); 47 (notification_.urgent() || remaining_minutes <= critical);
47 48
48 // This is a simple state machine with two states and three edges: 49 // This is a simple state machine with two states and three edges:
49 // States: visible_, !visible_ 50 // States: visible_, !visible_
50 // Edges: hide: is visible_ to !visible_ triggered if we transition 51 // Edges: hide: is visible_ to !visible_ triggered if we transition
(...skipping 23 matching lines...) Expand all
74 notification_.Show(l10n_util::GetStringFUTF16(IDS_LOW_BATTERY_MESSAGE, 75 notification_.Show(l10n_util::GetStringFUTF16(IDS_LOW_BATTERY_MESSAGE,
75 TimeFormat::TimeRemaining(remaining)), urgent, true); 76 TimeFormat::TimeRemaining(remaining)), urgent, true);
76 remaining_ = remaining.InMinutes(); 77 remaining_ = remaining.InMinutes();
77 } 78 }
78 79
79 void LowBatteryObserver::Hide() { 80 void LowBatteryObserver::Hide() {
80 notification_.Hide(); 81 notification_.Hide();
81 } 82 }
82 83
83 } // namespace chromeos 84 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/cros/power_library.cc ('k') | chrome/browser/chromeos/status/power_menu_button.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698