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

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

Issue 252113006: Add Battery Status API support in content/renderer and IPC messages. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased Created 6 years, 7 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..e6ab56e2b5fb1312e39955edc96787f36edfbb5d
--- /dev/null
+++ b/content/renderer/battery_status/battery_status_dispatcher.cc
@@ -0,0 +1,55 @@
+// 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/common/battery_status_messages.h"
+#include "content/renderer/render_thread_impl.h"
+#include "third_party/WebKit/public/platform/WebBatteryStatusListener.h"
+
+namespace content {
+
+BatteryStatusDispatcher::BatteryStatusDispatcher(RenderThread* thread)
+ : listener_(0) {
+ if (thread)
+ thread->AddObserver(this);
+}
+
+BatteryStatusDispatcher::~BatteryStatusDispatcher() {
+ if (listener_)
+ Stop();
+}
+
+bool BatteryStatusDispatcher::SetListener(
+ blink::WebBatteryStatusListener* listener) {
+ listener_ = listener;
+ return listener ? Start() : Stop();
+}
+
+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() {
+ return RenderThread::Get()->Send(new BatteryStatusHostMsg_Start());
+}
+
+bool BatteryStatusDispatcher::Stop() {
+ return RenderThread::Get()->Send(new BatteryStatusHostMsg_Stop());
+}
+
+void BatteryStatusDispatcher::OnDidChange(
+ const blink::WebBatteryStatus& status) {
+ if (listener_)
+ listener_->updateBatteryStatus(status);
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698