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

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

Issue 9802027: WebSocket Pepper API: synchronous completion support (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 8 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
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 "native_client/src/shared/ppapi_proxy/plugin_ppb_websocket.h" 5 #include "native_client/src/shared/ppapi_proxy/plugin_ppb_websocket.h"
6 6
7 #include "native_client/src/include/nacl_scoped_ptr.h" 7 #include "native_client/src/include/nacl_scoped_ptr.h"
8 #include "native_client/src/shared/ppapi_proxy/object_serialize.h" 8 #include "native_client/src/shared/ppapi_proxy/object_serialize.h"
9 #include "native_client/src/shared/ppapi_proxy/plugin_callback.h" 9 #include "native_client/src/shared/ppapi_proxy/plugin_callback.h"
10 #include "native_client/src/shared/ppapi_proxy/plugin_globals.h" 10 #include "native_client/src/shared/ppapi_proxy/plugin_globals.h"
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 if (srpc_result != NACL_SRPC_RESULT_OK) 113 if (srpc_result != NACL_SRPC_RESULT_OK)
114 pp_error = PP_ERROR_FAILED; 114 pp_error = PP_ERROR_FAILED;
115 return MayForceCallback(callback, pp_error); 115 return MayForceCallback(callback, pp_error);
116 } 116 }
117 117
118 int32_t ReceiveMessage(PP_Resource ws, 118 int32_t ReceiveMessage(PP_Resource ws,
119 PP_Var* message, 119 PP_Var* message,
120 PP_CompletionCallback callback) { 120 PP_CompletionCallback callback) {
121 DebugPrintf("PPB_WebSocket::ReceiveMessage: ws=%"NACL_PRId32"\n", ws); 121 DebugPrintf("PPB_WebSocket::ReceiveMessage: ws=%"NACL_PRId32"\n", ws);
122 122
123 if (message == NULL)
124 return PP_ERROR_FAILED;
123 int32_t callback_id = 125 int32_t callback_id =
124 CompletionCallbackTable::Get()->AddCallback(callback, message); 126 CompletionCallbackTable::Get()->AddCallback(callback, message);
125 if (callback_id == 0) 127 if (callback_id == 0)
126 return PP_ERROR_BLOCKS_MAIN_THREAD; 128 return PP_ERROR_BLOCKS_MAIN_THREAD;
127 129
128 // TODO(toyoshim): ReceiveMessage needs performance optimization to reduce 130 nacl_abi_size_t async_message_size = kMaxReturnVarSize;
129 // chances to call RPC. 131 nacl::scoped_array<char> async_message_bytes(new char[async_message_size]);
132
130 int32_t pp_error; 133 int32_t pp_error;
131 NaClSrpcError srpc_result = 134 NaClSrpcError srpc_result =
132 PpbWebSocketRpcClient::PPB_WebSocket_ReceiveMessage( 135 PpbWebSocketRpcClient::PPB_WebSocket_ReceiveMessage(
133 GetMainSrpcChannel(), 136 GetMainSrpcChannel(),
134 ws, 137 ws,
135 callback_id, 138 callback_id,
136 &pp_error); 139 &pp_error,
140 &async_message_size,
141 async_message_bytes.get());
137 DebugPrintf("PPB_WebSocket::ReceiveMessage: %s\n", 142 DebugPrintf("PPB_WebSocket::ReceiveMessage: %s\n",
138 NaClSrpcErrorString(srpc_result)); 143 NaClSrpcErrorString(srpc_result));
139 144
140 if (srpc_result != NACL_SRPC_RESULT_OK) 145 if (srpc_result != NACL_SRPC_RESULT_OK)
141 pp_error = PP_ERROR_FAILED; 146 pp_error = PP_ERROR_FAILED;
147
148 if (pp_error != PP_OK_COMPLETIONPENDING) {
149 // Consumes plugin callback and deserialize received data.
150 void* plugin_buffer;
151 PP_Var* plugin_var;
152 PP_CompletionCallback plugin_callback =
153 CompletionCallbackTable::Get()->RemoveCallback(callback_id,
154 &plugin_buffer,
155 &plugin_var);
156 if (plugin_callback.func != callback.func) {
157 DebugPrintf("PPB_WebSocket::ReceiveMessage: callbacks doesn't match\n");
158 } else if (plugin_var != message) {
159 DebugPrintf("PPB_WebSocket::ReceiveMessage: PP_Var doesn't match\n");
dmichael (off chromium) 2012/04/02 03:28:01 These two checks are just temporary while you debu
Takashi Toyoshima 2012/04/05 06:44:00 Oops... yes that's right. I should use DCHECK here
160 } else {
161 DebugPrintf("PPB_WebSocket::ReceiveMessage: asynchronous completion\n");
162 if (pp_error == PP_OK) {
163 *message = PP_MakeUndefined();
164 if (!DeserializeTo(async_message_bytes.get(), async_message_size, 1,
165 message))
166 return PP_ERROR_FAILED;
167 }
168 }
169 }
170
142 return MayForceCallback(callback, pp_error); 171 return MayForceCallback(callback, pp_error);
143 } 172 }
144 173
145 int32_t SendMessage(PP_Resource ws, 174 int32_t SendMessage(PP_Resource ws,
146 PP_Var message) { 175 PP_Var message) {
147 DebugPrintf("PPB_WebSocket::SendMessage: ws=%"NACL_PRId32"\n", ws); 176 DebugPrintf("PPB_WebSocket::SendMessage: ws=%"NACL_PRId32"\n", ws);
148 177
149 nacl_abi_size_t message_size = 0; 178 nacl_abi_size_t message_size = 0;
150 nacl::scoped_array<char> message_bytes( 179 nacl::scoped_array<char> message_bytes(
151 Serialize(&message, 1, &message_size)); 180 Serialize(&message, 1, &message_size));
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 &GetCloseWasClean, 348 &GetCloseWasClean,
320 &GetExtensions, 349 &GetExtensions,
321 &GetProtocol, 350 &GetProtocol,
322 &GetReadyState, 351 &GetReadyState,
323 &GetURL 352 &GetURL
324 }; 353 };
325 return &websocket_interface; 354 return &websocket_interface;
326 } 355 }
327 356
328 } // namespace ppapi_proxy 357 } // namespace ppapi_proxy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698