| 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 DEVICE_BATTERY_BATTERY_STATUS_SERVICE_H_ | 5 #ifndef DEVICE_BATTERY_BATTERY_STATUS_SERVICE_H_ |
| 6 #define DEVICE_BATTERY_BATTERY_STATUS_SERVICE_H_ | 6 #define DEVICE_BATTERY_BATTERY_STATUS_SERVICE_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/callback_list.h" | 10 #include "base/callback_list.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/singleton.h" | 12 #include "base/memory/singleton.h" |
| 13 #include "device/battery/battery_export.h" | 13 #include "device/battery/battery_export.h" |
| 14 #include "device/battery/battery_status.mojom.h" | 14 #include "device/battery/battery_status.mojom.h" |
| 15 | 15 |
| 16 namespace base { | 16 namespace base { |
| 17 class SingleThreadTaskRunner; | 17 class SingleThreadTaskRunner; |
| 18 } | 18 } |
| 19 | 19 |
| 20 namespace device { | 20 namespace device { |
| 21 class BatteryStatusManager; | 21 class BatteryStatusManager; |
| 22 | 22 |
| 23 class DEVICE_BATTERY_EXPORT BatteryStatusService { | 23 class DEVICE_BATTERY_EXPORT BatteryStatusService { |
| 24 public: | 24 public: |
| 25 typedef base::Callback<void(const BatteryStatus&)> BatteryUpdateCallback; | 25 typedef base::Callback<void(const mojom::BatteryStatus&)> |
| 26 typedef base::CallbackList<void(const BatteryStatus&)> | 26 BatteryUpdateCallback; |
| 27 typedef base::CallbackList<void(const mojom::BatteryStatus&)> |
| 27 BatteryUpdateCallbackList; | 28 BatteryUpdateCallbackList; |
| 28 typedef BatteryUpdateCallbackList::Subscription BatteryUpdateSubscription; | 29 typedef BatteryUpdateCallbackList::Subscription BatteryUpdateSubscription; |
| 29 | 30 |
| 30 // Returns the BatteryStatusService singleton. | 31 // Returns the BatteryStatusService singleton. |
| 31 static BatteryStatusService* GetInstance(); | 32 static BatteryStatusService* GetInstance(); |
| 32 | 33 |
| 33 // Adds a callback to receive battery status updates. Must be called on the | 34 // Adds a callback to receive battery status updates. Must be called on the |
| 34 // main thread. The callback itself will be called on the main thread as well. | 35 // main thread. The callback itself will be called on the main thread as well. |
| 35 // NOTE: The callback may be run before AddCallback returns! | 36 // NOTE: The callback may be run before AddCallback returns! |
| 36 std::unique_ptr<BatteryUpdateSubscription> AddCallback( | 37 std::unique_ptr<BatteryUpdateSubscription> AddCallback( |
| (...skipping 11 matching lines...) Expand all Loading... |
| 48 | 49 |
| 49 private: | 50 private: |
| 50 friend struct base::DefaultSingletonTraits<BatteryStatusService>; | 51 friend struct base::DefaultSingletonTraits<BatteryStatusService>; |
| 51 friend class BatteryStatusServiceTest; | 52 friend class BatteryStatusServiceTest; |
| 52 | 53 |
| 53 BatteryStatusService(); | 54 BatteryStatusService(); |
| 54 virtual ~BatteryStatusService(); | 55 virtual ~BatteryStatusService(); |
| 55 | 56 |
| 56 // Updates current battery status and sends new status to interested | 57 // Updates current battery status and sends new status to interested |
| 57 // render processes. Can be called on any thread via a callback. | 58 // render processes. Can be called on any thread via a callback. |
| 58 void NotifyConsumers(const BatteryStatus& status); | 59 void NotifyConsumers(const mojom::BatteryStatus& status); |
| 59 void NotifyConsumersOnMainThread(const BatteryStatus& status); | 60 void NotifyConsumersOnMainThread(const mojom::BatteryStatus& status); |
| 60 void ConsumersChanged(); | 61 void ConsumersChanged(); |
| 61 | 62 |
| 62 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_; | 63 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_; |
| 63 std::unique_ptr<BatteryStatusManager> battery_fetcher_; | 64 std::unique_ptr<BatteryStatusManager> battery_fetcher_; |
| 64 BatteryUpdateCallbackList callback_list_; | 65 BatteryUpdateCallbackList callback_list_; |
| 65 BatteryUpdateCallback update_callback_; | 66 BatteryUpdateCallback update_callback_; |
| 66 BatteryStatus status_; | 67 mojom::BatteryStatus status_; |
| 67 bool status_updated_; | 68 bool status_updated_; |
| 68 bool is_shutdown_; | 69 bool is_shutdown_; |
| 69 | 70 |
| 70 DISALLOW_COPY_AND_ASSIGN(BatteryStatusService); | 71 DISALLOW_COPY_AND_ASSIGN(BatteryStatusService); |
| 71 }; | 72 }; |
| 72 | 73 |
| 73 } // namespace device | 74 } // namespace device |
| 74 | 75 |
| 75 #endif // DEVICE_BATTERY_BATTERY_STATUS_SERVICE_H_ | 76 #endif // DEVICE_BATTERY_BATTERY_STATUS_SERVICE_H_ |
| OLD | NEW |