OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef CONTENT_RENDERER_BATTERY_STATUS_BATTERY_STATUS_DISPATCHER_H_ | 5 #ifndef BLINK_PLATFORM_BATTERY_BATTERY_DISPATCHER_PROXY_H_ |
6 #define CONTENT_RENDERER_BATTERY_STATUS_BATTERY_STATUS_DISPATCHER_H_ | 6 #define BLINK_PLATFORM_BATTERY_BATTERY_DISPATCHER_PROXY_H_ |
7 | 7 |
8 #include "base/compiler_specific.h" | |
9 #include "base/macros.h" | |
10 #include "content/common/content_export.h" | |
11 #include "device/battery/battery_monitor.mojom.h" | 8 #include "device/battery/battery_monitor.mojom.h" |
| 9 #include "platform/PlatformExport.h" |
| 10 #include "wtf/Noncopyable.h" |
12 | 11 |
13 namespace blink { | 12 namespace blink { |
14 class WebBatteryStatusListener; | |
15 } | |
16 | 13 |
17 namespace content { | 14 class BatteryStatus; |
18 | 15 |
19 class CONTENT_EXPORT BatteryStatusDispatcher { | 16 // This class connects a BatteryDispatcherProxy::Listener to the underlying Mojo |
| 17 // service. Note that currently the access to the Mojo service is limited in |
| 18 // platform/. In future, we'll let classes in core/ and modules/ directly |
| 19 // communicate with Mojo, and then, there will be no need to use this proxy |
| 20 // class. |
| 21 // |
| 22 // TODO(yukishiino): Remove this class once Mojo supports WTF-types. |
| 23 class PLATFORM_EXPORT BatteryDispatcherProxy { |
| 24 WTF_MAKE_NONCOPYABLE(BatteryDispatcherProxy); |
20 public: | 25 public: |
21 explicit BatteryStatusDispatcher(blink::WebBatteryStatusListener* listener); | 26 class Listener { |
22 ~BatteryStatusDispatcher(); | 27 public: |
| 28 virtual ~Listener() = default; |
| 29 |
| 30 // This method is called when a new battery status is available. |
| 31 virtual void OnUpdateBatteryStatus(const BatteryStatus&) = 0; |
| 32 }; |
| 33 |
| 34 explicit BatteryDispatcherProxy(Listener*); |
| 35 ~BatteryDispatcherProxy(); |
| 36 |
| 37 void StartListening(); |
| 38 void StopListening(); |
23 | 39 |
24 private: | 40 private: |
25 friend class BatteryStatusDispatcherTest; | |
26 | |
27 void QueryNextStatus(); | 41 void QueryNextStatus(); |
28 void DidChange(device::BatteryStatusPtr battery_status); | 42 void OnDidChange(device::BatteryStatusPtr); |
29 | 43 |
30 device::BatteryMonitorPtr monitor_; | 44 device::BatteryMonitorPtr monitor_; |
31 blink::WebBatteryStatusListener* listener_; | 45 Listener* listener_; |
32 | 46 |
33 DISALLOW_COPY_AND_ASSIGN(BatteryStatusDispatcher); | 47 friend class BatteryDispatcherProxyTest; |
34 }; | 48 }; |
35 | 49 |
36 } // namespace content | 50 } // namespace blink |
37 | 51 |
38 #endif // CONTENT_RENDERER_BATTERY_STATUS_BATTERY_STATUS_DISPATCHER_H_ | 52 #endif // BLINK_PLATFORM_BATTERY_BATTERY_DISPATCHER_PROXY_H_ |
OLD | NEW |