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

Unified Diff: content/renderer/battery_status/battery_status_dispatcher.cc

Issue 1740843002: Revert of Migrates battery_status from content/renderer/ to WebKit/platform/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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/renderer/battery_status/battery_status_dispatcher.cc
diff --git a/content/renderer/battery_status/battery_status_dispatcher.cc b/content/renderer/battery_status/battery_status_dispatcher.cc
new file mode 100644
index 0000000000000000000000000000000000000000..1034cb36d38867f449b6cb804e5926eccc75c75c
--- /dev/null
+++ b/content/renderer/battery_status/battery_status_dispatcher.cc
@@ -0,0 +1,49 @@
+// 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.
+
+#include "content/renderer/battery_status/battery_status_dispatcher.h"
+
+#include "content/public/common/service_registry.h"
+#include "content/public/renderer/render_thread.h"
+#include "third_party/WebKit/public/platform/WebBatteryStatusListener.h"
+
+namespace content {
+
+BatteryStatusDispatcher::BatteryStatusDispatcher(
+ blink::WebBatteryStatusListener* listener)
+ : listener_(listener) {
+ DCHECK(listener_);
+
+ if (ServiceRegistry* registry = RenderThread::Get()->GetServiceRegistry()) {
+ // registry can be null during testing.
+ registry->ConnectToRemoteService(mojo::GetProxy(&monitor_));
+ QueryNextStatus();
+ }
+}
+
+BatteryStatusDispatcher::~BatteryStatusDispatcher() {
+}
+
+void BatteryStatusDispatcher::QueryNextStatus() {
+ monitor_->QueryNextStatus(
+ base::Bind(&BatteryStatusDispatcher::DidChange, base::Unretained(this)));
+}
+
+void BatteryStatusDispatcher::DidChange(
+ device::BatteryStatusPtr battery_status) {
+ // monitor_ can be null during testing.
+ if (monitor_)
+ QueryNextStatus();
+
+ DCHECK(battery_status);
+
+ blink::WebBatteryStatus web_battery_status;
+ web_battery_status.charging = battery_status->charging;
+ web_battery_status.chargingTime = battery_status->charging_time;
+ web_battery_status.dischargingTime = battery_status->discharging_time;
+ web_battery_status.level = battery_status->level;
+ listener_->updateBatteryStatus(web_battery_status);
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698