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

Side by Side Diff: ppapi/proxy/gamepad_resource.cc

Issue 11022005: Converted PluginResource reply message handling to use base::Callback (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 2 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 | Annotate | Revision Log
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 "ppapi/proxy/gamepad_resource.h" 5 #include "ppapi/proxy/gamepad_resource.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 8
9 #include "base/bind.h"
9 #include "base/threading/platform_thread.h" 10 #include "base/threading/platform_thread.h"
10 #include "ppapi/proxy/dispatch_reply_message.h" 11 #include "ppapi/proxy/dispatch_reply_message.h"
11 #include "ppapi/proxy/ppapi_messages.h" 12 #include "ppapi/proxy/ppapi_messages.h"
12 #include "ppapi/shared_impl/ppb_gamepad_shared.h" 13 #include "ppapi/shared_impl/ppb_gamepad_shared.h"
13 14
14 namespace ppapi { 15 namespace ppapi {
15 namespace proxy { 16 namespace proxy {
16 17
17 namespace { 18 namespace {
18 19
(...skipping 22 matching lines...) Expand all
41 } 42 }
42 43
43 } // namespace 44 } // namespace
44 45
45 GamepadResource::GamepadResource(Connection connection, PP_Instance instance) 46 GamepadResource::GamepadResource(Connection connection, PP_Instance instance)
46 : PluginResource(connection, instance), 47 : PluginResource(connection, instance),
47 buffer_(NULL) { 48 buffer_(NULL) {
48 memset(&last_read_, 0, sizeof(last_read_)); 49 memset(&last_read_, 0, sizeof(last_read_));
49 50
50 SendCreateToBrowser(PpapiHostMsg_Gamepad_Create()); 51 SendCreateToBrowser(PpapiHostMsg_Gamepad_Create());
51 CallBrowser(PpapiHostMsg_Gamepad_RequestMemory()); 52 CallBrowser<PpapiPluginMsg_Gamepad_SendMemory>(
53 PpapiHostMsg_Gamepad_RequestMemory(),
54 base::Bind(&GamepadResource::OnPluginMsgSendMemory, this));
52 } 55 }
53 56
54 GamepadResource::~GamepadResource() { 57 GamepadResource::~GamepadResource() {
55 } 58 }
56 59
57 void GamepadResource::Sample(PP_GamepadsSampleData* data) { 60 void GamepadResource::Sample(PP_GamepadsSampleData* data) {
58 if (!buffer_) { 61 if (!buffer_) {
59 // Browser hasn't sent back our shared memory, give the plugin gamepad 62 // Browser hasn't sent back our shared memory, give the plugin gamepad
60 // data corresponding to "not connected". 63 // data corresponding to "not connected".
61 memset(data, 0, sizeof(PP_GamepadsSampleData)); 64 memset(data, 0, sizeof(PP_GamepadsSampleData));
(...skipping 22 matching lines...) Expand all
84 } while (ReadRetry(&buffer_->sequence, version)); 87 } while (ReadRetry(&buffer_->sequence, version));
85 88
86 // In the event of a read failure, just leave the last read data as-is (the 89 // In the event of a read failure, just leave the last read data as-is (the
87 // hardware thread is taking unusally long). 90 // hardware thread is taking unusally long).
88 if (contention_count < kMaximumContentionCount) 91 if (contention_count < kMaximumContentionCount)
89 ConvertWebKitGamepadData(read_into, &last_read_); 92 ConvertWebKitGamepadData(read_into, &last_read_);
90 93
91 memcpy(data, &last_read_, sizeof(PP_GamepadsSampleData)); 94 memcpy(data, &last_read_, sizeof(PP_GamepadsSampleData));
92 } 95 }
93 96
94 void GamepadResource::OnReplyReceived(const ResourceMessageReplyParams& params,
95 const IPC::Message& msg) {
96 IPC_BEGIN_MESSAGE_MAP(GamepadResource, msg)
97 PPAPI_DISPATCH_RESOURCE_REPLY_0(PpapiPluginMsg_Gamepad_SendMemory,
98 OnPluginMsgSendMemory)
99 IPC_END_MESSAGE_MAP()
100 }
101
102 void GamepadResource::OnPluginMsgSendMemory( 97 void GamepadResource::OnPluginMsgSendMemory(
103 const ResourceMessageReplyParams& params) { 98 const ResourceMessageReplyParams& params) {
104 // On failure, the handle will be null and the CHECK below will be tripped. 99 // On failure, the handle will be null and the CHECK below will be tripped.
105 base::SharedMemoryHandle handle; 100 base::SharedMemoryHandle handle;
106 params.GetSharedMemoryHandleAtIndex(0, &handle); 101 params.GetSharedMemoryHandleAtIndex(0, &handle);
107 102
108 shared_memory_.reset(new base::SharedMemory(handle, true)); 103 shared_memory_.reset(new base::SharedMemory(handle, true));
109 CHECK(shared_memory_->Map(sizeof(ContentGamepadHardwareBuffer))); 104 CHECK(shared_memory_->Map(sizeof(ContentGamepadHardwareBuffer)));
110 buffer_ = static_cast<const ContentGamepadHardwareBuffer*>( 105 buffer_ = static_cast<const ContentGamepadHardwareBuffer*>(
111 shared_memory_->memory()); 106 shared_memory_->memory());
112 } 107 }
113 108
114 } // namespace proxy 109 } // namespace proxy
115 } // namespace ppapi 110 } // namespace ppapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698