diff options
author | zea@chromium.org <zea@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-07-18 02:18:55 +0000 |
---|---|---|
committer | zea@chromium.org <zea@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-07-18 02:18:55 +0000 |
commit | 6f63606a8e7134077491ed24e883ad57120eeba3 (patch) | |
tree | d5988c0a6b1c1256ec92d4603ccd6f70d68322b7 /google_apis | |
parent | 4f897ec9161aa170fbd8d71a3d2aa9b8fb5d9d88 (diff) | |
download | chromium_src-6f63606a8e7134077491ed24e883ad57120eeba3.zip chromium_src-6f63606a8e7134077491ed24e883ad57120eeba3.tar.gz chromium_src-6f63606a8e7134077491ed24e883ad57120eeba3.tar.bz2 |
Leverage profile's http network session HttpAuthCache to support proxy auth.
This allows the connect job to leverage any auth cache credentials the profile
has, including those the user gets prompted for as part of loading a page
while behind an authenticated proxy. GCM continues to use its own network
session for creating the connections, but at connection time the HttpAuthCache
is coped over from the profile's http network session (if available).
BUG=385748
Review URL: https://codereview.chromium.org/375663002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@283973 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'google_apis')
-rw-r--r-- | google_apis/gcm/engine/connection_factory_impl.cc | 35 | ||||
-rw-r--r-- | google_apis/gcm/engine/connection_factory_impl.h | 19 | ||||
-rw-r--r-- | google_apis/gcm/engine/connection_factory_impl_unittest.cc | 1 | ||||
-rw-r--r-- | google_apis/gcm/tools/mcs_probe.cc | 1 |
4 files changed, 42 insertions, 14 deletions
diff --git a/google_apis/gcm/engine/connection_factory_impl.cc b/google_apis/gcm/engine/connection_factory_impl.cc index 0ff3175..f7cd669 100644 --- a/google_apis/gcm/engine/connection_factory_impl.cc +++ b/google_apis/gcm/engine/connection_factory_impl.cc @@ -45,14 +45,16 @@ bool ShouldRestorePreviousBackoff(const base::TimeTicks& login_time, ConnectionFactoryImpl::ConnectionFactoryImpl( const std::vector<GURL>& mcs_endpoints, const net::BackoffEntry::Policy& backoff_policy, - scoped_refptr<net::HttpNetworkSession> network_session, + const scoped_refptr<net::HttpNetworkSession>& gcm_network_session, + const scoped_refptr<net::HttpNetworkSession>& http_network_session, net::NetLog* net_log, GCMStatsRecorder* recorder) : mcs_endpoints_(mcs_endpoints), next_endpoint_(0), last_successful_endpoint_(0), backoff_policy_(backoff_policy), - network_session_(network_session), + gcm_network_session_(gcm_network_session), + http_network_session_(http_network_session), bound_net_log_( net::BoundNetLog::Make(net_log, net::NetLog::SOURCE_SOCKET)), pac_request_(NULL), @@ -64,13 +66,15 @@ ConnectionFactoryImpl::ConnectionFactoryImpl( listener_(NULL), weak_ptr_factory_(this) { DCHECK_GE(mcs_endpoints_.size(), 1U); + DCHECK(!http_network_session_.get() || + (gcm_network_session_.get() != http_network_session_.get())); } ConnectionFactoryImpl::~ConnectionFactoryImpl() { CloseSocket(); net::NetworkChangeNotifier::RemoveNetworkChangeObserver(this); if (pac_request_) { - network_session_->proxy_service()->CancelPacRequest(pac_request_); + gcm_network_session_->proxy_service()->CancelPacRequest(pac_request_); pac_request_ = NULL; } } @@ -280,7 +284,8 @@ void ConnectionFactoryImpl::ConnectImpl() { connecting_ = true; GURL current_endpoint = GetCurrentEndpoint(); recorder_->RecordConnectionInitiated(current_endpoint.host()); - int status = network_session_->proxy_service()->ResolveProxy( + RebuildNetworkSessionAuthCache(); + int status = gcm_network_session_->proxy_service()->ResolveProxy( current_endpoint, net::LOAD_NORMAL, &proxy_info_, @@ -425,10 +430,10 @@ void ConnectionFactoryImpl::OnProxyResolveDone(int status) { DVLOG(1) << "Resolved proxy with PAC:" << proxy_info_.ToPacString(); net::SSLConfig ssl_config; - network_session_->ssl_config_service()->GetSSLConfig(&ssl_config); + gcm_network_session_->ssl_config_service()->GetSSLConfig(&ssl_config); status = net::InitSocketHandleForTlsConnect( net::HostPortPair::FromURL(GetCurrentEndpoint()), - network_session_.get(), + gcm_network_session_.get(), proxy_info_, ssl_config, ssl_config, @@ -494,13 +499,13 @@ int ConnectionFactoryImpl::ReconsiderProxyAfterError(int error) { } net::SSLConfig ssl_config; - network_session_->ssl_config_service()->GetSSLConfig(&ssl_config); + gcm_network_session_->ssl_config_service()->GetSSLConfig(&ssl_config); if (proxy_info_.is_https() && ssl_config.send_client_cert) { - network_session_->ssl_client_auth_cache()->Remove( + gcm_network_session_->ssl_client_auth_cache()->Remove( proxy_info_.proxy_server().host_port_pair()); } - int status = network_session_->proxy_service()->ReconsiderProxyAfterError( + int status = gcm_network_session_->proxy_service()->ReconsiderProxyAfterError( GetCurrentEndpoint(), net::LOAD_NORMAL, error, &proxy_info_, base::Bind(&ConnectionFactoryImpl::OnProxyResolveDone, weak_ptr_factory_.GetWeakPtr()), @@ -529,8 +534,8 @@ int ConnectionFactoryImpl::ReconsiderProxyAfterError(int error) { } void ConnectionFactoryImpl::ReportSuccessfulProxyConnection() { - if (network_session_ && network_session_->proxy_service()) - network_session_->proxy_service()->ReportSuccess(proxy_info_); + if (gcm_network_session_ && gcm_network_session_->proxy_service()) + gcm_network_session_->proxy_service()->ReportSuccess(proxy_info_); } void ConnectionFactoryImpl::CloseSocket() { @@ -544,4 +549,12 @@ void ConnectionFactoryImpl::CloseSocket() { socket_handle_.Reset(); } +void ConnectionFactoryImpl::RebuildNetworkSessionAuthCache() { + if (!http_network_session_ || !http_network_session_->http_auth_cache()) + return; + + gcm_network_session_->http_auth_cache()->UpdateAllFrom( + *http_network_session_->http_auth_cache()); +} + } // namespace gcm diff --git a/google_apis/gcm/engine/connection_factory_impl.h b/google_apis/gcm/engine/connection_factory_impl.h index 80fbc94..ddd8173 100644 --- a/google_apis/gcm/engine/connection_factory_impl.h +++ b/google_apis/gcm/engine/connection_factory_impl.h @@ -31,10 +31,15 @@ class GCM_EXPORT ConnectionFactoryImpl : public ConnectionFactory, public net::NetworkChangeNotifier::NetworkChangeObserver { public: + // |http_network_session| is an optional network session to use as a source + // for proxy auth credentials (via its HttpAuthCache). |gcm_network_session| + // is the network session through which GCM connections should be made, and + // must not be the same as |http_network_session|. ConnectionFactoryImpl( const std::vector<GURL>& mcs_endpoints, const net::BackoffEntry::Policy& backoff_policy, - scoped_refptr<net::HttpNetworkSession> network_session, + const scoped_refptr<net::HttpNetworkSession>& gcm_network_session, + const scoped_refptr<net::HttpNetworkSession>& http_network_session, net::NetLog* net_log, GCMStatsRecorder* recorder); virtual ~ConnectionFactoryImpl(); @@ -110,8 +115,13 @@ class GCM_EXPORT ConnectionFactoryImpl : int ReconsiderProxyAfterError(int error); void ReportSuccessfulProxyConnection(); + // Closes the local socket if one is present, and resets connection handler. void CloseSocket(); + // Updates the GCM Network Session's HttpAuthCache with the HTTP Network + // Session's cache, if available. + void RebuildNetworkSessionAuthCache(); + // The MCS endpoints to make connections to, sorted in order of priority. const std::vector<GURL> mcs_endpoints_; // Index to the endpoint for which a connection should be attempted next. @@ -123,8 +133,11 @@ class GCM_EXPORT ConnectionFactoryImpl : const net::BackoffEntry::Policy backoff_policy_; // ---- net:: components for establishing connections. ---- - // Network session for creating new connections. - const scoped_refptr<net::HttpNetworkSession> network_session_; + // Network session for creating new GCM connections. + const scoped_refptr<net::HttpNetworkSession> gcm_network_session_; + // HTTP Network session. If set, is used for extracting proxy auth + // credentials. If not set, is ignored. + const scoped_refptr<net::HttpNetworkSession> http_network_session_; // Net log to use in connection attempts. net::BoundNetLog bound_net_log_; // The current PAC request, if one exists. Owned by the proxy service. diff --git a/google_apis/gcm/engine/connection_factory_impl_unittest.cc b/google_apis/gcm/engine/connection_factory_impl_unittest.cc index da9485f..310e831 100644 --- a/google_apis/gcm/engine/connection_factory_impl_unittest.cc +++ b/google_apis/gcm/engine/connection_factory_impl_unittest.cc @@ -159,6 +159,7 @@ TestConnectionFactoryImpl::TestConnectionFactoryImpl( net::BackoffEntry::Policy(), NULL, NULL, + NULL, &dummy_recorder_), connect_result_(net::ERR_UNEXPECTED), num_expected_attempts_(0), diff --git a/google_apis/gcm/tools/mcs_probe.cc b/google_apis/gcm/tools/mcs_probe.cc index 9e090fd..048b48c 100644 --- a/google_apis/gcm/tools/mcs_probe.cc +++ b/google_apis/gcm/tools/mcs_probe.cc @@ -303,6 +303,7 @@ void MCSProbe::Start() { new ConnectionFactoryImpl(endpoints, kDefaultBackoffPolicy, network_session_, + NULL, &net_log_, &recorder_)); gcm_store_.reset( |