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/http/http_proxy_client_socket_pool.h" | 5 #include "net/http/http_proxy_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/time/time.h" | 10 #include "base/time/time.h" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 static const int kHttpProxyConnectJobTimeoutInSeconds = 30; | 79 static const int kHttpProxyConnectJobTimeoutInSeconds = 30; |
80 #endif | 80 #endif |
81 | 81 |
82 HttpProxyConnectJob::HttpProxyConnectJob( | 82 HttpProxyConnectJob::HttpProxyConnectJob( |
83 const std::string& group_name, | 83 const std::string& group_name, |
84 RequestPriority priority, | 84 RequestPriority priority, |
85 const scoped_refptr<HttpProxySocketParams>& params, | 85 const scoped_refptr<HttpProxySocketParams>& params, |
86 const base::TimeDelta& timeout_duration, | 86 const base::TimeDelta& timeout_duration, |
87 TransportClientSocketPool* transport_pool, | 87 TransportClientSocketPool* transport_pool, |
88 SSLClientSocketPool* ssl_pool, | 88 SSLClientSocketPool* ssl_pool, |
89 HostResolver* host_resolver, | |
90 Delegate* delegate, | 89 Delegate* delegate, |
91 NetLog* net_log) | 90 NetLog* net_log) |
92 : ConnectJob(group_name, timeout_duration, priority, delegate, | 91 : ConnectJob(group_name, timeout_duration, priority, delegate, |
93 BoundNetLog::Make(net_log, NetLog::SOURCE_CONNECT_JOB)), | 92 BoundNetLog::Make(net_log, NetLog::SOURCE_CONNECT_JOB)), |
94 params_(params), | 93 params_(params), |
95 transport_pool_(transport_pool), | 94 transport_pool_(transport_pool), |
96 ssl_pool_(ssl_pool), | 95 ssl_pool_(ssl_pool), |
97 resolver_(host_resolver), | |
98 using_spdy_(false), | 96 using_spdy_(false), |
99 protocol_negotiated_(kProtoUnknown), | 97 protocol_negotiated_(kProtoUnknown), |
100 weak_ptr_factory_(this) { | 98 weak_ptr_factory_(this) { |
101 callback_= base::Bind(&HttpProxyConnectJob::OnIOComplete, | 99 callback_= base::Bind(&HttpProxyConnectJob::OnIOComplete, |
102 weak_ptr_factory_.GetWeakPtr()); | 100 weak_ptr_factory_.GetWeakPtr()); |
103 } | 101 } |
104 | 102 |
105 HttpProxyConnectJob::~HttpProxyConnectJob() {} | 103 HttpProxyConnectJob::~HttpProxyConnectJob() {} |
106 | 104 |
107 LoadState HttpProxyConnectJob::GetLoadState() const { | 105 LoadState HttpProxyConnectJob::GetLoadState() const { |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 } | 386 } |
389 | 387 |
390 return rv; | 388 return rv; |
391 } | 389 } |
392 | 390 |
393 HttpProxyClientSocketPool:: | 391 HttpProxyClientSocketPool:: |
394 HttpProxyConnectJobFactory::HttpProxyConnectJobFactory( | 392 HttpProxyConnectJobFactory::HttpProxyConnectJobFactory( |
395 TransportClientSocketPool* transport_pool, | 393 TransportClientSocketPool* transport_pool, |
396 SSLClientSocketPool* ssl_pool, | 394 SSLClientSocketPool* ssl_pool, |
397 HostResolver* host_resolver, | 395 HostResolver* host_resolver, |
398 const ProxyDelegate* proxy_delegate, | |
399 NetLog* net_log) | 396 NetLog* net_log) |
400 : transport_pool_(transport_pool), | 397 : transport_pool_(transport_pool), |
401 ssl_pool_(ssl_pool), | 398 ssl_pool_(ssl_pool), |
402 host_resolver_(host_resolver), | 399 host_resolver_(host_resolver), |
403 proxy_delegate_(proxy_delegate), | |
404 net_log_(net_log) { | 400 net_log_(net_log) { |
405 base::TimeDelta max_pool_timeout = base::TimeDelta(); | 401 base::TimeDelta max_pool_timeout = base::TimeDelta(); |
406 | 402 |
407 // TODO(kundaji): Proxy connect timeout should be independent of platform and be | 403 // TODO(kundaji): Proxy connect timeout should be independent of platform and be |
408 // based on proxy. Bug http://crbug.com/407446. | 404 // based on proxy. Bug http://crbug.com/407446. |
409 #if (defined(OS_ANDROID) || defined(OS_IOS)) | 405 #if (defined(OS_ANDROID) || defined(OS_IOS)) |
410 #else | 406 #else |
411 if (transport_pool_) | 407 if (transport_pool_) |
412 max_pool_timeout = transport_pool_->ConnectionTimeout(); | 408 max_pool_timeout = transport_pool_->ConnectionTimeout(); |
413 if (ssl_pool_) | 409 if (ssl_pool_) |
414 max_pool_timeout = std::max(max_pool_timeout, | 410 max_pool_timeout = std::max(max_pool_timeout, |
415 ssl_pool_->ConnectionTimeout()); | 411 ssl_pool_->ConnectionTimeout()); |
416 #endif | 412 #endif |
417 timeout_ = max_pool_timeout + | 413 timeout_ = max_pool_timeout + |
418 base::TimeDelta::FromSeconds(kHttpProxyConnectJobTimeoutInSeconds); | 414 base::TimeDelta::FromSeconds(kHttpProxyConnectJobTimeoutInSeconds); |
419 } | 415 } |
420 | 416 |
421 | 417 |
422 scoped_ptr<ConnectJob> | 418 scoped_ptr<ConnectJob> |
423 HttpProxyClientSocketPool::HttpProxyConnectJobFactory::NewConnectJob( | 419 HttpProxyClientSocketPool::HttpProxyConnectJobFactory::NewConnectJob( |
424 const std::string& group_name, | 420 const std::string& group_name, |
425 const PoolBase::Request& request, | 421 const PoolBase::Request& request, |
426 ConnectJob::Delegate* delegate) const { | 422 ConnectJob::Delegate* delegate) const { |
427 return scoped_ptr<ConnectJob>(new HttpProxyConnectJob(group_name, | 423 return scoped_ptr<ConnectJob>(new HttpProxyConnectJob(group_name, |
428 request.priority(), | 424 request.priority(), |
429 request.params(), | 425 request.params(), |
430 ConnectionTimeout(), | 426 ConnectionTimeout(), |
431 transport_pool_, | 427 transport_pool_, |
432 ssl_pool_, | 428 ssl_pool_, |
433 host_resolver_, | |
434 delegate, | 429 delegate, |
435 net_log_)); | 430 net_log_)); |
436 } | 431 } |
437 | 432 |
438 base::TimeDelta | 433 base::TimeDelta |
439 HttpProxyClientSocketPool::HttpProxyConnectJobFactory::ConnectionTimeout( | 434 HttpProxyClientSocketPool::HttpProxyConnectJobFactory::ConnectionTimeout( |
440 ) const { | 435 ) const { |
441 return timeout_; | 436 return timeout_; |
442 } | 437 } |
443 | 438 |
444 HttpProxyClientSocketPool::HttpProxyClientSocketPool( | 439 HttpProxyClientSocketPool::HttpProxyClientSocketPool( |
445 int max_sockets, | 440 int max_sockets, |
446 int max_sockets_per_group, | 441 int max_sockets_per_group, |
447 ClientSocketPoolHistograms* histograms, | 442 ClientSocketPoolHistograms* histograms, |
448 HostResolver* host_resolver, | 443 HostResolver* host_resolver, |
449 TransportClientSocketPool* transport_pool, | 444 TransportClientSocketPool* transport_pool, |
450 SSLClientSocketPool* ssl_pool, | 445 SSLClientSocketPool* ssl_pool, |
451 const ProxyDelegate* proxy_delegate, | |
452 NetLog* net_log) | 446 NetLog* net_log) |
453 : transport_pool_(transport_pool), | 447 : transport_pool_(transport_pool), |
454 ssl_pool_(ssl_pool), | 448 ssl_pool_(ssl_pool), |
455 base_(this, max_sockets, max_sockets_per_group, histograms, | 449 base_(this, max_sockets, max_sockets_per_group, histograms, |
456 ClientSocketPool::unused_idle_socket_timeout(), | 450 ClientSocketPool::unused_idle_socket_timeout(), |
457 ClientSocketPool::used_idle_socket_timeout(), | 451 ClientSocketPool::used_idle_socket_timeout(), |
458 new HttpProxyConnectJobFactory(transport_pool, | 452 new HttpProxyConnectJobFactory(transport_pool, |
459 ssl_pool, | 453 ssl_pool, |
460 host_resolver, | 454 host_resolver, |
461 proxy_delegate, | |
462 net_log)) { | 455 net_log)) { |
463 // We should always have a |transport_pool_| except in unit tests. | 456 // We should always have a |transport_pool_| except in unit tests. |
464 if (transport_pool_) | 457 if (transport_pool_) |
465 base_.AddLowerLayeredPool(transport_pool_); | 458 base_.AddLowerLayeredPool(transport_pool_); |
466 if (ssl_pool_) | 459 if (ssl_pool_) |
467 base_.AddLowerLayeredPool(ssl_pool_); | 460 base_.AddLowerLayeredPool(ssl_pool_); |
468 } | 461 } |
469 | 462 |
470 HttpProxyClientSocketPool::~HttpProxyClientSocketPool() { | 463 HttpProxyClientSocketPool::~HttpProxyClientSocketPool() { |
471 } | 464 } |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
570 base_.RemoveHigherLayeredPool(higher_pool); | 563 base_.RemoveHigherLayeredPool(higher_pool); |
571 } | 564 } |
572 | 565 |
573 bool HttpProxyClientSocketPool::CloseOneIdleConnection() { | 566 bool HttpProxyClientSocketPool::CloseOneIdleConnection() { |
574 if (base_.CloseOneIdleSocket()) | 567 if (base_.CloseOneIdleSocket()) |
575 return true; | 568 return true; |
576 return base_.CloseOneIdleConnectionInHigherLayeredPool(); | 569 return base_.CloseOneIdleConnectionInHigherLayeredPool(); |
577 } | 570 } |
578 | 571 |
579 } // namespace net | 572 } // namespace net |
OLD | NEW |