Index: base/power_monitor/power_monitor_source.cc |
diff --git a/base/power_monitor/power_monitor_source.cc b/base/power_monitor/power_monitor_source.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..3935e08c86d20d96ad6d89db77264585c6970dc2 |
--- /dev/null |
+++ b/base/power_monitor/power_monitor_source.cc |
@@ -0,0 +1,57 @@ |
+// Copyright 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "base/power_monitor/power_monitor_source.h" |
+ |
+#include "base/power_monitor/power_monitor.h" |
+ |
+namespace base { |
+ |
+PowerMonitorSource::PowerMonitorSource() |
+ : battery_in_use_(false), |
+ suspended_(false) { |
+} |
+ |
+PowerMonitorSource::~PowerMonitorSource() { |
+} |
+ |
+bool PowerMonitorSource::IsBatteryPower() { |
+ NOTIMPLEMENTED(); |
+ return false; |
+} |
+ |
+void PowerMonitorSource::ProcessPowerEvent(PowerEvent event_id) { |
+ PowerMonitor* monitor = PowerMonitor::Get(); |
+ |
+ // Suppress duplicate notifications. Some platforms may |
+ // send multiple notifications of the same event. |
+ switch (event_id) { |
+ case POWER_STATE_EVENT: |
+ { |
+ bool on_battery = IsBatteryPower(); |
+ if (on_battery != battery_in_use_) { |
+ battery_in_use_ = on_battery; |
+ if (monitor) |
+ monitor->NotifyPowerStateChange(on_battery); |
+ } |
+ } |
+ break; |
+ case RESUME_EVENT: |
+ if (suspended_) { |
+ suspended_ = false; |
+ if (monitor) |
+ monitor->NotifyResume(); |
+ } |
+ break; |
+ case SUSPEND_EVENT: |
+ if (!suspended_) { |
+ suspended_ = true; |
+ if (monitor) |
+ monitor->NotifySuspend(); |
+ } |
+ break; |
+ } |
+} |
+ |
+} // namespace base |