Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 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 "content/child/power_monitor_broadcast_source.h" | |
| 6 | |
| 7 #include "content/common/power_monitor_messages.h" | |
| 8 | |
| 9 namespace content { | |
| 10 | |
| 11 PowerMonitorBroadcastSource::PowerMonitorBroadcastSource( | |
| 12 scoped_refptr<base::MessageLoopProxy> message_loop) | |
| 13 : last_reported_battery_power_state_(false), | |
| 14 weak_factory_(this) { | |
| 15 message_filter_ = new PowerMessageFilter(weak_factory_.GetWeakPtr(), | |
| 16 message_loop); | |
| 17 } | |
| 18 | |
| 19 PowerMonitorBroadcastSource::~PowerMonitorBroadcastSource() { | |
| 20 } | |
| 21 | |
| 22 IPC::ChannelProxy::MessageFilter* | |
| 23 PowerMonitorBroadcastSource::MessageFilter() { | |
| 24 return message_filter_.get(); | |
| 25 } | |
| 26 | |
| 27 bool PowerMonitorBroadcastSource::IsOnBatteryPowerImpl() { | |
| 28 return last_reported_battery_power_state_; | |
| 29 } | |
| 30 | |
| 31 void PowerMonitorBroadcastSource::OnPowerStateChange(bool on_battery_power) { | |
| 32 last_reported_battery_power_state_ = on_battery_power; | |
| 33 ProcessPowerEvent(PowerMonitorSource::POWER_STATE_EVENT); | |
| 34 } | |
| 35 | |
| 36 void PowerMonitorBroadcastSource::OnSuspend() { | |
| 37 ProcessPowerEvent(PowerMonitorSource::SUSPEND_EVENT); | |
| 38 } | |
| 39 | |
| 40 void PowerMonitorBroadcastSource::OnResume() { | |
| 41 ProcessPowerEvent(PowerMonitorSource::RESUME_EVENT); | |
| 42 } | |
| 43 | |
| 44 PowerMonitorBroadcastSource::PowerMessageFilter::PowerMessageFilter( | |
| 45 base::WeakPtr<PowerMonitorBroadcastSource> source, | |
| 46 scoped_refptr<base::MessageLoopProxy> message_loop) | |
| 47 : source_(source), | |
| 48 message_loop_(message_loop) { | |
| 49 } | |
| 50 | |
| 51 PowerMonitorBroadcastSource::PowerMessageFilter::~PowerMessageFilter() { | |
| 52 } | |
| 53 | |
| 54 bool PowerMonitorBroadcastSource::PowerMessageFilter::OnMessageReceived( | |
| 55 const IPC::Message& message) { | |
| 56 bool msg_is_ok = false; | |
| 57 bool handled = true; | |
| 58 IPC_BEGIN_MESSAGE_MAP_EX(PowerMessageFilter, message, msg_is_ok) | |
| 59 IPC_MESSAGE_HANDLER(PowerMonitorMsg_PowerStateChange, OnPowerStateChange) | |
| 60 IPC_MESSAGE_HANDLER(PowerMonitorMsg_Suspend, OnSuspend) | |
| 61 IPC_MESSAGE_HANDLER(PowerMonitorMsg_Resume, OnResume) | |
| 62 IPC_MESSAGE_UNHANDLED(handled = false) | |
| 63 IPC_END_MESSAGE_MAP_EX() | |
| 64 return handled && msg_is_ok; | |
|
jam
2013/07/30 23:52:00
nit: take out the msg_is_ok stuff. this is only ne
| |
| 65 } | |
| 66 | |
| 67 void PowerMonitorBroadcastSource::PowerMessageFilter::OnPowerStateChange( | |
| 68 bool on_battery_power) { | |
| 69 message_loop_->PostTask(FROM_HERE, | |
| 70 base::Bind(&PowerMonitorBroadcastSource::OnPowerStateChange, source_, | |
| 71 on_battery_power)); | |
| 72 } | |
| 73 | |
| 74 void PowerMonitorBroadcastSource::PowerMessageFilter::OnSuspend() { | |
| 75 message_loop_->PostTask(FROM_HERE, | |
| 76 base::Bind(&PowerMonitorBroadcastSource::OnSuspend, source_)); | |
| 77 } | |
| 78 | |
| 79 void PowerMonitorBroadcastSource::PowerMessageFilter::OnResume() { | |
| 80 message_loop_->PostTask(FROM_HERE, | |
| 81 base::Bind(&PowerMonitorBroadcastSource::OnResume, source_)); | |
| 82 } | |
| 83 | |
| 84 } // namespace content | |
| OLD | NEW |