Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "google_apis/gcm/engine/connection_factory_impl.h" | 5 #include "google_apis/gcm/engine/connection_factory_impl.h" |
| 6 | 6 |
| 7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
| 8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "base/metrics/sparse_histogram.h" | 9 #include "base/metrics/sparse_histogram.h" |
| 10 #include "google_apis/gcm/engine/connection_handler_impl.h" | 10 #include "google_apis/gcm/engine/connection_handler_impl.h" |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 34 bool ShouldRestorePreviousBackoff(const base::TimeTicks& login_time, | 34 bool ShouldRestorePreviousBackoff(const base::TimeTicks& login_time, |
| 35 const base::TimeTicks& now_ticks) { | 35 const base::TimeTicks& now_ticks) { |
| 36 return !login_time.is_null() && | 36 return !login_time.is_null() && |
| 37 now_ticks - login_time <= | 37 now_ticks - login_time <= |
| 38 base::TimeDelta::FromSeconds(kConnectionResetWindowSecs); | 38 base::TimeDelta::FromSeconds(kConnectionResetWindowSecs); |
| 39 } | 39 } |
| 40 | 40 |
| 41 } // namespace | 41 } // namespace |
| 42 | 42 |
| 43 ConnectionFactoryImpl::ConnectionFactoryImpl( | 43 ConnectionFactoryImpl::ConnectionFactoryImpl( |
| 44 const GURL& mcs_endpoint, | 44 const std::vector<GURL>& mcs_endpoints, |
| 45 const net::BackoffEntry::Policy& backoff_policy, | 45 const net::BackoffEntry::Policy& backoff_policy, |
| 46 scoped_refptr<net::HttpNetworkSession> network_session, | 46 scoped_refptr<net::HttpNetworkSession> network_session, |
| 47 net::NetLog* net_log) | 47 net::NetLog* net_log) |
| 48 : mcs_endpoint_(mcs_endpoint), | 48 : mcs_endpoints_(mcs_endpoints), |
| 49 current_endpoint_(0), | |
| 49 backoff_policy_(backoff_policy), | 50 backoff_policy_(backoff_policy), |
| 50 network_session_(network_session), | 51 network_session_(network_session), |
| 51 bound_net_log_( | 52 bound_net_log_( |
| 52 net::BoundNetLog::Make(net_log, net::NetLog::SOURCE_SOCKET)), | 53 net::BoundNetLog::Make(net_log, net::NetLog::SOURCE_SOCKET)), |
| 53 pac_request_(NULL), | 54 pac_request_(NULL), |
| 54 connecting_(false), | 55 connecting_(false), |
| 55 logging_in_(false), | 56 logging_in_(false), |
| 56 weak_ptr_factory_(this) { | 57 weak_ptr_factory_(this) { |
| 58 DCHECK_GE(mcs_endpoints_.size(), 1U); | |
| 57 } | 59 } |
| 58 | 60 |
| 59 ConnectionFactoryImpl::~ConnectionFactoryImpl() { | 61 ConnectionFactoryImpl::~ConnectionFactoryImpl() { |
| 60 if (pac_request_) { | 62 if (pac_request_) { |
| 61 network_session_->proxy_service()->CancelPacRequest(pac_request_); | 63 network_session_->proxy_service()->CancelPacRequest(pac_request_); |
| 62 pac_request_ = NULL; | 64 pac_request_ = NULL; |
| 63 } | 65 } |
| 64 } | 66 } |
| 65 | 67 |
| 66 void ConnectionFactoryImpl::Initialize( | 68 void ConnectionFactoryImpl::Initialize( |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 182 backoff_entry_->Reset(); | 184 backoff_entry_->Reset(); |
| 183 // Connect(..) should be retrying with backoff already if a connection is | 185 // Connect(..) should be retrying with backoff already if a connection is |
| 184 // necessary, so no need to call again. | 186 // necessary, so no need to call again. |
| 185 } | 187 } |
| 186 | 188 |
| 187 void ConnectionFactoryImpl::ConnectImpl() { | 189 void ConnectionFactoryImpl::ConnectImpl() { |
| 188 DCHECK(connecting_); | 190 DCHECK(connecting_); |
| 189 DCHECK(!socket_handle_.socket()); | 191 DCHECK(!socket_handle_.socket()); |
| 190 | 192 |
| 191 int status = network_session_->proxy_service()->ResolveProxy( | 193 int status = network_session_->proxy_service()->ResolveProxy( |
| 192 mcs_endpoint_, | 194 mcs_endpoints_[current_endpoint_], |
| 193 &proxy_info_, | 195 &proxy_info_, |
| 194 base::Bind(&ConnectionFactoryImpl::OnProxyResolveDone, | 196 base::Bind(&ConnectionFactoryImpl::OnProxyResolveDone, |
| 195 weak_ptr_factory_.GetWeakPtr()), | 197 weak_ptr_factory_.GetWeakPtr()), |
| 196 &pac_request_, | 198 &pac_request_, |
| 197 bound_net_log_); | 199 bound_net_log_); |
| 198 if (status != net::ERR_IO_PENDING) | 200 if (status != net::ERR_IO_PENDING) |
| 199 OnProxyResolveDone(status); | 201 OnProxyResolveDone(status); |
| 200 } | 202 } |
| 201 | 203 |
| 202 void ConnectionFactoryImpl::InitHandler() { | 204 void ConnectionFactoryImpl::InitHandler() { |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 227 // not reconsidering a proxy) or returns ERR_IO_PENDING if it is considering | 229 // not reconsidering a proxy) or returns ERR_IO_PENDING if it is considering |
| 228 // another proxy. | 230 // another proxy. |
| 229 DCHECK_NE(result, net::OK); | 231 DCHECK_NE(result, net::OK); |
| 230 if (result == net::ERR_IO_PENDING) | 232 if (result == net::ERR_IO_PENDING) |
| 231 return; // Proxy reconsideration pending. Return. | 233 return; // Proxy reconsideration pending. Return. |
| 232 LOG(ERROR) << "Failed to connect to MCS endpoint with error " << result; | 234 LOG(ERROR) << "Failed to connect to MCS endpoint with error " << result; |
| 233 UMA_HISTOGRAM_BOOLEAN("GCM.ConnectionSuccessRate", false); | 235 UMA_HISTOGRAM_BOOLEAN("GCM.ConnectionSuccessRate", false); |
| 234 CloseSocket(); | 236 CloseSocket(); |
| 235 backoff_entry_->InformOfRequest(false); | 237 backoff_entry_->InformOfRequest(false); |
| 236 UMA_HISTOGRAM_SPARSE_SLOWLY("GCM.ConnectionFailureErrorCode", result); | 238 UMA_HISTOGRAM_SPARSE_SLOWLY("GCM.ConnectionFailureErrorCode", result); |
| 239 | |
| 240 // If there are other endpoints available, use the next endpoint on the | |
| 241 // subsequent retry. | |
| 242 current_endpoint_++; | |
| 243 if (current_endpoint_ >= mcs_endpoints_.size()) | |
| 244 current_endpoint_ = 0; | |
| 237 Connect(); | 245 Connect(); |
| 238 return; | 246 return; |
| 239 } | 247 } |
| 240 | 248 |
| 241 UMA_HISTOGRAM_BOOLEAN("GCM.ConnectionSuccessRate", true); | 249 UMA_HISTOGRAM_BOOLEAN("GCM.ConnectionSuccessRate", true); |
| 250 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
| |
| 251 UMA_HISTOGRAM_BOOLEAN("GCM.ConnectedViaProxy", | |
| 252 !(proxy_info_.is_empty() || proxy_info_.is_direct())); | |
| 242 ReportSuccessfulProxyConnection(); | 253 ReportSuccessfulProxyConnection(); |
| 243 | 254 |
| 255 // Reset the endpoint back to the default. | |
| 256 // TODO(zea): consider prioritizing endpoints more intelligently based on | |
| 257 // which ones succeed most for this client? Although that will affect | |
| 258 // measuring the success rate of the default endpoint vs fallback. | |
| 259 current_endpoint_ = 0; | |
| 244 connecting_ = false; | 260 connecting_ = false; |
| 245 logging_in_ = true; | 261 logging_in_ = true; |
| 246 DVLOG(1) << "MCS endpoint socket connection success, starting login."; | 262 DVLOG(1) << "MCS endpoint socket connection success, starting login."; |
| 247 InitHandler(); | 263 InitHandler(); |
| 248 } | 264 } |
| 249 | 265 |
| 250 void ConnectionFactoryImpl::ConnectionHandlerCallback(int result) { | 266 void ConnectionFactoryImpl::ConnectionHandlerCallback(int result) { |
| 251 DCHECK(!connecting_); | 267 DCHECK(!connecting_); |
| 252 if (result != net::OK) { | 268 if (result != net::OK) { |
| 253 // TODO(zea): Consider how to handle errors that may require some sort of | 269 // TODO(zea): Consider how to handle errors that may require some sort of |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 293 // Failed to resolve proxy. Retry later. | 309 // Failed to resolve proxy. Retry later. |
| 294 OnConnectDone(status); | 310 OnConnectDone(status); |
| 295 return; | 311 return; |
| 296 } | 312 } |
| 297 | 313 |
| 298 DVLOG(1) << "Resolved proxy with PAC:" << proxy_info_.ToPacString(); | 314 DVLOG(1) << "Resolved proxy with PAC:" << proxy_info_.ToPacString(); |
| 299 | 315 |
| 300 net::SSLConfig ssl_config; | 316 net::SSLConfig ssl_config; |
| 301 network_session_->ssl_config_service()->GetSSLConfig(&ssl_config); | 317 network_session_->ssl_config_service()->GetSSLConfig(&ssl_config); |
| 302 status = net::InitSocketHandleForTlsConnect( | 318 status = net::InitSocketHandleForTlsConnect( |
| 303 net::HostPortPair::FromURL(mcs_endpoint_), | 319 net::HostPortPair::FromURL(mcs_endpoints_[current_endpoint_]), |
| 304 network_session_.get(), | 320 network_session_.get(), |
| 305 proxy_info_, | 321 proxy_info_, |
| 306 ssl_config, | 322 ssl_config, |
| 307 ssl_config, | 323 ssl_config, |
| 308 net::kPrivacyModeDisabled, | 324 net::kPrivacyModeDisabled, |
| 309 bound_net_log_, | 325 bound_net_log_, |
| 310 &socket_handle_, | 326 &socket_handle_, |
| 311 base::Bind(&ConnectionFactoryImpl::OnConnectDone, | 327 base::Bind(&ConnectionFactoryImpl::OnConnectDone, |
| 312 weak_ptr_factory_.GetWeakPtr())); | 328 weak_ptr_factory_.GetWeakPtr())); |
| 313 if (status != net::ERR_IO_PENDING) | 329 if (status != net::ERR_IO_PENDING) |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 367 } | 383 } |
| 368 | 384 |
| 369 net::SSLConfig ssl_config; | 385 net::SSLConfig ssl_config; |
| 370 network_session_->ssl_config_service()->GetSSLConfig(&ssl_config); | 386 network_session_->ssl_config_service()->GetSSLConfig(&ssl_config); |
| 371 if (proxy_info_.is_https() && ssl_config.send_client_cert) { | 387 if (proxy_info_.is_https() && ssl_config.send_client_cert) { |
| 372 network_session_->ssl_client_auth_cache()->Remove( | 388 network_session_->ssl_client_auth_cache()->Remove( |
| 373 proxy_info_.proxy_server().host_port_pair()); | 389 proxy_info_.proxy_server().host_port_pair()); |
| 374 } | 390 } |
| 375 | 391 |
| 376 int status = network_session_->proxy_service()->ReconsiderProxyAfterError( | 392 int status = network_session_->proxy_service()->ReconsiderProxyAfterError( |
| 377 mcs_endpoint_, &proxy_info_, | 393 mcs_endpoints_[current_endpoint_], &proxy_info_, |
| 378 base::Bind(&ConnectionFactoryImpl::OnProxyResolveDone, | 394 base::Bind(&ConnectionFactoryImpl::OnProxyResolveDone, |
| 379 weak_ptr_factory_.GetWeakPtr()), | 395 weak_ptr_factory_.GetWeakPtr()), |
| 380 &pac_request_, | 396 &pac_request_, |
| 381 bound_net_log_); | 397 bound_net_log_); |
| 382 if (status == net::OK || status == net::ERR_IO_PENDING) { | 398 if (status == net::OK || status == net::ERR_IO_PENDING) { |
| 383 CloseSocket(); | 399 CloseSocket(); |
| 384 } else { | 400 } else { |
| 385 // If ReconsiderProxyAfterError() failed synchronously, it means | 401 // If ReconsiderProxyAfterError() failed synchronously, it means |
| 386 // there was nothing left to fall-back to, so fail the transaction | 402 // there was nothing left to fall-back to, so fail the transaction |
| 387 // with the last connection error we got. | 403 // with the last connection error we got. |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 410 // the destroyed socket. | 426 // the destroyed socket. |
| 411 if (connection_handler_) | 427 if (connection_handler_) |
| 412 connection_handler_->Reset(); | 428 connection_handler_->Reset(); |
| 413 | 429 |
| 414 if (socket_handle_.socket() && socket_handle_.socket()->IsConnected()) | 430 if (socket_handle_.socket() && socket_handle_.socket()->IsConnected()) |
| 415 socket_handle_.socket()->Disconnect(); | 431 socket_handle_.socket()->Disconnect(); |
| 416 socket_handle_.Reset(); | 432 socket_handle_.Reset(); |
| 417 } | 433 } |
| 418 | 434 |
| 419 } // namespace gcm | 435 } // namespace gcm |
| OLD | NEW |