Chromium Code Reviews| 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 <vector> | |
| 9 | |
| 10 #include "base/memory/scoped_ptr.h" | |
| 11 #include "base/memory/singleton.h" | |
| 12 #include "content/browser/battery_status/battery_status_update_callback.h" | |
| 13 #include "content/common/content_export.h" | |
| 14 #include "third_party/WebKit/public/platform/WebBatteryStatus.h" | |
| 15 | |
| 16 namespace content { | |
| 17 class BatteryStatusManagerInterface; | |
| 18 | |
| 19 class CONTENT_EXPORT BatteryStatusService { | |
| 20 public: | |
| 21 // Returns the BatteryStatusService singleton. | |
| 22 static BatteryStatusService* GetInstance(); | |
| 23 | |
| 24 // Adds a callback to receive battery status updates. | |
| 25 // Must be called on the I/O thread. | |
| 26 void AddCallback(const BatteryStatusUpdateCallback& callback); | |
|
jochen (gone - plz use gerrit)
2014/05/19 13:14:22
can you move BatteryStatusUpdateCallback's definit
timvolodine
2014/05/22 10:02:33
done. I've put it inside this class.
| |
| 27 | |
| 28 // Removes a callback. Must be called on the I/O thread. | |
| 29 void RemoveCallback(const BatteryStatusUpdateCallback& callback); | |
| 30 | |
| 31 // Gracefully clean-up. | |
| 32 void Shutdown(); | |
| 33 | |
| 34 // Injects a custom battery status manager for testing purposes. | |
| 35 // This class takes ownership of the injected object. | |
| 36 void SetBatteryManagerForTests( | |
|
jochen (gone - plz use gerrit)
2014/05/19 13:14:22
ForTesting instead of ForTests
timvolodine
2014/05/22 10:02:33
Done.
| |
| 37 BatteryStatusManagerInterface* test_battery_manager); | |
| 38 | |
| 39 // Returns callback to invoke when battery is changed. Used for testing. | |
| 40 const BatteryStatusUpdateCallback& update_callback() const; | |
|
jochen (gone - plz use gerrit)
2014/05/19 13:14:22
GetUpdateCallbackForTesting
timvolodine
2014/05/22 10:02:33
Done.
| |
| 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 | |
| 53 scoped_ptr<BatteryStatusManagerInterface> battery_fetcher_; | |
| 54 std::vector<BatteryStatusUpdateCallback> callbacks_; | |
|
Michael van Ouwerkerk
2014/05/19 11:19:22
Looks like base::CallbackList would be suitable he
jochen (gone - plz use gerrit)
2014/05/19 13:14:22
+1
timvolodine
2014/05/22 10:02:33
Done.
timvolodine
2014/05/22 10:02:33
Done.
| |
| 55 blink::WebBatteryStatus status_; | |
| 56 BatteryStatusUpdateCallback update_callback_; | |
| 57 bool status_updated_; | |
| 58 bool is_shutdown_; | |
| 59 | |
| 60 DISALLOW_COPY_AND_ASSIGN(BatteryStatusService); | |
| 61 }; | |
| 62 | |
| 63 } // namespace content | |
| 64 | |
| 65 #endif // CONTENT_BROWSER_BATTERY_STATUS_BATTERY_STATUS_SERVICE_H_ | |
| OLD | NEW |