Index: content/common/power_monitor_message_filter.cc |
diff --git a/content/common/power_monitor_message_filter.cc b/content/common/power_monitor_message_filter.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..64482de8d5fb923d14a5f0c8017c65e05258ef66 |
--- /dev/null |
+++ b/content/common/power_monitor_message_filter.cc |
@@ -0,0 +1,73 @@ |
+// 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_message_filter.h" |
+ |
+#include "content/common/power_monitor_messages.h" |
+ |
+namespace content { |
+ |
+PowerMonitorBroadcastSource::PowerMonitorBroadcastSource() |
+ : on_battery_power_(false) { |
+ message_filter_ = new PowerMessageFilter(this); |
vandebo (ex-Chrome)
2013/06/26 21:40:33
memory leak
bajones
2013/06/26 22:37:22
This is tricky. This filter will be passed to the
vandebo (ex-Chrome)
2013/06/26 22:50:12
If channel_ owns it, are we sure that it won't be
Ken Russell (switch to Gerrit)
2013/06/27 13:08:23
See gpu_channel.cc for an example and ipc_channel_
|
+} |
+ |
+PowerMonitorBroadcastSource::~PowerMonitorBroadcastSource() { |
+} |
+ |
+IPC::ChannelProxy::MessageFilter* PowerMonitorBroadcastSource::MessageFilter() { |
+ return message_filter_; |
+} |
+ |
+bool PowerMonitorBroadcastSource::IsBatteryPower() { |
+ return on_battery_power_; |
+} |
+ |
+void PowerMonitorBroadcastSource::OnPowerStateChange(bool on_battery_power) { |
+ on_battery_power_ = on_battery_power; |
+ ProcessPowerEvent(PowerMonitorSource::POWER_STATE_EVENT); |
+} |
+ |
+void PowerMonitorBroadcastSource::OnSuspend() { |
+ ProcessPowerEvent(PowerMonitorSource::RESUME_EVENT); |
+} |
+ |
+void PowerMonitorBroadcastSource::OnResume() { |
+ ProcessPowerEvent(PowerMonitorSource::SUSPEND_EVENT); |
+} |
+ |
+PowerMonitorBroadcastSource::PowerMessageFilter::PowerMessageFilter( |
+ PowerMonitorBroadcastSource* source) : source_(source) { |
+} |
+ |
+PowerMonitorBroadcastSource::PowerMessageFilter::~PowerMessageFilter() { |
+} |
+ |
+bool PowerMonitorBroadcastSource::PowerMessageFilter::OnMessageReceived( |
+ const IPC::Message& message) { |
+ bool msg_is_ok = true; |
+ 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) { |
+ source_->OnPowerStateChange(on_battery_power); |
+} |
+ |
+void PowerMonitorBroadcastSource::PowerMessageFilter::OnSuspend() { |
+ source_->OnSuspend(); |
+} |
+ |
+void PowerMonitorBroadcastSource::PowerMessageFilter::OnResume() { |
+ source_->OnResume(); |
+} |
+ |
+} // namespace content |