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