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

Side by Side Diff: content/browser/renderer_host/pepper/pepper_gamepad_host.cc

Issue 195873019: Gamepad API: add support for connection events (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: and a missing override 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 unified diff | Download patch
« no previous file with comments | « content/browser/renderer_host/pepper/pepper_gamepad_host.h ('k') | content/common/DEPS » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/renderer_host/pepper/pepper_gamepad_host.h" 5 #include "content/browser/renderer_host/pepper/pepper_gamepad_host.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "content/browser/gamepad/gamepad_service.h" 8 #include "content/browser/gamepad/gamepad_service.h"
9 #include "content/public/browser/browser_ppapi_host.h" 9 #include "content/public/browser/browser_ppapi_host.h"
10 #include "ppapi/c/pp_errors.h" 10 #include "ppapi/c/pp_errors.h"
(...skipping 19 matching lines...) Expand all
30 PP_Instance instance, 30 PP_Instance instance,
31 PP_Resource resource) 31 PP_Resource resource)
32 : ResourceHost(host->GetPpapiHost(), instance, resource), 32 : ResourceHost(host->GetPpapiHost(), instance, resource),
33 browser_ppapi_host_(host), 33 browser_ppapi_host_(host),
34 gamepad_service_(gamepad_service), 34 gamepad_service_(gamepad_service),
35 is_started_(false), 35 is_started_(false),
36 weak_factory_(this) {} 36 weak_factory_(this) {}
37 37
38 PepperGamepadHost::~PepperGamepadHost() { 38 PepperGamepadHost::~PepperGamepadHost() {
39 if (is_started_) 39 if (is_started_)
40 gamepad_service_->RemoveConsumer(); 40 gamepad_service_->RemoveConsumer(this);
41 } 41 }
42 42
43 int32_t PepperGamepadHost::OnResourceMessageReceived( 43 int32_t PepperGamepadHost::OnResourceMessageReceived(
44 const IPC::Message& msg, 44 const IPC::Message& msg,
45 ppapi::host::HostMessageContext* context) { 45 ppapi::host::HostMessageContext* context) {
46 IPC_BEGIN_MESSAGE_MAP(PepperGamepadHost, msg) 46 IPC_BEGIN_MESSAGE_MAP(PepperGamepadHost, msg)
47 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_Gamepad_RequestMemory, 47 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_Gamepad_RequestMemory,
48 OnRequestMemory) 48 OnRequestMemory)
49 IPC_END_MESSAGE_MAP() 49 IPC_END_MESSAGE_MAP()
50 return PP_ERROR_FAILED; 50 return PP_ERROR_FAILED;
51 } 51 }
52 52
53 int32_t PepperGamepadHost::OnRequestMemory( 53 int32_t PepperGamepadHost::OnRequestMemory(
54 ppapi::host::HostMessageContext* context) { 54 ppapi::host::HostMessageContext* context) {
55 if (is_started_) 55 if (is_started_)
56 return PP_ERROR_FAILED; 56 return PP_ERROR_FAILED;
57 57
58 gamepad_service_->AddConsumer(); 58 gamepad_service_->ConsumerBecameActive(this);
59 is_started_ = true; 59 is_started_ = true;
60 60
61 // Don't send the shared memory back until the user has interacted with the 61 // Don't send the shared memory back until the user has interacted with the
62 // gamepad. This is to prevent fingerprinting and matches what the web 62 // gamepad. This is to prevent fingerprinting and matches what the web
63 // platform does. 63 // platform does.
64 gamepad_service_->RegisterForUserGesture( 64 gamepad_service_->RegisterForUserGesture(
65 base::Bind(&PepperGamepadHost::GotUserGesture, 65 base::Bind(&PepperGamepadHost::GotUserGesture,
66 weak_factory_.GetWeakPtr(), 66 weak_factory_.GetWeakPtr(),
67 context->MakeReplyMessageContext())); 67 context->MakeReplyMessageContext()));
68 return PP_OK_COMPLETIONPENDING; 68 return PP_OK_COMPLETIONPENDING;
69 } 69 }
70 70
71 void PepperGamepadHost::GotUserGesture( 71 void PepperGamepadHost::GotUserGesture(
72 const ppapi::host::ReplyMessageContext& context) { 72 const ppapi::host::ReplyMessageContext& context) {
73 base::SharedMemoryHandle handle = 73 base::SharedMemoryHandle handle =
74 gamepad_service_->GetSharedMemoryHandleForProcess( 74 gamepad_service_->GetSharedMemoryHandleForProcess(
75 browser_ppapi_host_->GetPluginProcessHandle()); 75 browser_ppapi_host_->GetPluginProcessHandle());
76 76
77 context.params.AppendHandle(ppapi::proxy::SerializedHandle( 77 context.params.AppendHandle(ppapi::proxy::SerializedHandle(
78 handle, sizeof(ppapi::ContentGamepadHardwareBuffer))); 78 handle, sizeof(ppapi::ContentGamepadHardwareBuffer)));
79 host()->SendReply(context, PpapiPluginMsg_Gamepad_SendMemory()); 79 host()->SendReply(context, PpapiPluginMsg_Gamepad_SendMemory());
80 } 80 }
81 81
82 } // namespace content 82 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/pepper/pepper_gamepad_host.h ('k') | content/common/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698