Chromium Code Reviews| 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <cstring> | 8 #include <cstring> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 61 } | 61 } |
| 62 | 62 |
| 63 int32_t UDPSocketResourceBase::SetOptionImpl( | 63 int32_t UDPSocketResourceBase::SetOptionImpl( |
| 64 PP_UDPSocket_Option name, | 64 PP_UDPSocket_Option name, |
| 65 const PP_Var& value, | 65 const PP_Var& value, |
| 66 bool check_bind_state, | 66 bool check_bind_state, |
| 67 scoped_refptr<TrackedCallback> callback) { | 67 scoped_refptr<TrackedCallback> callback) { |
| 68 if (closed_) | 68 if (closed_) |
| 69 return PP_ERROR_FAILED; | 69 return PP_ERROR_FAILED; |
| 70 | 70 |
| 71 SocketOptionData option_data; | 71 // Check if socket is expected to be bound or not according to the option |
|
bbudge
2015/02/13 00:03:16
nit: period at end of sentence.
etrunko
2015/02/13 20:19:58
Done.
| |
| 72 switch (name) { | 72 switch (name) { |
| 73 case PP_UDPSOCKET_OPTION_ADDRESS_REUSE: | 73 case PP_UDPSOCKET_OPTION_ADDRESS_REUSE: |
| 74 case PP_UDPSOCKET_OPTION_BROADCAST: { | 74 check_bind_state = true; // fallthrough |
| 75 if ((check_bind_state || name == PP_UDPSOCKET_OPTION_ADDRESS_REUSE) && | 75 case PP_UDPSOCKET_OPTION_BROADCAST: |
| 76 bind_called_) { | 76 case PP_UDPSOCKET_OPTION_MULTICAST_LOOP: |
| 77 case PP_UDPSOCKET_OPTION_MULTICAST_TTL: { | |
| 78 if (check_bind_state && bind_called_) { | |
| 77 // SetOption should fail in this case in order to give predictable | 79 // SetOption should fail in this case in order to give predictable |
| 78 // behavior while binding. Note that we use |bind_called_| rather | 80 // behavior while binding. Note that we use |bind_called_| rather |
| 79 // than |bound_| since the latter is only set on successful completion | 81 // than |bound_| since the latter is only set on successful completion |
| 80 // of Bind(). | 82 // of Bind(). |
| 81 return PP_ERROR_FAILED; | 83 return PP_ERROR_FAILED; |
| 82 } | 84 } |
| 85 break; | |
| 86 } | |
| 87 case PP_UDPSOCKET_OPTION_SEND_BUFFER_SIZE: | |
| 88 case PP_UDPSOCKET_OPTION_RECV_BUFFER_SIZE: { | |
| 89 if (check_bind_state && !bound_) | |
| 90 return PP_ERROR_FAILED; | |
| 91 break; | |
| 92 } | |
| 93 } | |
| 94 | |
| 95 SocketOptionData option_data; | |
| 96 switch (name) { | |
| 97 case PP_UDPSOCKET_OPTION_ADDRESS_REUSE: | |
| 98 case PP_UDPSOCKET_OPTION_BROADCAST: | |
| 99 case PP_UDPSOCKET_OPTION_MULTICAST_LOOP: { | |
| 83 if (value.type != PP_VARTYPE_BOOL) | 100 if (value.type != PP_VARTYPE_BOOL) |
| 84 return PP_ERROR_BADARGUMENT; | 101 return PP_ERROR_BADARGUMENT; |
| 85 option_data.SetBool(PP_ToBool(value.value.as_bool)); | 102 option_data.SetBool(PP_ToBool(value.value.as_bool)); |
| 86 break; | 103 break; |
| 87 } | 104 } |
| 88 case PP_UDPSOCKET_OPTION_SEND_BUFFER_SIZE: | 105 case PP_UDPSOCKET_OPTION_SEND_BUFFER_SIZE: |
| 89 case PP_UDPSOCKET_OPTION_RECV_BUFFER_SIZE: { | 106 case PP_UDPSOCKET_OPTION_RECV_BUFFER_SIZE: { |
| 90 if (check_bind_state && !bound_) | |
| 91 return PP_ERROR_FAILED; | |
| 92 if (value.type != PP_VARTYPE_INT32) | 107 if (value.type != PP_VARTYPE_INT32) |
| 93 return PP_ERROR_BADARGUMENT; | 108 return PP_ERROR_BADARGUMENT; |
| 94 option_data.SetInt32(value.value.as_int); | 109 option_data.SetInt32(value.value.as_int); |
| 95 break; | 110 break; |
| 96 } | 111 } |
| 112 case PP_UDPSOCKET_OPTION_MULTICAST_TTL: { | |
| 113 int32_t ival = value.value.as_int; | |
| 114 if (value.type != PP_VARTYPE_INT32 && (ival < 0 || ival > 255)) | |
| 115 return PP_ERROR_BADARGUMENT; | |
| 116 option_data.SetInt32(ival); | |
| 117 break; | |
| 118 } | |
| 97 default: { | 119 default: { |
| 98 NOTREACHED(); | 120 NOTREACHED(); |
| 99 return PP_ERROR_BADARGUMENT; | 121 return PP_ERROR_BADARGUMENT; |
| 100 } | 122 } |
| 101 } | 123 } |
| 102 | 124 |
| 103 Call<PpapiPluginMsg_UDPSocket_SetOptionReply>( | 125 Call<PpapiPluginMsg_UDPSocket_SetOptionReply>( |
| 104 BROWSER, | 126 BROWSER, |
| 105 PpapiHostMsg_UDPSocket_SetOption(name, option_data), | 127 PpapiHostMsg_UDPSocket_SetOption(name, option_data), |
| 106 base::Bind(&UDPSocketResourceBase::OnPluginMsgSetOptionReply, | 128 base::Bind(&UDPSocketResourceBase::OnPluginMsgSetOptionReply, |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 226 while (!sendto_callbacks_.empty()) { | 248 while (!sendto_callbacks_.empty()) { |
| 227 scoped_refptr<TrackedCallback> callback = sendto_callbacks_.front(); | 249 scoped_refptr<TrackedCallback> callback = sendto_callbacks_.front(); |
| 228 sendto_callbacks_.pop(); | 250 sendto_callbacks_.pop(); |
| 229 PostAbortIfNecessary(&callback); | 251 PostAbortIfNecessary(&callback); |
| 230 } | 252 } |
| 231 | 253 |
| 232 read_buffer_ = NULL; | 254 read_buffer_ = NULL; |
| 233 bytes_to_read_ = -1; | 255 bytes_to_read_ = -1; |
| 234 } | 256 } |
| 235 | 257 |
| 258 int32_t UDPSocketResourceBase::JoinGroupImpl( | |
| 259 const PP_NetAddress_Private *group, | |
| 260 scoped_refptr<TrackedCallback> callback) { | |
| 261 if (!group) | |
| 262 return PP_ERROR_BADARGUMENT; | |
|
bbudge
2015/02/13 00:03:16
A plugin error isn't quite right here, because the
etrunko
2015/02/13 20:19:58
Done.
| |
| 263 | |
| 264 Call<PpapiPluginMsg_UDPSocket_JoinGroupReply>( | |
| 265 BROWSER, | |
| 266 PpapiHostMsg_UDPSocket_JoinGroup(*group), | |
| 267 base::Bind(&UDPSocketResourceBase::OnPluginMsgSetOptionReply, | |
|
bbudge
2015/02/13 00:03:16
I think at this point we should rename this method
etrunko
2015/02/13 20:19:58
Done.
I guess so, by the time I wondered if this
| |
| 268 base::Unretained(this), | |
| 269 callback), | |
| 270 callback); | |
| 271 return PP_OK_COMPLETIONPENDING; | |
| 272 } | |
| 273 | |
| 274 int32_t UDPSocketResourceBase::LeaveGroupImpl( | |
| 275 const PP_NetAddress_Private *group, | |
| 276 scoped_refptr<TrackedCallback> callback) { | |
| 277 if (!group) | |
| 278 return PP_ERROR_BADARGUMENT; | |
|
bbudge
2015/02/13 00:03:16
DCHECK
etrunko
2015/02/13 20:19:58
Done.
| |
| 279 | |
| 280 Call<PpapiPluginMsg_UDPSocket_LeaveGroupReply>( | |
| 281 BROWSER, | |
| 282 PpapiHostMsg_UDPSocket_LeaveGroup(*group), | |
| 283 base::Bind(&UDPSocketResourceBase::OnPluginMsgSetOptionReply, | |
| 284 base::Unretained(this), | |
| 285 callback), | |
| 286 callback); | |
| 287 return PP_OK_COMPLETIONPENDING; | |
| 288 } | |
| 289 | |
| 236 void UDPSocketResourceBase::OnReplyReceived( | 290 void UDPSocketResourceBase::OnReplyReceived( |
| 237 const ResourceMessageReplyParams& params, | 291 const ResourceMessageReplyParams& params, |
| 238 const IPC::Message& msg) { | 292 const IPC::Message& msg) { |
| 239 PPAPI_BEGIN_MESSAGE_MAP(UDPSocketResourceBase, msg) | 293 PPAPI_BEGIN_MESSAGE_MAP(UDPSocketResourceBase, msg) |
| 240 PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL( | 294 PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL( |
| 241 PpapiPluginMsg_UDPSocket_PushRecvResult, | 295 PpapiPluginMsg_UDPSocket_PushRecvResult, |
| 242 OnPluginMsgPushRecvResult) | 296 OnPluginMsgPushRecvResult) |
| 243 PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL_UNHANDLED( | 297 PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL_UNHANDLED( |
| 244 PluginResource::OnReplyReceived(params, msg)) | 298 PluginResource::OnReplyReceived(params, msg)) |
| 245 PPAPI_END_MESSAGE_MAP() | 299 PPAPI_END_MESSAGE_MAP() |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 365 if (result == PP_OK && !data.empty()) | 419 if (result == PP_OK && !data.empty()) |
| 366 memcpy(output_buffer, data.c_str(), data.size()); | 420 memcpy(output_buffer, data.c_str(), data.size()); |
| 367 | 421 |
| 368 recvfrom_addr_ = addr; | 422 recvfrom_addr_ = addr; |
| 369 | 423 |
| 370 return result == PP_OK ? static_cast<int32_t>(data.size()) : result; | 424 return result == PP_OK ? static_cast<int32_t>(data.size()) : result; |
| 371 } | 425 } |
| 372 | 426 |
| 373 } // namespace proxy | 427 } // namespace proxy |
| 374 } // namespace ppapi | 428 } // namespace ppapi |
| OLD | NEW |