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