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

Side by Side Diff: ppapi/proxy/udp_socket_resource_base.cc

Issue 632113003: Pepper: Allow plugins to call PPB_UDP_Socket::SendTo multiple times. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix rebase weirdness. Created 5 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
« no previous file with comments | « ppapi/proxy/udp_socket_resource_base.h ('k') | ppapi/tests/test_udp_socket.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "ppapi/proxy/udp_socket_resource_base.h" 5 #include "ppapi/proxy/udp_socket_resource_base.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cstring> 8 #include <cstring>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 10 matching lines...) Expand all
21 namespace ppapi { 21 namespace ppapi {
22 namespace proxy { 22 namespace proxy {
23 23
24 const int32_t UDPSocketResourceBase::kMaxReadSize = 128 * 1024; 24 const int32_t UDPSocketResourceBase::kMaxReadSize = 128 * 1024;
25 const int32_t UDPSocketResourceBase::kMaxWriteSize = 128 * 1024; 25 const int32_t UDPSocketResourceBase::kMaxWriteSize = 128 * 1024;
26 const int32_t UDPSocketResourceBase::kMaxSendBufferSize = 26 const int32_t UDPSocketResourceBase::kMaxSendBufferSize =
27 1024 * UDPSocketResourceBase::kMaxWriteSize; 27 1024 * UDPSocketResourceBase::kMaxWriteSize;
28 const int32_t UDPSocketResourceBase::kMaxReceiveBufferSize = 28 const int32_t UDPSocketResourceBase::kMaxReceiveBufferSize =
29 1024 * UDPSocketResourceBase::kMaxReadSize; 29 1024 * UDPSocketResourceBase::kMaxReadSize;
30 const size_t UDPSocketResourceBase::kPluginReceiveBufferSlots = 32u; 30 const size_t UDPSocketResourceBase::kPluginReceiveBufferSlots = 32u;
31 const size_t UDPSocketResourceBase::kPluginSendBufferSlots = 8u;
31 32
32 UDPSocketResourceBase::UDPSocketResourceBase(Connection connection, 33 UDPSocketResourceBase::UDPSocketResourceBase(Connection connection,
33 PP_Instance instance, 34 PP_Instance instance,
34 bool private_api) 35 bool private_api)
35 : PluginResource(connection, instance), 36 : PluginResource(connection, instance),
36 private_api_(private_api), 37 private_api_(private_api),
37 bind_called_(false), 38 bind_called_(false),
38 bound_(false), 39 bound_(false),
39 closed_(false), 40 closed_(false),
40 read_buffer_(NULL), 41 read_buffer_(NULL),
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 187
187 int32_t UDPSocketResourceBase::SendToImpl( 188 int32_t UDPSocketResourceBase::SendToImpl(
188 const char* buffer, 189 const char* buffer,
189 int32_t num_bytes, 190 int32_t num_bytes,
190 const PP_NetAddress_Private* addr, 191 const PP_NetAddress_Private* addr,
191 scoped_refptr<TrackedCallback> callback) { 192 scoped_refptr<TrackedCallback> callback) {
192 if (!buffer || num_bytes <= 0 || !addr) 193 if (!buffer || num_bytes <= 0 || !addr)
193 return PP_ERROR_BADARGUMENT; 194 return PP_ERROR_BADARGUMENT;
194 if (!bound_) 195 if (!bound_)
195 return PP_ERROR_FAILED; 196 return PP_ERROR_FAILED;
196 if (TrackedCallback::IsPending(sendto_callback_)) 197 if (sendto_callbacks_.size() == kPluginSendBufferSlots)
197 return PP_ERROR_INPROGRESS; 198 return PP_ERROR_INPROGRESS;
198 199
199 if (num_bytes > kMaxWriteSize) 200 if (num_bytes > kMaxWriteSize)
200 num_bytes = kMaxWriteSize; 201 num_bytes = kMaxWriteSize;
201 202
202 sendto_callback_ = callback; 203 sendto_callbacks_.push(callback);
203 204
204 // Send the request, the browser will call us back via SendToReply. 205 // Send the request, the browser will call us back via SendToReply.
205 Call<PpapiPluginMsg_UDPSocket_SendToReply>( 206 Call<PpapiPluginMsg_UDPSocket_SendToReply>(
206 BROWSER, 207 BROWSER,
207 PpapiHostMsg_UDPSocket_SendTo(std::string(buffer, num_bytes), *addr), 208 PpapiHostMsg_UDPSocket_SendTo(std::string(buffer, num_bytes), *addr),
208 base::Bind(&UDPSocketResourceBase::OnPluginMsgSendToReply, 209 base::Bind(&UDPSocketResourceBase::OnPluginMsgSendToReply,
209 base::Unretained(this)), 210 base::Unretained(this)),
210 callback); 211 callback);
211 return PP_OK_COMPLETIONPENDING; 212 return PP_OK_COMPLETIONPENDING;
212 } 213 }
213 214
214 void UDPSocketResourceBase::CloseImpl() { 215 void UDPSocketResourceBase::CloseImpl() {
215 if(closed_) 216 if(closed_)
216 return; 217 return;
217 218
218 bound_ = false; 219 bound_ = false;
219 closed_ = true; 220 closed_ = true;
220 221
221 Post(BROWSER, PpapiHostMsg_UDPSocket_Close()); 222 Post(BROWSER, PpapiHostMsg_UDPSocket_Close());
222 223
223 PostAbortIfNecessary(&bind_callback_); 224 PostAbortIfNecessary(&bind_callback_);
224 PostAbortIfNecessary(&recvfrom_callback_); 225 PostAbortIfNecessary(&recvfrom_callback_);
225 PostAbortIfNecessary(&sendto_callback_); 226 while (!sendto_callbacks_.empty()) {
227 scoped_refptr<TrackedCallback> callback = sendto_callbacks_.front();
228 sendto_callbacks_.pop();
229 PostAbortIfNecessary(&callback);
230 }
226 231
227 read_buffer_ = NULL; 232 read_buffer_ = NULL;
228 bytes_to_read_ = -1; 233 bytes_to_read_ = -1;
229 } 234 }
230 235
231 void UDPSocketResourceBase::OnReplyReceived( 236 void UDPSocketResourceBase::OnReplyReceived(
232 const ResourceMessageReplyParams& params, 237 const ResourceMessageReplyParams& params,
233 const IPC::Message& msg) { 238 const IPC::Message& msg) {
234 PPAPI_BEGIN_MESSAGE_MAP(UDPSocketResourceBase, msg) 239 PPAPI_BEGIN_MESSAGE_MAP(UDPSocketResourceBase, msg)
235 PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL( 240 PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL(
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 read_buffer_ = NULL; 313 read_buffer_ = NULL;
309 bytes_to_read_ = -1; 314 bytes_to_read_ = -1;
310 recvfrom_addr_resource_ = NULL; 315 recvfrom_addr_resource_ = NULL;
311 316
312 RunCallback(recvfrom_callback_, result); 317 RunCallback(recvfrom_callback_, result);
313 } 318 }
314 319
315 void UDPSocketResourceBase::OnPluginMsgSendToReply( 320 void UDPSocketResourceBase::OnPluginMsgSendToReply(
316 const ResourceMessageReplyParams& params, 321 const ResourceMessageReplyParams& params,
317 int32_t bytes_written) { 322 int32_t bytes_written) {
318 if (!TrackedCallback::IsPending(sendto_callback_)) 323 scoped_refptr<TrackedCallback> callback = sendto_callbacks_.front();
324 sendto_callbacks_.pop();
325 if (!TrackedCallback::IsPending(callback))
319 return; 326 return;
320 327
321 if (params.result() == PP_OK) 328 if (params.result() == PP_OK)
322 RunCallback(sendto_callback_, bytes_written); 329 RunCallback(callback, bytes_written);
323 else 330 else
324 RunCallback(sendto_callback_, params.result()); 331 RunCallback(callback, params.result());
325 } 332 }
326 333
327 void UDPSocketResourceBase::RunCallback(scoped_refptr<TrackedCallback> callback, 334 void UDPSocketResourceBase::RunCallback(scoped_refptr<TrackedCallback> callback,
328 int32_t pp_result) { 335 int32_t pp_result) {
329 callback->Run(ConvertNetworkAPIErrorForCompatibility(pp_result, 336 callback->Run(ConvertNetworkAPIErrorForCompatibility(pp_result,
330 private_api_)); 337 private_api_));
331 } 338 }
332 339
333 int32_t UDPSocketResourceBase::SetRecvFromOutput( 340 int32_t UDPSocketResourceBase::SetRecvFromOutput(
334 int32_t browser_result, 341 int32_t browser_result,
(...skipping 18 matching lines...) Expand all
353 if (result == PP_OK && !data.empty()) 360 if (result == PP_OK && !data.empty())
354 memcpy(output_buffer, data.c_str(), data.size()); 361 memcpy(output_buffer, data.c_str(), data.size());
355 362
356 recvfrom_addr_ = addr; 363 recvfrom_addr_ = addr;
357 364
358 return result == PP_OK ? static_cast<int32_t>(data.size()) : result; 365 return result == PP_OK ? static_cast<int32_t>(data.size()) : result;
359 } 366 }
360 367
361 } // namespace proxy 368 } // namespace proxy
362 } // namespace ppapi 369 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/proxy/udp_socket_resource_base.h ('k') | ppapi/tests/test_udp_socket.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698