Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(211)

Unified Diff: content/browser/battery_status/battery_status_service.h

Issue 278043002: Battery Status API: browser-side implementation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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_

Powered by Google App Engine
This is Rietveld 408576698