| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "net/spdy/spdy_session_pool.h" | 5 #include "net/spdy/spdy_session_pool.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 | 31 |
| 32 } // namespace | 32 } // namespace |
| 33 | 33 |
| 34 SpdySessionPool::SpdySessionPool( | 34 SpdySessionPool::SpdySessionPool( |
| 35 HostResolver* resolver, | 35 HostResolver* resolver, |
| 36 SSLConfigService* ssl_config_service, | 36 SSLConfigService* ssl_config_service, |
| 37 HttpServerProperties* http_server_properties, | 37 HttpServerProperties* http_server_properties, |
| 38 TransportSecurityState* transport_security_state, | 38 TransportSecurityState* transport_security_state, |
| 39 bool enable_ping_based_connection_checking, | 39 bool enable_ping_based_connection_checking, |
| 40 bool enable_priority_dependencies, | 40 bool enable_priority_dependencies, |
| 41 NextProto default_protocol, | |
| 42 size_t session_max_recv_window_size, | 41 size_t session_max_recv_window_size, |
| 43 size_t stream_max_recv_window_size, | 42 size_t stream_max_recv_window_size, |
| 44 SpdySessionPool::TimeFunc time_func, | 43 SpdySessionPool::TimeFunc time_func, |
| 45 ProxyDelegate* proxy_delegate) | 44 ProxyDelegate* proxy_delegate) |
| 46 : http_server_properties_(http_server_properties), | 45 : http_server_properties_(http_server_properties), |
| 47 transport_security_state_(transport_security_state), | 46 transport_security_state_(transport_security_state), |
| 48 ssl_config_service_(ssl_config_service), | 47 ssl_config_service_(ssl_config_service), |
| 49 resolver_(resolver), | 48 resolver_(resolver), |
| 50 verify_domain_authentication_(true), | 49 verify_domain_authentication_(true), |
| 51 enable_sending_initial_data_(true), | 50 enable_sending_initial_data_(true), |
| 52 enable_ping_based_connection_checking_( | 51 enable_ping_based_connection_checking_( |
| 53 enable_ping_based_connection_checking), | 52 enable_ping_based_connection_checking), |
| 54 enable_priority_dependencies_(enable_priority_dependencies), | 53 enable_priority_dependencies_(enable_priority_dependencies), |
| 55 // TODO(akalin): Force callers to have a valid value of | |
| 56 // |default_protocol_|. | |
| 57 default_protocol_((default_protocol == kProtoUnknown) ? kProtoSPDY31 | |
| 58 : default_protocol), | |
| 59 session_max_recv_window_size_(session_max_recv_window_size), | 54 session_max_recv_window_size_(session_max_recv_window_size), |
| 60 stream_max_recv_window_size_(stream_max_recv_window_size), | 55 stream_max_recv_window_size_(stream_max_recv_window_size), |
| 61 time_func_(time_func), | 56 time_func_(time_func), |
| 62 proxy_delegate_(proxy_delegate) { | 57 proxy_delegate_(proxy_delegate) { |
| 63 DCHECK(default_protocol_ >= kProtoSPDYMinimumVersion && | |
| 64 default_protocol_ <= kProtoSPDYMaximumVersion); | |
| 65 NetworkChangeNotifier::AddIPAddressObserver(this); | 58 NetworkChangeNotifier::AddIPAddressObserver(this); |
| 66 if (ssl_config_service_.get()) | 59 if (ssl_config_service_.get()) |
| 67 ssl_config_service_->AddObserver(this); | 60 ssl_config_service_->AddObserver(this); |
| 68 CertDatabase::GetInstance()->AddObserver(this); | 61 CertDatabase::GetInstance()->AddObserver(this); |
| 69 } | 62 } |
| 70 | 63 |
| 71 SpdySessionPool::~SpdySessionPool() { | 64 SpdySessionPool::~SpdySessionPool() { |
| 72 CloseAllSessions(); | 65 CloseAllSessions(); |
| 73 | 66 |
| 74 while (!sessions_.empty()) { | 67 while (!sessions_.empty()) { |
| 75 // Destroy sessions to enforce that lifetime is scoped to SpdySessionPool. | 68 // Destroy sessions to enforce that lifetime is scoped to SpdySessionPool. |
| 76 // Write callbacks queued upon session drain are not invoked. | 69 // Write callbacks queued upon session drain are not invoked. |
| 77 RemoveUnavailableSession((*sessions_.begin())->GetWeakPtr()); | 70 RemoveUnavailableSession((*sessions_.begin())->GetWeakPtr()); |
| 78 } | 71 } |
| 79 | 72 |
| 80 if (ssl_config_service_.get()) | 73 if (ssl_config_service_.get()) |
| 81 ssl_config_service_->RemoveObserver(this); | 74 ssl_config_service_->RemoveObserver(this); |
| 82 NetworkChangeNotifier::RemoveIPAddressObserver(this); | 75 NetworkChangeNotifier::RemoveIPAddressObserver(this); |
| 83 CertDatabase::GetInstance()->RemoveObserver(this); | 76 CertDatabase::GetInstance()->RemoveObserver(this); |
| 84 } | 77 } |
| 85 | 78 |
| 86 base::WeakPtr<SpdySession> SpdySessionPool::CreateAvailableSessionFromSocket( | 79 base::WeakPtr<SpdySession> SpdySessionPool::CreateAvailableSessionFromSocket( |
| 87 const SpdySessionKey& key, | 80 const SpdySessionKey& key, |
| 88 std::unique_ptr<ClientSocketHandle> connection, | 81 std::unique_ptr<ClientSocketHandle> connection, |
| 89 const BoundNetLog& net_log, | 82 const BoundNetLog& net_log, |
| 90 int certificate_error_code, | 83 int certificate_error_code, |
| 91 bool is_secure) { | 84 bool is_secure) { |
| 92 TRACE_EVENT0("net", "SpdySessionPool::CreateAvailableSessionFromSocket"); | 85 TRACE_EVENT0("net", "SpdySessionPool::CreateAvailableSessionFromSocket"); |
| 93 DCHECK_GE(default_protocol_, kProtoSPDYMinimumVersion); | |
| 94 DCHECK_LE(default_protocol_, kProtoSPDYMaximumVersion); | |
| 95 | 86 |
| 96 UMA_HISTOGRAM_ENUMERATION( | 87 UMA_HISTOGRAM_ENUMERATION( |
| 97 "Net.SpdySessionGet", IMPORTED_FROM_SOCKET, SPDY_SESSION_GET_MAX); | 88 "Net.SpdySessionGet", IMPORTED_FROM_SOCKET, SPDY_SESSION_GET_MAX); |
| 98 | 89 |
| 99 std::unique_ptr<SpdySession> new_session(new SpdySession( | 90 std::unique_ptr<SpdySession> new_session(new SpdySession( |
| 100 key, http_server_properties_, transport_security_state_, | 91 key, http_server_properties_, transport_security_state_, |
| 101 verify_domain_authentication_, enable_sending_initial_data_, | 92 verify_domain_authentication_, enable_sending_initial_data_, |
| 102 enable_ping_based_connection_checking_, enable_priority_dependencies_, | 93 enable_ping_based_connection_checking_, enable_priority_dependencies_, |
| 103 default_protocol_, session_max_recv_window_size_, | 94 session_max_recv_window_size_, stream_max_recv_window_size_, time_func_, |
| 104 stream_max_recv_window_size_, time_func_, proxy_delegate_, | 95 proxy_delegate_, net_log.net_log())); |
| 105 net_log.net_log())); | |
| 106 | 96 |
| 107 new_session->InitializeWithSocket(std::move(connection), this, is_secure, | 97 new_session->InitializeWithSocket(std::move(connection), this, is_secure, |
| 108 certificate_error_code); | 98 certificate_error_code); |
| 109 | 99 |
| 110 base::WeakPtr<SpdySession> available_session = new_session->GetWeakPtr(); | 100 base::WeakPtr<SpdySession> available_session = new_session->GetWeakPtr(); |
| 111 sessions_.insert(new_session.release()); | 101 sessions_.insert(new_session.release()); |
| 112 MapKeyToAvailableSession(key, available_session); | 102 MapKeyToAvailableSession(key, available_session); |
| 113 | 103 |
| 114 net_log.AddEvent( | 104 net_log.AddEvent( |
| 115 NetLog::TYPE_HTTP2_SESSION_POOL_IMPORTED_SESSION_FROM_SOCKET, | 105 NetLog::TYPE_HTTP2_SESSION_POOL_IMPORTED_SESSION_FROM_SOCKET, |
| (...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 | 439 |
| 450 if (idle_only && (*it)->is_active()) | 440 if (idle_only && (*it)->is_active()) |
| 451 continue; | 441 continue; |
| 452 | 442 |
| 453 (*it)->CloseSessionOnError(error, description); | 443 (*it)->CloseSessionOnError(error, description); |
| 454 DCHECK(!IsSessionAvailable(*it)); | 444 DCHECK(!IsSessionAvailable(*it)); |
| 455 } | 445 } |
| 456 } | 446 } |
| 457 | 447 |
| 458 } // namespace net | 448 } // namespace net |
| OLD | NEW |