| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "blimp/net/tcp_client_transport.h" | 5 #include "blimp/net/tcp_client_transport.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/callback_helpers.h" | 11 #include "base/callback_helpers.h" |
| 12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 14 #include "blimp/net/message_port.h" | 14 #include "blimp/net/message_port.h" |
| 15 #include "blimp/net/stream_socket_connection.h" | 15 #include "blimp/net/stream_socket_connection.h" |
| 16 #include "net/log/net_log_source.h" |
| 16 #include "net/socket/client_socket_factory.h" | 17 #include "net/socket/client_socket_factory.h" |
| 17 #include "net/socket/stream_socket.h" | 18 #include "net/socket/stream_socket.h" |
| 18 #include "net/socket/tcp_client_socket.h" | 19 #include "net/socket/tcp_client_socket.h" |
| 19 | 20 |
| 20 namespace blimp { | 21 namespace blimp { |
| 21 | 22 |
| 22 TCPClientTransport::TCPClientTransport(const net::IPEndPoint& ip_endpoint, | 23 TCPClientTransport::TCPClientTransport(const net::IPEndPoint& ip_endpoint, |
| 23 net::NetLog* net_log) | 24 net::NetLog* net_log) |
| 24 : ip_endpoint_(ip_endpoint), | 25 : ip_endpoint_(ip_endpoint), |
| 25 net_log_(net_log), | 26 net_log_(net_log), |
| 26 socket_factory_(net::ClientSocketFactory::GetDefaultFactory()) {} | 27 socket_factory_(net::ClientSocketFactory::GetDefaultFactory()) {} |
| 27 | 28 |
| 28 TCPClientTransport::~TCPClientTransport() {} | 29 TCPClientTransport::~TCPClientTransport() {} |
| 29 | 30 |
| 30 void TCPClientTransport::SetClientSocketFactoryForTest( | 31 void TCPClientTransport::SetClientSocketFactoryForTest( |
| 31 net::ClientSocketFactory* factory) { | 32 net::ClientSocketFactory* factory) { |
| 32 DCHECK(factory); | 33 DCHECK(factory); |
| 33 socket_factory_ = factory; | 34 socket_factory_ = factory; |
| 34 } | 35 } |
| 35 | 36 |
| 36 void TCPClientTransport::Connect(const net::CompletionCallback& callback) { | 37 void TCPClientTransport::Connect(const net::CompletionCallback& callback) { |
| 37 DCHECK(!socket_); | 38 DCHECK(!socket_); |
| 38 DCHECK(!callback.is_null()); | 39 DCHECK(!callback.is_null()); |
| 39 | 40 |
| 40 connect_callback_ = callback; | 41 connect_callback_ = callback; |
| 41 socket_ = socket_factory_->CreateTransportClientSocket( | 42 socket_ = socket_factory_->CreateTransportClientSocket( |
| 42 net::AddressList(ip_endpoint_), nullptr, net_log_, net::NetLog::Source()); | 43 net::AddressList(ip_endpoint_), nullptr, net_log_, net::NetLogSource()); |
| 43 net::CompletionCallback completion_callback = base::Bind( | 44 net::CompletionCallback completion_callback = base::Bind( |
| 44 &TCPClientTransport::OnTCPConnectComplete, base::Unretained(this)); | 45 &TCPClientTransport::OnTCPConnectComplete, base::Unretained(this)); |
| 45 | 46 |
| 46 int result = socket_->Connect(completion_callback); | 47 int result = socket_->Connect(completion_callback); |
| 47 if (result == net::ERR_IO_PENDING) { | 48 if (result == net::ERR_IO_PENDING) { |
| 48 return; | 49 return; |
| 49 } | 50 } |
| 50 | 51 |
| 51 OnTCPConnectComplete(result); | 52 OnTCPConnectComplete(result); |
| 52 } | 53 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 80 void TCPClientTransport::SetSocket(std::unique_ptr<net::StreamSocket> socket) { | 81 void TCPClientTransport::SetSocket(std::unique_ptr<net::StreamSocket> socket) { |
| 81 DCHECK(socket); | 82 DCHECK(socket); |
| 82 socket_ = std::move(socket); | 83 socket_ = std::move(socket); |
| 83 } | 84 } |
| 84 | 85 |
| 85 net::ClientSocketFactory* TCPClientTransport::socket_factory() const { | 86 net::ClientSocketFactory* TCPClientTransport::socket_factory() const { |
| 86 return socket_factory_; | 87 return socket_factory_; |
| 87 } | 88 } |
| 88 | 89 |
| 89 } // namespace blimp | 90 } // namespace blimp |
| OLD | NEW |