| Index: blimp/net/tcp_client_transport.cc
|
| diff --git a/blimp/net/tcp_client_transport.cc b/blimp/net/tcp_client_transport.cc
|
| index 9dbb880341cf72767cb525f4ea6b08e0650f2f8f..ba3eb4a43d7cffb67cdb779bac75879a772ff011 100644
|
| --- a/blimp/net/tcp_client_transport.cc
|
| +++ b/blimp/net/tcp_client_transport.cc
|
| @@ -9,6 +9,7 @@
|
| #include "base/memory/scoped_ptr.h"
|
| #include "base/message_loop/message_loop.h"
|
| #include "blimp/net/stream_socket_connection.h"
|
| +#include "net/socket/client_socket_factory.h"
|
| #include "net/socket/stream_socket.h"
|
| #include "net/socket/tcp_client_socket.h"
|
|
|
| @@ -16,31 +17,34 @@ namespace blimp {
|
|
|
| TCPClientTransport::TCPClientTransport(const net::AddressList& addresses,
|
| net::NetLog* net_log)
|
| - : addresses_(addresses), net_log_(net_log) {}
|
| + : addresses_(addresses),
|
| + net_log_(net_log),
|
| + socket_factory_(net::ClientSocketFactory::GetDefaultFactory()) {}
|
|
|
| TCPClientTransport::~TCPClientTransport() {}
|
|
|
| +void TCPClientTransport::SetClientSocketFactoryForTest(
|
| + net::ClientSocketFactory* factory) {
|
| + DCHECK(factory);
|
| + socket_factory_ = factory;
|
| +}
|
| +
|
| void TCPClientTransport::Connect(const net::CompletionCallback& callback) {
|
| DCHECK(!socket_);
|
| DCHECK(!callback.is_null());
|
|
|
| - socket_.reset(
|
| - new net::TCPClientSocket(addresses_, net_log_, net::NetLog::Source()));
|
| + connect_callback_ = callback;
|
| + socket_ = socket_factory_->CreateTransportClientSocket(addresses_, net_log_,
|
| + net::NetLog::Source());
|
| net::CompletionCallback completion_callback = base::Bind(
|
| &TCPClientTransport::OnTCPConnectComplete, base::Unretained(this));
|
|
|
| int result = socket_->Connect(completion_callback);
|
| if (result == net::ERR_IO_PENDING) {
|
| - connect_callback_ = callback;
|
| return;
|
| }
|
|
|
| - if (result != net::OK) {
|
| - socket_ = nullptr;
|
| - }
|
| -
|
| - base::MessageLoop::current()->PostTask(FROM_HERE,
|
| - base::Bind(callback, result));
|
| + OnTCPConnectComplete(result);
|
| }
|
|
|
| scoped_ptr<BlimpConnection> TCPClientTransport::TakeConnection() {
|
| @@ -55,11 +59,26 @@ const std::string TCPClientTransport::GetName() const {
|
|
|
| void TCPClientTransport::OnTCPConnectComplete(int result) {
|
| DCHECK_NE(net::ERR_IO_PENDING, result);
|
| - DCHECK(socket_);
|
| + OnConnectComplete(result);
|
| +}
|
| +
|
| +void TCPClientTransport::OnConnectComplete(int result) {
|
| if (result != net::OK) {
|
| socket_ = nullptr;
|
| }
|
| base::ResetAndReturn(&connect_callback_).Run(result);
|
| }
|
|
|
| +scoped_ptr<net::StreamSocket> TCPClientTransport::TakeSocket() {
|
| + return std::move(socket_);
|
| +}
|
| +
|
| +void TCPClientTransport::SetSocket(scoped_ptr<net::StreamSocket> socket) {
|
| + socket_ = std::move(socket);
|
| +}
|
| +
|
| +net::ClientSocketFactory* TCPClientTransport::socket_factory() const {
|
| + return socket_factory_;
|
| +}
|
| +
|
| } // namespace blimp
|
|
|