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..96f4f56d9f9cab83b866c24897f99a992a709b8b |
--- /dev/null |
+++ b/content/renderer/battery_status_dispatcher.cc |
@@ -0,0 +1,51 @@ |
+// 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 IPC::Message& message) { |
+ const char* data; |
+ int data_length; |
+ PickleIterator iter(message); |
+ if (message.ReadData(&iter, &data, &data_length)) { |
+ const WebKit::WebBatteryStatus* web_status = |
+ reinterpret_cast<const WebKit::WebBatteryStatus*>(data); |
+ render_view()->GetWebView()->updateBatteryStatus(*web_status); |
+ } |
+} |