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

Unified Diff: content/renderer/wake_lock_dispatcher.cc

Issue 406483004: Initial implementation of API WakeLock. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 5 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/wake_lock_dispatcher.cc
diff --git a/content/renderer/wake_lock_dispatcher.cc b/content/renderer/wake_lock_dispatcher.cc
new file mode 100644
index 0000000000000000000000000000000000000000..90f4b9caec81747cafc8ad34bc49ae9410999686
--- /dev/null
+++ b/content/renderer/wake_lock_dispatcher.cc
@@ -0,0 +1,68 @@
+// Copyright (c) 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 "content/renderer/wake_lock_dispatcher.h"
+
+#include "content/common/wake_lock_messages.h"
+#include "content/renderer/render_view_impl.h"
+
+namespace content {
+
+WakeLockDispatcher::WakeLockDispatcher(content::RenderView* render_view)
+ : RenderViewObserver(render_view),
+ blink::WebWakeLockClient() {
+ routing_id_ = render_view->GetRoutingID();
+}
+
+WakeLockDispatcher::~WakeLockDispatcher() {}
+
+bool WakeLockDispatcher::OnMessageReceived(const IPC::Message& message) {
+ bool handled = true;
+ IPC_BEGIN_MESSAGE_MAP(WakeLockDispatcher, message)
+ IPC_MESSAGE_HANDLER(WakeLockScreenViewMsg_LockedSuccessful,
+ OnWakeLockCreatedSuccessful)
+ IPC_MESSAGE_HANDLER(WakeLockScreenViewMsg_LockedFailed,
+ OnWakeLockCreatedFailed)
+ IPC_MESSAGE_HANDLER(WakeLockScreenViewMsg_UnlockedSuccessful,
+ OnWakeLockUnlockedSuccessful)
+ IPC_MESSAGE_HANDLER(WakeLockScreenViewMsg_UnlockedFailed,
+ OnWakeLockUnlockedFailed)
+ IPC_MESSAGE_UNHANDLED(handled = false)
+ IPC_END_MESSAGE_MAP()
+ return handled;
+}
+
+void WakeLockDispatcher::requestWakeLock() {
+ Send(new WakeLockScreenViewHostMsg_RequestLock(routing_id_));
+}
+
+void WakeLockDispatcher::requestWakeUnlock() {
+ Send(new WakeLockScreenViewHostMsg_RequestUnlock(routing_id_));
+}
+
+void WakeLockDispatcher::OnWakeLockCreatedSuccessful() {
+ controller_->onCreatedWakeLockScreenSuccessful();
+}
+
+void WakeLockDispatcher::OnWakeLockCreatedFailed() {
+ controller_->onCreatedWakeLockScreenFailed();
+}
+
+void WakeLockDispatcher::OnWakeLockUnlockedSuccessful() {
+ controller_->onUnlockedWakeLockScreenSuccessful();
+}
+
+void WakeLockDispatcher::OnWakeLockUnlockedFailed() {
+ controller_->onUnlockedWakeLockScreenFailed();
+}
+
+void WakeLockDispatcher::wakeLockDestroyed() {
+ controller_.reset();
+}
+
+void WakeLockDispatcher::setController(
+ blink::WebWakeLockController* controller) {
+ controller_.reset(controller);
+}
+}

Powered by Google App Engine
This is Rietveld 408576698