| 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 | 8 |
| 9 namespace base { | 9 namespace base { |
| 10 | 10 |
| 11 PowerMonitorSource::PowerMonitorSource() | 11 PowerMonitorSource::PowerMonitorSource() |
| 12 : on_battery_power_(false), | 12 : on_battery_power_(false), |
| 13 suspended_(false) { | 13 suspended_(false) { |
| 14 } | 14 } |
| 15 | 15 |
| 16 PowerMonitorSource::~PowerMonitorSource() { | 16 PowerMonitorSource::~PowerMonitorSource() { |
| 17 } | 17 } |
| 18 | 18 |
| 19 bool PowerMonitorSource::IsOnBatteryPower() { | 19 bool PowerMonitorSource::IsOnBatteryPower() { |
| 20 AutoLock auto_lock(battery_lock_); | 20 AutoLock auto_lock(battery_lock_); |
| 21 return on_battery_power_; | 21 return on_battery_power_; |
| 22 } | 22 } |
| 23 | 23 |
| 24 void PowerMonitorSource::ProcessPowerEvent(PowerEvent event_id) { | 24 void PowerMonitorSource::ProcessPowerEvent(PowerEvent event_id) { |
| 25 PowerMonitor* monitor = PowerMonitor::Get(); | 25 AutoLock lock(*PowerMonitor::GetSingletonLock()); |
| 26 PowerMonitor* monitor = PowerMonitor::GetSingleton(); |
| 26 if (!monitor) | 27 if (!monitor) |
| 27 return; | 28 return; |
| 28 | 29 |
| 29 PowerMonitorSource* source = monitor->Source(); | 30 PowerMonitorSource* source = monitor->Source(); |
| 30 | 31 |
| 31 // Suppress duplicate notifications. Some platforms may | 32 // Suppress duplicate notifications. Some platforms may |
| 32 // send multiple notifications of the same event. | 33 // send multiple notifications of the same event. |
| 33 switch (event_id) { | 34 switch (event_id) { |
| 34 case POWER_STATE_EVENT: | 35 case POWER_STATE_EVENT: |
| 35 { | 36 { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 57 case SUSPEND_EVENT: | 58 case SUSPEND_EVENT: |
| 58 if (!source->suspended_) { | 59 if (!source->suspended_) { |
| 59 source->suspended_ = true; | 60 source->suspended_ = true; |
| 60 monitor->NotifySuspend(); | 61 monitor->NotifySuspend(); |
| 61 } | 62 } |
| 62 break; | 63 break; |
| 63 } | 64 } |
| 64 } | 65 } |
| 65 | 66 |
| 66 } // namespace base | 67 } // namespace base |
| OLD | NEW |