OLD | NEW |
| (Empty) |
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 | |
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_list.h" | |
9 #include "base/memory/singleton.h" | |
10 #include "content/common/content_export.h" | |
11 #include "third_party/WebKit/public/platform/WebBatteryStatus.h" | |
12 | |
13 namespace content { | |
14 class BatteryStatusManager; | |
15 | |
16 class CONTENT_EXPORT BatteryStatusService { | |
17 public: | |
18 typedef base::Callback<void(const blink::WebBatteryStatus&)> | |
19 BatteryUpdateCallback; | |
20 typedef base::CallbackList<void(const blink::WebBatteryStatus&)> | |
21 BatteryUpdateCallbackList; | |
22 typedef BatteryUpdateCallbackList::Subscription BatteryUpdateSubscription; | |
23 | |
24 // Returns the BatteryStatusService singleton. | |
25 static BatteryStatusService* GetInstance(); | |
26 | |
27 // Adds a callback to receive battery status updates. | |
28 // Must be called on the I/O thread. | |
29 scoped_ptr<BatteryUpdateSubscription> AddCallback( | |
30 const BatteryUpdateCallback& callback); | |
31 | |
32 // Gracefully clean-up. | |
33 void Shutdown(); | |
34 | |
35 // Injects a custom battery status manager for testing purposes. | |
36 // This class takes ownership of the injected object. | |
37 void SetBatteryManagerForTesting(BatteryStatusManager* test_battery_manager); | |
38 | |
39 // Returns callback to invoke when battery is changed. Used for testing. | |
40 const BatteryUpdateCallback& GetUpdateCallbackForTesting() const; | |
41 | |
42 private: | |
43 friend struct DefaultSingletonTraits<BatteryStatusService>; | |
44 | |
45 BatteryStatusService(); | |
46 virtual ~BatteryStatusService(); | |
47 | |
48 // Updates current battery status and sends new status to interested | |
49 // render processes. Can be called on any thread via a callback. | |
50 void UpdateBatteryStatus(const blink::WebBatteryStatus& status); | |
51 void NotifyConsumers(const blink::WebBatteryStatus& status); | |
52 void ConsumersChanged(); | |
53 | |
54 scoped_ptr<BatteryStatusManager> battery_fetcher_; | |
55 BatteryUpdateCallbackList callback_list_; | |
56 BatteryUpdateCallback update_callback_; | |
57 blink::WebBatteryStatus status_; | |
58 bool status_updated_; | |
59 bool is_shutdown_; | |
60 | |
61 DISALLOW_COPY_AND_ASSIGN(BatteryStatusService); | |
62 }; | |
63 | |
64 } // namespace content | |
65 | |
66 #endif // CONTENT_BROWSER_BATTERY_STATUS_BATTERY_STATUS_SERVICE_H_ | |
OLD | NEW |