| 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 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 static base::LazyInstance<base::Lock>::Leaky | 54 static base::LazyInstance<base::Lock>::Leaky |
| 55 g_last_connect_time_lock = LAZY_INSTANCE_INITIALIZER; | 55 g_last_connect_time_lock = LAZY_INSTANCE_INITIALIZER; |
| 56 | 56 |
| 57 // |g_last_connect_time| has the last time a connect() call is made. | 57 // |g_last_connect_time| has the last time a connect() call is made. |
| 58 static base::LazyInstance<base::TimeTicks>::Leaky | 58 static base::LazyInstance<base::TimeTicks>::Leaky |
| 59 g_last_connect_time = LAZY_INSTANCE_INITIALIZER; | 59 g_last_connect_time = LAZY_INSTANCE_INITIALIZER; |
| 60 | 60 |
| 61 TransportSocketParams::TransportSocketParams( | 61 TransportSocketParams::TransportSocketParams( |
| 62 const HostPortPair& host_port_pair, | 62 const HostPortPair& host_port_pair, |
| 63 bool disable_resolver_cache, | 63 bool disable_resolver_cache, |
| 64 bool ignore_limits, | |
| 65 const OnHostResolutionCallback& host_resolution_callback, | 64 const OnHostResolutionCallback& host_resolution_callback, |
| 66 CombineConnectAndWritePolicy combine_connect_and_write_if_supported) | 65 CombineConnectAndWritePolicy combine_connect_and_write_if_supported) |
| 67 : destination_(host_port_pair), | 66 : destination_(host_port_pair), |
| 68 ignore_limits_(ignore_limits), | |
| 69 host_resolution_callback_(host_resolution_callback), | 67 host_resolution_callback_(host_resolution_callback), |
| 70 combine_connect_and_write_(combine_connect_and_write_if_supported) { | 68 combine_connect_and_write_(combine_connect_and_write_if_supported) { |
| 71 if (disable_resolver_cache) | 69 if (disable_resolver_cache) |
| 72 destination_.set_allow_cached_response(false); | 70 destination_.set_allow_cached_response(false); |
| 73 // combine_connect_and_write currently translates to TCP FastOpen. | 71 // combine_connect_and_write currently translates to TCP FastOpen. |
| 74 // Enable TCP FastOpen if user wants it. | 72 // Enable TCP FastOpen if user wants it. |
| 75 if (combine_connect_and_write_ == COMBINE_CONNECT_AND_WRITE_DEFAULT) { | 73 if (combine_connect_and_write_ == COMBINE_CONNECT_AND_WRITE_DEFAULT) { |
| 76 IsTCPFastOpenUserEnabled() ? combine_connect_and_write_ = | 74 IsTCPFastOpenUserEnabled() ? combine_connect_and_write_ = |
| 77 COMBINE_CONNECT_AND_WRITE_DESIRED : | 75 COMBINE_CONNECT_AND_WRITE_DESIRED : |
| 78 COMBINE_CONNECT_AND_WRITE_PROHIBITED; | 76 COMBINE_CONNECT_AND_WRITE_PROHIBITED; |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 NOTREACHED(); | 187 NOTREACHED(); |
| 190 break; | 188 break; |
| 191 } | 189 } |
| 192 | 190 |
| 193 return connect_duration; | 191 return connect_duration; |
| 194 } | 192 } |
| 195 | 193 |
| 196 TransportConnectJob::TransportConnectJob( | 194 TransportConnectJob::TransportConnectJob( |
| 197 const std::string& group_name, | 195 const std::string& group_name, |
| 198 RequestPriority priority, | 196 RequestPriority priority, |
| 197 ClientSocketPool::IgnoreLimits ignore_limits, |
| 199 const scoped_refptr<TransportSocketParams>& params, | 198 const scoped_refptr<TransportSocketParams>& params, |
| 200 base::TimeDelta timeout_duration, | 199 base::TimeDelta timeout_duration, |
| 201 ClientSocketFactory* client_socket_factory, | 200 ClientSocketFactory* client_socket_factory, |
| 202 HostResolver* host_resolver, | 201 HostResolver* host_resolver, |
| 203 Delegate* delegate, | 202 Delegate* delegate, |
| 204 NetLog* net_log) | 203 NetLog* net_log) |
| 205 : ConnectJob(group_name, | 204 : ConnectJob(group_name, |
| 206 timeout_duration, | 205 timeout_duration, |
| 207 priority, | 206 priority, |
| 207 ignore_limits, |
| 208 delegate, | 208 delegate, |
| 209 BoundNetLog::Make(net_log, NetLog::SOURCE_CONNECT_JOB)), | 209 BoundNetLog::Make(net_log, NetLog::SOURCE_CONNECT_JOB)), |
| 210 helper_(params, client_socket_factory, host_resolver, &connect_timing_), | 210 helper_(params, client_socket_factory, host_resolver, &connect_timing_), |
| 211 interval_between_connects_(CONNECT_INTERVAL_GT_20MS), | 211 interval_between_connects_(CONNECT_INTERVAL_GT_20MS), |
| 212 resolve_result_(OK) { | 212 resolve_result_(OK) { |
| 213 helper_.SetOnIOComplete(this); | 213 helper_.SetOnIOComplete(this); |
| 214 } | 214 } |
| 215 | 215 |
| 216 TransportConnectJob::~TransportConnectJob() { | 216 TransportConnectJob::~TransportConnectJob() { |
| 217 // We don't worry about cancelling the host resolution and TCP connect, since | 217 // We don't worry about cancelling the host resolution and TCP connect, since |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 480 fallback_transport_socket_->GetConnectionAttempts( | 480 fallback_transport_socket_->GetConnectionAttempts( |
| 481 &fallback_connection_attempts_); | 481 &fallback_connection_attempts_); |
| 482 } | 482 } |
| 483 } | 483 } |
| 484 | 484 |
| 485 scoped_ptr<ConnectJob> | 485 scoped_ptr<ConnectJob> |
| 486 TransportClientSocketPool::TransportConnectJobFactory::NewConnectJob( | 486 TransportClientSocketPool::TransportConnectJobFactory::NewConnectJob( |
| 487 const std::string& group_name, | 487 const std::string& group_name, |
| 488 const PoolBase::Request& request, | 488 const PoolBase::Request& request, |
| 489 ConnectJob::Delegate* delegate) const { | 489 ConnectJob::Delegate* delegate) const { |
| 490 return scoped_ptr<ConnectJob>( | 490 return scoped_ptr<ConnectJob>(new TransportConnectJob( |
| 491 new TransportConnectJob(group_name, | 491 group_name, request.priority(), request.ignore_limits(), request.params(), |
| 492 request.priority(), | 492 ConnectionTimeout(), client_socket_factory_, host_resolver_, delegate, |
| 493 request.params(), | 493 net_log_)); |
| 494 ConnectionTimeout(), | |
| 495 client_socket_factory_, | |
| 496 host_resolver_, | |
| 497 delegate, | |
| 498 net_log_)); | |
| 499 } | 494 } |
| 500 | 495 |
| 501 base::TimeDelta | 496 base::TimeDelta |
| 502 TransportClientSocketPool::TransportConnectJobFactory::ConnectionTimeout() | 497 TransportClientSocketPool::TransportConnectJobFactory::ConnectionTimeout() |
| 503 const { | 498 const { |
| 504 return base::TimeDelta::FromSeconds(kTransportConnectJobTimeoutInSeconds); | 499 return base::TimeDelta::FromSeconds(kTransportConnectJobTimeoutInSeconds); |
| 505 } | 500 } |
| 506 | 501 |
| 507 TransportClientSocketPool::TransportClientSocketPool( | 502 TransportClientSocketPool::TransportClientSocketPool( |
| 508 int max_sockets, | 503 int max_sockets, |
| 509 int max_sockets_per_group, | 504 int max_sockets_per_group, |
| 510 HostResolver* host_resolver, | 505 HostResolver* host_resolver, |
| 511 ClientSocketFactory* client_socket_factory, | 506 ClientSocketFactory* client_socket_factory, |
| 512 NetLog* net_log) | 507 NetLog* net_log) |
| 513 : base_(NULL, | 508 : base_(NULL, |
| 514 max_sockets, | 509 max_sockets, |
| 515 max_sockets_per_group, | 510 max_sockets_per_group, |
| 516 ClientSocketPool::unused_idle_socket_timeout(), | 511 ClientSocketPool::unused_idle_socket_timeout(), |
| 517 ClientSocketPool::used_idle_socket_timeout(), | 512 ClientSocketPool::used_idle_socket_timeout(), |
| 518 new TransportConnectJobFactory(client_socket_factory, | 513 new TransportConnectJobFactory(client_socket_factory, |
| 519 host_resolver, | 514 host_resolver, |
| 520 net_log)) { | 515 net_log)) { |
| 521 base_.EnableConnectBackupJobs(); | 516 base_.EnableConnectBackupJobs(); |
| 522 } | 517 } |
| 523 | 518 |
| 524 TransportClientSocketPool::~TransportClientSocketPool() {} | 519 TransportClientSocketPool::~TransportClientSocketPool() {} |
| 525 | 520 |
| 526 int TransportClientSocketPool::RequestSocket( | 521 int TransportClientSocketPool::RequestSocket(const std::string& group_name, |
| 527 const std::string& group_name, | 522 const void* params, |
| 528 const void* params, | 523 RequestPriority priority, |
| 529 RequestPriority priority, | 524 IgnoreLimits ignore_limits, |
| 530 ClientSocketHandle* handle, | 525 ClientSocketHandle* handle, |
| 531 const CompletionCallback& callback, | 526 const CompletionCallback& callback, |
| 532 const BoundNetLog& net_log) { | 527 const BoundNetLog& net_log) { |
| 533 const scoped_refptr<TransportSocketParams>* casted_params = | 528 const scoped_refptr<TransportSocketParams>* casted_params = |
| 534 static_cast<const scoped_refptr<TransportSocketParams>*>(params); | 529 static_cast<const scoped_refptr<TransportSocketParams>*>(params); |
| 535 | 530 |
| 536 NetLogTcpClientSocketPoolRequestedSocket(net_log, casted_params); | 531 NetLogTcpClientSocketPoolRequestedSocket(net_log, casted_params); |
| 537 | 532 |
| 538 return base_.RequestSocket(group_name, *casted_params, priority, handle, | 533 return base_.RequestSocket(group_name, *casted_params, priority, |
| 539 callback, net_log); | 534 ignore_limits, handle, callback, net_log); |
| 540 } | 535 } |
| 541 | 536 |
| 542 void TransportClientSocketPool::NetLogTcpClientSocketPoolRequestedSocket( | 537 void TransportClientSocketPool::NetLogTcpClientSocketPoolRequestedSocket( |
| 543 const BoundNetLog& net_log, | 538 const BoundNetLog& net_log, |
| 544 const scoped_refptr<TransportSocketParams>* casted_params) { | 539 const scoped_refptr<TransportSocketParams>* casted_params) { |
| 545 if (net_log.IsCapturing()) { | 540 if (net_log.IsCapturing()) { |
| 546 // TODO(eroman): Split out the host and port parameters. | 541 // TODO(eroman): Split out the host and port parameters. |
| 547 net_log.AddEvent( | 542 net_log.AddEvent( |
| 548 NetLog::TYPE_TCP_CLIENT_SOCKET_POOL_REQUESTED_SOCKET, | 543 NetLog::TYPE_TCP_CLIENT_SOCKET_POOL_REQUESTED_SOCKET, |
| 549 CreateNetLogHostPortPairCallback( | 544 CreateNetLogHostPortPairCallback( |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 624 HigherLayeredPool* higher_pool) { | 619 HigherLayeredPool* higher_pool) { |
| 625 base_.AddHigherLayeredPool(higher_pool); | 620 base_.AddHigherLayeredPool(higher_pool); |
| 626 } | 621 } |
| 627 | 622 |
| 628 void TransportClientSocketPool::RemoveHigherLayeredPool( | 623 void TransportClientSocketPool::RemoveHigherLayeredPool( |
| 629 HigherLayeredPool* higher_pool) { | 624 HigherLayeredPool* higher_pool) { |
| 630 base_.RemoveHigherLayeredPool(higher_pool); | 625 base_.RemoveHigherLayeredPool(higher_pool); |
| 631 } | 626 } |
| 632 | 627 |
| 633 } // namespace net | 628 } // namespace net |
| OLD | NEW |