| 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" |
| 11 #include "base/thread_task_runner_handle.h" | 11 #include "base/thread_task_runner_handle.h" |
| 12 #include "google_apis/gcm/engine/connection_handler_impl.h" | 12 #include "google_apis/gcm/engine/connection_handler_impl.h" |
| 13 #include "google_apis/gcm/monitoring/gcm_stats_recorder.h" | 13 #include "google_apis/gcm/monitoring/gcm_stats_recorder.h" |
| 14 #include "google_apis/gcm/protocol/mcs.pb.h" | 14 #include "google_apis/gcm/protocol/mcs.pb.h" |
| 15 #include "net/base/load_flags.h" | 15 #include "net/base/load_flags.h" |
| 16 #include "net/base/net_errors.h" | 16 #include "net/base/net_errors.h" |
| 17 #include "net/http/http_network_session.h" | 17 #include "net/http/http_network_session.h" |
| 18 #include "net/http/http_request_headers.h" | 18 #include "net/http/http_request_headers.h" |
| 19 #include "net/log/net_log.h" | |
| 20 #include "net/proxy/proxy_info.h" | 19 #include "net/proxy/proxy_info.h" |
| 21 #include "net/socket/client_socket_handle.h" | 20 #include "net/socket/client_socket_handle.h" |
| 22 #include "net/socket/client_socket_pool_manager.h" | 21 #include "net/socket/client_socket_pool_manager.h" |
| 23 #include "net/ssl/ssl_config_service.h" | 22 #include "net/ssl/ssl_config_service.h" |
| 24 | 23 |
| 25 namespace gcm { | 24 namespace gcm { |
| 26 | 25 |
| 27 namespace { | 26 namespace { |
| 28 | 27 |
| 29 // The amount of time a Socket read should wait before timing out. | 28 // The amount of time a Socket read should wait before timing out. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 41 return !login_time.is_null() && | 40 return !login_time.is_null() && |
| 42 now_ticks - login_time <= | 41 now_ticks - login_time <= |
| 43 base::TimeDelta::FromSeconds(kConnectionResetWindowSecs); | 42 base::TimeDelta::FromSeconds(kConnectionResetWindowSecs); |
| 44 } | 43 } |
| 45 | 44 |
| 46 } // namespace | 45 } // namespace |
| 47 | 46 |
| 48 ConnectionFactoryImpl::ConnectionFactoryImpl( | 47 ConnectionFactoryImpl::ConnectionFactoryImpl( |
| 49 const std::vector<GURL>& mcs_endpoints, | 48 const std::vector<GURL>& mcs_endpoints, |
| 50 const net::BackoffEntry::Policy& backoff_policy, | 49 const net::BackoffEntry::Policy& backoff_policy, |
| 51 net::HttpNetworkSession* gcm_network_session, | 50 const scoped_refptr<net::HttpNetworkSession>& gcm_network_session, |
| 52 net::HttpNetworkSession* http_network_session, | 51 const scoped_refptr<net::HttpNetworkSession>& http_network_session, |
| 53 net::NetLog* net_log, | 52 net::NetLog* net_log, |
| 54 GCMStatsRecorder* recorder) | 53 GCMStatsRecorder* recorder) |
| 55 : mcs_endpoints_(mcs_endpoints), | 54 : mcs_endpoints_(mcs_endpoints), |
| 56 next_endpoint_(0), | 55 next_endpoint_(0), |
| 57 last_successful_endpoint_(0), | 56 last_successful_endpoint_(0), |
| 58 backoff_policy_(backoff_policy), | 57 backoff_policy_(backoff_policy), |
| 59 gcm_network_session_(gcm_network_session), | 58 gcm_network_session_(gcm_network_session), |
| 60 http_network_session_(http_network_session), | 59 http_network_session_(http_network_session), |
| 61 bound_net_log_( | 60 bound_net_log_( |
| 62 net::BoundNetLog::Make(net_log, net::NetLog::SOURCE_SOCKET)), | 61 net::BoundNetLog::Make(net_log, net::NetLog::SOURCE_SOCKET)), |
| 63 pac_request_(NULL), | 62 pac_request_(NULL), |
| 64 connecting_(false), | 63 connecting_(false), |
| 65 waiting_for_backoff_(false), | 64 waiting_for_backoff_(false), |
| 66 waiting_for_network_online_(false), | 65 waiting_for_network_online_(false), |
| 67 logging_in_(false), | 66 logging_in_(false), |
| 68 recorder_(recorder), | 67 recorder_(recorder), |
| 69 listener_(NULL), | 68 listener_(NULL), |
| 70 weak_ptr_factory_(this) { | 69 weak_ptr_factory_(this) { |
| 71 DCHECK_GE(mcs_endpoints_.size(), 1U); | 70 DCHECK_GE(mcs_endpoints_.size(), 1U); |
| 72 DCHECK(!http_network_session_ || | 71 DCHECK(!http_network_session_.get() || |
| 73 (gcm_network_session_ != http_network_session_)); | 72 (gcm_network_session_.get() != http_network_session_.get())); |
| 74 } | 73 } |
| 75 | 74 |
| 76 ConnectionFactoryImpl::~ConnectionFactoryImpl() { | 75 ConnectionFactoryImpl::~ConnectionFactoryImpl() { |
| 77 CloseSocket(); | 76 CloseSocket(); |
| 78 net::NetworkChangeNotifier::RemoveNetworkChangeObserver(this); | 77 net::NetworkChangeNotifier::RemoveNetworkChangeObserver(this); |
| 79 if (pac_request_) { | 78 if (pac_request_) { |
| 80 gcm_network_session_->proxy_service()->CancelPacRequest(pac_request_); | 79 gcm_network_session_->proxy_service()->CancelPacRequest(pac_request_); |
| 81 pac_request_ = NULL; | 80 pac_request_ = NULL; |
| 82 } | 81 } |
| 83 } | 82 } |
| (...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 451 OnConnectDone(status); | 450 OnConnectDone(status); |
| 452 return; | 451 return; |
| 453 } | 452 } |
| 454 | 453 |
| 455 DVLOG(1) << "Resolved proxy with PAC:" << proxy_info_.ToPacString(); | 454 DVLOG(1) << "Resolved proxy with PAC:" << proxy_info_.ToPacString(); |
| 456 | 455 |
| 457 net::SSLConfig ssl_config; | 456 net::SSLConfig ssl_config; |
| 458 gcm_network_session_->ssl_config_service()->GetSSLConfig(&ssl_config); | 457 gcm_network_session_->ssl_config_service()->GetSSLConfig(&ssl_config); |
| 459 status = net::InitSocketHandleForTlsConnect( | 458 status = net::InitSocketHandleForTlsConnect( |
| 460 net::HostPortPair::FromURL(GetCurrentEndpoint()), | 459 net::HostPortPair::FromURL(GetCurrentEndpoint()), |
| 461 gcm_network_session_, | 460 gcm_network_session_.get(), |
| 462 proxy_info_, | 461 proxy_info_, |
| 463 ssl_config, | 462 ssl_config, |
| 464 ssl_config, | 463 ssl_config, |
| 465 net::PRIVACY_MODE_DISABLED, | 464 net::PRIVACY_MODE_DISABLED, |
| 466 bound_net_log_, | 465 bound_net_log_, |
| 467 &socket_handle_, | 466 &socket_handle_, |
| 468 base::Bind(&ConnectionFactoryImpl::OnConnectDone, | 467 base::Bind(&ConnectionFactoryImpl::OnConnectDone, |
| 469 weak_ptr_factory_.GetWeakPtr())); | 468 weak_ptr_factory_.GetWeakPtr())); |
| 470 if (status != net::ERR_IO_PENDING) | 469 if (status != net::ERR_IO_PENDING) |
| 471 OnConnectDone(status); | 470 OnConnectDone(status); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 552 base::ThreadTaskRunnerHandle::Get()->PostTask( | 551 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 553 FROM_HERE, | 552 FROM_HERE, |
| 554 base::Bind(&ConnectionFactoryImpl::OnProxyResolveDone, | 553 base::Bind(&ConnectionFactoryImpl::OnProxyResolveDone, |
| 555 weak_ptr_factory_.GetWeakPtr(), status)); | 554 weak_ptr_factory_.GetWeakPtr(), status)); |
| 556 status = net::ERR_IO_PENDING; | 555 status = net::ERR_IO_PENDING; |
| 557 } | 556 } |
| 558 return status; | 557 return status; |
| 559 } | 558 } |
| 560 | 559 |
| 561 void ConnectionFactoryImpl::ReportSuccessfulProxyConnection() { | 560 void ConnectionFactoryImpl::ReportSuccessfulProxyConnection() { |
| 562 if (gcm_network_session_ && gcm_network_session_->proxy_service()) | 561 if (gcm_network_session_.get() && gcm_network_session_->proxy_service()) |
| 563 gcm_network_session_->proxy_service()->ReportSuccess(proxy_info_, NULL); | 562 gcm_network_session_->proxy_service()->ReportSuccess(proxy_info_, NULL); |
| 564 } | 563 } |
| 565 | 564 |
| 566 void ConnectionFactoryImpl::CloseSocket() { | 565 void ConnectionFactoryImpl::CloseSocket() { |
| 567 // 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 |
| 568 // the destroyed socket. | 567 // the destroyed socket. |
| 569 if (connection_handler_) | 568 if (connection_handler_) |
| 570 connection_handler_->Reset(); | 569 connection_handler_->Reset(); |
| 571 | 570 |
| 572 if (socket_handle_.socket() && socket_handle_.socket()->IsConnected()) | 571 if (socket_handle_.socket() && socket_handle_.socket()->IsConnected()) |
| 573 socket_handle_.socket()->Disconnect(); | 572 socket_handle_.socket()->Disconnect(); |
| 574 socket_handle_.Reset(); | 573 socket_handle_.Reset(); |
| 575 } | 574 } |
| 576 | 575 |
| 577 void ConnectionFactoryImpl::RebuildNetworkSessionAuthCache() { | 576 void ConnectionFactoryImpl::RebuildNetworkSessionAuthCache() { |
| 578 if (!http_network_session_ || !http_network_session_->http_auth_cache()) | 577 if (!http_network_session_.get() || !http_network_session_->http_auth_cache()) |
| 579 return; | 578 return; |
| 580 | 579 |
| 581 gcm_network_session_->http_auth_cache()->UpdateAllFrom( | 580 gcm_network_session_->http_auth_cache()->UpdateAllFrom( |
| 582 *http_network_session_->http_auth_cache()); | 581 *http_network_session_->http_auth_cache()); |
| 583 } | 582 } |
| 584 | 583 |
| 585 } // namespace gcm | 584 } // namespace gcm |
| OLD | NEW |