| 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/callback.h" |
| 9 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 10 #include "base/time/time.h" | 11 #include "base/time/time.h" |
| 11 #include "base/values.h" | 12 #include "base/values.h" |
| 12 #include "net/base/load_flags.h" | 13 #include "net/base/load_flags.h" |
| 13 #include "net/base/net_errors.h" | 14 #include "net/base/net_errors.h" |
| 14 #include "net/http/http_network_session.h" | 15 #include "net/http/http_network_session.h" |
| 15 #include "net/http/http_proxy_client_socket.h" | 16 #include "net/http/http_proxy_client_socket.h" |
| 16 #include "net/socket/client_socket_factory.h" | 17 #include "net/socket/client_socket_factory.h" |
| 17 #include "net/socket/client_socket_handle.h" | 18 #include "net/socket/client_socket_handle.h" |
| 18 #include "net/socket/client_socket_pool_base.h" | 19 #include "net/socket/client_socket_pool_base.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 30 | 31 |
| 31 HttpProxySocketParams::HttpProxySocketParams( | 32 HttpProxySocketParams::HttpProxySocketParams( |
| 32 const scoped_refptr<TransportSocketParams>& transport_params, | 33 const scoped_refptr<TransportSocketParams>& transport_params, |
| 33 const scoped_refptr<SSLSocketParams>& ssl_params, | 34 const scoped_refptr<SSLSocketParams>& ssl_params, |
| 34 const GURL& request_url, | 35 const GURL& request_url, |
| 35 const std::string& user_agent, | 36 const std::string& user_agent, |
| 36 const HostPortPair& endpoint, | 37 const HostPortPair& endpoint, |
| 37 HttpAuthCache* http_auth_cache, | 38 HttpAuthCache* http_auth_cache, |
| 38 HttpAuthHandlerFactory* http_auth_handler_factory, | 39 HttpAuthHandlerFactory* http_auth_handler_factory, |
| 39 SpdySessionPool* spdy_session_pool, | 40 SpdySessionPool* spdy_session_pool, |
| 40 bool tunnel) | 41 bool tunnel, |
| 42 const base::Callback<void(const HostPortPair&, HttpRequestHeaders*)>& |
| 43 before_proxy_tunnel_connect_callback) |
| 41 : transport_params_(transport_params), | 44 : transport_params_(transport_params), |
| 42 ssl_params_(ssl_params), | 45 ssl_params_(ssl_params), |
| 43 spdy_session_pool_(spdy_session_pool), | 46 spdy_session_pool_(spdy_session_pool), |
| 44 request_url_(request_url), | 47 request_url_(request_url), |
| 45 user_agent_(user_agent), | 48 user_agent_(user_agent), |
| 46 endpoint_(endpoint), | 49 endpoint_(endpoint), |
| 47 http_auth_cache_(tunnel ? http_auth_cache : NULL), | 50 http_auth_cache_(tunnel ? http_auth_cache : NULL), |
| 48 http_auth_handler_factory_(tunnel ? http_auth_handler_factory : NULL), | 51 http_auth_handler_factory_(tunnel ? http_auth_handler_factory : NULL), |
| 49 tunnel_(tunnel) { | 52 tunnel_(tunnel), |
| 53 before_proxy_tunnel_request_callback_( |
| 54 before_proxy_tunnel_connect_callback) { |
| 50 DCHECK((transport_params.get() == NULL && ssl_params.get() != NULL) || | 55 DCHECK((transport_params.get() == NULL && ssl_params.get() != NULL) || |
| 51 (transport_params.get() != NULL && ssl_params.get() == NULL)); | 56 (transport_params.get() != NULL && ssl_params.get() == NULL)); |
| 52 if (transport_params_.get()) { | 57 if (transport_params_.get()) { |
| 53 ignore_limits_ = transport_params->ignore_limits(); | 58 ignore_limits_ = transport_params->ignore_limits(); |
| 54 } else { | 59 } else { |
| 55 ignore_limits_ = ssl_params->ignore_limits(); | 60 ignore_limits_ = ssl_params->ignore_limits(); |
| 56 } | 61 } |
| 57 } | 62 } |
| 58 | 63 |
| 59 const HostResolver::RequestInfo& HttpProxySocketParams::destination() const { | 64 const HostResolver::RequestInfo& HttpProxySocketParams::destination() const { |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 new HttpProxyClientSocket(transport_socket_handle_.release(), | 289 new HttpProxyClientSocket(transport_socket_handle_.release(), |
| 285 params_->request_url(), | 290 params_->request_url(), |
| 286 params_->user_agent(), | 291 params_->user_agent(), |
| 287 params_->endpoint(), | 292 params_->endpoint(), |
| 288 proxy_server, | 293 proxy_server, |
| 289 params_->http_auth_cache(), | 294 params_->http_auth_cache(), |
| 290 params_->http_auth_handler_factory(), | 295 params_->http_auth_handler_factory(), |
| 291 params_->tunnel(), | 296 params_->tunnel(), |
| 292 using_spdy_, | 297 using_spdy_, |
| 293 protocol_negotiated_, | 298 protocol_negotiated_, |
| 299 params_->before_proxy_tunnel_request_callback(), |
| 294 params_->ssl_params().get() != NULL)); | 300 params_->ssl_params().get() != NULL)); |
| 295 return transport_socket_->Connect(callback_); | 301 return transport_socket_->Connect(callback_); |
| 296 } | 302 } |
| 297 | 303 |
| 298 int HttpProxyConnectJob::DoHttpProxyConnectComplete(int result) { | 304 int HttpProxyConnectJob::DoHttpProxyConnectComplete(int result) { |
| 299 if (result == OK || result == ERR_PROXY_AUTH_REQUESTED || | 305 if (result == OK || result == ERR_PROXY_AUTH_REQUESTED || |
| 300 result == ERR_HTTPS_PROXY_TUNNEL_RESPONSE) { | 306 result == ERR_HTTPS_PROXY_TUNNEL_RESPONSE) { |
| 301 SetSocket(transport_socket_.PassAs<StreamSocket>()); | 307 SetSocket(transport_socket_.PassAs<StreamSocket>()); |
| 302 } | 308 } |
| 303 | 309 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 next_state_ = STATE_SSL_CONNECT; | 371 next_state_ = STATE_SSL_CONNECT; |
| 366 } | 372 } |
| 367 return DoLoop(OK); | 373 return DoLoop(OK); |
| 368 } | 374 } |
| 369 | 375 |
| 370 HttpProxyClientSocketPool:: | 376 HttpProxyClientSocketPool:: |
| 371 HttpProxyConnectJobFactory::HttpProxyConnectJobFactory( | 377 HttpProxyConnectJobFactory::HttpProxyConnectJobFactory( |
| 372 TransportClientSocketPool* transport_pool, | 378 TransportClientSocketPool* transport_pool, |
| 373 SSLClientSocketPool* ssl_pool, | 379 SSLClientSocketPool* ssl_pool, |
| 374 HostResolver* host_resolver, | 380 HostResolver* host_resolver, |
| 381 base::Callback<void(const HostPortPair&, HttpRequestHeaders*)> |
| 382 before_proxy_tunnel_request_callback, |
| 375 NetLog* net_log) | 383 NetLog* net_log) |
| 376 : transport_pool_(transport_pool), | 384 : transport_pool_(transport_pool), |
| 377 ssl_pool_(ssl_pool), | 385 ssl_pool_(ssl_pool), |
| 378 host_resolver_(host_resolver), | 386 host_resolver_(host_resolver), |
| 387 before_proxy_tunnel_request_callback_( |
| 388 before_proxy_tunnel_request_callback), |
| 379 net_log_(net_log) { | 389 net_log_(net_log) { |
| 380 base::TimeDelta max_pool_timeout = base::TimeDelta(); | 390 base::TimeDelta max_pool_timeout = base::TimeDelta(); |
| 381 | 391 |
| 382 #if (defined(OS_ANDROID) || defined(OS_IOS)) && defined(SPDY_PROXY_AUTH_ORIGIN) | 392 #if (defined(OS_ANDROID) || defined(OS_IOS)) && defined(SPDY_PROXY_AUTH_ORIGIN) |
| 383 #else | 393 #else |
| 384 if (transport_pool_) | 394 if (transport_pool_) |
| 385 max_pool_timeout = transport_pool_->ConnectionTimeout(); | 395 max_pool_timeout = transport_pool_->ConnectionTimeout(); |
| 386 if (ssl_pool_) | 396 if (ssl_pool_) |
| 387 max_pool_timeout = std::max(max_pool_timeout, | 397 max_pool_timeout = std::max(max_pool_timeout, |
| 388 ssl_pool_->ConnectionTimeout()); | 398 ssl_pool_->ConnectionTimeout()); |
| 389 #endif | 399 #endif |
| 390 timeout_ = max_pool_timeout + | 400 timeout_ = max_pool_timeout + |
| 391 base::TimeDelta::FromSeconds(kHttpProxyConnectJobTimeoutInSeconds); | 401 base::TimeDelta::FromSeconds(kHttpProxyConnectJobTimeoutInSeconds); |
| 392 } | 402 } |
| 393 | 403 |
| 404 HttpProxyClientSocketPool:: |
| 405 HttpProxyConnectJobFactory::~HttpProxyConnectJobFactory() { |
| 406 } |
| 407 |
| 394 | 408 |
| 395 scoped_ptr<ConnectJob> | 409 scoped_ptr<ConnectJob> |
| 396 HttpProxyClientSocketPool::HttpProxyConnectJobFactory::NewConnectJob( | 410 HttpProxyClientSocketPool::HttpProxyConnectJobFactory::NewConnectJob( |
| 397 const std::string& group_name, | 411 const std::string& group_name, |
| 398 const PoolBase::Request& request, | 412 const PoolBase::Request& request, |
| 399 ConnectJob::Delegate* delegate) const { | 413 ConnectJob::Delegate* delegate) const { |
| 400 return scoped_ptr<ConnectJob>(new HttpProxyConnectJob(group_name, | 414 return scoped_ptr<ConnectJob>(new HttpProxyConnectJob(group_name, |
| 401 request.priority(), | 415 request.priority(), |
| 402 request.params(), | 416 request.params(), |
| 403 ConnectionTimeout(), | 417 ConnectionTimeout(), |
| (...skipping 10 matching lines...) Expand all Loading... |
| 414 return timeout_; | 428 return timeout_; |
| 415 } | 429 } |
| 416 | 430 |
| 417 HttpProxyClientSocketPool::HttpProxyClientSocketPool( | 431 HttpProxyClientSocketPool::HttpProxyClientSocketPool( |
| 418 int max_sockets, | 432 int max_sockets, |
| 419 int max_sockets_per_group, | 433 int max_sockets_per_group, |
| 420 ClientSocketPoolHistograms* histograms, | 434 ClientSocketPoolHistograms* histograms, |
| 421 HostResolver* host_resolver, | 435 HostResolver* host_resolver, |
| 422 TransportClientSocketPool* transport_pool, | 436 TransportClientSocketPool* transport_pool, |
| 423 SSLClientSocketPool* ssl_pool, | 437 SSLClientSocketPool* ssl_pool, |
| 438 const base::Callback<void(const HostPortPair&, HttpRequestHeaders*)>& |
| 439 before_proxy_tunnel_request_callback, |
| 424 NetLog* net_log) | 440 NetLog* net_log) |
| 425 : transport_pool_(transport_pool), | 441 : transport_pool_(transport_pool), |
| 426 ssl_pool_(ssl_pool), | 442 ssl_pool_(ssl_pool), |
| 427 base_(this, max_sockets, max_sockets_per_group, histograms, | 443 base_(this, max_sockets, max_sockets_per_group, histograms, |
| 428 ClientSocketPool::unused_idle_socket_timeout(), | 444 ClientSocketPool::unused_idle_socket_timeout(), |
| 429 ClientSocketPool::used_idle_socket_timeout(), | 445 ClientSocketPool::used_idle_socket_timeout(), |
| 430 new HttpProxyConnectJobFactory(transport_pool, | 446 new HttpProxyConnectJobFactory(transport_pool, |
| 431 ssl_pool, | 447 ssl_pool, |
| 432 host_resolver, | 448 host_resolver, |
| 449 before_proxy_tunnel_request_callback, |
| 433 net_log)) { | 450 net_log)) { |
| 434 // We should always have a |transport_pool_| except in unit tests. | 451 // We should always have a |transport_pool_| except in unit tests. |
| 435 if (transport_pool_) | 452 if (transport_pool_) |
| 436 base_.AddLowerLayeredPool(transport_pool_); | 453 base_.AddLowerLayeredPool(transport_pool_); |
| 437 if (ssl_pool_) | 454 if (ssl_pool_) |
| 438 base_.AddLowerLayeredPool(ssl_pool_); | 455 base_.AddLowerLayeredPool(ssl_pool_); |
| 439 } | 456 } |
| 440 | 457 |
| 441 HttpProxyClientSocketPool::~HttpProxyClientSocketPool() { | 458 HttpProxyClientSocketPool::~HttpProxyClientSocketPool() { |
| 442 } | 459 } |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 541 base_.RemoveHigherLayeredPool(higher_pool); | 558 base_.RemoveHigherLayeredPool(higher_pool); |
| 542 } | 559 } |
| 543 | 560 |
| 544 bool HttpProxyClientSocketPool::CloseOneIdleConnection() { | 561 bool HttpProxyClientSocketPool::CloseOneIdleConnection() { |
| 545 if (base_.CloseOneIdleSocket()) | 562 if (base_.CloseOneIdleSocket()) |
| 546 return true; | 563 return true; |
| 547 return base_.CloseOneIdleConnectionInHigherLayeredPool(); | 564 return base_.CloseOneIdleConnectionInHigherLayeredPool(); |
| 548 } | 565 } |
| 549 | 566 |
| 550 } // namespace net | 567 } // namespace net |
| OLD | NEW |