| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "net/base/address_list.h" | 10 #include "net/base/address_list.h" |
| 11 #include "net/base/sys_addrinfo.h" | 11 #include "net/base/sys_addrinfo.h" |
| 12 #include "net/http/http_network_session.h" | 12 #include "net/http/http_network_session.h" |
| 13 #include "net/http/http_server_properties.h" |
| 13 #include "net/spdy/spdy_session.h" | 14 #include "net/spdy/spdy_session.h" |
| 14 | 15 |
| 15 | 16 |
| 16 namespace net { | 17 namespace net { |
| 17 | 18 |
| 18 namespace { | 19 namespace { |
| 19 | 20 |
| 20 enum SpdySessionGetTypes { | 21 enum SpdySessionGetTypes { |
| 21 CREATED_NEW = 0, | 22 CREATED_NEW = 0, |
| 22 FOUND_EXISTING = 1, | 23 FOUND_EXISTING = 1, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 33 } | 34 } |
| 34 | 35 |
| 35 // The maximum number of sessions to open to a single domain. | 36 // The maximum number of sessions to open to a single domain. |
| 36 static const size_t kMaxSessionsPerDomain = 1; | 37 static const size_t kMaxSessionsPerDomain = 1; |
| 37 | 38 |
| 38 size_t SpdySessionPool::g_max_sessions_per_domain = kMaxSessionsPerDomain; | 39 size_t SpdySessionPool::g_max_sessions_per_domain = kMaxSessionsPerDomain; |
| 39 bool SpdySessionPool::g_force_single_domain = false; | 40 bool SpdySessionPool::g_force_single_domain = false; |
| 40 bool SpdySessionPool::g_enable_ip_pooling = true; | 41 bool SpdySessionPool::g_enable_ip_pooling = true; |
| 41 | 42 |
| 42 SpdySessionPool::SpdySessionPool(HostResolver* resolver, | 43 SpdySessionPool::SpdySessionPool(HostResolver* resolver, |
| 43 SSLConfigService* ssl_config_service) | 44 SSLConfigService* ssl_config_service, |
| 44 : ssl_config_service_(ssl_config_service), | 45 HttpServerProperties* http_server_properties) |
| 46 : http_server_properties_(http_server_properties), |
| 47 ssl_config_service_(ssl_config_service), |
| 45 resolver_(resolver), | 48 resolver_(resolver), |
| 46 verify_domain_authentication_(true) { | 49 verify_domain_authentication_(true) { |
| 47 NetworkChangeNotifier::AddIPAddressObserver(this); | 50 NetworkChangeNotifier::AddIPAddressObserver(this); |
| 48 if (ssl_config_service_) | 51 if (ssl_config_service_) |
| 49 ssl_config_service_->AddObserver(this); | 52 ssl_config_service_->AddObserver(this); |
| 50 CertDatabase::AddObserver(this); | 53 CertDatabase::AddObserver(this); |
| 51 } | 54 } |
| 52 | 55 |
| 53 SpdySessionPool::~SpdySessionPool() { | 56 SpdySessionPool::~SpdySessionPool() { |
| 54 CloseAllSessions(); | 57 CloseAllSessions(); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 spdy_session = GetExistingSession(list, net_log); | 106 spdy_session = GetExistingSession(list, net_log); |
| 104 net_log.AddEvent( | 107 net_log.AddEvent( |
| 105 NetLog::TYPE_SPDY_SESSION_POOL_FOUND_EXISTING_SESSION, | 108 NetLog::TYPE_SPDY_SESSION_POOL_FOUND_EXISTING_SESSION, |
| 106 make_scoped_refptr(new NetLogSourceParameter( | 109 make_scoped_refptr(new NetLogSourceParameter( |
| 107 "session", spdy_session->net_log().source()))); | 110 "session", spdy_session->net_log().source()))); |
| 108 return spdy_session; | 111 return spdy_session; |
| 109 } | 112 } |
| 110 | 113 |
| 111 DCHECK(!only_use_existing_sessions); | 114 DCHECK(!only_use_existing_sessions); |
| 112 | 115 |
| 113 spdy_session = new SpdySession(host_port_proxy_pair, this, &spdy_settings_, | 116 spdy_session = new SpdySession(host_port_proxy_pair, this, |
| 117 http_server_properties_, |
| 114 verify_domain_authentication_, | 118 verify_domain_authentication_, |
| 115 net_log.net_log()); | 119 net_log.net_log()); |
| 116 UMA_HISTOGRAM_ENUMERATION("Net.SpdySessionGet", | 120 UMA_HISTOGRAM_ENUMERATION("Net.SpdySessionGet", |
| 117 CREATED_NEW, | 121 CREATED_NEW, |
| 118 SPDY_SESSION_GET_MAX); | 122 SPDY_SESSION_GET_MAX); |
| 119 list->push_back(spdy_session); | 123 list->push_back(spdy_session); |
| 120 net_log.AddEvent( | 124 net_log.AddEvent( |
| 121 NetLog::TYPE_SPDY_SESSION_POOL_CREATED_NEW_SESSION, | 125 NetLog::TYPE_SPDY_SESSION_POOL_CREATED_NEW_SESSION, |
| 122 make_scoped_refptr(new NetLogSourceParameter( | 126 make_scoped_refptr(new NetLogSourceParameter( |
| 123 "session", spdy_session->net_log().source()))); | 127 "session", spdy_session->net_log().source()))); |
| 124 DCHECK_LE(list->size(), g_max_sessions_per_domain); | 128 DCHECK_LE(list->size(), g_max_sessions_per_domain); |
| 125 return spdy_session; | 129 return spdy_session; |
| 126 } | 130 } |
| 127 | 131 |
| 128 net::Error SpdySessionPool::GetSpdySessionFromSocket( | 132 net::Error SpdySessionPool::GetSpdySessionFromSocket( |
| 129 const HostPortProxyPair& host_port_proxy_pair, | 133 const HostPortProxyPair& host_port_proxy_pair, |
| 130 ClientSocketHandle* connection, | 134 ClientSocketHandle* connection, |
| 131 const BoundNetLog& net_log, | 135 const BoundNetLog& net_log, |
| 132 int certificate_error_code, | 136 int certificate_error_code, |
| 133 scoped_refptr<SpdySession>* spdy_session, | 137 scoped_refptr<SpdySession>* spdy_session, |
| 134 bool is_secure) { | 138 bool is_secure) { |
| 135 UMA_HISTOGRAM_ENUMERATION("Net.SpdySessionGet", | 139 UMA_HISTOGRAM_ENUMERATION("Net.SpdySessionGet", |
| 136 IMPORTED_FROM_SOCKET, | 140 IMPORTED_FROM_SOCKET, |
| 137 SPDY_SESSION_GET_MAX); | 141 SPDY_SESSION_GET_MAX); |
| 138 // Create the SPDY session and add it to the pool. | 142 // Create the SPDY session and add it to the pool. |
| 139 *spdy_session = new SpdySession(host_port_proxy_pair, this, &spdy_settings_, | 143 *spdy_session = new SpdySession(host_port_proxy_pair, this, |
| 144 http_server_properties_, |
| 140 verify_domain_authentication_, | 145 verify_domain_authentication_, |
| 141 net_log.net_log()); | 146 net_log.net_log()); |
| 142 SpdySessionList* list = GetSessionList(host_port_proxy_pair); | 147 SpdySessionList* list = GetSessionList(host_port_proxy_pair); |
| 143 if (!list) | 148 if (!list) |
| 144 list = AddSessionList(host_port_proxy_pair); | 149 list = AddSessionList(host_port_proxy_pair); |
| 145 DCHECK(list->empty()); | 150 DCHECK(list->empty()); |
| 146 list->push_back(*spdy_session); | 151 list->push_back(*spdy_session); |
| 147 | 152 |
| 148 net_log.AddEvent( | 153 net_log.AddEvent( |
| 149 NetLog::TYPE_SPDY_SESSION_POOL_IMPORTED_SESSION_FROM_SOCKET, | 154 NetLog::TYPE_SPDY_SESSION_POOL_IMPORTED_SESSION_FROM_SOCKET, |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 for (SpdySessionList::const_iterator session = sessions->begin(); | 205 for (SpdySessionList::const_iterator session = sessions->begin(); |
| 201 session != sessions->end(); ++session) { | 206 session != sessions->end(); ++session) { |
| 202 list->Append(session->get()->GetInfoAsValue()); | 207 list->Append(session->get()->GetInfoAsValue()); |
| 203 } | 208 } |
| 204 } | 209 } |
| 205 return list; | 210 return list; |
| 206 } | 211 } |
| 207 | 212 |
| 208 void SpdySessionPool::OnIPAddressChanged() { | 213 void SpdySessionPool::OnIPAddressChanged() { |
| 209 CloseCurrentSessions(); | 214 CloseCurrentSessions(); |
| 210 spdy_settings_.Clear(); | 215 http_server_properties_->ClearSpdySettings(); |
| 211 } | 216 } |
| 212 | 217 |
| 213 void SpdySessionPool::OnSSLConfigChanged() { | 218 void SpdySessionPool::OnSSLConfigChanged() { |
| 214 CloseCurrentSessions(); | 219 CloseCurrentSessions(); |
| 215 } | 220 } |
| 216 | 221 |
| 217 scoped_refptr<SpdySession> SpdySessionPool::GetExistingSession( | 222 scoped_refptr<SpdySession> SpdySessionPool::GetExistingSession( |
| 218 SpdySessionList* list, | 223 SpdySessionList* list, |
| 219 const BoundNetLog& net_log) const { | 224 const BoundNetLog& net_log) const { |
| 220 DCHECK(list); | 225 DCHECK(list); |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 // Assumes there is only 1 element in the list | 428 // Assumes there is only 1 element in the list |
| 424 SpdySessionList::iterator session_it = list->begin(); | 429 SpdySessionList::iterator session_it = list->begin(); |
| 425 const scoped_refptr<SpdySession>& session = *session_it; | 430 const scoped_refptr<SpdySession>& session = *session_it; |
| 426 CHECK(session); | 431 CHECK(session); |
| 427 if (!session->is_active()) | 432 if (!session->is_active()) |
| 428 session->CloseSessionOnError(net::ERR_ABORTED, true); | 433 session->CloseSessionOnError(net::ERR_ABORTED, true); |
| 429 } | 434 } |
| 430 } | 435 } |
| 431 | 436 |
| 432 } // namespace net | 437 } // namespace net |
| OLD | NEW |