Chromium Code Reviews| Index: ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_websocket.cc |
| diff --git a/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_websocket.cc b/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_websocket.cc |
| index 1fdbf2cca27984223d5bdc0f30f7edefbbfe21e7..39159aabf4396bb203450ef553ed19c3ae8f27b1 100644 |
| --- a/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_websocket.cc |
| +++ b/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_websocket.cc |
| @@ -120,25 +120,54 @@ int32_t ReceiveMessage(PP_Resource ws, |
| PP_CompletionCallback callback) { |
| DebugPrintf("PPB_WebSocket::ReceiveMessage: ws=%"NACL_PRId32"\n", ws); |
| + if (message == NULL) |
| + return PP_ERROR_FAILED; |
| int32_t callback_id = |
| CompletionCallbackTable::Get()->AddCallback(callback, message); |
| if (callback_id == 0) |
| return PP_ERROR_BLOCKS_MAIN_THREAD; |
| - // TODO(toyoshim): ReceiveMessage needs performance optimization to reduce |
| - // chances to call RPC. |
| + nacl_abi_size_t async_message_size = kMaxReturnVarSize; |
| + nacl::scoped_array<char> async_message_bytes(new char[async_message_size]); |
| + |
| int32_t pp_error; |
| NaClSrpcError srpc_result = |
| PpbWebSocketRpcClient::PPB_WebSocket_ReceiveMessage( |
| GetMainSrpcChannel(), |
| ws, |
| callback_id, |
| - &pp_error); |
| + &pp_error, |
| + &async_message_size, |
| + async_message_bytes.get()); |
| DebugPrintf("PPB_WebSocket::ReceiveMessage: %s\n", |
| NaClSrpcErrorString(srpc_result)); |
| if (srpc_result != NACL_SRPC_RESULT_OK) |
| pp_error = PP_ERROR_FAILED; |
| + |
| + if (pp_error != PP_OK_COMPLETIONPENDING) { |
| + // Consumes plugin callback and deserialize received data. |
| + void* plugin_buffer; |
| + PP_Var* plugin_var; |
| + PP_CompletionCallback plugin_callback = |
| + CompletionCallbackTable::Get()->RemoveCallback(callback_id, |
| + &plugin_buffer, |
| + &plugin_var); |
| + if (plugin_callback.func != callback.func) { |
| + DebugPrintf("PPB_WebSocket::ReceiveMessage: callbacks doesn't match\n"); |
| + } else if (plugin_var != message) { |
| + 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
|
| + } else { |
| + DebugPrintf("PPB_WebSocket::ReceiveMessage: asynchronous completion\n"); |
| + if (pp_error == PP_OK) { |
| + *message = PP_MakeUndefined(); |
| + if (!DeserializeTo(async_message_bytes.get(), async_message_size, 1, |
| + message)) |
| + return PP_ERROR_FAILED; |
| + } |
| + } |
| + } |
| + |
| return MayForceCallback(callback, pp_error); |
| } |