Replace the only use of media::MockStatisticsCB with a bound method.
[chromium-blink-merge.git] / base / power_monitor / power_monitor.cc
blob14dc4b517832785c07153abfed2bcc4a3a738940
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"
8 namespace base {
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;
24 // static
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() {
38 return source_.get();
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")
47 << " battery";
48 observers_->Notify(&PowerObserver::OnPowerStateChange, battery_in_use);
51 void PowerMonitor::NotifySuspend() {
52 DVLOG(1) << "Power Suspending";
53 observers_->Notify(&PowerObserver::OnSuspend);
56 void PowerMonitor::NotifyResume() {
57 DVLOG(1) << "Power Resuming";
58 observers_->Notify(&PowerObserver::OnResume);
61 } // namespace base