Chromium Code Reviews| Index: google_apis/gcm/engine/connection_factory_impl.cc |
| diff --git a/google_apis/gcm/engine/connection_factory_impl.cc b/google_apis/gcm/engine/connection_factory_impl.cc |
| index ebfd367c9a85c571da3b3914477dab303e1fc673..25c7e5118b73e58737df1c60a0ec5ff9aa06d91e 100644 |
| --- a/google_apis/gcm/engine/connection_factory_impl.cc |
| +++ b/google_apis/gcm/engine/connection_factory_impl.cc |
| @@ -41,11 +41,12 @@ bool ShouldRestorePreviousBackoff(const base::TimeTicks& login_time, |
| } // namespace |
| ConnectionFactoryImpl::ConnectionFactoryImpl( |
| - const GURL& mcs_endpoint, |
| + const std::vector<GURL>& mcs_endpoints, |
| const net::BackoffEntry::Policy& backoff_policy, |
| scoped_refptr<net::HttpNetworkSession> network_session, |
| net::NetLog* net_log) |
| - : mcs_endpoint_(mcs_endpoint), |
| + : mcs_endpoints_(mcs_endpoints), |
| + current_endpoint_(0), |
| backoff_policy_(backoff_policy), |
| network_session_(network_session), |
| bound_net_log_( |
| @@ -54,6 +55,7 @@ ConnectionFactoryImpl::ConnectionFactoryImpl( |
| connecting_(false), |
| logging_in_(false), |
| weak_ptr_factory_(this) { |
| + DCHECK_GE(mcs_endpoints_.size(), 1U); |
| } |
| ConnectionFactoryImpl::~ConnectionFactoryImpl() { |
| @@ -189,7 +191,7 @@ void ConnectionFactoryImpl::ConnectImpl() { |
| DCHECK(!socket_handle_.socket()); |
| int status = network_session_->proxy_service()->ResolveProxy( |
| - mcs_endpoint_, |
| + mcs_endpoints_[current_endpoint_], |
| &proxy_info_, |
| base::Bind(&ConnectionFactoryImpl::OnProxyResolveDone, |
| weak_ptr_factory_.GetWeakPtr()), |
| @@ -234,13 +236,27 @@ void ConnectionFactoryImpl::OnConnectDone(int result) { |
| CloseSocket(); |
| backoff_entry_->InformOfRequest(false); |
| UMA_HISTOGRAM_SPARSE_SLOWLY("GCM.ConnectionFailureErrorCode", result); |
| + |
| + // If there are other endpoints available, use the next endpoint on the |
| + // subsequent retry. |
| + current_endpoint_++; |
| + if (current_endpoint_ >= mcs_endpoints_.size()) |
| + current_endpoint_ = 0; |
| Connect(); |
| return; |
| } |
| UMA_HISTOGRAM_BOOLEAN("GCM.ConnectionSuccessRate", true); |
| + UMA_HISTOGRAM_COUNTS("GCM.ConnectionEndpoint", current_endpoint_); |
|
fgorski
2014/03/20 16:45:42
How/what exactly do you mean to measure here? (thi
Nicolas Zea
2014/03/20 20:10:02
I'd like to understand what % of users are able to
|
| + UMA_HISTOGRAM_BOOLEAN("GCM.ConnectedViaProxy", |
| + !(proxy_info_.is_empty() || proxy_info_.is_direct())); |
| ReportSuccessfulProxyConnection(); |
| + // Reset the endpoint back to the default. |
| + // TODO(zea): consider prioritizing endpoints more intelligently based on |
| + // which ones succeed most for this client? Although that will affect |
| + // measuring the success rate of the default endpoint vs fallback. |
| + current_endpoint_ = 0; |
| connecting_ = false; |
| logging_in_ = true; |
| DVLOG(1) << "MCS endpoint socket connection success, starting login."; |
| @@ -300,7 +316,7 @@ void ConnectionFactoryImpl::OnProxyResolveDone(int status) { |
| net::SSLConfig ssl_config; |
| network_session_->ssl_config_service()->GetSSLConfig(&ssl_config); |
| status = net::InitSocketHandleForTlsConnect( |
| - net::HostPortPair::FromURL(mcs_endpoint_), |
| + net::HostPortPair::FromURL(mcs_endpoints_[current_endpoint_]), |
| network_session_.get(), |
| proxy_info_, |
| ssl_config, |
| @@ -374,7 +390,7 @@ int ConnectionFactoryImpl::ReconsiderProxyAfterError(int error) { |
| } |
| int status = network_session_->proxy_service()->ReconsiderProxyAfterError( |
| - mcs_endpoint_, &proxy_info_, |
| + mcs_endpoints_[current_endpoint_], &proxy_info_, |
| base::Bind(&ConnectionFactoryImpl::OnProxyResolveDone, |
| weak_ptr_factory_.GetWeakPtr()), |
| &pac_request_, |