| 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/callback_helpers.h" |
| 7 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 8 #include "base/logging.h" | 9 #include "base/logging.h" |
| 9 #include "base/macros.h" | 10 #include "base/macros.h" |
| 10 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 11 #include "extensions/browser/api/api_resource.h" | 12 #include "extensions/browser/api/api_resource.h" |
| 12 #include "net/base/address_list.h" | 13 #include "net/base/address_list.h" |
| 13 #include "net/base/ip_endpoint.h" | 14 #include "net/base/ip_endpoint.h" |
| 14 #include "net/base/net_errors.h" | 15 #include "net/base/net_errors.h" |
| 15 #include "net/base/rand_callback.h" | 16 #include "net/base/rand_callback.h" |
| 16 #include "net/socket/tcp_client_socket.h" | 17 #include "net/socket/tcp_client_socket.h" |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 if (result != net::ERR_IO_PENDING) | 109 if (result != net::ERR_IO_PENDING) |
| 109 OnConnectComplete(result); | 110 OnConnectComplete(result); |
| 110 } | 111 } |
| 111 | 112 |
| 112 void TCPSocket::Disconnect() { | 113 void TCPSocket::Disconnect() { |
| 113 is_connected_ = false; | 114 is_connected_ = false; |
| 114 if (socket_.get()) | 115 if (socket_.get()) |
| 115 socket_->Disconnect(); | 116 socket_->Disconnect(); |
| 116 server_socket_.reset(NULL); | 117 server_socket_.reset(NULL); |
| 117 connect_callback_.Reset(); | 118 connect_callback_.Reset(); |
| 118 read_callback_.Reset(); | 119 // TODO(devlin): Should we do this for all callbacks? |
| 120 if (!read_callback_.is_null()) { |
| 121 base::ResetAndReturn(&read_callback_) |
| 122 .Run(net::ERR_CONNECTION_CLOSED, nullptr); |
| 123 } |
| 119 accept_callback_.Reset(); | 124 accept_callback_.Reset(); |
| 120 accept_socket_.reset(NULL); | 125 accept_socket_.reset(NULL); |
| 121 } | 126 } |
| 122 | 127 |
| 123 int TCPSocket::Bind(const std::string& address, uint16_t port) { | 128 int TCPSocket::Bind(const std::string& address, uint16_t port) { |
| 124 return net::ERR_FAILED; | 129 return net::ERR_FAILED; |
| 125 } | 130 } |
| 126 | 131 |
| 127 void TCPSocket::Read(int count, const ReadCompletionCallback& callback) { | 132 void TCPSocket::Read(int count, const ReadCompletionCallback& callback) { |
| 128 DCHECK(!callback.is_null()); | 133 DCHECK(!callback.is_null()); |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 | 360 |
| 356 bool ResumableTCPSocket::IsPersistent() const { return persistent(); } | 361 bool ResumableTCPSocket::IsPersistent() const { return persistent(); } |
| 357 | 362 |
| 358 ResumableTCPServerSocket::ResumableTCPServerSocket( | 363 ResumableTCPServerSocket::ResumableTCPServerSocket( |
| 359 const std::string& owner_extension_id) | 364 const std::string& owner_extension_id) |
| 360 : TCPSocket(owner_extension_id), persistent_(false), paused_(false) {} | 365 : TCPSocket(owner_extension_id), persistent_(false), paused_(false) {} |
| 361 | 366 |
| 362 bool ResumableTCPServerSocket::IsPersistent() const { return persistent(); } | 367 bool ResumableTCPServerSocket::IsPersistent() const { return persistent(); } |
| 363 | 368 |
| 364 } // namespace extensions | 369 } // namespace extensions |
| OLD | NEW |