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