mac: Let IPhotoDataProvider::GetAlbumNames() return albums in a deterministic order.
[chromium-blink-merge.git] / base / power_monitor / power_monitor.cc
blob98c9c68c1dfae151f7252b816103af14d5f09e9f
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(FROM_HERE, &PowerObserver::OnPowerStateChange,
49 battery_in_use);
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);
62 } // namespace base