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

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

Issue 258173004: [NO SUBMIT] Battery Status API skeleton implementation ASYNC Base URL: https://chromium.googlesource.com/chromium/src.git@April-17-battery-status-renderer-and-IPC
Patch Set: Created 6 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/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

Powered by Google App Engine
This is Rietveld 408576698