OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/power_monitor/power_monitor_source.h" | 5 #include "base/power_monitor/power_monitor_source.h" |
6 | 6 |
7 #include "base/power_monitor/power_monitor.h" | 7 #include "base/power_monitor/power_monitor.h" |
| 8 #include "build/build_config.h" |
8 | 9 |
9 namespace base { | 10 namespace base { |
10 | 11 |
11 PowerMonitorSource::PowerMonitorSource() | 12 PowerMonitorSource::PowerMonitorSource() {} |
12 : on_battery_power_(false), | 13 PowerMonitorSource::~PowerMonitorSource() {} |
13 suspended_(false) { | |
14 } | |
15 | |
16 PowerMonitorSource::~PowerMonitorSource() { | |
17 } | |
18 | 14 |
19 bool PowerMonitorSource::IsOnBatteryPower() { | 15 bool PowerMonitorSource::IsOnBatteryPower() { |
20 AutoLock auto_lock(battery_lock_); | 16 AutoLock auto_lock(battery_lock_); |
21 return on_battery_power_; | 17 return on_battery_power_; |
22 } | 18 } |
23 | 19 |
24 void PowerMonitorSource::ProcessPowerEvent(PowerEvent event_id) { | 20 void PowerMonitorSource::ProcessPowerEvent(PowerEvent event_id) { |
25 PowerMonitor* monitor = PowerMonitor::Get(); | 21 PowerMonitor* monitor = PowerMonitor::Get(); |
26 if (!monitor) | 22 if (!monitor) |
27 return; | 23 return; |
(...skipping 28 matching lines...) Expand all Loading... |
56 break; | 52 break; |
57 case SUSPEND_EVENT: | 53 case SUSPEND_EVENT: |
58 if (!source->suspended_) { | 54 if (!source->suspended_) { |
59 source->suspended_ = true; | 55 source->suspended_ = true; |
60 monitor->NotifySuspend(); | 56 monitor->NotifySuspend(); |
61 } | 57 } |
62 break; | 58 break; |
63 } | 59 } |
64 } | 60 } |
65 | 61 |
| 62 void PowerMonitorSource::SetInitialOnBatteryPowerState(bool on_battery_power) { |
| 63 // Must only be called before a monitor exists, otherwise the caller should |
| 64 // have just used a normal ProcessPowerEvent(POWER_STATE_EVENT) call. |
| 65 DCHECK(!PowerMonitor::Get()); |
| 66 on_battery_power_ = on_battery_power; |
| 67 } |
| 68 |
66 } // namespace base | 69 } // namespace base |
OLD | NEW |