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

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

Issue 22923014: TCPSockets are switched to the new Pepper proxy. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync. Created 7 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « ppapi/proxy/udp_socket_resource_base.h ('k') | ppapi/shared_impl/api_id.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"
11 #include "ppapi/c/pp_bool.h" 11 #include "ppapi/c/pp_bool.h"
12 #include "ppapi/c/pp_completion_callback.h" 12 #include "ppapi/c/pp_completion_callback.h"
13 #include "ppapi/c/pp_errors.h" 13 #include "ppapi/c/pp_errors.h"
14 #include "ppapi/proxy/error_conversion.h"
14 #include "ppapi/proxy/ppapi_messages.h" 15 #include "ppapi/proxy/ppapi_messages.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 #include "ppapi/thunk/resource_creation_api.h" 18 #include "ppapi/thunk/resource_creation_api.h"
18 19
19 namespace ppapi { 20 namespace ppapi {
20 namespace proxy { 21 namespace proxy {
21 22
22 namespace {
23
24 int32_t ConvertPPError(int32_t pp_error, bool private_api) {
25 // The private API doesn't return network-specific error codes or
26 // PP_ERROR_NOACCESS. In order to preserve the behavior, we convert those to
27 // PP_ERROR_FAILED.
28 if (private_api &&
29 (pp_error <= PP_ERROR_CONNECTION_CLOSED ||
30 pp_error == PP_ERROR_NOACCESS)) {
31 return PP_ERROR_FAILED;
32 }
33
34 return pp_error;
35 }
36
37 } // namespace
38
39 const int32_t UDPSocketResourceBase::kMaxReadSize = 1024 * 1024; 23 const int32_t UDPSocketResourceBase::kMaxReadSize = 1024 * 1024;
40 const int32_t UDPSocketResourceBase::kMaxWriteSize = 1024 * 1024; 24 const int32_t UDPSocketResourceBase::kMaxWriteSize = 1024 * 1024;
41 const int32_t UDPSocketResourceBase::kMaxSendBufferSize = 25 const int32_t UDPSocketResourceBase::kMaxSendBufferSize =
42 1024 * UDPSocketResourceBase::kMaxWriteSize; 26 1024 * UDPSocketResourceBase::kMaxWriteSize;
43 const int32_t UDPSocketResourceBase::kMaxReceiveBufferSize = 27 const int32_t UDPSocketResourceBase::kMaxReceiveBufferSize =
44 1024 * UDPSocketResourceBase::kMaxReadSize; 28 1024 * UDPSocketResourceBase::kMaxReadSize;
45 29
46 30
47 UDPSocketResourceBase::UDPSocketResourceBase(Connection connection, 31 UDPSocketResourceBase::UDPSocketResourceBase(Connection connection,
48 PP_Instance instance, 32 PP_Instance instance,
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 void UDPSocketResourceBase::PostAbortIfNecessary( 204 void UDPSocketResourceBase::PostAbortIfNecessary(
221 scoped_refptr<TrackedCallback>* callback) { 205 scoped_refptr<TrackedCallback>* callback) {
222 if (TrackedCallback::IsPending(*callback)) 206 if (TrackedCallback::IsPending(*callback))
223 (*callback)->PostAbort(); 207 (*callback)->PostAbort();
224 } 208 }
225 209
226 void UDPSocketResourceBase::OnPluginMsgSetOptionReply( 210 void UDPSocketResourceBase::OnPluginMsgSetOptionReply(
227 scoped_refptr<TrackedCallback> callback, 211 scoped_refptr<TrackedCallback> callback,
228 const ResourceMessageReplyParams& params) { 212 const ResourceMessageReplyParams& params) {
229 if (TrackedCallback::IsPending(callback)) 213 if (TrackedCallback::IsPending(callback))
230 callback->Run(ConvertPPError(params.result(), private_api_)); 214 RunCallback(callback, params.result());
231 } 215 }
232 216
233 void UDPSocketResourceBase::OnPluginMsgBindReply( 217 void UDPSocketResourceBase::OnPluginMsgBindReply(
234 const ResourceMessageReplyParams& params, 218 const ResourceMessageReplyParams& params,
235 const PP_NetAddress_Private& bound_addr) { 219 const PP_NetAddress_Private& bound_addr) {
236 // It is possible that |bind_callback_| is pending while |closed_| is true: 220 // It is possible that |bind_callback_| is pending while |closed_| is true:
237 // CloseImpl() has been called, but a BindReply came earlier than the task to 221 // CloseImpl() has been called, but a BindReply came earlier than the task to
238 // abort |bind_callback_|. We don't want to update |bound_| or |bound_addr_| 222 // abort |bind_callback_|. We don't want to update |bound_| or |bound_addr_|
239 // in that case. 223 // in that case.
240 if (!TrackedCallback::IsPending(bind_callback_) || closed_) 224 if (!TrackedCallback::IsPending(bind_callback_) || closed_)
241 return; 225 return;
242 226
243 if (params.result() == PP_OK) 227 if (params.result() == PP_OK)
244 bound_ = true; 228 bound_ = true;
245 bound_addr_ = bound_addr; 229 bound_addr_ = bound_addr;
246 bind_callback_->Run(ConvertPPError(params.result(), private_api_)); 230 RunCallback(bind_callback_, params.result());
247 } 231 }
248 232
249 void UDPSocketResourceBase::OnPluginMsgRecvFromReply( 233 void UDPSocketResourceBase::OnPluginMsgRecvFromReply(
250 PP_Resource* output_addr, 234 PP_Resource* output_addr,
251 const ResourceMessageReplyParams& params, 235 const ResourceMessageReplyParams& params,
252 const std::string& data, 236 const std::string& data,
253 const PP_NetAddress_Private& addr) { 237 const PP_NetAddress_Private& addr) {
254 // It is possible that |recvfrom_callback_| is pending while |read_buffer_| is 238 // It is possible that |recvfrom_callback_| is pending while |read_buffer_| is
255 // NULL: CloseImpl() has been called, but a RecvFromReply came earlier than 239 // NULL: CloseImpl() has been called, but a RecvFromReply came earlier than
256 // the task to abort |recvfrom_callback_|. We shouldn't access the buffer in 240 // the task to abort |recvfrom_callback_|. We shouldn't access the buffer in
(...skipping 16 matching lines...) Expand all
273 CHECK_LE(static_cast<int32_t>(data.size()), bytes_to_read_); 257 CHECK_LE(static_cast<int32_t>(data.size()), bytes_to_read_);
274 if (!data.empty()) 258 if (!data.empty())
275 memcpy(read_buffer_, data.c_str(), data.size()); 259 memcpy(read_buffer_, data.c_str(), data.size());
276 } 260 }
277 261
278 read_buffer_ = NULL; 262 read_buffer_ = NULL;
279 bytes_to_read_ = -1; 263 bytes_to_read_ = -1;
280 recvfrom_addr_ = addr; 264 recvfrom_addr_ = addr;
281 265
282 if (result == PP_OK) 266 if (result == PP_OK)
283 recvfrom_callback_->Run(static_cast<int32_t>(data.size())); 267 RunCallback(recvfrom_callback_, static_cast<int32_t>(data.size()));
284 else 268 else
285 recvfrom_callback_->Run(ConvertPPError(result, private_api_)); 269 RunCallback(recvfrom_callback_, result);
286 } 270 }
287 271
288 void UDPSocketResourceBase::OnPluginMsgSendToReply( 272 void UDPSocketResourceBase::OnPluginMsgSendToReply(
289 const ResourceMessageReplyParams& params, 273 const ResourceMessageReplyParams& params,
290 int32_t bytes_written) { 274 int32_t bytes_written) {
291 if (!TrackedCallback::IsPending(sendto_callback_)) 275 if (!TrackedCallback::IsPending(sendto_callback_))
292 return; 276 return;
293 277
294 if (params.result() == PP_OK) 278 if (params.result() == PP_OK)
295 sendto_callback_->Run(bytes_written); 279 RunCallback(sendto_callback_, bytes_written);
296 else 280 else
297 sendto_callback_->Run(ConvertPPError(params.result(), private_api_)); 281 RunCallback(sendto_callback_, params.result());
282 }
283
284 void UDPSocketResourceBase::RunCallback(scoped_refptr<TrackedCallback> callback,
285 int32_t pp_result) {
286 callback->Run(ConvertNetworkAPIErrorForCompatibility(pp_result,
287 private_api_));
298 } 288 }
299 289
300 } // namespace proxy 290 } // namespace proxy
301 } // namespace ppapi 291 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/proxy/udp_socket_resource_base.h ('k') | ppapi/shared_impl/api_id.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698