Index: content/common/power_monitor_broadcast_source.cc |
diff --git a/content/common/power_monitor_broadcast_source.cc b/content/common/power_monitor_broadcast_source.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..ae6d5ac096062be5740df9813fe7547e7331aed8 |
--- /dev/null |
+++ b/content/common/power_monitor_broadcast_source.cc |
@@ -0,0 +1,80 @@ |
+// Copyright (c) 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 "content/common/power_monitor_broadcast_source.h" |
+ |
+#include "content/common/power_monitor_messages.h" |
+ |
+namespace content { |
+ |
+PowerMonitorBroadcastSource::PowerMonitorBroadcastSource() |
+ : on_battery_power_(false), |
+ weak_factory_(this) { |
+ message_filter_ = new PowerMessageFilter(weak_factory_.GetWeakPtr()); |
+} |
+ |
+PowerMonitorBroadcastSource::~PowerMonitorBroadcastSource() { |
+} |
+ |
+// MessageFilters are owned by the Channel they are added to, so this class does |
+// not need to retain a reference. |
+IPC::ChannelProxy::MessageFilter* |
+PowerMonitorBroadcastSource::MessageFilter() { |
+ return message_filter_.get(); |
+} |
+ |
+bool PowerMonitorBroadcastSource::IsBatteryPower() { |
+ return on_battery_power_; |
+} |
+ |
+void PowerMonitorBroadcastSource::OnPowerStateChange(bool on_battery_power) { |
vandebo (ex-Chrome)
2013/07/09 22:22:08
A comment on this method might help...
|
+ on_battery_power_ = on_battery_power; |
+ ProcessPowerEvent(PowerMonitorSource::POWER_STATE_EVENT); |
+} |
+ |
+void PowerMonitorBroadcastSource::OnSuspend() { |
+ ProcessPowerEvent(PowerMonitorSource::SUSPEND_EVENT); |
+} |
+ |
+void PowerMonitorBroadcastSource::OnResume() { |
+ ProcessPowerEvent(PowerMonitorSource::RESUME_EVENT); |
+} |
+ |
+PowerMonitorBroadcastSource::PowerMessageFilter::PowerMessageFilter( |
+ base::WeakPtr<PowerMonitorBroadcastSource> source) : source_(source) { |
+} |
+ |
+PowerMonitorBroadcastSource::PowerMessageFilter::~PowerMessageFilter() { |
+} |
+ |
+bool PowerMonitorBroadcastSource::PowerMessageFilter::OnMessageReceived( |
+ const IPC::Message& message) { |
+ bool msg_is_ok = true; |
palmer
2013/07/09 21:16:10
So we don't intend to handle any kind of message s
bajones
2013/07/09 22:28:00
Forgive my lack of familiarity with these things,
|
+ bool handled = true; |
+ IPC_BEGIN_MESSAGE_MAP_EX(PowerMessageFilter, message, msg_is_ok) |
+ IPC_MESSAGE_HANDLER(PowerMonitorMsg_PowerStateChange, OnPowerStateChange) |
+ IPC_MESSAGE_HANDLER(PowerMonitorMsg_Suspend, OnSuspend) |
+ IPC_MESSAGE_HANDLER(PowerMonitorMsg_Resume, OnResume) |
+ IPC_MESSAGE_UNHANDLED(handled = false) |
+ IPC_END_MESSAGE_MAP_EX() |
+ return handled; |
+} |
+ |
+void PowerMonitorBroadcastSource::PowerMessageFilter::OnPowerStateChange( |
+ bool on_battery_power) { |
+ if (source_.get()) |
+ source_->OnPowerStateChange(on_battery_power); |
+} |
+ |
+void PowerMonitorBroadcastSource::PowerMessageFilter::OnSuspend() { |
+ if (source_.get()) |
+ source_->OnSuspend(); |
+} |
+ |
+void PowerMonitorBroadcastSource::PowerMessageFilter::OnResume() { |
+ if (source_.get()) |
+ source_->OnResume(); |
+} |
+ |
+} // namespace content |