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