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

Side by Side Diff: content/browser/wake_lock/wake_lock_dispatcher_host.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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/browser/wake_lock/wake_lock_dispatcher_host.h"
6
7 #include "base/bind.h"
8 #include "content/browser/renderer_host/render_view_host_impl.h"
9 #include "content/browser/wake_lock/wake_lock_manager.h"
10 #include "content/browser/wake_lock/wake_lock_web_contents_observer.h"
11 #include "content/common/wake_lock_messages.h"
12 #include "content/public/browser/wake_lock_permission_context.h"
13
14 namespace content {
15
16 void SendWakeLockPermissionResponse(int render_process_id,
17 int routed_id,
18 bool allowed) {
19 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
20 RenderViewHostImpl* render_view_host =
21 RenderViewHostImpl::FromID(render_process_id, routed_id);
22 if (!render_view_host)
23 return;
24 if (allowed) {
25 WakeLockManager::GetInstance()->createWebContentsObserver(
26 render_process_id, routed_id);
27 WakeLockManager::GetInstance()->createScreenLock(
28 render_process_id, routed_id);
29 render_view_host->Send(
30 new WakeLockScreenViewMsg_LockedSuccessful(routed_id));
31 } else {
32 render_view_host->Send(
33 new WakeLockScreenViewMsg_LockedFailed(routed_id));
34 }
35 }
36
37 WakeLockDispatcherHost::WakeLockDispatcherHost(
38 int render_process_id, WakeLockPermissionContext* wakelock_context)
39 : content::BrowserMessageFilter(WakeLockMsgStart),
40 render_process_id_(render_process_id),
41 wakelock_permission_context_(wakelock_context) {
42 }
43
44 WakeLockDispatcherHost::~WakeLockDispatcherHost() {
45 }
46
47 bool WakeLockDispatcherHost::OnMessageReceived(const IPC::Message& message) {
48 bool handled = true;
49 IPC_BEGIN_MESSAGE_MAP(WakeLockDispatcherHost, message)
50 static_cast<void>(param__);
51 IPC_MESSAGE_HANDLER_GENERIC(WakeLockScreenViewHostMsg_RequestLock,
52 OnRequestWakeLockScreen(message.routing_id()))
53 IPC_MESSAGE_HANDLER_GENERIC(WakeLockScreenViewHostMsg_RequestUnlock,
54 OnRequestWakeUnlockScreen(message.routing_id()))
55 IPC_MESSAGE_UNHANDLED(handled = false)
56 IPC_END_MESSAGE_MAP()
57 return handled;
58 }
59
60 void WakeLockDispatcherHost::OnRequestWakeLockScreen(int routed_id) {
61 GURL requesting_frame;
62 if (wakelock_permission_context_.get()) {
63 wakelock_permission_context_->RequestWakeLockPermission(
64 render_process_id_,
65 routed_id,
66 requesting_frame,
67 base::Bind(&SendWakeLockPermissionResponse,
68 render_process_id_,
69 routed_id));
70 } else {
71 BrowserThread::PostTask(
72 BrowserThread::UI, FROM_HERE,
73 base::Bind(&SendWakeLockPermissionResponse, render_process_id_,
74 routed_id, true));
75 }
76 }
77
78 void WakeLockDispatcherHost::OnRequestWakeUnlockScreen(int routed_id) {
79 bool isUnlocked = WakeLockManager::GetInstance()->releaseScreenLock(
80 render_process_id_, routed_id);
81 if (isUnlocked)
82 Send(new WakeLockScreenViewMsg_UnlockedSuccessful(routed_id));
83 else
84 Send(new WakeLockScreenViewMsg_UnlockedFailed(routed_id));
85 }
86 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698