| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/browser/api/socket/tcp_socket.h" | 5 #include "extensions/browser/api/socket/tcp_socket.h" |
| 6 | 6 |
| 7 #include "base/logging.h" |
| 7 #include "extensions/browser/api/api_resource.h" | 8 #include "extensions/browser/api/api_resource.h" |
| 8 #include "net/base/address_list.h" | 9 #include "net/base/address_list.h" |
| 9 #include "net/base/ip_endpoint.h" | 10 #include "net/base/ip_endpoint.h" |
| 10 #include "net/base/net_errors.h" | 11 #include "net/base/net_errors.h" |
| 11 #include "net/base/rand_callback.h" | 12 #include "net/base/rand_callback.h" |
| 12 #include "net/socket/tcp_client_socket.h" | 13 #include "net/socket/tcp_client_socket.h" |
| 13 | 14 |
| 14 namespace extensions { | 15 namespace extensions { |
| 15 | 16 |
| 16 const char kTCPSocketTypeInvalidError[] = | 17 const char kTCPSocketTypeInvalidError[] = |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 DCHECK(!accept_callback_.is_null()); | 298 DCHECK(!accept_callback_.is_null()); |
| 298 if (result == net::OK && accept_socket_.get()) { | 299 if (result == net::OK && accept_socket_.get()) { |
| 299 accept_callback_.Run( | 300 accept_callback_.Run( |
| 300 result, static_cast<net::TCPClientSocket*>(accept_socket_.release())); | 301 result, static_cast<net::TCPClientSocket*>(accept_socket_.release())); |
| 301 } else { | 302 } else { |
| 302 accept_callback_.Run(result, NULL); | 303 accept_callback_.Run(result, NULL); |
| 303 } | 304 } |
| 304 accept_callback_.Reset(); | 305 accept_callback_.Reset(); |
| 305 } | 306 } |
| 306 | 307 |
| 308 void TCPSocket::Release() { |
| 309 // Release() is only invoked when the underlying sockets are taken (via |
| 310 // ClientStream()) by TLSSocket. TLSSocket only supports CLIENT-mode |
| 311 // sockets. |
| 312 DCHECK(!server_socket_.release() && !accept_socket_.release() && |
| 313 socket_mode_ == CLIENT) |
| 314 << "Called in server mode."; |
| 315 |
| 316 // Release() doesn't disconnect the underlying sockets, but it does |
| 317 // disconnect them from this TCPSocket. |
| 318 is_connected_ = false; |
| 319 |
| 320 connect_callback_.Reset(); |
| 321 read_callback_.Reset(); |
| 322 accept_callback_.Reset(); |
| 323 |
| 324 net::TCPClientSocket* client_socket = socket_.release(); |
| 325 DCHECK(client_socket) << "Called on null client socket."; |
| 326 } |
| 327 |
| 328 net::TCPClientSocket* TCPSocket::ClientStream() { |
| 329 if (socket_mode_ != CLIENT || GetSocketType() != TYPE_TCP) |
| 330 return NULL; |
| 331 return socket_.get(); |
| 332 } |
| 333 |
| 334 bool TCPSocket::HasPendingRead() const { return !read_callback_.is_null(); } |
| 335 |
| 307 ResumableTCPSocket::ResumableTCPSocket(const std::string& owner_extension_id) | 336 ResumableTCPSocket::ResumableTCPSocket(const std::string& owner_extension_id) |
| 308 : TCPSocket(owner_extension_id), | 337 : TCPSocket(owner_extension_id), |
| 309 persistent_(false), | 338 persistent_(false), |
| 310 buffer_size_(0), | 339 buffer_size_(0), |
| 311 paused_(false) {} | 340 paused_(false) {} |
| 312 | 341 |
| 313 ResumableTCPSocket::ResumableTCPSocket(net::TCPClientSocket* tcp_client_socket, | 342 ResumableTCPSocket::ResumableTCPSocket(net::TCPClientSocket* tcp_client_socket, |
| 314 const std::string& owner_extension_id, | 343 const std::string& owner_extension_id, |
| 315 bool is_connected) | 344 bool is_connected) |
| 316 : TCPSocket(tcp_client_socket, owner_extension_id, is_connected), | 345 : TCPSocket(tcp_client_socket, owner_extension_id, is_connected), |
| 317 persistent_(false), | 346 persistent_(false), |
| 318 buffer_size_(0), | 347 buffer_size_(0), |
| 319 paused_(false) {} | 348 paused_(false) {} |
| 320 | 349 |
| 321 bool ResumableTCPSocket::IsPersistent() const { return persistent(); } | 350 bool ResumableTCPSocket::IsPersistent() const { return persistent(); } |
| 322 | 351 |
| 323 ResumableTCPServerSocket::ResumableTCPServerSocket( | 352 ResumableTCPServerSocket::ResumableTCPServerSocket( |
| 324 const std::string& owner_extension_id) | 353 const std::string& owner_extension_id) |
| 325 : TCPSocket(owner_extension_id), persistent_(false), paused_(false) {} | 354 : TCPSocket(owner_extension_id), persistent_(false), paused_(false) {} |
| 326 | 355 |
| 327 bool ResumableTCPServerSocket::IsPersistent() const { return persistent(); } | 356 bool ResumableTCPServerSocket::IsPersistent() const { return persistent(); } |
| 328 | 357 |
| 329 } // namespace extensions | 358 } // namespace extensions |
| OLD | NEW |