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

Side by Side Diff: content/browser/renderer_host/pepper/pepper_udp_socket_message_filter.cc

Issue 690903002: Remove timing limitation of SetOption invocation for PPAPI sockets. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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
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 "content/browser/renderer_host/pepper/pepper_udp_socket_message_filter. h" 5 #include "content/browser/renderer_host/pepper/pepper_udp_socket_message_filter. h"
6 6
7 #include <cstring> 7 #include <cstring>
8 8
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 26 matching lines...) Expand all
37 size_t g_num_instances = 0; 37 size_t g_num_instances = 0;
38 38
39 } // namespace 39 } // namespace
40 40
41 namespace content { 41 namespace content {
42 42
43 PepperUDPSocketMessageFilter::PepperUDPSocketMessageFilter( 43 PepperUDPSocketMessageFilter::PepperUDPSocketMessageFilter(
44 BrowserPpapiHostImpl* host, 44 BrowserPpapiHostImpl* host,
45 PP_Instance instance, 45 PP_Instance instance,
46 bool private_api) 46 bool private_api)
47 : allow_address_reuse_(false), 47 : socket_options_(0),
48 allow_broadcast_(false),
49 closed_(false), 48 closed_(false),
50 remaining_recv_slots_( 49 remaining_recv_slots_(
51 ppapi::proxy::UDPSocketResourceBase::kPluginReceiveBufferSlots), 50 ppapi::proxy::UDPSocketResourceBase::kPluginReceiveBufferSlots),
52 external_plugin_(host->external_plugin()), 51 external_plugin_(host->external_plugin()),
53 private_api_(private_api), 52 private_api_(private_api),
54 render_process_id_(0), 53 render_process_id_(0),
55 render_frame_id_(0) { 54 render_frame_id_(0) {
56 ++g_num_instances; 55 ++g_num_instances;
57 DCHECK(host); 56 DCHECK(host);
58 57
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 int32_t PepperUDPSocketMessageFilter::OnMsgSetOption( 106 int32_t PepperUDPSocketMessageFilter::OnMsgSetOption(
108 const ppapi::host::HostMessageContext* context, 107 const ppapi::host::HostMessageContext* context,
109 PP_UDPSocket_Option name, 108 PP_UDPSocket_Option name,
110 const ppapi::SocketOptionData& value) { 109 const ppapi::SocketOptionData& value) {
111 DCHECK_CURRENTLY_ON(BrowserThread::IO); 110 DCHECK_CURRENTLY_ON(BrowserThread::IO);
112 111
113 if (closed_) 112 if (closed_)
114 return PP_ERROR_FAILED; 113 return PP_ERROR_FAILED;
115 114
116 switch (name) { 115 switch (name) {
117 case PP_UDPSOCKET_OPTION_ADDRESS_REUSE: 116 case PP_UDPSOCKET_OPTION_ADDRESS_REUSE: {
118 case PP_UDPSOCKET_OPTION_BROADCAST: {
119 if (socket_.get()) {
120 // They only take effect before the socket is bound.
121 return PP_ERROR_FAILED;
122 }
123
124 bool boolean_value = false; 117 bool boolean_value = false;
125 if (!value.GetBool(&boolean_value)) 118 if (!value.GetBool(&boolean_value))
126 return PP_ERROR_BADARGUMENT; 119 return PP_ERROR_BADARGUMENT;
127 120
128 if (name == PP_UDPSOCKET_OPTION_ADDRESS_REUSE) 121 if (socket_.get()) {
129 allow_address_reuse_ = boolean_value; 122 return NetErrorToPepperError(
130 else 123 boolean_value ?
131 allow_broadcast_ = boolean_value; 124 socket_->AllowAddressReuse() : socket_->DisallowAddressReuse());
125 }
126 if (boolean_value) {
127 socket_options_ |= SOCKET_OPTION_ADDRESS_REUSE;
128 } else {
129 socket_options_ &= ~SOCKET_OPTION_ADDRESS_REUSE;
130 }
131 return PP_OK;
132 }
133 case PP_UDPSOCKET_OPTION_BROADCAST: {
134 bool boolean_value = false;
135 if (!value.GetBool(&boolean_value))
136 return PP_ERROR_BADARGUMENT;
137
138 if (socket_.get()) {
139 return NetErrorToPepperError(
140 boolean_value ?
141 socket_->AllowBroadcast() : socket_->DisallowBroadcast());
142 }
143 if (boolean_value) {
144 socket_options_ |= SOCKET_OPTION_BROADCAST;
145 } else {
146 socket_options_ &= ~SOCKET_OPTION_BROADCAST;
147 }
132 return PP_OK; 148 return PP_OK;
133 } 149 }
134 case PP_UDPSOCKET_OPTION_SEND_BUFFER_SIZE: 150 case PP_UDPSOCKET_OPTION_SEND_BUFFER_SIZE:
135 case PP_UDPSOCKET_OPTION_RECV_BUFFER_SIZE: { 151 case PP_UDPSOCKET_OPTION_RECV_BUFFER_SIZE: {
136 if (!socket_.get()) {
137 // They only take effect after the socket is bound.
138 return PP_ERROR_FAILED;
139 }
140 int32_t integer_value = 0; 152 int32_t integer_value = 0;
141 if (!value.GetInt32(&integer_value) || integer_value <= 0) 153 if (!value.GetInt32(&integer_value) || integer_value <= 0)
142 return PP_ERROR_BADARGUMENT; 154 return PP_ERROR_BADARGUMENT;
143 155
144 int net_result = net::ERR_UNEXPECTED;
145 if (name == PP_UDPSOCKET_OPTION_SEND_BUFFER_SIZE) { 156 if (name == PP_UDPSOCKET_OPTION_SEND_BUFFER_SIZE) {
146 if (integer_value > 157 if (integer_value >
147 ppapi::proxy::UDPSocketResourceBase::kMaxSendBufferSize) { 158 ppapi::proxy::UDPSocketResourceBase::kMaxSendBufferSize) {
148 return PP_ERROR_BADARGUMENT; 159 return PP_ERROR_BADARGUMENT;
149 } 160 }
150 net_result = socket_->SetSendBufferSize(integer_value); 161 if (socket_.get()) {
162 return NetErrorToPepperError(
163 socket_->SetSendBufferSize(integer_value));
164 }
165 socket_options_ |= SOCKET_OPTION_SNDBUF_SIZE;
166 sndbuf_size_ = integer_value;
167 return PP_OK;
151 } else { 168 } else {
152 if (integer_value > 169 if (integer_value >
153 ppapi::proxy::UDPSocketResourceBase::kMaxReceiveBufferSize) { 170 ppapi::proxy::UDPSocketResourceBase::kMaxReceiveBufferSize) {
154 return PP_ERROR_BADARGUMENT; 171 return PP_ERROR_BADARGUMENT;
155 } 172 }
156 net_result = socket_->SetReceiveBufferSize(integer_value); 173 if (socket_.get()) {
174 return NetErrorToPepperError(
175 socket_->SetReceiveBufferSize(integer_value));
176 }
177 socket_options_ |= SOCKET_OPTION_RCVBUF_SIZE;
178 rcvbuf_size_ = integer_value;
179 return PP_OK;
157 } 180 }
158 // TODO(wtc): Add error mapping code.
159 return (net_result == net::OK) ? PP_OK : PP_ERROR_FAILED;
160 } 181 }
161 default: { 182 default: {
162 NOTREACHED(); 183 NOTREACHED();
163 return PP_ERROR_BADARGUMENT; 184 return PP_ERROR_BADARGUMENT;
164 } 185 }
165 } 186 }
166 } 187 }
167 188
168 int32_t PepperUDPSocketMessageFilter::OnMsgBind( 189 int32_t PepperUDPSocketMessageFilter::OnMsgBind(
169 const ppapi::host::HostMessageContext* context, 190 const ppapi::host::HostMessageContext* context,
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 scoped_ptr<net::UDPServerSocket> socket( 277 scoped_ptr<net::UDPServerSocket> socket(
257 new net::UDPServerSocket(NULL, net::NetLog::Source())); 278 new net::UDPServerSocket(NULL, net::NetLog::Source()));
258 279
259 net::IPAddressNumber address; 280 net::IPAddressNumber address;
260 int port; 281 int port;
261 if (!NetAddressPrivateImpl::NetAddressToIPEndPoint(addr, &address, &port)) { 282 if (!NetAddressPrivateImpl::NetAddressToIPEndPoint(addr, &address, &port)) {
262 SendBindError(context, PP_ERROR_ADDRESS_INVALID); 283 SendBindError(context, PP_ERROR_ADDRESS_INVALID);
263 return; 284 return;
264 } 285 }
265 286
266 if (allow_address_reuse_) 287 int32_t pp_result;
267 socket->AllowAddressReuse(); 288 if (socket_options_ & SOCKET_OPTION_ADDRESS_REUSE) {
jar (doing other things) 2014/11/04 22:51:09 For better or worse... it appears that the old cod
hidehiko 2014/11/05 12:48:30 Yes... IMHO, we should handle the error, rather th
268 if (allow_broadcast_) 289 pp_result = NetErrorToPepperError(socket->AllowAddressReuse());
269 socket->AllowBroadcast(); 290 if (pp_result != PP_OK) {
291 SendBindError(context, pp_result);
jar (doing other things) 2014/11/04 22:51:09 It is valid to SendBindError an error which may pr
hidehiko 2014/11/05 12:48:30 I think it is ok, as this function already returns
292 return;
293 }
294 }
295 if (socket_options_ & SOCKET_OPTION_BROADCAST) {
296 pp_result = NetErrorToPepperError(socket->AllowBroadcast());
297 if (pp_result != PP_OK) {
298 SendBindError(context, pp_result);
299 return;
300 }
301 }
302 if (socket_options_ & SOCKET_OPTION_RCVBUF_SIZE) {
303 pp_result = NetErrorToPepperError(
304 socket->SetReceiveBufferSize(rcvbuf_size_));
305 if (pp_result != PP_OK) {
306 SendBindError(context, pp_result);
307 return;
308 }
309 }
310 if (socket_options_ & SOCKET_OPTION_SNDBUF_SIZE) {
311 pp_result = NetErrorToPepperError(socket->SetSendBufferSize(sndbuf_size_));
312 if (pp_result != PP_OK) {
313 SendBindError(context, pp_result);
314 return;
315 }
316 }
270 317
271 int32_t pp_result = 318 pp_result =
272 NetErrorToPepperError(socket->Listen(net::IPEndPoint(address, port))); 319 NetErrorToPepperError(socket->Listen(net::IPEndPoint(address, port)));
273 if (pp_result != PP_OK) { 320 if (pp_result != PP_OK) {
274 SendBindError(context, pp_result); 321 SendBindError(context, pp_result);
275 return; 322 return;
276 } 323 }
277 324
278 net::IPEndPoint bound_address; 325 net::IPEndPoint bound_address;
279 pp_result = NetErrorToPepperError(socket->GetLocalAddress(&bound_address)); 326 pp_result = NetErrorToPepperError(socket->GetLocalAddress(&bound_address));
280 if (pp_result != PP_OK) { 327 if (pp_result != PP_OK) {
281 SendBindError(context, pp_result); 328 SendBindError(context, pp_result);
282 return; 329 return;
283 } 330 }
284 331
285 PP_NetAddress_Private net_address = NetAddressPrivateImpl::kInvalidNetAddress; 332 PP_NetAddress_Private net_address = NetAddressPrivateImpl::kInvalidNetAddress;
286 if (!NetAddressPrivateImpl::IPEndPointToNetAddress( 333 if (!NetAddressPrivateImpl::IPEndPointToNetAddress(
287 bound_address.address(), bound_address.port(), &net_address)) { 334 bound_address.address(), bound_address.port(), &net_address)) {
288 SendBindError(context, PP_ERROR_ADDRESS_INVALID); 335 SendBindError(context, PP_ERROR_ADDRESS_INVALID);
289 return; 336 return;
290 } 337 }
291 338
292 allow_address_reuse_ = false; 339 socket_options_ = 0;
293 allow_broadcast_ = false;
294 socket_.swap(socket); 340 socket_.swap(socket);
295 SendBindReply(context, PP_OK, net_address); 341 SendBindReply(context, PP_OK, net_address);
296 342
297 DoRecvFrom(); 343 DoRecvFrom();
298 } 344 }
299 345
300 void PepperUDPSocketMessageFilter::DoRecvFrom() { 346 void PepperUDPSocketMessageFilter::DoRecvFrom() {
301 DCHECK_CURRENTLY_ON(BrowserThread::IO); 347 DCHECK_CURRENTLY_ON(BrowserThread::IO);
302 DCHECK(!closed_); 348 DCHECK(!closed_);
303 DCHECK(socket_.get()); 349 DCHECK(socket_.get());
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 NetAddressPrivateImpl::kInvalidNetAddress); 511 NetAddressPrivateImpl::kInvalidNetAddress);
466 } 512 }
467 513
468 void PepperUDPSocketMessageFilter::SendSendToError( 514 void PepperUDPSocketMessageFilter::SendSendToError(
469 const ppapi::host::ReplyMessageContext& context, 515 const ppapi::host::ReplyMessageContext& context,
470 int32_t result) { 516 int32_t result) {
471 SendSendToReply(context, result, 0); 517 SendSendToReply(context, result, 0);
472 } 518 }
473 519
474 } // namespace content 520 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698