| OLD | NEW |
| 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 Loading... |
| 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 sync_read_buffer_size = kMaxReturnVarSize; |
| 129 // chances to call RPC. | 131 nacl::scoped_array<char> sync_read_buffer_bytes( |
| 132 new char[sync_read_buffer_size]); |
| 133 |
| 130 int32_t pp_error; | 134 int32_t pp_error; |
| 131 NaClSrpcError srpc_result = | 135 NaClSrpcError srpc_result = |
| 132 PpbWebSocketRpcClient::PPB_WebSocket_ReceiveMessage( | 136 PpbWebSocketRpcClient::PPB_WebSocket_ReceiveMessage( |
| 133 GetMainSrpcChannel(), | 137 GetMainSrpcChannel(), |
| 134 ws, | 138 ws, |
| 135 callback_id, | 139 callback_id, |
| 136 &pp_error); | 140 &pp_error, |
| 141 &sync_read_buffer_size, |
| 142 sync_read_buffer_bytes.get()); |
| 137 DebugPrintf("PPB_WebSocket::ReceiveMessage: %s\n", | 143 DebugPrintf("PPB_WebSocket::ReceiveMessage: %s\n", |
| 138 NaClSrpcErrorString(srpc_result)); | 144 NaClSrpcErrorString(srpc_result)); |
| 139 | 145 |
| 140 if (srpc_result != NACL_SRPC_RESULT_OK) | 146 if (srpc_result != NACL_SRPC_RESULT_OK) |
| 141 pp_error = PP_ERROR_FAILED; | 147 pp_error = PP_ERROR_FAILED; |
| 148 |
| 149 if (pp_error != PP_OK_COMPLETIONPENDING) { |
| 150 // Consumes plugin callback and deserialize received data. |
| 151 void* plugin_buffer; |
| 152 PP_Var* plugin_var; |
| 153 PP_CompletionCallback plugin_callback = |
| 154 CompletionCallbackTable::Get()->RemoveCallback(callback_id, |
| 155 &plugin_buffer, |
| 156 &plugin_var); |
| 157 DCHECK(plugin_callback.func == callback.func); |
| 158 DCHECK(plugin_var == message); |
| 159 if (pp_error == PP_OK) { |
| 160 *message = PP_MakeUndefined(); |
| 161 if (!DeserializeTo(sync_read_buffer_bytes.get(), |
| 162 sync_read_buffer_size, 1, message)) |
| 163 return PP_ERROR_FAILED; |
| 164 } |
| 165 } |
| 166 |
| 142 return MayForceCallback(callback, pp_error); | 167 return MayForceCallback(callback, pp_error); |
| 143 } | 168 } |
| 144 | 169 |
| 145 int32_t SendMessage(PP_Resource ws, | 170 int32_t SendMessage(PP_Resource ws, |
| 146 PP_Var message) { | 171 PP_Var message) { |
| 147 DebugPrintf("PPB_WebSocket::SendMessage: ws=%"NACL_PRId32"\n", ws); | 172 DebugPrintf("PPB_WebSocket::SendMessage: ws=%"NACL_PRId32"\n", ws); |
| 148 | 173 |
| 149 nacl_abi_size_t message_size = 0; | 174 nacl_abi_size_t message_size = 0; |
| 150 nacl::scoped_array<char> message_bytes( | 175 nacl::scoped_array<char> message_bytes( |
| 151 Serialize(&message, 1, &message_size)); | 176 Serialize(&message, 1, &message_size)); |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 &GetCloseWasClean, | 344 &GetCloseWasClean, |
| 320 &GetExtensions, | 345 &GetExtensions, |
| 321 &GetProtocol, | 346 &GetProtocol, |
| 322 &GetReadyState, | 347 &GetReadyState, |
| 323 &GetURL | 348 &GetURL |
| 324 }; | 349 }; |
| 325 return &websocket_interface; | 350 return &websocket_interface; |
| 326 } | 351 } |
| 327 | 352 |
| 328 } // namespace ppapi_proxy | 353 } // namespace ppapi_proxy |
| OLD | NEW |