OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/transport_client_socket_pool.h" | 5 #include "net/socket/transport_client_socket_pool.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 ClientSocketFactory* client_socket_factory, | 89 ClientSocketFactory* client_socket_factory, |
90 HostResolver* host_resolver, | 90 HostResolver* host_resolver, |
91 Delegate* delegate, | 91 Delegate* delegate, |
92 NetLog* net_log) | 92 NetLog* net_log) |
93 : ConnectJob(group_name, timeout_duration, priority, delegate, | 93 : ConnectJob(group_name, timeout_duration, priority, delegate, |
94 BoundNetLog::Make(net_log, NetLog::SOURCE_CONNECT_JOB)), | 94 BoundNetLog::Make(net_log, NetLog::SOURCE_CONNECT_JOB)), |
95 params_(params), | 95 params_(params), |
96 client_socket_factory_(client_socket_factory), | 96 client_socket_factory_(client_socket_factory), |
97 resolver_(host_resolver), | 97 resolver_(host_resolver), |
98 next_state_(STATE_NONE), | 98 next_state_(STATE_NONE), |
99 less_than_20ms_since_connect_(true) { | 99 interval_between_connects_(CONNECT_INTERVAL_GT_20MS) { |
100 } | 100 } |
101 | 101 |
102 TransportConnectJob::~TransportConnectJob() { | 102 TransportConnectJob::~TransportConnectJob() { |
103 // We don't worry about cancelling the host resolution and TCP connect, since | 103 // We don't worry about cancelling the host resolution and TCP connect, since |
104 // ~SingleRequestHostResolver and ~StreamSocket will take care of it. | 104 // ~SingleRequestHostResolver and ~StreamSocket will take care of it. |
105 } | 105 } |
106 | 106 |
107 LoadState TransportConnectJob::GetLoadState() const { | 107 LoadState TransportConnectJob::GetLoadState() const { |
108 switch (next_state_) { | 108 switch (next_state_) { |
109 case STATE_RESOLVE_HOST: | 109 case STATE_RESOLVE_HOST: |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 } | 197 } |
198 | 198 |
199 int TransportConnectJob::DoTransportConnect() { | 199 int TransportConnectJob::DoTransportConnect() { |
200 base::TimeTicks now = base::TimeTicks::Now(); | 200 base::TimeTicks now = base::TimeTicks::Now(); |
201 base::TimeTicks last_connect_time; | 201 base::TimeTicks last_connect_time; |
202 { | 202 { |
203 base::AutoLock lock(g_last_connect_time_lock.Get()); | 203 base::AutoLock lock(g_last_connect_time_lock.Get()); |
204 last_connect_time = g_last_connect_time.Get(); | 204 last_connect_time = g_last_connect_time.Get(); |
205 *g_last_connect_time.Pointer() = now; | 205 *g_last_connect_time.Pointer() = now; |
206 } | 206 } |
207 if (last_connect_time.is_null() || | 207 if (last_connect_time.is_null()) { |
208 (now - last_connect_time).InMilliseconds() < 20) { | 208 interval_between_connects_ = CONNECT_INTERVAL_GT_20MS; |
209 less_than_20ms_since_connect_ = true; | |
210 } else { | 209 } else { |
211 less_than_20ms_since_connect_ = false; | 210 int64 interval = (now - last_connect_time).InMilliseconds(); |
| 211 if (interval <= 10) |
| 212 interval_between_connects_ = CONNECT_INTERVAL_LE_10MS; |
| 213 else if (interval <= 20) |
| 214 interval_between_connects_ = CONNECT_INTERVAL_LE_20MS; |
| 215 else |
| 216 interval_between_connects_ = CONNECT_INTERVAL_GT_20MS; |
212 } | 217 } |
213 | 218 |
214 next_state_ = STATE_TRANSPORT_CONNECT_COMPLETE; | 219 next_state_ = STATE_TRANSPORT_CONNECT_COMPLETE; |
215 transport_socket_ = client_socket_factory_->CreateTransportClientSocket( | 220 transport_socket_ = client_socket_factory_->CreateTransportClientSocket( |
216 addresses_, net_log().net_log(), net_log().source()); | 221 addresses_, net_log().net_log(), net_log().source()); |
217 int rv = transport_socket_->Connect( | 222 int rv = transport_socket_->Connect( |
218 base::Bind(&TransportConnectJob::OnIOComplete, base::Unretained(this))); | 223 base::Bind(&TransportConnectJob::OnIOComplete, base::Unretained(this))); |
219 if (rv == ERR_IO_PENDING && | 224 if (rv == ERR_IO_PENDING && |
220 addresses_.front().GetFamily() == ADDRESS_FAMILY_IPV6 && | 225 addresses_.front().GetFamily() == ADDRESS_FAMILY_IPV6 && |
221 !AddressListOnlyContainsIPv6(addresses_)) { | 226 !AddressListOnlyContainsIPv6(addresses_)) { |
(...skipping 18 matching lines...) Expand all Loading... |
240 base::TimeDelta::FromMinutes(10), | 245 base::TimeDelta::FromMinutes(10), |
241 100); | 246 100); |
242 | 247 |
243 base::TimeDelta connect_duration = now - connect_timing_.connect_start; | 248 base::TimeDelta connect_duration = now - connect_timing_.connect_start; |
244 UMA_HISTOGRAM_CUSTOM_TIMES("Net.TCP_Connection_Latency", | 249 UMA_HISTOGRAM_CUSTOM_TIMES("Net.TCP_Connection_Latency", |
245 connect_duration, | 250 connect_duration, |
246 base::TimeDelta::FromMilliseconds(1), | 251 base::TimeDelta::FromMilliseconds(1), |
247 base::TimeDelta::FromMinutes(10), | 252 base::TimeDelta::FromMinutes(10), |
248 100); | 253 100); |
249 | 254 |
250 if (less_than_20ms_since_connect_) { | 255 switch (interval_between_connects_) { |
251 UMA_HISTOGRAM_CUSTOM_TIMES( | 256 case CONNECT_INTERVAL_LE_10MS: |
252 "Net.TCP_Connection_Latency_Interval_20ms_Minus", | 257 UMA_HISTOGRAM_CUSTOM_TIMES( |
253 connect_duration, | 258 "Net.TCP_Connection_Latency_Interval_LessThanOrEqual_10ms", |
254 base::TimeDelta::FromMilliseconds(1), | 259 connect_duration, |
255 base::TimeDelta::FromMinutes(10), | 260 base::TimeDelta::FromMilliseconds(1), |
256 100); | 261 base::TimeDelta::FromMinutes(10), |
257 } else { | 262 100); |
258 UMA_HISTOGRAM_CUSTOM_TIMES( | 263 break; |
259 "Net.TCP_Connection_Latency_Interval_20ms_Plus", | 264 case CONNECT_INTERVAL_LE_20MS: |
260 connect_duration, | 265 UMA_HISTOGRAM_CUSTOM_TIMES( |
261 base::TimeDelta::FromMilliseconds(1), | 266 "Net.TCP_Connection_Latency_Interval_LessThanOrEqual_20ms", |
262 base::TimeDelta::FromMinutes(10), | 267 connect_duration, |
263 100); | 268 base::TimeDelta::FromMilliseconds(1), |
| 269 base::TimeDelta::FromMinutes(10), |
| 270 100); |
| 271 break; |
| 272 case CONNECT_INTERVAL_GT_20MS: |
| 273 UMA_HISTOGRAM_CUSTOM_TIMES( |
| 274 "Net.TCP_Connection_Latency_Interval_GreaterThan_20ms", |
| 275 connect_duration, |
| 276 base::TimeDelta::FromMilliseconds(1), |
| 277 base::TimeDelta::FromMinutes(10), |
| 278 100); |
| 279 break; |
| 280 default: |
| 281 NOTREACHED(); |
| 282 break; |
264 } | 283 } |
265 | 284 |
266 if (is_ipv4) { | 285 if (is_ipv4) { |
267 UMA_HISTOGRAM_CUSTOM_TIMES("Net.TCP_Connection_Latency_IPv4_No_Race", | 286 UMA_HISTOGRAM_CUSTOM_TIMES("Net.TCP_Connection_Latency_IPv4_No_Race", |
268 connect_duration, | 287 connect_duration, |
269 base::TimeDelta::FromMilliseconds(1), | 288 base::TimeDelta::FromMilliseconds(1), |
270 base::TimeDelta::FromMinutes(10), | 289 base::TimeDelta::FromMinutes(10), |
271 100); | 290 100); |
272 } else { | 291 } else { |
273 if (AddressListOnlyContainsIPv6(addresses_)) { | 292 if (AddressListOnlyContainsIPv6(addresses_)) { |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
509 HigherLayeredPool* higher_pool) { | 528 HigherLayeredPool* higher_pool) { |
510 base_.AddHigherLayeredPool(higher_pool); | 529 base_.AddHigherLayeredPool(higher_pool); |
511 } | 530 } |
512 | 531 |
513 void TransportClientSocketPool::RemoveHigherLayeredPool( | 532 void TransportClientSocketPool::RemoveHigherLayeredPool( |
514 HigherLayeredPool* higher_pool) { | 533 HigherLayeredPool* higher_pool) { |
515 base_.RemoveHigherLayeredPool(higher_pool); | 534 base_.RemoveHigherLayeredPool(higher_pool); |
516 } | 535 } |
517 | 536 |
518 } // namespace net | 537 } // namespace net |
OLD | NEW |