OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_private_message
_filter.h" | 5 #include "content/browser/renderer_host/pepper/pepper_udp_socket_private_message
_filter.h" |
6 | 6 |
7 #include <cstring> | 7 #include <cstring> |
8 #include <limits> | 8 #include <limits> |
9 | 9 |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 int32_t PepperUDPSocketPrivateMessageFilter::OnMsgRecvFrom( | 158 int32_t PepperUDPSocketPrivateMessageFilter::OnMsgRecvFrom( |
159 const ppapi::host::HostMessageContext* context, | 159 const ppapi::host::HostMessageContext* context, |
160 int32_t num_bytes) { | 160 int32_t num_bytes) { |
161 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 161 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
162 DCHECK(context); | 162 DCHECK(context); |
163 DCHECK(socket_.get()); | 163 DCHECK(socket_.get()); |
164 | 164 |
165 if (closed_) | 165 if (closed_) |
166 return PP_ERROR_FAILED; | 166 return PP_ERROR_FAILED; |
167 | 167 |
168 if (recvfrom_buffer_) | 168 if (recvfrom_buffer_.get()) |
169 return PP_ERROR_INPROGRESS; | 169 return PP_ERROR_INPROGRESS; |
170 if (num_bytes > ppapi::proxy::UDPSocketPrivateResource::kMaxReadSize) { | 170 if (num_bytes > ppapi::proxy::UDPSocketPrivateResource::kMaxReadSize) { |
171 // |num_bytes| value is checked on the plugin side. | 171 // |num_bytes| value is checked on the plugin side. |
172 NOTREACHED(); | 172 NOTREACHED(); |
173 num_bytes = ppapi::proxy::UDPSocketPrivateResource::kMaxReadSize; | 173 num_bytes = ppapi::proxy::UDPSocketPrivateResource::kMaxReadSize; |
174 } | 174 } |
175 recvfrom_buffer_ = new net::IOBuffer(num_bytes); | 175 recvfrom_buffer_ = new net::IOBuffer(num_bytes); |
176 int result = socket_->RecvFrom( | 176 int result = socket_->RecvFrom( |
177 recvfrom_buffer_, num_bytes, &recvfrom_address_, | 177 recvfrom_buffer_.get(), |
| 178 num_bytes, |
| 179 &recvfrom_address_, |
178 base::Bind(&PepperUDPSocketPrivateMessageFilter::OnRecvFromCompleted, | 180 base::Bind(&PepperUDPSocketPrivateMessageFilter::OnRecvFromCompleted, |
179 this, context->MakeReplyMessageContext())); | 181 this, |
| 182 context->MakeReplyMessageContext())); |
180 if (result != net::ERR_IO_PENDING) | 183 if (result != net::ERR_IO_PENDING) |
181 OnRecvFromCompleted(context->MakeReplyMessageContext(), result); | 184 OnRecvFromCompleted(context->MakeReplyMessageContext(), result); |
182 return PP_OK_COMPLETIONPENDING; | 185 return PP_OK_COMPLETIONPENDING; |
183 } | 186 } |
184 | 187 |
185 int32_t PepperUDPSocketPrivateMessageFilter::OnMsgSendTo( | 188 int32_t PepperUDPSocketPrivateMessageFilter::OnMsgSendTo( |
186 const ppapi::host::HostMessageContext* context, | 189 const ppapi::host::HostMessageContext* context, |
187 const std::string& data, | 190 const std::string& data, |
188 const PP_NetAddress_Private& addr) { | 191 const PP_NetAddress_Private& addr) { |
189 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 192 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 const std::string& data, | 259 const std::string& data, |
257 const PP_NetAddress_Private& addr) { | 260 const PP_NetAddress_Private& addr) { |
258 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 261 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
259 DCHECK(socket_.get()); | 262 DCHECK(socket_.get()); |
260 | 263 |
261 if (closed_) { | 264 if (closed_) { |
262 SendSendToError(context, PP_ERROR_FAILED); | 265 SendSendToError(context, PP_ERROR_FAILED); |
263 return; | 266 return; |
264 } | 267 } |
265 | 268 |
266 if (sendto_buffer_) { | 269 if (sendto_buffer_.get()) { |
267 SendSendToError(context, PP_ERROR_INPROGRESS); | 270 SendSendToError(context, PP_ERROR_INPROGRESS); |
268 return; | 271 return; |
269 } | 272 } |
270 | 273 |
271 if (data.empty() || | 274 if (data.empty() || |
272 data.size() > static_cast<size_t>(std::numeric_limits<int>::max())) { | 275 data.size() > static_cast<size_t>(std::numeric_limits<int>::max())) { |
273 SendSendToError(context, PP_ERROR_BADARGUMENT); | 276 SendSendToError(context, PP_ERROR_BADARGUMENT); |
274 return; | 277 return; |
275 } | 278 } |
276 size_t num_bytes = data.size(); | 279 size_t num_bytes = data.size(); |
277 if (num_bytes > static_cast<size_t>( | 280 if (num_bytes > static_cast<size_t>( |
278 ppapi::proxy::UDPSocketPrivateResource::kMaxWriteSize)) { | 281 ppapi::proxy::UDPSocketPrivateResource::kMaxWriteSize)) { |
279 // Size of |data| is checked on the plugin side. | 282 // Size of |data| is checked on the plugin side. |
280 NOTREACHED(); | 283 NOTREACHED(); |
281 num_bytes = static_cast<size_t>( | 284 num_bytes = static_cast<size_t>( |
282 ppapi::proxy::UDPSocketPrivateResource::kMaxWriteSize); | 285 ppapi::proxy::UDPSocketPrivateResource::kMaxWriteSize); |
283 } | 286 } |
284 sendto_buffer_ = new net::IOBufferWithSize(num_bytes); | 287 sendto_buffer_ = new net::IOBufferWithSize(num_bytes); |
285 memcpy(sendto_buffer_->data(), data.data(), num_bytes); | 288 memcpy(sendto_buffer_->data(), data.data(), num_bytes); |
286 | 289 |
287 net::IPAddressNumber address; | 290 net::IPAddressNumber address; |
288 int port; | 291 int port; |
289 if (!NetAddressPrivateImpl::NetAddressToIPEndPoint(addr, &address, &port)) { | 292 if (!NetAddressPrivateImpl::NetAddressToIPEndPoint(addr, &address, &port)) { |
290 SendSendToError(context, PP_ERROR_FAILED); | 293 SendSendToError(context, PP_ERROR_FAILED); |
291 return; | 294 return; |
292 } | 295 } |
293 | 296 |
294 int result = socket_->SendTo( | 297 int result = socket_->SendTo( |
295 sendto_buffer_, sendto_buffer_->size(), net::IPEndPoint(address, port), | 298 sendto_buffer_.get(), |
296 base::Bind(&PepperUDPSocketPrivateMessageFilter::OnSendToCompleted, this, | 299 sendto_buffer_->size(), |
| 300 net::IPEndPoint(address, port), |
| 301 base::Bind(&PepperUDPSocketPrivateMessageFilter::OnSendToCompleted, |
| 302 this, |
297 context)); | 303 context)); |
298 if (result != net::ERR_IO_PENDING) | 304 if (result != net::ERR_IO_PENDING) |
299 OnSendToCompleted(context, result); | 305 OnSendToCompleted(context, result); |
300 } | 306 } |
301 | 307 |
302 void PepperUDPSocketPrivateMessageFilter::Close() { | 308 void PepperUDPSocketPrivateMessageFilter::Close() { |
303 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 309 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
304 if (socket_.get() && !closed_) | 310 if (socket_.get() && !closed_) |
305 socket_->Close(); | 311 socket_->Close(); |
306 closed_ = true; | 312 closed_ = true; |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 NetAddressPrivateImpl::kInvalidNetAddress); | 392 NetAddressPrivateImpl::kInvalidNetAddress); |
387 } | 393 } |
388 | 394 |
389 void PepperUDPSocketPrivateMessageFilter::SendSendToError( | 395 void PepperUDPSocketPrivateMessageFilter::SendSendToError( |
390 const ppapi::host::ReplyMessageContext& context, | 396 const ppapi::host::ReplyMessageContext& context, |
391 int32_t result) { | 397 int32_t result) { |
392 SendSendToReply(context, result, 0); | 398 SendSendToReply(context, result, 0); |
393 } | 399 } |
394 | 400 |
395 } // namespace content | 401 } // namespace content |
OLD | NEW |