Chromium Code Reviews| Index: content/browser/battery_status/battery_status_service.h |
| diff --git a/content/browser/battery_status/battery_status_service.h b/content/browser/battery_status/battery_status_service.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..cfc22dad6bc44e9ac7964af8398e697fff581433 |
| --- /dev/null |
| +++ b/content/browser/battery_status/battery_status_service.h |
| @@ -0,0 +1,65 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CONTENT_BROWSER_BATTERY_STATUS_BATTERY_STATUS_SERVICE_H_ |
| +#define CONTENT_BROWSER_BATTERY_STATUS_BATTERY_STATUS_SERVICE_H_ |
| + |
| +#include <vector> |
| + |
| +#include "base/memory/scoped_ptr.h" |
| +#include "base/memory/singleton.h" |
| +#include "content/browser/battery_status/battery_status_update_callback.h" |
| +#include "content/common/content_export.h" |
| +#include "third_party/WebKit/public/platform/WebBatteryStatus.h" |
| + |
| +namespace content { |
| +class BatteryStatusManagerInterface; |
| + |
| +class CONTENT_EXPORT BatteryStatusService { |
| + public: |
| + // Returns the BatteryStatusService singleton. |
| + static BatteryStatusService* GetInstance(); |
| + |
| + // Adds a callback to receive battery status updates. |
| + // Must be called on the I/O thread. |
| + 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.
|
| + |
| + // Removes a callback. Must be called on the I/O thread. |
| + void RemoveCallback(const BatteryStatusUpdateCallback& callback); |
| + |
| + // Gracefully clean-up. |
| + void Shutdown(); |
| + |
| + // Injects a custom battery status manager for testing purposes. |
| + // This class takes ownership of the injected object. |
| + 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.
|
| + BatteryStatusManagerInterface* test_battery_manager); |
| + |
| + // Returns callback to invoke when battery is changed. Used for testing. |
| + 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.
|
| + |
| + private: |
| + friend struct DefaultSingletonTraits<BatteryStatusService>; |
| + |
| + BatteryStatusService(); |
| + virtual ~BatteryStatusService(); |
| + |
| + // Updates current battery status and sends new status to interested |
| + // render processes. Can be called on any thread via a callback. |
| + void UpdateBatteryStatus(const blink::WebBatteryStatus& status); |
| + void NotifyConsumers(const blink::WebBatteryStatus& status); |
| + |
| + scoped_ptr<BatteryStatusManagerInterface> battery_fetcher_; |
| + 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.
|
| + blink::WebBatteryStatus status_; |
| + BatteryStatusUpdateCallback update_callback_; |
| + bool status_updated_; |
| + bool is_shutdown_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(BatteryStatusService); |
| +}; |
| + |
| +} // namespace content |
| + |
| +#endif // CONTENT_BROWSER_BATTERY_STATUS_BATTERY_STATUS_SERVICE_H_ |