OLD | NEW |
---|---|
(Empty) | |
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. | |
4 | |
5 #include "base/power_monitor/power_monitor_source.h" | |
6 | |
7 #include "base/power_monitor/power_monitor.h" | |
8 | |
9 namespace base { | |
10 | |
11 PowerMonitorSource::PowerMonitorSource() | |
12 : battery_in_use_(false), | |
13 suspended_(false) { | |
14 } | |
15 | |
16 PowerMonitorSource::~PowerMonitorSource() { | |
17 } | |
18 | |
19 bool PowerMonitorSource::BatteryPower() { | |
20 AutoLock auto_lock(lock_); | |
21 return battery_in_use_; | |
22 } | |
23 | |
24 bool PowerMonitorSource::IsBatteryPower() { | |
palmer
2013/07/09 21:16:10
This is a very strange wart.
| |
25 NOTIMPLEMENTED(); | |
26 return false; | |
27 } | |
28 | |
29 void PowerMonitorSource::ProcessPowerEvent(PowerEvent event_id) { | |
30 PowerMonitor* monitor = PowerMonitor::Get(); | |
31 | |
32 // Suppress duplicate notifications. Some platforms may | |
33 // send multiple notifications of the same event. | |
34 switch (event_id) { | |
35 case POWER_STATE_EVENT: | |
36 { | |
37 bool on_battery = IsBatteryPower(); | |
palmer
2013/07/09 21:16:10
This will trigger NOTIMPLEMENTED.
| |
38 if (on_battery != battery_in_use_) { | |
39 lock_.Acquire(); | |
40 battery_in_use_ = on_battery; | |
41 lock_.Release(); | |
42 if (monitor) | |
43 monitor->NotifyPowerStateChange(on_battery); | |
44 } | |
45 } | |
46 break; | |
47 case RESUME_EVENT: | |
48 if (suspended_) { | |
49 suspended_ = false; | |
50 if (monitor) | |
51 monitor->NotifyResume(); | |
52 } | |
53 break; | |
54 case SUSPEND_EVENT: | |
55 if (!suspended_) { | |
56 suspended_ = true; | |
57 if (monitor) | |
58 monitor->NotifySuspend(); | |
59 } | |
60 break; | |
61 } | |
62 } | |
63 | |
64 } // namespace base | |
OLD | NEW |