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_BATTERY_STATUS_BATTERY_STATUS_SERVICE_H_ |
| 6 #define CONTENT_BROWSER_BATTERY_STATUS_BATTERY_STATUS_SERVICE_H_ |
| 7 |
| 8 #include "base/callback_forward.h" |
| 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/memory/singleton.h" |
| 11 #include "content/common/content_export.h" |
| 12 |
| 13 #include "content/browser/battery_status/battery_status_manager_android.h" |
| 14 #include <vector> |
| 15 |
| 16 #include "third_party/WebKit/public/platform/WebBatteryStatus.h" |
| 17 |
| 18 namespace content { |
| 19 |
| 20 class CONTENT_EXPORT BatteryStatusService { |
| 21 public: |
| 22 // Returns the BatteryStatusService singleton. |
| 23 static BatteryStatusService* GetInstance(); |
| 24 |
| 25 typedef base::Callback<void(const blink::WebBatteryStatus&)> BatteryStatusUpda
teCallback; |
| 26 |
| 27 // Adds a callback to receive battery status updates. |
| 28 // Must be called on the I/O thread. |
| 29 void AddConsumer(const BatteryStatusUpdateCallback& callback); |
| 30 |
| 31 // Removes a callback. Must be called on the I/O thread. |
| 32 void RemoveConsumer(const BatteryStatusUpdateCallback& callback); |
| 33 |
| 34 // TODO: is this needed? |
| 35 void Shutdown(); |
| 36 |
| 37 // Injects a custom battery status manager for testing purposes. This class ta
kes |
| 38 // ownership of the injected object. |
| 39 //void SetDataFetcherForTests(BatteryStatusManager* test_data_fetcher); |
| 40 |
| 41 void UpdateBatteryStatus(bool charging, double chargingTime, double dischargin
gTime, double level); |
| 42 const blink::WebBatteryStatus& GetBatteryStatus() const; |
| 43 |
| 44 private: |
| 45 friend struct DefaultSingletonTraits<BatteryStatusService>; |
| 46 |
| 47 BatteryStatusService(); |
| 48 virtual ~BatteryStatusService(); |
| 49 |
| 50 void NotifyConsumers(); |
| 51 |
| 52 bool is_shutdown_; |
| 53 scoped_ptr<BatteryStatusManagerAndroid> battery_fetcher_; |
| 54 std::vector<BatteryStatusUpdateCallback> callbacks_; |
| 55 blink::WebBatteryStatus status_; |
| 56 |
| 57 DISALLOW_COPY_AND_ASSIGN(BatteryStatusService); |
| 58 }; |
| 59 |
| 60 } // namespace content |
| 61 |
| 62 #endif // CONTENT_BROWSER_BATTERY_STATUS_BATTERY_STATUS_SERVICE_H_ |
OLD | NEW |