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 #ifndef CONTENT_COMMON_POWER_MONITOR_BROADCAST_SOURCE_H_ | |
6 #define CONTENT_COMMON_POWER_MONITOR_BROADCAST_SOURCE_H_ | |
7 | |
8 #include "base/memory/weak_ptr.h" | |
9 #include "base/power_monitor/power_monitor_source.h" | |
10 #include "content/common/content_export.h" | |
11 #include "ipc/ipc_channel.h" | |
12 #include "ipc/ipc_channel_proxy.h" | |
13 | |
14 namespace content { | |
15 | |
16 // Receives Power Monitor IPC messages sent from the browser process and relays | |
17 // them to the PowerMonitor of the current process. | |
18 class CONTENT_EXPORT PowerMonitorBroadcastSource : | |
19 public base::PowerMonitorSource { | |
20 public: | |
21 PowerMonitorBroadcastSource(); | |
22 virtual ~PowerMonitorBroadcastSource(); | |
23 | |
24 IPC::ChannelProxy::MessageFilter* MessageFilter(); | |
25 | |
26 private: | |
27 friend class PowerMonitorMessageFilter; | |
28 | |
29 class PowerMessageFilter : public IPC::ChannelProxy::MessageFilter { | |
30 public: | |
31 explicit PowerMessageFilter( | |
32 base::WeakPtr<PowerMonitorBroadcastSource> source); | |
33 | |
34 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | |
35 | |
36 private: | |
37 friend class base::RefCounted<PowerMessageFilter>; | |
38 | |
39 virtual ~PowerMessageFilter(); | |
40 | |
41 void OnPowerStateChange(bool on_battery_power); | |
42 void OnSuspend(); | |
43 void OnResume(); | |
44 | |
45 base::WeakPtr<PowerMonitorBroadcastSource> source_; | |
46 | |
47 DISALLOW_COPY_AND_ASSIGN(PowerMessageFilter); | |
48 }; | |
49 | |
50 virtual bool IsOnBatteryPowerImpl() OVERRIDE; | |
51 | |
52 void OnPowerStateChange(bool on_battery_power); | |
53 void OnSuspend(); | |
54 void OnResume(); | |
55 | |
56 bool last_reported_battery_power_state_; | |
57 scoped_refptr<PowerMessageFilter> message_filter_; | |
58 base::WeakPtrFactory<PowerMonitorBroadcastSource> weak_factory_; | |
59 }; | |
piman
2013/07/12 21:09:58
nit: DISALLOW_COPY_AND_ASSIGN
| |
60 | |
61 } // namespace content | |
62 | |
63 #endif // CONTENT_COMMON_POWER_MONITOR_MESSAGE_FILTER_H_ | |
OLD | NEW |