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::IsBatteryPower() { |
| 20 NOTIMPLEMENTED(); |
| 21 return false; |
| 22 } |
| 23 |
| 24 void PowerMonitorSource::ProcessPowerEvent(PowerEvent event_id) { |
| 25 PowerMonitor* monitor = PowerMonitor::Get(); |
| 26 |
| 27 // Suppress duplicate notifications. Some platforms may |
| 28 // send multiple notifications of the same event. |
| 29 switch (event_id) { |
| 30 case POWER_STATE_EVENT: |
| 31 { |
| 32 bool on_battery = IsBatteryPower(); |
| 33 if (on_battery != battery_in_use_) { |
| 34 battery_in_use_ = on_battery; |
| 35 if (monitor) |
| 36 monitor->NotifyPowerStateChange(on_battery); |
| 37 } |
| 38 } |
| 39 break; |
| 40 case RESUME_EVENT: |
| 41 if (suspended_) { |
| 42 suspended_ = false; |
| 43 if (monitor) |
| 44 monitor->NotifyResume(); |
| 45 } |
| 46 break; |
| 47 case SUSPEND_EVENT: |
| 48 if (!suspended_) { |
| 49 suspended_ = true; |
| 50 if (monitor) |
| 51 monitor->NotifySuspend(); |
| 52 } |
| 53 break; |
| 54 } |
| 55 } |
| 56 |
| 57 } // namespace base |
OLD | NEW |