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.h"
6 #include "base/power_monitor/power_monitor_source.h"
10 static PowerMonitor
* g_power_monitor
= NULL
;
12 PowerMonitor::PowerMonitor(scoped_ptr
<PowerMonitorSource
> source
)
13 : observers_(new ObserverListThreadSafe
<PowerObserver
>()),
14 source_(source
.Pass()) {
15 DCHECK(!g_power_monitor
);
16 g_power_monitor
= this;
19 PowerMonitor::~PowerMonitor() {
20 DCHECK_EQ(this, g_power_monitor
);
21 g_power_monitor
= NULL
;
25 PowerMonitor
* PowerMonitor::Get() {
26 return g_power_monitor
;
29 void PowerMonitor::AddObserver(PowerObserver
* obs
) {
30 observers_
->AddObserver(obs
);
33 void PowerMonitor::RemoveObserver(PowerObserver
* obs
) {
34 observers_
->RemoveObserver(obs
);
37 PowerMonitorSource
* PowerMonitor::Source() {
41 bool PowerMonitor::IsOnBatteryPower() {
42 return source_
->IsOnBatteryPower();
45 void PowerMonitor::NotifyPowerStateChange(bool battery_in_use
) {
46 DVLOG(1) << "PowerStateChange: " << (battery_in_use
? "On" : "Off")
48 observers_
->Notify(FROM_HERE
, &PowerObserver::OnPowerStateChange
,
52 void PowerMonitor::NotifySuspend() {
53 DVLOG(1) << "Power Suspending";
54 observers_
->Notify(FROM_HERE
, &PowerObserver::OnSuspend
);
57 void PowerMonitor::NotifyResume() {
58 DVLOG(1) << "Power Resuming";
59 observers_
->Notify(FROM_HERE
, &PowerObserver::OnResume
);