Commit 6f63606a authored by zea@chromium.org's avatar zea@chromium.org

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
parent 4f897ec9
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "google_apis/gcm/protocol/checkin.pb.h" #include "google_apis/gcm/protocol/checkin.pb.h"
#include "google_apis/gcm/protocol/mcs.pb.h" #include "google_apis/gcm/protocol/mcs.pb.h"
#include "net/http/http_network_session.h" #include "net/http/http_network_session.h"
#include "net/http/http_transaction_factory.h"
#include "net/url_request/url_request_context.h" #include "net/url_request/url_request_context.h"
#include "url/gurl.h" #include "url/gurl.h"
...@@ -236,13 +237,15 @@ scoped_ptr<MCSClient> GCMInternalsBuilder::BuildMCSClient( ...@@ -236,13 +237,15 @@ scoped_ptr<MCSClient> GCMInternalsBuilder::BuildMCSClient(
scoped_ptr<ConnectionFactory> GCMInternalsBuilder::BuildConnectionFactory( scoped_ptr<ConnectionFactory> GCMInternalsBuilder::BuildConnectionFactory(
const std::vector<GURL>& endpoints, const std::vector<GURL>& endpoints,
const net::BackoffEntry::Policy& backoff_policy, 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, net::NetLog* net_log,
GCMStatsRecorder* recorder) { GCMStatsRecorder* recorder) {
return make_scoped_ptr<ConnectionFactory>( return make_scoped_ptr<ConnectionFactory>(
new ConnectionFactoryImpl(endpoints, new ConnectionFactoryImpl(endpoints,
backoff_policy, backoff_policy,
network_session, gcm_network_session,
http_network_session,
net_log, net_log,
recorder)); recorder));
} }
...@@ -371,6 +374,9 @@ void GCMClientImpl::InitializeMCSClient( ...@@ -371,6 +374,9 @@ void GCMClientImpl::InitializeMCSClient(
endpoints, endpoints,
kDefaultBackoffPolicy, kDefaultBackoffPolicy,
network_session_, network_session_,
url_request_context_getter_->GetURLRequestContext()
->http_transaction_factory()
->GetSession(),
net_log_.net_log(), net_log_.net_log(),
&recorder_); &recorder_);
connection_factory_->SetConnectionListener(this); connection_factory_->SetConnectionListener(this);
......
...@@ -65,7 +65,8 @@ class GCMInternalsBuilder { ...@@ -65,7 +65,8 @@ class GCMInternalsBuilder {
virtual scoped_ptr<ConnectionFactory> BuildConnectionFactory( virtual scoped_ptr<ConnectionFactory> BuildConnectionFactory(
const std::vector<GURL>& endpoints, const std::vector<GURL>& endpoints,
const net::BackoffEntry::Policy& backoff_policy, 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, net::NetLog* net_log,
GCMStatsRecorder* recorder); GCMStatsRecorder* recorder);
}; };
......
...@@ -168,7 +168,8 @@ class FakeGCMInternalsBuilder : public GCMInternalsBuilder { ...@@ -168,7 +168,8 @@ class FakeGCMInternalsBuilder : public GCMInternalsBuilder {
virtual scoped_ptr<ConnectionFactory> BuildConnectionFactory( virtual scoped_ptr<ConnectionFactory> BuildConnectionFactory(
const std::vector<GURL>& endpoints, const std::vector<GURL>& endpoints,
const net::BackoffEntry::Policy& backoff_policy, 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, net::NetLog* net_log,
GCMStatsRecorder* recorder) OVERRIDE; GCMStatsRecorder* recorder) OVERRIDE;
...@@ -201,7 +202,8 @@ scoped_ptr<MCSClient> FakeGCMInternalsBuilder::BuildMCSClient( ...@@ -201,7 +202,8 @@ scoped_ptr<MCSClient> FakeGCMInternalsBuilder::BuildMCSClient(
scoped_ptr<ConnectionFactory> FakeGCMInternalsBuilder::BuildConnectionFactory( scoped_ptr<ConnectionFactory> FakeGCMInternalsBuilder::BuildConnectionFactory(
const std::vector<GURL>& endpoints, const std::vector<GURL>& endpoints,
const net::BackoffEntry::Policy& backoff_policy, 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, net::NetLog* net_log,
GCMStatsRecorder* recorder) { GCMStatsRecorder* recorder) {
return make_scoped_ptr<ConnectionFactory>(new FakeConnectionFactory()); return make_scoped_ptr<ConnectionFactory>(new FakeConnectionFactory());
......
...@@ -45,14 +45,16 @@ bool ShouldRestorePreviousBackoff(const base::TimeTicks& login_time, ...@@ -45,14 +45,16 @@ bool ShouldRestorePreviousBackoff(const base::TimeTicks& login_time,
ConnectionFactoryImpl::ConnectionFactoryImpl( ConnectionFactoryImpl::ConnectionFactoryImpl(
const std::vector<GURL>& mcs_endpoints, const std::vector<GURL>& mcs_endpoints,
const net::BackoffEntry::Policy& backoff_policy, 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, net::NetLog* net_log,
GCMStatsRecorder* recorder) GCMStatsRecorder* recorder)
: mcs_endpoints_(mcs_endpoints), : mcs_endpoints_(mcs_endpoints),
next_endpoint_(0), next_endpoint_(0),
last_successful_endpoint_(0), last_successful_endpoint_(0),
backoff_policy_(backoff_policy), backoff_policy_(backoff_policy),
network_session_(network_session), gcm_network_session_(gcm_network_session),
http_network_session_(http_network_session),
bound_net_log_( bound_net_log_(
net::BoundNetLog::Make(net_log, net::NetLog::SOURCE_SOCKET)), net::BoundNetLog::Make(net_log, net::NetLog::SOURCE_SOCKET)),
pac_request_(NULL), pac_request_(NULL),
...@@ -64,13 +66,15 @@ ConnectionFactoryImpl::ConnectionFactoryImpl( ...@@ -64,13 +66,15 @@ ConnectionFactoryImpl::ConnectionFactoryImpl(
listener_(NULL), listener_(NULL),
weak_ptr_factory_(this) { weak_ptr_factory_(this) {
DCHECK_GE(mcs_endpoints_.size(), 1U); DCHECK_GE(mcs_endpoints_.size(), 1U);
DCHECK(!http_network_session_.get() ||
(gcm_network_session_.get() != http_network_session_.get()));
} }
ConnectionFactoryImpl::~ConnectionFactoryImpl() { ConnectionFactoryImpl::~ConnectionFactoryImpl() {
CloseSocket(); CloseSocket();
net::NetworkChangeNotifier::RemoveNetworkChangeObserver(this); net::NetworkChangeNotifier::RemoveNetworkChangeObserver(this);
if (pac_request_) { if (pac_request_) {
network_session_->proxy_service()->CancelPacRequest(pac_request_); gcm_network_session_->proxy_service()->CancelPacRequest(pac_request_);
pac_request_ = NULL; pac_request_ = NULL;
} }
} }
...@@ -280,7 +284,8 @@ void ConnectionFactoryImpl::ConnectImpl() { ...@@ -280,7 +284,8 @@ void ConnectionFactoryImpl::ConnectImpl() {
connecting_ = true; connecting_ = true;
GURL current_endpoint = GetCurrentEndpoint(); GURL current_endpoint = GetCurrentEndpoint();
recorder_->RecordConnectionInitiated(current_endpoint.host()); recorder_->RecordConnectionInitiated(current_endpoint.host());
int status = network_session_->proxy_service()->ResolveProxy( RebuildNetworkSessionAuthCache();
int status = gcm_network_session_->proxy_service()->ResolveProxy(
current_endpoint, current_endpoint,
net::LOAD_NORMAL, net::LOAD_NORMAL,
&proxy_info_, &proxy_info_,
...@@ -425,10 +430,10 @@ void ConnectionFactoryImpl::OnProxyResolveDone(int status) { ...@@ -425,10 +430,10 @@ void ConnectionFactoryImpl::OnProxyResolveDone(int status) {
DVLOG(1) << "Resolved proxy with PAC:" << proxy_info_.ToPacString(); DVLOG(1) << "Resolved proxy with PAC:" << proxy_info_.ToPacString();
net::SSLConfig ssl_config; net::SSLConfig ssl_config;
network_session_->ssl_config_service()->GetSSLConfig(&ssl_config); gcm_network_session_->ssl_config_service()->GetSSLConfig(&ssl_config);
status = net::InitSocketHandleForTlsConnect( status = net::InitSocketHandleForTlsConnect(
net::HostPortPair::FromURL(GetCurrentEndpoint()), net::HostPortPair::FromURL(GetCurrentEndpoint()),
network_session_.get(), gcm_network_session_.get(),
proxy_info_, proxy_info_,
ssl_config, ssl_config,
ssl_config, ssl_config,
...@@ -494,13 +499,13 @@ int ConnectionFactoryImpl::ReconsiderProxyAfterError(int error) { ...@@ -494,13 +499,13 @@ int ConnectionFactoryImpl::ReconsiderProxyAfterError(int error) {
} }
net::SSLConfig ssl_config; 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) { 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()); 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_, GetCurrentEndpoint(), net::LOAD_NORMAL, error, &proxy_info_,
base::Bind(&ConnectionFactoryImpl::OnProxyResolveDone, base::Bind(&ConnectionFactoryImpl::OnProxyResolveDone,
weak_ptr_factory_.GetWeakPtr()), weak_ptr_factory_.GetWeakPtr()),
...@@ -529,8 +534,8 @@ int ConnectionFactoryImpl::ReconsiderProxyAfterError(int error) { ...@@ -529,8 +534,8 @@ int ConnectionFactoryImpl::ReconsiderProxyAfterError(int error) {
} }
void ConnectionFactoryImpl::ReportSuccessfulProxyConnection() { void ConnectionFactoryImpl::ReportSuccessfulProxyConnection() {
if (network_session_ && network_session_->proxy_service()) if (gcm_network_session_ && gcm_network_session_->proxy_service())
network_session_->proxy_service()->ReportSuccess(proxy_info_); gcm_network_session_->proxy_service()->ReportSuccess(proxy_info_);
} }
void ConnectionFactoryImpl::CloseSocket() { void ConnectionFactoryImpl::CloseSocket() {
...@@ -544,4 +549,12 @@ void ConnectionFactoryImpl::CloseSocket() { ...@@ -544,4 +549,12 @@ void ConnectionFactoryImpl::CloseSocket() {
socket_handle_.Reset(); 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 } // namespace gcm
...@@ -31,10 +31,15 @@ class GCM_EXPORT ConnectionFactoryImpl : ...@@ -31,10 +31,15 @@ class GCM_EXPORT ConnectionFactoryImpl :
public ConnectionFactory, public ConnectionFactory,
public net::NetworkChangeNotifier::NetworkChangeObserver { public net::NetworkChangeNotifier::NetworkChangeObserver {
public: 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( ConnectionFactoryImpl(
const std::vector<GURL>& mcs_endpoints, const std::vector<GURL>& mcs_endpoints,
const net::BackoffEntry::Policy& backoff_policy, 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, net::NetLog* net_log,
GCMStatsRecorder* recorder); GCMStatsRecorder* recorder);
virtual ~ConnectionFactoryImpl(); virtual ~ConnectionFactoryImpl();
...@@ -110,8 +115,13 @@ class GCM_EXPORT ConnectionFactoryImpl : ...@@ -110,8 +115,13 @@ class GCM_EXPORT ConnectionFactoryImpl :
int ReconsiderProxyAfterError(int error); int ReconsiderProxyAfterError(int error);
void ReportSuccessfulProxyConnection(); void ReportSuccessfulProxyConnection();
// Closes the local socket if one is present, and resets connection handler.
void CloseSocket(); 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. // The MCS endpoints to make connections to, sorted in order of priority.
const std::vector<GURL> mcs_endpoints_; const std::vector<GURL> mcs_endpoints_;
// Index to the endpoint for which a connection should be attempted next. // Index to the endpoint for which a connection should be attempted next.
...@@ -123,8 +133,11 @@ class GCM_EXPORT ConnectionFactoryImpl : ...@@ -123,8 +133,11 @@ class GCM_EXPORT ConnectionFactoryImpl :
const net::BackoffEntry::Policy backoff_policy_; const net::BackoffEntry::Policy backoff_policy_;
// ---- net:: components for establishing connections. ---- // ---- net:: components for establishing connections. ----
// Network session for creating new connections. // Network session for creating new GCM connections.
const scoped_refptr<net::HttpNetworkSession> network_session_; 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 log to use in connection attempts.
net::BoundNetLog bound_net_log_; net::BoundNetLog bound_net_log_;
// The current PAC request, if one exists. Owned by the proxy service. // The current PAC request, if one exists. Owned by the proxy service.
......
...@@ -159,6 +159,7 @@ TestConnectionFactoryImpl::TestConnectionFactoryImpl( ...@@ -159,6 +159,7 @@ TestConnectionFactoryImpl::TestConnectionFactoryImpl(
net::BackoffEntry::Policy(), net::BackoffEntry::Policy(),
NULL, NULL,
NULL, NULL,
NULL,
&dummy_recorder_), &dummy_recorder_),
connect_result_(net::ERR_UNEXPECTED), connect_result_(net::ERR_UNEXPECTED),
num_expected_attempts_(0), num_expected_attempts_(0),
......
...@@ -303,6 +303,7 @@ void MCSProbe::Start() { ...@@ -303,6 +303,7 @@ void MCSProbe::Start() {
new ConnectionFactoryImpl(endpoints, new ConnectionFactoryImpl(endpoints,
kDefaultBackoffPolicy, kDefaultBackoffPolicy,
network_session_, network_session_,
NULL,
&net_log_, &net_log_,
&recorder_)); &recorder_));
gcm_store_.reset( gcm_store_.reset(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment