Chromium Code Reviews| 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/browser_callback.h" | 5 #include "native_client/src/shared/ppapi_proxy/browser_callback.h" |
| 6 | 6 |
| 7 #include <new> | 7 #include <new> |
| 8 | 8 |
| 9 #include "native_client/src/include/nacl_macros.h" | 9 #include "native_client/src/include/nacl_macros.h" |
| 10 #include "native_client/src/include/nacl_scoped_ptr.h" | 10 #include "native_client/src/include/nacl_scoped_ptr.h" |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 129 | 129 |
| 130 if (bytes_to_read > 0 && buffer != NULL) { | 130 if (bytes_to_read > 0 && buffer != NULL) { |
| 131 *buffer = new(std::nothrow) char[bytes_to_read]; | 131 *buffer = new(std::nothrow) char[bytes_to_read]; |
| 132 if (*buffer == NULL) // new failed. | 132 if (*buffer == NULL) // new failed. |
| 133 return PP_BlockUntilComplete(); | 133 return PP_BlockUntilComplete(); |
| 134 remote_callback->read_buffer = *buffer; | 134 remote_callback->read_buffer = *buffer; |
| 135 } | 135 } |
| 136 if (var) | 136 if (var) |
| 137 *var = &remote_callback->read_var; | 137 *var = &remote_callback->read_var; |
| 138 | 138 |
| 139 // If caller requires to copy data at completion, the callback must be | |
| 140 // asynchronous. Because the copy is performed in RunRemoteCallback. | |
| 141 if ((bytes_to_read > 0 && buffer != NULL) || var) | |
| 142 return PP_MakeCompletionCallback( | |
| 143 RunRemoteCallback, remote_callback.release()); | |
|
dmichael (off chromium)
2012/03/21 19:16:47
This is going to affect URLLoader::ReadResponseBod
| |
| 144 | |
| 139 return PP_MakeOptionalCompletionCallback( | 145 return PP_MakeOptionalCompletionCallback( |
| 140 RunRemoteCallback, remote_callback.release()); | 146 RunRemoteCallback, remote_callback.release()); |
| 141 } | 147 } |
| 142 | 148 |
| 143 struct PP_CompletionCallback MakeRemoteCompletionCallback( | 149 struct PP_CompletionCallback MakeRemoteCompletionCallback( |
| 144 NaClSrpcChannel* srpc_channel, | 150 NaClSrpcChannel* srpc_channel, |
| 145 int32_t callback_id, | 151 int32_t callback_id, |
| 146 int32_t bytes_to_read, | 152 int32_t bytes_to_read, |
| 147 char** buffer, | 153 char** buffer, |
| 148 CheckResultFunc check_result_func, | 154 CheckResultFunc check_result_func, |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 175 return MakeRemoteCompletionCallback(srpc_channel, callback_id, 0, NULL); | 181 return MakeRemoteCompletionCallback(srpc_channel, callback_id, 0, NULL); |
| 176 } | 182 } |
| 177 | 183 |
| 178 void DeleteRemoteCallbackInfo(struct PP_CompletionCallback callback) { | 184 void DeleteRemoteCallbackInfo(struct PP_CompletionCallback callback) { |
| 179 nacl::scoped_ptr<RemoteCallbackInfo> remote_callback( | 185 nacl::scoped_ptr<RemoteCallbackInfo> remote_callback( |
| 180 reinterpret_cast<RemoteCallbackInfo*>(callback.user_data)); | 186 reinterpret_cast<RemoteCallbackInfo*>(callback.user_data)); |
| 181 nacl::scoped_array<char> read_buffer(remote_callback->read_buffer); | 187 nacl::scoped_array<char> read_buffer(remote_callback->read_buffer); |
| 182 } | 188 } |
| 183 | 189 |
| 184 } // namespace ppapi_proxy | 190 } // namespace ppapi_proxy |
| OLD | NEW |