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

Unified Diff: content/renderer/battery_status_dispatcher.cc

Issue 10024013: chromeos: Add support for the battery status API on chromeos. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 8 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_dispatcher.cc
diff --git a/content/renderer/battery_status_dispatcher.cc b/content/renderer/battery_status_dispatcher.cc
new file mode 100644
index 0000000000000000000000000000000000000000..57c8ad48784fecb10380b38f77385da9ed76a92a
--- /dev/null
+++ b/content/renderer/battery_status_dispatcher.cc
@@ -0,0 +1,44 @@
+// Copyright (c) 2012 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_dispatcher.h"
+
+#include "base/pickle.h"
+#include "content/common/battery_status_messages.h"
+#include "content/renderer/render_view_impl.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebBatteryStatus.h"
+
+BatteryStatusDispatcher::BatteryStatusDispatcher(RenderViewImpl* render_view)
+ : content::RenderViewObserver(render_view),
+ started_(false) {
+}
+
+BatteryStatusDispatcher::~BatteryStatusDispatcher() {
+ if (started_)
+ stopUpdating();
+}
+
+bool BatteryStatusDispatcher::OnMessageReceived(const IPC::Message& msg) {
+ bool handled = true;
+ IPC_BEGIN_MESSAGE_MAP(BatteryStatusDispatcher, msg)
+ IPC_MESSAGE_HANDLER(BatteryStatusMsg_Updated, OnBatteryStatusUpdated)
+ IPC_MESSAGE_UNHANDLED(handled = false)
+ IPC_END_MESSAGE_MAP()
+ return handled;
+}
+
+void BatteryStatusDispatcher::startUpdating() {
+ Send(new BatteryStatusHostMsg_StartUpdating(routing_id()));
+ started_ = true;
+}
+
+void BatteryStatusDispatcher::stopUpdating() {
+ Send(new BatteryStatusHostMsg_StopUpdating(routing_id()));
+ started_ = false;
+}
+
+void BatteryStatusDispatcher::OnBatteryStatusUpdated(
+ const WebKit::WebBatteryStatus& battery_status) {
+ render_view()->GetWebView()->updateBatteryStatus(battery_status);
+}

Powered by Google App Engine
This is Rietveld 408576698