Chromium Code Reviews| Index: content/child/power_monitor_broadcast_source.h |
| diff --git a/content/child/power_monitor_broadcast_source.h b/content/child/power_monitor_broadcast_source.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..96a86b9c6b44cc25e35b5b797abd3cd2c8d4785f |
| --- /dev/null |
| +++ b/content/child/power_monitor_broadcast_source.h |
| @@ -0,0 +1,69 @@ |
| +// 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. |
| + |
| +#ifndef CONTENT_COMMON_POWER_MONITOR_BROADCAST_SOURCE_H_ |
|
scottmg
2013/07/30 23:52:53
nit; header guard CONTENT_CHILD_...
|
| +#define CONTENT_COMMON_POWER_MONITOR_BROADCAST_SOURCE_H_ |
| + |
| +#include "base/memory/weak_ptr.h" |
| +#include "base/message_loop/message_loop.h" |
| +#include "base/power_monitor/power_monitor_source.h" |
| +#include "content/common/content_export.h" |
| +#include "ipc/ipc_channel.h" |
| +#include "ipc/ipc_channel_proxy.h" |
| + |
| +namespace content { |
| + |
| +// Receives Power Monitor IPC messages sent from the browser process and relays |
| +// them to the PowerMonitor of the current process. |
| +class CONTENT_EXPORT PowerMonitorBroadcastSource : |
| + public base::PowerMonitorSource { |
| + public: |
| + explicit PowerMonitorBroadcastSource( |
| + scoped_refptr<base::MessageLoopProxy> message_loop); |
| + virtual ~PowerMonitorBroadcastSource(); |
| + |
| + IPC::ChannelProxy::MessageFilter* MessageFilter(); |
|
jam
2013/07/30 23:52:00
nit: GetMessageFilter
|
| + |
| + private: |
| + friend class PowerMonitorMessageFilter; |
| + |
| + class PowerMessageFilter : public IPC::ChannelProxy::MessageFilter { |
|
jam
2013/07/30 23:52:00
nit: since this is a private class, just move the
|
| + public: |
| + PowerMessageFilter( |
| + base::WeakPtr<PowerMonitorBroadcastSource> source, |
| + scoped_refptr<base::MessageLoopProxy> message_loop); |
| + |
| + virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
| + |
| + private: |
| + friend class base::RefCounted<PowerMessageFilter>; |
| + |
| + virtual ~PowerMessageFilter(); |
| + |
| + void OnPowerStateChange(bool on_battery_power); |
| + void OnSuspend(); |
| + void OnResume(); |
| + |
| + base::WeakPtr<PowerMonitorBroadcastSource> source_; |
| + scoped_refptr<base::MessageLoopProxy> message_loop_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(PowerMessageFilter); |
| + }; |
| + |
| + virtual bool IsOnBatteryPowerImpl() OVERRIDE; |
| + |
| + void OnPowerStateChange(bool on_battery_power); |
| + void OnSuspend(); |
| + void OnResume(); |
| + |
| + bool last_reported_battery_power_state_; |
| + scoped_refptr<PowerMessageFilter> message_filter_; |
| + base::WeakPtrFactory<PowerMonitorBroadcastSource> weak_factory_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(PowerMonitorBroadcastSource); |
| +}; |
| + |
| +} // namespace content |
| + |
| +#endif // CONTENT_COMMON_POWER_MONITOR_MESSAGE_FILTER_H_ |