diff options
Diffstat (limited to 'net/socket/tcp_client_socket_pool.cc')
-rw-r--r-- | net/socket/tcp_client_socket_pool.cc | 52 |
1 files changed, 18 insertions, 34 deletions
diff --git a/net/socket/tcp_client_socket_pool.cc b/net/socket/tcp_client_socket_pool.cc index 9892605..c9af808 100644 --- a/net/socket/tcp_client_socket_pool.cc +++ b/net/socket/tcp_client_socket_pool.cc @@ -23,7 +23,8 @@ TCPConnectJob::TCPConnectJob( const HostResolver::RequestInfo& resolve_info, const ClientSocketHandle* handle, ClientSocketFactory* client_socket_factory, - ClientSocketPoolBase* pool) + HostResolver* host_resolver, + Delegate* delegate) : group_name_(group_name), resolve_info_(resolve_info), handle_(handle), @@ -31,8 +32,8 @@ TCPConnectJob::TCPConnectJob( ALLOW_THIS_IN_INITIALIZER_LIST( callback_(this, &TCPConnectJob::OnIOComplete)), - pool_(pool), - resolver_(pool->GetHostResolver()) {} + delegate_(delegate), + resolver_(host_resolver) {} TCPConnectJob::~TCPConnectJob() { // We don't worry about cancelling the host resolution and TCP connect, since @@ -40,6 +41,7 @@ TCPConnectJob::~TCPConnectJob() { } int TCPConnectJob::Connect() { + set_load_state(LOAD_STATE_RESOLVING_HOST); int rv = resolver_.Resolve(resolve_info_, &addresses_, &callback_); if (rv != ERR_IO_PENDING) rv = OnIOCompleteInternal(rv, true /* synchronous */); @@ -54,12 +56,8 @@ int TCPConnectJob::OnIOCompleteInternal( int result, bool synchronous) { CHECK(result != ERR_IO_PENDING); - ClientSocketPoolBase::Request* request = pool_->GetConnectingRequest( - group_name_, handle_); - CHECK(request); - - if (result == OK && request->load_state == LOAD_STATE_RESOLVING_HOST) { - request->load_state = LOAD_STATE_CONNECTING; + if (result == OK && load_state() == LOAD_STATE_RESOLVING_HOST) { + set_load_state(LOAD_STATE_CONNECTING); socket_.reset(client_socket_factory_->CreateTCPClientSocket(addresses_)); connect_start_time_ = base::TimeTicks::Now(); result = socket_->Connect(&callback_); @@ -68,7 +66,7 @@ int TCPConnectJob::OnIOCompleteInternal( } if (result == OK) { - CHECK(request->load_state == LOAD_STATE_CONNECTING); + DCHECK_EQ(load_state(), LOAD_STATE_CONNECTING); CHECK(connect_start_time_ != base::TimeTicks()); base::TimeDelta connect_duration = base::TimeTicks::Now() - connect_start_time_; @@ -83,38 +81,24 @@ int TCPConnectJob::OnIOCompleteInternal( // Now, we either succeeded at Connect()'ing, or we failed at host resolution // or Connect()'ing. Either way, we'll run the callback to alert the client. - CompletionCallback* callback = NULL; - - if (result == OK) { - callback = pool_->OnConnectingRequestComplete( - group_name_, - handle_, - false /* don't deactivate socket */, - socket_.release()); - } else { - callback = pool_->OnConnectingRequestComplete( - group_name_, - handle_, - true /* deactivate socket */, - NULL /* no connected socket to give */); - } + delegate_->OnConnectJobComplete( + group_name_, + handle_, + result == OK ? socket_.release() : NULL, + result, + !synchronous); // |this| is deleted after this point. - - CHECK(callback); - - if (!synchronous) - callback->Run(result); return result; } ConnectJob* TCPClientSocketPool::TCPConnectJobFactory::NewConnectJob( const std::string& group_name, const ClientSocketPoolBase::Request& request, - ClientSocketPoolBase* pool) const { + ConnectJob::Delegate* delegate) const { return new TCPConnectJob( group_name, request.resolve_info, request.handle, - client_socket_factory_, pool); + client_socket_factory_, host_resolver_, delegate); } TCPClientSocketPool::TCPClientSocketPool( @@ -122,8 +106,8 @@ TCPClientSocketPool::TCPClientSocketPool( HostResolver* host_resolver, ClientSocketFactory* client_socket_factory) : base_(new ClientSocketPoolBase( - max_sockets_per_group, host_resolver, - new TCPConnectJobFactory(client_socket_factory))) {} + max_sockets_per_group, + new TCPConnectJobFactory(client_socket_factory, host_resolver))) {} TCPClientSocketPool::~TCPClientSocketPool() {} |