| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/child/power_monitor_broadcast_source.h" | 5 #include "content/child/power_monitor_broadcast_source.h" |
| 6 | 6 |
| 7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
| 8 #include "content/common/power_monitor_messages.h" | 8 #include "content/common/power_monitor_messages.h" |
| 9 #include "ipc/message_filter.h" |
| 9 | 10 |
| 10 namespace content { | 11 namespace content { |
| 11 | 12 |
| 12 class PowerMessageFilter : public IPC::ChannelProxy::MessageFilter { | 13 class PowerMessageFilter : public IPC::MessageFilter { |
| 13 public: | 14 public: |
| 14 PowerMessageFilter( | 15 PowerMessageFilter( |
| 15 PowerMonitorBroadcastSource* source, | 16 PowerMonitorBroadcastSource* source, |
| 16 scoped_refptr<base::MessageLoopProxy> message_loop) | 17 scoped_refptr<base::MessageLoopProxy> message_loop) |
| 17 : source_(source), | 18 : source_(source), |
| 18 message_loop_(message_loop) { | 19 message_loop_(message_loop) { |
| 19 } | 20 } |
| 20 | 21 |
| 21 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE { | 22 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE { |
| 22 bool handled = true; | 23 bool handled = true; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 PowerMonitorBroadcastSource::PowerMonitorBroadcastSource() | 77 PowerMonitorBroadcastSource::PowerMonitorBroadcastSource() |
| 77 : last_reported_battery_power_state_(false) { | 78 : last_reported_battery_power_state_(false) { |
| 78 message_filter_ = new PowerMessageFilter(this, | 79 message_filter_ = new PowerMessageFilter(this, |
| 79 base::MessageLoopProxy::current()); | 80 base::MessageLoopProxy::current()); |
| 80 } | 81 } |
| 81 | 82 |
| 82 PowerMonitorBroadcastSource::~PowerMonitorBroadcastSource() { | 83 PowerMonitorBroadcastSource::~PowerMonitorBroadcastSource() { |
| 83 message_filter_->RemoveSource(); | 84 message_filter_->RemoveSource(); |
| 84 } | 85 } |
| 85 | 86 |
| 86 IPC::ChannelProxy::MessageFilter* | 87 IPC::MessageFilter* PowerMonitorBroadcastSource::GetMessageFilter() { |
| 87 PowerMonitorBroadcastSource::GetMessageFilter() { | |
| 88 return message_filter_.get(); | 88 return message_filter_.get(); |
| 89 } | 89 } |
| 90 | 90 |
| 91 bool PowerMonitorBroadcastSource::IsOnBatteryPowerImpl() { | 91 bool PowerMonitorBroadcastSource::IsOnBatteryPowerImpl() { |
| 92 return last_reported_battery_power_state_; | 92 return last_reported_battery_power_state_; |
| 93 } | 93 } |
| 94 | 94 |
| 95 void PowerMonitorBroadcastSource::OnPowerStateChange(bool on_battery_power) { | 95 void PowerMonitorBroadcastSource::OnPowerStateChange(bool on_battery_power) { |
| 96 last_reported_battery_power_state_ = on_battery_power; | 96 last_reported_battery_power_state_ = on_battery_power; |
| 97 ProcessPowerEvent(PowerMonitorSource::POWER_STATE_EVENT); | 97 ProcessPowerEvent(PowerMonitorSource::POWER_STATE_EVENT); |
| 98 } | 98 } |
| 99 | 99 |
| 100 void PowerMonitorBroadcastSource::OnSuspend() { | 100 void PowerMonitorBroadcastSource::OnSuspend() { |
| 101 ProcessPowerEvent(PowerMonitorSource::SUSPEND_EVENT); | 101 ProcessPowerEvent(PowerMonitorSource::SUSPEND_EVENT); |
| 102 } | 102 } |
| 103 | 103 |
| 104 void PowerMonitorBroadcastSource::OnResume() { | 104 void PowerMonitorBroadcastSource::OnResume() { |
| 105 ProcessPowerEvent(PowerMonitorSource::RESUME_EVENT); | 105 ProcessPowerEvent(PowerMonitorSource::RESUME_EVENT); |
| 106 } | 106 } |
| 107 | 107 |
| 108 } // namespace content | 108 } // namespace content |
| OLD | NEW |