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

Unified Diff: base/power_monitor/power_monitor.cc

Issue 17074009: Created multi-process-friendly PowerMonitor interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixing windows unit test errors Created 7 years, 5 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 | « base/power_monitor/power_monitor.h ('k') | base/power_monitor/power_monitor_android.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/power_monitor/power_monitor.cc
diff --git a/base/power_monitor/power_monitor.cc b/base/power_monitor/power_monitor.cc
index 87188f1c591eb1c6a4bdf38bacc4125f045b91bd..14dc4b517832785c07153abfed2bcc4a3a738940 100644
--- a/base/power_monitor/power_monitor.cc
+++ b/base/power_monitor/power_monitor.cc
@@ -3,41 +3,20 @@
// found in the LICENSE file.
#include "base/power_monitor/power_monitor.h"
-
-#include "base/time/time.h"
+#include "base/power_monitor/power_monitor_source.h"
namespace base {
static PowerMonitor* g_power_monitor = NULL;
-#if defined(ENABLE_BATTERY_MONITORING)
-// The amount of time (in ms) to wait before running the initial
-// battery check.
-static int kDelayedBatteryCheckMs = 10 * 1000;
-#endif // defined(ENABLE_BATTERY_MONITORING)
-
-PowerMonitor::PowerMonitor()
+PowerMonitor::PowerMonitor(scoped_ptr<PowerMonitorSource> source)
: observers_(new ObserverListThreadSafe<PowerObserver>()),
- battery_in_use_(false),
- suspended_(false) {
+ source_(source.Pass()) {
DCHECK(!g_power_monitor);
g_power_monitor = this;
-
- DCHECK(MessageLoop::current());
-#if defined(ENABLE_BATTERY_MONITORING)
- delayed_battery_check_.Start(FROM_HERE,
- base::TimeDelta::FromMilliseconds(kDelayedBatteryCheckMs), this,
- &PowerMonitor::BatteryCheck);
-#endif // defined(ENABLE_BATTERY_MONITORING)
-#if defined(OS_MACOSX)
- PlatformInit();
-#endif
}
PowerMonitor::~PowerMonitor() {
-#if defined(OS_MACOSX)
- PlatformDestroy();
-#endif
DCHECK_EQ(this, g_power_monitor);
g_power_monitor = NULL;
}
@@ -55,42 +34,18 @@ void PowerMonitor::RemoveObserver(PowerObserver* obs) {
observers_->RemoveObserver(obs);
}
-void PowerMonitor::ProcessPowerEvent(PowerEvent event_id) {
- // Suppress duplicate notifications. Some platforms may
- // send multiple notifications of the same event.
- switch (event_id) {
- case POWER_STATE_EVENT:
- {
- bool on_battery = IsBatteryPower();
- if (on_battery != battery_in_use_) {
- battery_in_use_ = on_battery;
- NotifyPowerStateChange();
- }
- }
- break;
- case RESUME_EVENT:
- if (suspended_) {
- suspended_ = false;
- NotifyResume();
- }
- break;
- case SUSPEND_EVENT:
- if (!suspended_) {
- suspended_ = true;
- NotifySuspend();
- }
- break;
- }
+PowerMonitorSource* PowerMonitor::Source() {
+ return source_.get();
}
-void PowerMonitor::BatteryCheck() {
- ProcessPowerEvent(PowerMonitor::POWER_STATE_EVENT);
+bool PowerMonitor::IsOnBatteryPower() {
+ return source_->IsOnBatteryPower();
}
-void PowerMonitor::NotifyPowerStateChange() {
- DVLOG(1) << "PowerStateChange: " << (BatteryPower() ? "On" : "Off")
+void PowerMonitor::NotifyPowerStateChange(bool battery_in_use) {
+ DVLOG(1) << "PowerStateChange: " << (battery_in_use ? "On" : "Off")
<< " battery";
- observers_->Notify(&PowerObserver::OnPowerStateChange, BatteryPower());
+ observers_->Notify(&PowerObserver::OnPowerStateChange, battery_in_use);
}
void PowerMonitor::NotifySuspend() {
« no previous file with comments | « base/power_monitor/power_monitor.h ('k') | base/power_monitor/power_monitor_android.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698