| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "net/socket/tcp_client_socket_pool.h" | 5 #include "net/socket/tcp_client_socket_pool.h" |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/time.h" | 10 #include "base/time.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 ALLOW_THIS_IN_INITIALIZER_LIST( | 37 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 38 callback_(this, | 38 callback_(this, |
| 39 &TCPConnectJob::OnIOComplete)), | 39 &TCPConnectJob::OnIOComplete)), |
| 40 resolver_(host_resolver) {} | 40 resolver_(host_resolver) {} |
| 41 | 41 |
| 42 TCPConnectJob::~TCPConnectJob() { | 42 TCPConnectJob::~TCPConnectJob() { |
| 43 // We don't worry about cancelling the host resolution and TCP connect, since | 43 // We don't worry about cancelling the host resolution and TCP connect, since |
| 44 // ~SingleRequestHostResolver and ~ClientSocket will take care of it. | 44 // ~SingleRequestHostResolver and ~ClientSocket will take care of it. |
| 45 } | 45 } |
| 46 | 46 |
| 47 LoadState TCPConnectJob::GetLoadState() const { |
| 48 switch (next_state_) { |
| 49 case kStateResolveHost: |
| 50 case kStateResolveHostComplete: |
| 51 return LOAD_STATE_RESOLVING_HOST; |
| 52 case kStateTCPConnect: |
| 53 case kStateTCPConnectComplete: |
| 54 return LOAD_STATE_CONNECTING; |
| 55 default: |
| 56 NOTREACHED(); |
| 57 return LOAD_STATE_IDLE; |
| 58 } |
| 59 } |
| 60 |
| 47 int TCPConnectJob::ConnectInternal() { | 61 int TCPConnectJob::ConnectInternal() { |
| 48 next_state_ = kStateResolveHost; | 62 next_state_ = kStateResolveHost; |
| 49 return DoLoop(OK); | 63 return DoLoop(OK); |
| 50 } | 64 } |
| 51 | 65 |
| 52 void TCPConnectJob::OnIOComplete(int result) { | 66 void TCPConnectJob::OnIOComplete(int result) { |
| 53 int rv = DoLoop(result); | 67 int rv = DoLoop(result); |
| 54 if (rv != ERR_IO_PENDING) | 68 if (rv != ERR_IO_PENDING) |
| 55 NotifyDelegateOfCompletion(rv); // Deletes |this| | 69 NotifyDelegateOfCompletion(rv); // Deletes |this| |
| 56 } | 70 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 81 NOTREACHED(); | 95 NOTREACHED(); |
| 82 rv = ERR_FAILED; | 96 rv = ERR_FAILED; |
| 83 break; | 97 break; |
| 84 } | 98 } |
| 85 } while (rv != ERR_IO_PENDING && next_state_ != kStateNone); | 99 } while (rv != ERR_IO_PENDING && next_state_ != kStateNone); |
| 86 | 100 |
| 87 return rv; | 101 return rv; |
| 88 } | 102 } |
| 89 | 103 |
| 90 int TCPConnectJob::DoResolveHost() { | 104 int TCPConnectJob::DoResolveHost() { |
| 91 set_load_state(LOAD_STATE_RESOLVING_HOST); | |
| 92 next_state_ = kStateResolveHostComplete; | 105 next_state_ = kStateResolveHostComplete; |
| 93 return resolver_.Resolve(resolve_info_, &addresses_, &callback_, load_log()); | 106 return resolver_.Resolve(resolve_info_, &addresses_, &callback_, load_log()); |
| 94 } | 107 } |
| 95 | 108 |
| 96 int TCPConnectJob::DoResolveHostComplete(int result) { | 109 int TCPConnectJob::DoResolveHostComplete(int result) { |
| 97 DCHECK_EQ(LOAD_STATE_RESOLVING_HOST, load_state()); | |
| 98 if (result == OK) | 110 if (result == OK) |
| 99 next_state_ = kStateTCPConnect; | 111 next_state_ = kStateTCPConnect; |
| 100 return result; | 112 return result; |
| 101 } | 113 } |
| 102 | 114 |
| 103 int TCPConnectJob::DoTCPConnect() { | 115 int TCPConnectJob::DoTCPConnect() { |
| 104 next_state_ = kStateTCPConnectComplete; | 116 next_state_ = kStateTCPConnectComplete; |
| 105 set_load_state(LOAD_STATE_CONNECTING); | |
| 106 set_socket(client_socket_factory_->CreateTCPClientSocket(addresses_)); | 117 set_socket(client_socket_factory_->CreateTCPClientSocket(addresses_)); |
| 107 connect_start_time_ = base::TimeTicks::Now(); | 118 connect_start_time_ = base::TimeTicks::Now(); |
| 108 // TODO(eroman): Socket::Connect() should take a LoadLog. | 119 // TODO(eroman): Socket::Connect() should take a LoadLog. |
| 109 return socket()->Connect(&callback_); | 120 return socket()->Connect(&callback_); |
| 110 } | 121 } |
| 111 | 122 |
| 112 int TCPConnectJob::DoTCPConnectComplete(int result) { | 123 int TCPConnectJob::DoTCPConnectComplete(int result) { |
| 113 DCHECK_EQ(load_state(), LOAD_STATE_CONNECTING); | |
| 114 if (result == OK) { | 124 if (result == OK) { |
| 115 DCHECK(connect_start_time_ != base::TimeTicks()); | 125 DCHECK(connect_start_time_ != base::TimeTicks()); |
| 116 base::TimeDelta connect_duration = | 126 base::TimeDelta connect_duration = |
| 117 base::TimeTicks::Now() - connect_start_time_; | 127 base::TimeTicks::Now() - connect_start_time_; |
| 118 | 128 |
| 119 UMA_HISTOGRAM_CLIPPED_TIMES("Net.TCP_Connection_Latency", | 129 UMA_HISTOGRAM_CLIPPED_TIMES("Net.TCP_Connection_Latency", |
| 120 connect_duration, | 130 connect_duration, |
| 121 base::TimeDelta::FromMilliseconds(1), | 131 base::TimeDelta::FromMilliseconds(1), |
| 122 base::TimeDelta::FromMinutes(10), | 132 base::TimeDelta::FromMinutes(10), |
| 123 100); | 133 100); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 const std::string& group_name) const { | 193 const std::string& group_name) const { |
| 184 return base_.IdleSocketCountInGroup(group_name); | 194 return base_.IdleSocketCountInGroup(group_name); |
| 185 } | 195 } |
| 186 | 196 |
| 187 LoadState TCPClientSocketPool::GetLoadState( | 197 LoadState TCPClientSocketPool::GetLoadState( |
| 188 const std::string& group_name, const ClientSocketHandle* handle) const { | 198 const std::string& group_name, const ClientSocketHandle* handle) const { |
| 189 return base_.GetLoadState(group_name, handle); | 199 return base_.GetLoadState(group_name, handle); |
| 190 } | 200 } |
| 191 | 201 |
| 192 } // namespace net | 202 } // namespace net |
| OLD | NEW |