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/common/power_monitor_broadcast_source.h" |
| 6 |
| 7 #include "content/common/power_monitor_messages.h" |
| 8 |
| 9 namespace content { |
| 10 |
| 11 PowerMonitorBroadcastSource::PowerMonitorBroadcastSource() |
| 12 : on_battery_power_(false), |
| 13 message_filter_(new PowerMessageFilter(this)) { |
| 14 } |
| 15 |
| 16 PowerMonitorBroadcastSource::~PowerMonitorBroadcastSource() { |
| 17 } |
| 18 |
| 19 // MessageFilters are owned by the Channel they are added to, so this class does |
| 20 // not need to retain a reference. |
| 21 IPC::ChannelProxy::MessageFilter* |
| 22 PowerMonitorBroadcastSource::MessageFilter() { |
| 23 return message_filter_.get(); |
| 24 } |
| 25 |
| 26 bool PowerMonitorBroadcastSource::IsBatteryPower() { |
| 27 return on_battery_power_; |
| 28 } |
| 29 |
| 30 void PowerMonitorBroadcastSource::OnPowerStateChange(bool on_battery_power) { |
| 31 on_battery_power_ = on_battery_power; |
| 32 ProcessPowerEvent(PowerMonitorSource::POWER_STATE_EVENT); |
| 33 } |
| 34 |
| 35 void PowerMonitorBroadcastSource::OnSuspend() { |
| 36 ProcessPowerEvent(PowerMonitorSource::SUSPEND_EVENT); |
| 37 } |
| 38 |
| 39 void PowerMonitorBroadcastSource::OnResume() { |
| 40 ProcessPowerEvent(PowerMonitorSource::RESUME_EVENT); |
| 41 } |
| 42 |
| 43 PowerMonitorBroadcastSource::PowerMessageFilter::PowerMessageFilter( |
| 44 PowerMonitorBroadcastSource* source) : source_(source) { |
| 45 } |
| 46 |
| 47 PowerMonitorBroadcastSource::PowerMessageFilter::~PowerMessageFilter() { |
| 48 } |
| 49 |
| 50 bool PowerMonitorBroadcastSource::PowerMessageFilter::OnMessageReceived( |
| 51 const IPC::Message& message) { |
| 52 bool msg_is_ok = true; |
| 53 bool handled = true; |
| 54 IPC_BEGIN_MESSAGE_MAP_EX(PowerMessageFilter, message, msg_is_ok) |
| 55 IPC_MESSAGE_HANDLER(PowerMonitorMsg_PowerStateChange, OnPowerStateChange) |
| 56 IPC_MESSAGE_HANDLER(PowerMonitorMsg_Suspend, OnSuspend) |
| 57 IPC_MESSAGE_HANDLER(PowerMonitorMsg_Resume, OnResume) |
| 58 IPC_MESSAGE_UNHANDLED(handled = false) |
| 59 IPC_END_MESSAGE_MAP_EX() |
| 60 return handled; |
| 61 } |
| 62 |
| 63 void PowerMonitorBroadcastSource::PowerMessageFilter::OnPowerStateChange( |
| 64 bool on_battery_power) { |
| 65 source_->OnPowerStateChange(on_battery_power); |
| 66 } |
| 67 |
| 68 void PowerMonitorBroadcastSource::PowerMessageFilter::OnSuspend() { |
| 69 source_->OnSuspend(); |
| 70 } |
| 71 |
| 72 void PowerMonitorBroadcastSource::PowerMessageFilter::OnResume() { |
| 73 source_->OnResume(); |
| 74 } |
| 75 |
| 76 } // namespace content |
OLD | NEW |