OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 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_BROWSER_POWER_MONITOR_MESSAGE_BROADCASTER_H_ | |
6 #define CONTENT_BROWSER_POWER_MONITOR_MESSAGE_BROADCASTER_H_ | |
7 | |
8 #include "base/basictypes.h" | |
9 #include "base/memory/ref_counted.h" | |
10 #include "base/power_monitor/power_observer.h" | |
11 #include "content/common/content_export.h" | |
12 #include "content/public/browser/browser_message_filter.h" | |
13 #include "content/public/browser/browser_thread.h" | |
14 | |
15 | |
16 namespace IPC { | |
17 class Sender; | |
18 } | |
19 | |
20 namespace content { | |
21 | |
22 // A class used to monitor the power state change and communicate it to child | |
23 // processes via IPC. All interaction with this class must be done on the UI | |
24 // thread. | |
25 class CONTENT_EXPORT PowerMonitorMessageBroadcaster | |
26 : public base::PowerObserver, | |
27 public base::RefCountedThreadSafe< | |
28 PowerMonitorMessageBroadcaster, BrowserThread::DeleteOnUIThread> { | |
29 public: | |
30 explicit PowerMonitorMessageBroadcaster(IPC::Sender* sender); | |
31 | |
32 // Implement PowerObserver. | |
33 virtual void OnPowerStateChange(bool on_battery_power) OVERRIDE; | |
34 virtual void OnSuspend() OVERRIDE; | |
35 virtual void OnResume() OVERRIDE; | |
36 | |
37 private: | |
38 friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>; | |
39 friend class base::DeleteHelper<PowerMonitorMessageBroadcaster>; | |
40 virtual ~PowerMonitorMessageBroadcaster(); | |
41 | |
42 friend class PowerMonitorMessageFilter; | |
43 void RemoveSender(); | |
44 | |
45 IPC::Sender* sender_; | |
46 | |
47 DISALLOW_COPY_AND_ASSIGN(PowerMonitorMessageBroadcaster); | |
48 }; | |
49 | |
50 class PowerMonitorMessageFilter : public BrowserMessageFilter { | |
piman
2013/07/29 21:18:18
At a high level, I'm not sure why you create a fil
bajones
2013/07/29 21:33:36
Please see @jam's two previous comments.
| |
51 public: | |
52 PowerMonitorMessageFilter(); | |
53 | |
54 virtual void OnChannelClosing() OVERRIDE; | |
55 | |
56 virtual bool OnMessageReceived( | |
57 const IPC::Message& message, | |
58 bool* message_was_ok) OVERRIDE; | |
59 | |
60 private: | |
61 virtual ~PowerMonitorMessageFilter(); | |
62 | |
63 // These two functions must be called on the UI thread | |
64 void CreateBroadcaster(); | |
65 void DisableBroadcaster(); | |
66 | |
67 scoped_refptr<PowerMonitorMessageBroadcaster> broadcaster_; | |
68 }; | |
69 | |
70 } // namespace base | |
71 | |
72 #endif // CONTENT_BROWSER_POWER_MONITOR_MESSAGE_BROADCASTER_H_ | |
OLD | NEW |