| 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() {
|
|
|