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

Side by Side Diff: ppapi/native_client/src/shared/ppapi_proxy/browser_ppb_websocket_rpc_server.cc

Issue 9227008: WebSocket Pepper API: SRPC proxy implementation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase and add TODO for performance optimization Created 8 years, 11 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
(Empty)
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
3 // found in the LICENSE file.
4 //
5 // SRPC-abstraction wrappers around PPB_WebSocket functions.
6
7 #include "native_client/src/include/nacl_scoped_ptr.h"
8 #include "native_client/src/shared/ppapi_proxy/browser_callback.h"
9 #include "native_client/src/shared/ppapi_proxy/browser_globals.h"
10 #include "native_client/src/shared/ppapi_proxy/object_serialize.h"
11 #include "native_client/src/shared/ppapi_proxy/utility.h"
12 #include "ppapi/c/pp_completion_callback.h"
13 #include "ppapi/c/pp_errors.h"
14 #include "ppapi/c/dev/ppb_websocket_dev.h"
15 #include "srpcgen/ppb_rpc.h"
16
17 using ppapi_proxy::DebugPrintf;
18 using ppapi_proxy::DeleteRemoteCallbackInfo;
19 using ppapi_proxy::DeserializeTo;
20 using ppapi_proxy::MakeRemoteCompletionCallback;
21 using ppapi_proxy::PPBWebSocketInterface;
22 using ppapi_proxy::SerializeTo;
23
24 void PpbWebSocketRpcServer::PPB_WebSocket_Create(
25 NaClSrpcRpc* rpc,
26 NaClSrpcClosure* done,
27 // inputs
28 PP_Instance instance,
29 // outputs
30 PP_Resource* resource) {
31 NaClSrpcClosureRunner runner(done);
32 rpc->result = NACL_SRPC_RESULT_APP_ERROR;
33
34 *resource = PPBWebSocketInterface()->Create(instance);
35 DebugPrintf("PPB_WebSocket::Create: resource=%"NACL_PRId32"\n", *resource);
36
37 rpc->result = NACL_SRPC_RESULT_OK;
38 }
39
40 void PpbWebSocketRpcServer::PPB_WebSocket_IsWebSocket(
41 NaClSrpcRpc* rpc,
42 NaClSrpcClosure* done,
43 // inputs
44 PP_Resource resource,
45 // outputs
46 int32_t* success) {
47 NaClSrpcClosureRunner runner(done);
48 rpc->result = NACL_SRPC_RESULT_APP_ERROR;
49
50 PP_Bool pp_success = PPBWebSocketInterface()->IsWebSocket(resource);
51 *success = PP_ToBool(pp_success);
52 DebugPrintf("PPB_WebSocket::IsWebSocket: success=%d\n", *success);
dmichael (off chromium) 2012/01/18 17:04:40 Is it safe to use %d for bool? Generally, sizeof(i
dmichael (off chromium) 2012/01/18 17:07:48 Aaah, nevermind, it's an int32_t, not a bool. You
53 rpc->result = NACL_SRPC_RESULT_OK;
54 }
55
56 void PpbWebSocketRpcServer::PPB_WebSocket_Connect(
57 NaClSrpcRpc* rpc,
58 NaClSrpcClosure* done,
59 // inputs
60 PP_Resource ws,
61 nacl_abi_size_t url_size,
62 char* url_bytes,
63 nacl_abi_size_t protocols_size,
64 char* protocols_bytes,
65 int32_t protocol_count,
66 int32_t callback_id,
67 // outputs
68 int32_t* pp_error) {
69 NaClSrpcClosureRunner runner(done);
70 rpc->result = NACL_SRPC_RESULT_APP_ERROR;
71
72 PP_CompletionCallback remote_callback =
73 MakeRemoteCompletionCallback(rpc->channel, callback_id);
74 if (NULL == remote_callback.func)
75 return;
76
77 PP_Var url;
78 if (!DeserializeTo(url_bytes, url_size, 1, &url))
79 return;
80
81 nacl::scoped_array<PP_Var> protocols(new PP_Var[protocol_count]);
82 if (!DeserializeTo(
83 protocols_bytes, protocols_size, protocol_count, protocols.get()))
84 return;
85
86 *pp_error = PPBWebSocketInterface()->Connect(
87 ws,
88 url,
89 protocols.get(),
90 static_cast<uint32_t>(protocol_count),
91 remote_callback);
92 DebugPrintf("PPB_WebSocket::Connect: pp_error=%"NACL_PRId32"\n", *pp_error);
93
94 if (*pp_error != PP_OK_COMPLETIONPENDING)
95 DeleteRemoteCallbackInfo(remote_callback);
96 rpc->result = NACL_SRPC_RESULT_OK;
97 }
98
99 void PpbWebSocketRpcServer::PPB_WebSocket_Close(
100 NaClSrpcRpc* rpc,
101 NaClSrpcClosure* done,
102 // inputs
103 PP_Resource ws,
104 int32_t code,
105 nacl_abi_size_t reason_size,
106 char* reason_bytes,
107 int32_t callback_id,
108 // outputs
109 int32_t* pp_error) {
110 NaClSrpcClosureRunner runner(done);
111 rpc->result = NACL_SRPC_RESULT_APP_ERROR;
112
113 PP_CompletionCallback remote_callback =
114 MakeRemoteCompletionCallback(rpc->channel, callback_id);
115 if (NULL == remote_callback.func)
116 return;
117
118 PP_Var reason;
119 if (!DeserializeTo(reason_bytes, reason_size, 1, &reason))
120 return;
121
122 *pp_error = PPBWebSocketInterface()->Close(
123 ws, code, reason, remote_callback);
124 DebugPrintf("PPB_WebSocket::Close: pp_error=%"NACL_PRId32"\n", *pp_error);
125
126 if (*pp_error != PP_OK_COMPLETIONPENDING)
127 DeleteRemoteCallbackInfo(remote_callback);
128 rpc->result = NACL_SRPC_RESULT_OK;
129 }
130
131 void PpbWebSocketRpcServer::PPB_WebSocket_ReceiveMessage(
132 NaClSrpcRpc* rpc,
133 NaClSrpcClosure* done,
134 // inputs
135 PP_Resource ws,
136 int32_t callback_id,
137 // outputs
138 int32_t* pp_error) {
139 NaClSrpcClosureRunner runner(done);
140 rpc->result = NACL_SRPC_RESULT_APP_ERROR;
141
142 PP_Var* callback_var = NULL;
143 PP_CompletionCallback remote_callback =
144 MakeRemoteCompletionCallback(rpc->channel, callback_id, &callback_var);
dmichael (off chromium) 2012/01/18 17:04:40 Maybe add a comment somewhere nearby to note that
Takashi Toyoshima 2012/01/19 04:18:57 Done.
145 if (NULL == remote_callback.func)
146 return;
147
148 *pp_error = PPBWebSocketInterface()->ReceiveMessage(
149 ws, callback_var, remote_callback);
150 DebugPrintf("PPB_WebSocket::ReceiveMessage: pp_error=%"NACL_PRId32"\n",
151 *pp_error);
152
153 if (*pp_error != PP_OK_COMPLETIONPENDING)
154 DeleteRemoteCallbackInfo(remote_callback);
155 rpc->result = NACL_SRPC_RESULT_OK;
156 }
157
158 void PpbWebSocketRpcServer::PPB_WebSocket_SendMessage(
159 NaClSrpcRpc* rpc,
160 NaClSrpcClosure* done,
161 // inputs
162 PP_Resource ws,
163 nacl_abi_size_t message_size,
164 char* message_bytes,
165 // outputs
166 int32_t* pp_error) {
167 NaClSrpcClosureRunner runner(done);
168 rpc->result = NACL_SRPC_RESULT_APP_ERROR;
169
170 PP_Var message;
171 if (!DeserializeTo(message_bytes, message_size, 1, &message))
172 return;
173
174 *pp_error = PPBWebSocketInterface()->SendMessage(ws, message);
175 DebugPrintf("PPB_WebSocket::SendMessage: pp_error=%"NACL_PRId32"\n",
176 *pp_error);
177
178 rpc->result = NACL_SRPC_RESULT_OK;
179 }
180
181 void PpbWebSocketRpcServer::PPB_WebSocket_GetBufferedAmount(
182 NaClSrpcRpc* rpc,
183 NaClSrpcClosure* done,
184 // inputs
185 PP_Resource ws,
186 // outputs
187 int64_t* buffered_amount) {
188 NaClSrpcClosureRunner runner(done);
189 rpc->result = NACL_SRPC_RESULT_APP_ERROR;
190
191 *buffered_amount = static_cast<int64_t>(
192 PPBWebSocketInterface()->GetBufferedAmount(ws));
193 DebugPrintf("PPB_WebSocket::GetBufferedAmount: buffered_amount=%lu\n",
194 *buffered_amount);
195
196 rpc->result = NACL_SRPC_RESULT_OK;
197 }
198
199 void PpbWebSocketRpcServer::PPB_WebSocket_GetCloseCode(
200 NaClSrpcRpc* rpc,
201 NaClSrpcClosure* done,
202 // inputs
203 PP_Resource ws,
204 // outputs
205 int32_t* close_code) {
206 NaClSrpcClosureRunner runner(done);
207 rpc->result = NACL_SRPC_RESULT_APP_ERROR;
208
209 *close_code = static_cast<int32_t>(
210 PPBWebSocketInterface()->GetCloseCode(ws));
211 DebugPrintf("PPB_WebSocket::GetCloseCode: close_code=%d\n", *close_code);
212
213 rpc->result = NACL_SRPC_RESULT_OK;
214 }
215
216 void PpbWebSocketRpcServer::PPB_WebSocket_GetCloseReason(
217 NaClSrpcRpc* rpc,
218 NaClSrpcClosure* done,
219 // inputs
220 PP_Resource ws,
221 // outputs
222 nacl_abi_size_t* reason_size,
223 char* reason_bytes) {
224 NaClSrpcClosureRunner runner(done);
225 rpc->result = NACL_SRPC_RESULT_APP_ERROR;
226
227 PP_Var reason = PPBWebSocketInterface()->GetCloseReason(ws);
228 DebugPrintf("PPB_WebSocket::GetCloseReason:: reason.type=%d\n", reason.type);
229
230 if (SerializeTo(&reason, reason_bytes, reason_size))
231 rpc->result = NACL_SRPC_RESULT_OK;
232 }
233
234 void PpbWebSocketRpcServer::PPB_WebSocket_GetCloseWasClean(
235 NaClSrpcRpc* rpc,
236 NaClSrpcClosure* done,
237 // inputs
238 PP_Resource ws,
239 // outputs
240 int32_t* was_clean) {
241 NaClSrpcClosureRunner runner(done);
242 rpc->result = NACL_SRPC_RESULT_APP_ERROR;
243
244 PP_Bool pp_was_clean = PPBWebSocketInterface()->GetCloseWasClean(ws);
245 *was_clean = PP_ToBool(pp_was_clean);
246 DebugPrintf("PPB_WebSocket::GetCloseWasClean: was_clean=%d\n", *was_clean);
247 rpc->result = NACL_SRPC_RESULT_OK;
248 }
249
250 void PpbWebSocketRpcServer::PPB_WebSocket_GetExtensions(
251 NaClSrpcRpc* rpc,
252 NaClSrpcClosure* done,
253 // inputs
254 PP_Resource ws,
255 // outputs
256 nacl_abi_size_t* extensions_size,
257 char* extensions_bytes) {
258 NaClSrpcClosureRunner runner(done);
259 rpc->result = NACL_SRPC_RESULT_APP_ERROR;
260
261 PP_Var extensions = PPBWebSocketInterface()->GetExtensions(ws);
262 DebugPrintf("PPB_WebSocket::GetExtensions:: extensions.type=%d\n",
263 extensions.type);
264
265 if (SerializeTo(&extensions, extensions_bytes, extensions_size))
266 rpc->result = NACL_SRPC_RESULT_OK;
267 }
268
269 void PpbWebSocketRpcServer::PPB_WebSocket_GetProtocol(
270 NaClSrpcRpc* rpc,
271 NaClSrpcClosure* done,
272 // inputs
273 PP_Resource ws,
274 // outputs
275 nacl_abi_size_t* protocol_size,
276 char* protocol_bytes) {
277 NaClSrpcClosureRunner runner(done);
278 rpc->result = NACL_SRPC_RESULT_APP_ERROR;
279
280 PP_Var protocol = PPBWebSocketInterface()->GetProtocol(ws);
281 DebugPrintf("PPB_WebSocket::GetProtocol:: protocol.type=%d\n",
282 protocol.type);
283
284 if (SerializeTo(&protocol, protocol_bytes, protocol_size))
285 rpc->result = NACL_SRPC_RESULT_OK;
286 }
287
288 void PpbWebSocketRpcServer::PPB_WebSocket_GetReadyState(
289 NaClSrpcRpc* rpc,
290 NaClSrpcClosure* done,
291 // inputs
292 PP_Resource ws,
293 // outputs
294 int32_t* ready_state) {
295 NaClSrpcClosureRunner runner(done);
296 rpc->result = NACL_SRPC_RESULT_APP_ERROR;
297
298 *ready_state = static_cast<int32_t>(
299 PPBWebSocketInterface()->GetReadyState(ws));
300 DebugPrintf("PPB_WebSocket::GetReadyState:: ready_state=%d\n", ready_state);
301
302 rpc->result = NACL_SRPC_RESULT_OK;
303 }
304
305 void PpbWebSocketRpcServer::PPB_WebSocket_GetURL(
306 NaClSrpcRpc* rpc,
307 NaClSrpcClosure* done,
308 // inputs
309 PP_Resource ws,
310 // outputs
311 nacl_abi_size_t* url_size,
312 char* url_bytes) {
313 NaClSrpcClosureRunner runner(done);
314 rpc->result = NACL_SRPC_RESULT_APP_ERROR;
315
316 PP_Var url = PPBWebSocketInterface()->GetURL(ws);
317 DebugPrintf("PPB_WebSocket::GetURL:: url.type=%d\n", url.type);
318
319 if (SerializeTo(&url, url_bytes, url_size))
320 rpc->result = NACL_SRPC_RESULT_OK;
321 }
322
323 void PpbWebSocketRpcServer::PPB_WebSocket_SetBinaryType(
324 NaClSrpcRpc* rpc,
325 NaClSrpcClosure* done,
326 // inputs
327 PP_Resource ws,
328 int32_t binary_type,
329 // outputs
330 int32_t* success) {
331 NaClSrpcClosureRunner runner(done);
332 rpc->result = NACL_SRPC_RESULT_APP_ERROR;
333
334 PP_Bool pp_success = PPBWebSocketInterface()->SetBinaryType(
335 ws, static_cast<PP_WebSocketBinaryType_Dev>(binary_type));
336 *success = PP_ToBool(pp_success);
337 DebugPrintf("PPB_WebSocket::SetBinaryType:: success=%d\n", *success);
338
339 rpc->result = NACL_SRPC_RESULT_OK;
340 }
341
342 void PpbWebSocketRpcServer::PPB_WebSocket_GetBinaryType(
343 NaClSrpcRpc* rpc,
344 NaClSrpcClosure* done,
345 // inputs
346 PP_Resource ws,
347 // outputs
348 int32_t* binary_type) {
349 NaClSrpcClosureRunner runner(done);
350 rpc->result = NACL_SRPC_RESULT_APP_ERROR;
351
352 *binary_type = static_cast<int32_t>(
353 PPBWebSocketInterface()->GetBinaryType(ws));
354 DebugPrintf(
355 "PPB_WebSocket::GetBinaryType:: binary_type=%d\n", *binary_type);
356
357 rpc->result = NACL_SRPC_RESULT_OK;
358 }
OLDNEW
« no previous file with comments | « ppapi/native_client/src/shared/ppapi_proxy/browser_globals.cc ('k') | ppapi/native_client/src/shared/ppapi_proxy/build.scons » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698