| 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 BatteryDispatcher_h | 5 #ifndef BatteryDispatcher_h |
| 6 #define BatteryDispatcher_h | 6 #define BatteryDispatcher_h |
| 7 | 7 |
| 8 #include "core/frame/PlatformEventDispatcher.h" | 8 #include "core/frame/PlatformEventDispatcher.h" |
| 9 #include "device/battery/battery_monitor.mojom.h" | 9 #include "device/battery/battery_monitor.mojom.h" |
| 10 #include "modules/ModulesExport.h" | 10 #include "modules/ModulesExport.h" |
| 11 #include "modules/battery/BatteryManager.h" | 11 #include "modules/battery/BatteryManager.h" |
| 12 #include "modules/battery/battery_status.h" | 12 #include "modules/battery/battery_status.h" |
| 13 #include "wtf/OwnPtr.h" | 13 #include "wtf/OwnPtr.h" |
| 14 | 14 |
| 15 namespace blink { | 15 namespace blink { |
| 16 | 16 |
| 17 class MODULES_EXPORT BatteryDispatcher final : public GarbageCollectedFinalized<
BatteryDispatcher>, public PlatformEventDispatcher { | 17 class MODULES_EXPORT BatteryDispatcher final : public GarbageCollectedFinalized<
BatteryDispatcher>, public PlatformEventDispatcher { |
| 18 USING_GARBAGE_COLLECTED_MIXIN(BatteryDispatcher); | 18 USING_GARBAGE_COLLECTED_MIXIN(BatteryDispatcher); |
| 19 WTF_MAKE_NONCOPYABLE(BatteryDispatcher); | 19 WTF_MAKE_NONCOPYABLE(BatteryDispatcher); |
| 20 public: | 20 public: |
| 21 static BatteryDispatcher& instance(); | 21 static BatteryDispatcher& instance(); |
| 22 | 22 |
| 23 const BatteryStatus* latestData() const | 23 const BatteryStatus* latestData() const |
| 24 { | 24 { |
| 25 return m_hasLatestData ? &m_batteryStatus : nullptr; | 25 return m_hasLatestData ? &m_batteryStatus : nullptr; |
| 26 } | 26 } |
| 27 | 27 |
| 28 void updateBatteryStatusForTesting(const BatteryStatus& batteryStatus) | |
| 29 { | |
| 30 updateBatteryStatus(batteryStatus); | |
| 31 } | |
| 32 | |
| 33 private: | 28 private: |
| 34 BatteryDispatcher(); | 29 BatteryDispatcher(); |
| 35 | 30 |
| 36 void queryNextStatus(); | 31 void queryNextStatus(); |
| 37 void onDidChange(device::BatteryStatusPtr); | 32 void onDidChange(device::BatteryStatusPtr); |
| 38 void updateBatteryStatus(const BatteryStatus&); | 33 void updateBatteryStatus(const BatteryStatus&); |
| 39 | 34 |
| 40 // Inherited from PlatformEventDispatcher. | 35 // Inherited from PlatformEventDispatcher. |
| 41 void startListening() override; | 36 void startListening() override; |
| 42 void stopListening() override; | 37 void stopListening() override; |
| 43 | 38 |
| 44 device::BatteryMonitorPtr m_monitor; | 39 device::BatteryMonitorPtr m_monitor; |
| 45 BatteryStatus m_batteryStatus; | 40 BatteryStatus m_batteryStatus; |
| 46 bool m_hasLatestData; | 41 bool m_hasLatestData; |
| 47 }; | 42 }; |
| 48 | 43 |
| 49 } // namespace blink | 44 } // namespace blink |
| 50 | 45 |
| 51 #endif // BatteryDispatcher_h | 46 #endif // BatteryDispatcher_h |
| OLD | NEW |