1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/power_monitor/power_monitor_source.h"
7 #include "base/power_monitor/power_monitor.h"
11 PowerMonitorSource::PowerMonitorSource()
12 : on_battery_power_(false),
16 PowerMonitorSource::~PowerMonitorSource() {
19 bool PowerMonitorSource::IsOnBatteryPower() {
20 AutoLock auto_lock(battery_lock_);
21 return on_battery_power_;
24 void PowerMonitorSource::ProcessPowerEvent(PowerEvent event_id) {
25 PowerMonitor* monitor = PowerMonitor::Get();
29 PowerMonitorSource* source = monitor->Source();
31 // Suppress duplicate notifications. Some platforms may
32 // send multiple notifications of the same event.
34 case POWER_STATE_EVENT:
36 bool new_on_battery_power = source->IsOnBatteryPowerImpl();
40 AutoLock auto_lock(source->battery_lock_);
41 if (source->on_battery_power_ != new_on_battery_power) {
43 source->on_battery_power_ = new_on_battery_power;
48 monitor->NotifyPowerStateChange(new_on_battery_power);
52 if (source->suspended_) {
53 source->suspended_ = false;
54 monitor->NotifyResume();
58 if (!source->suspended_) {
59 source->suspended_ = true;
60 monitor->NotifySuspend();