OLD | NEW |
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 <cstring> | 7 #include <cstring> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "ppapi/c/pp_bool.h" | 10 #include "ppapi/c/pp_bool.h" |
11 #include "ppapi/c/pp_errors.h" | 11 #include "ppapi/c/pp_errors.h" |
12 #include "ppapi/proxy/error_conversion.h" | 12 #include "ppapi/proxy/error_conversion.h" |
13 #include "ppapi/proxy/plugin_globals.h" | 13 #include "ppapi/proxy/plugin_globals.h" |
14 #include "ppapi/proxy/ppapi_messages.h" | 14 #include "ppapi/proxy/ppapi_messages.h" |
| 15 #include "ppapi/proxy/udp_socket_resource_constants.h" |
15 #include "ppapi/shared_impl/socket_option_data.h" | 16 #include "ppapi/shared_impl/socket_option_data.h" |
16 #include "ppapi/thunk/enter.h" | 17 #include "ppapi/thunk/enter.h" |
17 | 18 |
18 namespace ppapi { | 19 namespace ppapi { |
19 namespace proxy { | 20 namespace proxy { |
20 | 21 |
21 const int32_t UDPSocketResourceBase::kMaxWriteSize = 128 * 1024; | |
22 const int32_t UDPSocketResourceBase::kMaxSendBufferSize = | |
23 1024 * UDPSocketResourceBase::kMaxWriteSize; | |
24 const size_t UDPSocketResourceBase::kPluginSendBufferSlots = 8u; | |
25 | |
26 namespace { | 22 namespace { |
27 | 23 |
28 void RunCallback(scoped_refptr<TrackedCallback> callback, | 24 void RunCallback(scoped_refptr<TrackedCallback> callback, |
29 int32_t pp_result, | 25 int32_t pp_result, |
30 bool private_api) { | 26 bool private_api) { |
31 callback->Run(ConvertNetworkAPIErrorForCompatibility(pp_result, private_api)); | 27 callback->Run(ConvertNetworkAPIErrorForCompatibility(pp_result, private_api)); |
32 } | 28 } |
33 | 29 |
34 void PostAbortIfNecessary(const scoped_refptr<TrackedCallback>& callback) { | 30 void PostAbortIfNecessary(const scoped_refptr<TrackedCallback>& callback) { |
35 if (TrackedCallback::IsPending(callback)) | 31 if (TrackedCallback::IsPending(callback)) |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 | 182 |
187 int32_t UDPSocketResourceBase::SendToImpl( | 183 int32_t UDPSocketResourceBase::SendToImpl( |
188 const char* buffer, | 184 const char* buffer, |
189 int32_t num_bytes, | 185 int32_t num_bytes, |
190 const PP_NetAddress_Private* addr, | 186 const PP_NetAddress_Private* addr, |
191 scoped_refptr<TrackedCallback> callback) { | 187 scoped_refptr<TrackedCallback> callback) { |
192 if (!buffer || num_bytes <= 0 || !addr) | 188 if (!buffer || num_bytes <= 0 || !addr) |
193 return PP_ERROR_BADARGUMENT; | 189 return PP_ERROR_BADARGUMENT; |
194 if (!bound_) | 190 if (!bound_) |
195 return PP_ERROR_FAILED; | 191 return PP_ERROR_FAILED; |
196 if (sendto_callbacks_.size() == kPluginSendBufferSlots) | 192 if (sendto_callbacks_.size() == |
| 193 UDPSocketResourceConstants::kPluginSendBufferSlots) |
197 return PP_ERROR_INPROGRESS; | 194 return PP_ERROR_INPROGRESS; |
198 | 195 |
199 if (num_bytes > kMaxWriteSize) | 196 if (num_bytes > UDPSocketResourceConstants::kMaxWriteSize) |
200 num_bytes = kMaxWriteSize; | 197 num_bytes = UDPSocketResourceConstants::kMaxWriteSize; |
201 | 198 |
202 sendto_callbacks_.push(callback); | 199 sendto_callbacks_.push(callback); |
203 | 200 |
204 // Send the request, the browser will call us back via SendToReply. | 201 // Send the request, the browser will call us back via SendToReply. |
205 Call<PpapiPluginMsg_UDPSocket_SendToReply>( | 202 Call<PpapiPluginMsg_UDPSocket_SendToReply>( |
206 BROWSER, | 203 BROWSER, |
207 PpapiHostMsg_UDPSocket_SendTo(std::string(buffer, num_bytes), *addr), | 204 PpapiHostMsg_UDPSocket_SendTo(std::string(buffer, num_bytes), *addr), |
208 base::Bind(&UDPSocketResourceBase::OnPluginMsgSendToReply, | 205 base::Bind(&UDPSocketResourceBase::OnPluginMsgSendToReply, |
209 base::Unretained(this)), | 206 base::Unretained(this)), |
210 callback); | 207 callback); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 if (enter_private.succeeded()) | 313 if (enter_private.succeeded()) |
317 thiz = static_cast<UDPSocketResourceBase*>(enter_private.resource()); | 314 thiz = static_cast<UDPSocketResourceBase*>(enter_private.resource()); |
318 } | 315 } |
319 | 316 |
320 if (thiz && !thiz->closed_) | 317 if (thiz && !thiz->closed_) |
321 thiz->Post(BROWSER, PpapiHostMsg_UDPSocket_RecvSlotAvailable()); | 318 thiz->Post(BROWSER, PpapiHostMsg_UDPSocket_RecvSlotAvailable()); |
322 } | 319 } |
323 | 320 |
324 } // namespace proxy | 321 } // namespace proxy |
325 } // namespace ppapi | 322 } // namespace ppapi |
OLD | NEW |