| 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/location.h" | 7 #include "base/location.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 "base/profiler/scoped_tracker.h" | 10 #include "base/profiler/scoped_tracker.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 return !login_time.is_null() && | 40 return !login_time.is_null() && |
| 41 now_ticks - login_time <= | 41 now_ticks - login_time <= |
| 42 base::TimeDelta::FromSeconds(kConnectionResetWindowSecs); | 42 base::TimeDelta::FromSeconds(kConnectionResetWindowSecs); |
| 43 } | 43 } |
| 44 | 44 |
| 45 } // namespace | 45 } // namespace |
| 46 | 46 |
| 47 ConnectionFactoryImpl::ConnectionFactoryImpl( | 47 ConnectionFactoryImpl::ConnectionFactoryImpl( |
| 48 const std::vector<GURL>& mcs_endpoints, | 48 const std::vector<GURL>& mcs_endpoints, |
| 49 const net::BackoffEntry::Policy& backoff_policy, | 49 const net::BackoffEntry::Policy& backoff_policy, |
| 50 const scoped_refptr<net::HttpNetworkSession>& gcm_network_session, | 50 net::HttpNetworkSession* gcm_network_session, |
| 51 const scoped_refptr<net::HttpNetworkSession>& http_network_session, | 51 net::HttpNetworkSession* http_network_session, |
| 52 net::NetLog* net_log, | 52 net::NetLog* net_log, |
| 53 GCMStatsRecorder* recorder) | 53 GCMStatsRecorder* recorder) |
| 54 : mcs_endpoints_(mcs_endpoints), | 54 : mcs_endpoints_(mcs_endpoints), |
| 55 next_endpoint_(0), | 55 next_endpoint_(0), |
| 56 last_successful_endpoint_(0), | 56 last_successful_endpoint_(0), |
| 57 backoff_policy_(backoff_policy), | 57 backoff_policy_(backoff_policy), |
| 58 gcm_network_session_(gcm_network_session), | 58 gcm_network_session_(gcm_network_session), |
| 59 http_network_session_(http_network_session), | 59 http_network_session_(http_network_session), |
| 60 bound_net_log_( | 60 bound_net_log_( |
| 61 net::BoundNetLog::Make(net_log, net::NetLog::SOURCE_SOCKET)), | 61 net::BoundNetLog::Make(net_log, net::NetLog::SOURCE_SOCKET)), |
| 62 pac_request_(NULL), | 62 pac_request_(NULL), |
| 63 connecting_(false), | 63 connecting_(false), |
| 64 waiting_for_backoff_(false), | 64 waiting_for_backoff_(false), |
| 65 waiting_for_network_online_(false), | 65 waiting_for_network_online_(false), |
| 66 logging_in_(false), | 66 logging_in_(false), |
| 67 recorder_(recorder), | 67 recorder_(recorder), |
| 68 listener_(NULL), | 68 listener_(NULL), |
| 69 weak_ptr_factory_(this) { | 69 weak_ptr_factory_(this) { |
| 70 DCHECK_GE(mcs_endpoints_.size(), 1U); | 70 DCHECK_GE(mcs_endpoints_.size(), 1U); |
| 71 DCHECK(!http_network_session_.get() || | 71 DCHECK(!http_network_session_ || |
| 72 (gcm_network_session_.get() != http_network_session_.get())); | 72 (gcm_network_session_ != http_network_session_)); |
| 73 } | 73 } |
| 74 | 74 |
| 75 ConnectionFactoryImpl::~ConnectionFactoryImpl() { | 75 ConnectionFactoryImpl::~ConnectionFactoryImpl() { |
| 76 CloseSocket(); | 76 CloseSocket(); |
| 77 net::NetworkChangeNotifier::RemoveNetworkChangeObserver(this); | 77 net::NetworkChangeNotifier::RemoveNetworkChangeObserver(this); |
| 78 if (pac_request_) { | 78 if (pac_request_) { |
| 79 gcm_network_session_->proxy_service()->CancelPacRequest(pac_request_); | 79 gcm_network_session_->proxy_service()->CancelPacRequest(pac_request_); |
| 80 pac_request_ = NULL; | 80 pac_request_ = NULL; |
| 81 } | 81 } |
| 82 } | 82 } |
| (...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 OnConnectDone(status); | 450 OnConnectDone(status); |
| 451 return; | 451 return; |
| 452 } | 452 } |
| 453 | 453 |
| 454 DVLOG(1) << "Resolved proxy with PAC:" << proxy_info_.ToPacString(); | 454 DVLOG(1) << "Resolved proxy with PAC:" << proxy_info_.ToPacString(); |
| 455 | 455 |
| 456 net::SSLConfig ssl_config; | 456 net::SSLConfig ssl_config; |
| 457 gcm_network_session_->ssl_config_service()->GetSSLConfig(&ssl_config); | 457 gcm_network_session_->ssl_config_service()->GetSSLConfig(&ssl_config); |
| 458 status = net::InitSocketHandleForTlsConnect( | 458 status = net::InitSocketHandleForTlsConnect( |
| 459 net::HostPortPair::FromURL(GetCurrentEndpoint()), | 459 net::HostPortPair::FromURL(GetCurrentEndpoint()), |
| 460 gcm_network_session_.get(), | 460 gcm_network_session_, |
| 461 proxy_info_, | 461 proxy_info_, |
| 462 ssl_config, | 462 ssl_config, |
| 463 ssl_config, | 463 ssl_config, |
| 464 net::PRIVACY_MODE_DISABLED, | 464 net::PRIVACY_MODE_DISABLED, |
| 465 bound_net_log_, | 465 bound_net_log_, |
| 466 &socket_handle_, | 466 &socket_handle_, |
| 467 base::Bind(&ConnectionFactoryImpl::OnConnectDone, | 467 base::Bind(&ConnectionFactoryImpl::OnConnectDone, |
| 468 weak_ptr_factory_.GetWeakPtr())); | 468 weak_ptr_factory_.GetWeakPtr())); |
| 469 if (status != net::ERR_IO_PENDING) | 469 if (status != net::ERR_IO_PENDING) |
| 470 OnConnectDone(status); | 470 OnConnectDone(status); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 551 base::ThreadTaskRunnerHandle::Get()->PostTask( | 551 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 552 FROM_HERE, | 552 FROM_HERE, |
| 553 base::Bind(&ConnectionFactoryImpl::OnProxyResolveDone, | 553 base::Bind(&ConnectionFactoryImpl::OnProxyResolveDone, |
| 554 weak_ptr_factory_.GetWeakPtr(), status)); | 554 weak_ptr_factory_.GetWeakPtr(), status)); |
| 555 status = net::ERR_IO_PENDING; | 555 status = net::ERR_IO_PENDING; |
| 556 } | 556 } |
| 557 return status; | 557 return status; |
| 558 } | 558 } |
| 559 | 559 |
| 560 void ConnectionFactoryImpl::ReportSuccessfulProxyConnection() { | 560 void ConnectionFactoryImpl::ReportSuccessfulProxyConnection() { |
| 561 if (gcm_network_session_.get() && gcm_network_session_->proxy_service()) | 561 if (gcm_network_session_ && gcm_network_session_->proxy_service()) |
| 562 gcm_network_session_->proxy_service()->ReportSuccess(proxy_info_, NULL); | 562 gcm_network_session_->proxy_service()->ReportSuccess(proxy_info_, NULL); |
| 563 } | 563 } |
| 564 | 564 |
| 565 void ConnectionFactoryImpl::CloseSocket() { | 565 void ConnectionFactoryImpl::CloseSocket() { |
| 566 // The connection handler needs to be reset, else it'll attempt to keep using | 566 // The connection handler needs to be reset, else it'll attempt to keep using |
| 567 // the destroyed socket. | 567 // the destroyed socket. |
| 568 if (connection_handler_) | 568 if (connection_handler_) |
| 569 connection_handler_->Reset(); | 569 connection_handler_->Reset(); |
| 570 | 570 |
| 571 if (socket_handle_.socket() && socket_handle_.socket()->IsConnected()) | 571 if (socket_handle_.socket() && socket_handle_.socket()->IsConnected()) |
| 572 socket_handle_.socket()->Disconnect(); | 572 socket_handle_.socket()->Disconnect(); |
| 573 socket_handle_.Reset(); | 573 socket_handle_.Reset(); |
| 574 } | 574 } |
| 575 | 575 |
| 576 void ConnectionFactoryImpl::RebuildNetworkSessionAuthCache() { | 576 void ConnectionFactoryImpl::RebuildNetworkSessionAuthCache() { |
| 577 if (!http_network_session_.get() || !http_network_session_->http_auth_cache()) | 577 if (!http_network_session_ || !http_network_session_->http_auth_cache()) |
| 578 return; | 578 return; |
| 579 | 579 |
| 580 gcm_network_session_->http_auth_cache()->UpdateAllFrom( | 580 gcm_network_session_->http_auth_cache()->UpdateAllFrom( |
| 581 *http_network_session_->http_auth_cache()); | 581 *http_network_session_->http_auth_cache()); |
| 582 } | 582 } |
| 583 | 583 |
| 584 } // namespace gcm | 584 } // namespace gcm |
| OLD | NEW |