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 "chrome/browser/extensions/api/socket/tcp_socket.h" | 5 #include "chrome/browser/extensions/api/socket/tcp_socket.h" |
6 | 6 |
7 #include "chrome/browser/extensions/api/api_resource.h" | 7 #include "chrome/browser/extensions/api/api_resource.h" |
8 #include "net/base/address_list.h" | 8 #include "net/base/address_list.h" |
9 #include "net/base/ip_endpoint.h" | 9 #include "net/base/ip_endpoint.h" |
10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 DCHECK(!accept_callback_.is_null()); | 299 DCHECK(!accept_callback_.is_null()); |
300 if (result == net::OK && accept_socket_.get()) { | 300 if (result == net::OK && accept_socket_.get()) { |
301 accept_callback_.Run( | 301 accept_callback_.Run( |
302 result, static_cast<net::TCPClientSocket*>(accept_socket_.release())); | 302 result, static_cast<net::TCPClientSocket*>(accept_socket_.release())); |
303 } else { | 303 } else { |
304 accept_callback_.Run(result, NULL); | 304 accept_callback_.Run(result, NULL); |
305 } | 305 } |
306 accept_callback_.Reset(); | 306 accept_callback_.Reset(); |
307 } | 307 } |
308 | 308 |
| 309 |
| 310 void TCPSocket::Release() { |
| 311 if (server_socket_.release() || accept_socket_.release()) { |
| 312 VLOG(1) << "TCPSocket::Release getting called in server mode. Odd."; |
| 313 return; |
| 314 } |
| 315 |
| 316 // Release() doesn't disconnect the underlying sockets, but it does |
| 317 // disconnect them from this TCPSocket. |
| 318 is_connected_ = false; |
| 319 |
| 320 // Really, the 'server' bool/checks are to get around warn_unused_result on |
| 321 // scoped_ptr.release(). |
| 322 connect_callback_.Reset(); |
| 323 read_callback_.Reset(); |
| 324 accept_callback_.Reset(); |
| 325 |
| 326 if (socket_.release() == NULL && socket_mode_ == CLIENT) { |
| 327 VLOG(1) << "TCPSocket::Release on null client socket."; |
| 328 } |
| 329 } |
| 330 |
| 331 net::TCPClientSocket* TCPSocket::ClientStream() { |
| 332 if (socket_mode_ != CLIENT || GetSocketType() != TYPE_TCP) |
| 333 return NULL; |
| 334 return socket_.get(); |
| 335 } |
| 336 |
309 ResumableTCPSocket::ResumableTCPSocket(const std::string& owner_extension_id) | 337 ResumableTCPSocket::ResumableTCPSocket(const std::string& owner_extension_id) |
310 : TCPSocket(owner_extension_id), | 338 : TCPSocket(owner_extension_id), |
311 persistent_(false), | 339 persistent_(false), |
312 buffer_size_(0), | 340 buffer_size_(0), |
313 paused_(false) { | 341 paused_(false) { |
314 } | 342 } |
315 | 343 |
316 ResumableTCPSocket::ResumableTCPSocket(net::TCPClientSocket* tcp_client_socket, | 344 ResumableTCPSocket::ResumableTCPSocket(net::TCPClientSocket* tcp_client_socket, |
317 const std::string& owner_extension_id, | 345 const std::string& owner_extension_id, |
318 bool is_connected) | 346 bool is_connected) |
(...skipping 12 matching lines...) Expand all Loading... |
331 : TCPSocket(owner_extension_id), | 359 : TCPSocket(owner_extension_id), |
332 persistent_(false), | 360 persistent_(false), |
333 paused_(false) { | 361 paused_(false) { |
334 } | 362 } |
335 | 363 |
336 bool ResumableTCPServerSocket::IsPersistent() const { | 364 bool ResumableTCPServerSocket::IsPersistent() const { |
337 return persistent(); | 365 return persistent(); |
338 } | 366 } |
339 | 367 |
340 } // namespace extensions | 368 } // namespace extensions |
OLD | NEW |