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..3ca8f5faae354e56f6da43836e1d3c3bdd88e95c |
--- /dev/null |
+++ b/content/renderer/battery_status/battery_status_dispatcher.cc |
@@ -0,0 +1,56 @@ |
+// 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 "battery_status_dispatcher.h" |
+ |
+#include "base/logging.h" |
+#include "content/public/renderer/render_thread.h" |
+#include "content/common/battery_status_messages.h" |
+#include "third_party/WebKit/public/platform/WebBatteryListener.h" |
+ |
+namespace content { |
+ |
+BatteryStatusDispatcher::BatteryStatusDispatcher() : listener_(0) { } |
+ |
+BatteryStatusDispatcher::~BatteryStatusDispatcher() { } |
+ |
+bool BatteryStatusDispatcher::SetListener(blink::WebBatteryListener* listener) { |
+ listener_ = listener; |
+ return listener ? Start() : Stop(); |
+} |
+ |
+void BatteryStatusDispatcher::Attach(RenderThread* thread) { |
+ if (!thread) |
+ return; |
+ thread->AddObserver(this); |
+} |
+ |
+bool BatteryStatusDispatcher::OnControlMessageReceived( |
+ const IPC::Message& message) { |
+ bool handled = true; |
+ IPC_BEGIN_MESSAGE_MAP(BatteryStatusDispatcher, message) |
+ IPC_MESSAGE_HANDLER(BatteryStatusMsg_DidChange, OnDidChange) |
+ IPC_MESSAGE_UNHANDLED(handled = false) |
+ IPC_END_MESSAGE_MAP() |
+ return handled; |
+} |
+ |
+bool BatteryStatusDispatcher::Start() { |
+LOG(INFO)<<"BLA: BatteryStatusDispatcher::Start"; |
+ return RenderThread::Get()->Send(new BatteryStatusHostMsg_Start()); |
+ |
+} |
+ |
+bool BatteryStatusDispatcher::Stop() { |
+ LOG(INFO)<<"BLA: BatteryStatusDispatcher::Stop"; |
+ return RenderThread::Get()->Send(new BatteryStatusHostMsg_Stop()); |
+} |
+ |
+void BatteryStatusDispatcher::OnDidChange(const blink::WebBatteryStatus& status) { |
+LOG(INFO) << "BLA: BatteryStatusDispatcher::OnDidChange level="<<status.level; |
+ if (listener_) |
+ listener_->updateBatteryStatus(status); |
+} |
+ |
+} // namespace content |