Skip to content

Commit

Permalink
Leverage profile's http network session HttpAuthCache to support prox…
Browse files Browse the repository at this point in the history
…y 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
  • Loading branch information
zea@chromium.org committed Jul 18, 2014
1 parent 4f897ec commit 6f63606
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 19 deletions.
10 changes: 8 additions & 2 deletions components/gcm_driver/gcm_client_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "google_apis/gcm/protocol/checkin.pb.h"
#include "google_apis/gcm/protocol/mcs.pb.h"
#include "net/http/http_network_session.h"
#include "net/http/http_transaction_factory.h"
#include "net/url_request/url_request_context.h"
#include "url/gurl.h"

Expand Down Expand Up @@ -236,13 +237,15 @@ scoped_ptr<MCSClient> GCMInternalsBuilder::BuildMCSClient(
scoped_ptr<ConnectionFactory> GCMInternalsBuilder::BuildConnectionFactory(
const std::vector<GURL>& 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) {
return make_scoped_ptr<ConnectionFactory>(
new ConnectionFactoryImpl(endpoints,
backoff_policy,
network_session,
gcm_network_session,
http_network_session,
net_log,
recorder));
}
Expand Down Expand Up @@ -371,6 +374,9 @@ void GCMClientImpl::InitializeMCSClient(
endpoints,
kDefaultBackoffPolicy,
network_session_,
url_request_context_getter_->GetURLRequestContext()
->http_transaction_factory()
->GetSession(),
net_log_.net_log(),
&recorder_);
connection_factory_->SetConnectionListener(this);
Expand Down
3 changes: 2 additions & 1 deletion components/gcm_driver/gcm_client_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ class GCMInternalsBuilder {
virtual scoped_ptr<ConnectionFactory> BuildConnectionFactory(
const std::vector<GURL>& 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);
};
Expand Down
6 changes: 4 additions & 2 deletions components/gcm_driver/gcm_client_impl_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ class FakeGCMInternalsBuilder : public GCMInternalsBuilder {
virtual scoped_ptr<ConnectionFactory> BuildConnectionFactory(
const std::vector<GURL>& 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) OVERRIDE;

Expand Down Expand Up @@ -201,7 +202,8 @@ scoped_ptr<MCSClient> FakeGCMInternalsBuilder::BuildMCSClient(
scoped_ptr<ConnectionFactory> FakeGCMInternalsBuilder::BuildConnectionFactory(
const std::vector<GURL>& 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) {
return make_scoped_ptr<ConnectionFactory>(new FakeConnectionFactory());
Expand Down
35 changes: 24 additions & 11 deletions google_apis/gcm/engine/connection_factory_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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_,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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()),
Expand Down Expand Up @@ -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() {
Expand All @@ -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
19 changes: 16 additions & 3 deletions google_apis/gcm/engine/connection_factory_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down
1 change: 1 addition & 0 deletions google_apis/gcm/engine/connection_factory_impl_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ TestConnectionFactoryImpl::TestConnectionFactoryImpl(
net::BackoffEntry::Policy(),
NULL,
NULL,
NULL,
&dummy_recorder_),
connect_result_(net::ERR_UNEXPECTED),
num_expected_attempts_(0),
Expand Down
1 change: 1 addition & 0 deletions google_apis/gcm/tools/mcs_probe.cc
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ void MCSProbe::Start() {
new ConnectionFactoryImpl(endpoints,
kDefaultBackoffPolicy,
network_session_,
NULL,
&net_log_,
&recorder_));
gcm_store_.reset(
Expand Down

0 comments on commit 6f63606

Please sign in to comment.