| 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" |
| 11 #include "base/profiler/scoped_tracker.h" | 11 #include "base/profiler/scoped_tracker.h" |
| 12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
| 13 #include "base/trace_event/trace_event.h" | 13 #include "base/trace_event/trace_event.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "net/base/address_list.h" | 15 #include "net/base/address_list.h" |
| 16 #include "net/http/http_network_session.h" | 16 #include "net/http/http_network_session.h" |
| 17 #include "net/http/http_server_properties.h" | 17 #include "net/http/http_server_properties.h" |
| 18 #include "net/log/net_log_event_type.h" |
| 18 #include "net/spdy/spdy_session.h" | 19 #include "net/spdy/spdy_session.h" |
| 19 | 20 |
| 20 namespace net { | 21 namespace net { |
| 21 | 22 |
| 22 namespace { | 23 namespace { |
| 23 | 24 |
| 24 enum SpdySessionGetTypes { | 25 enum SpdySessionGetTypes { |
| 25 CREATED_NEW = 0, | 26 CREATED_NEW = 0, |
| 26 FOUND_EXISTING = 1, | 27 FOUND_EXISTING = 1, |
| 27 FOUND_EXISTING_FROM_IP_POOL = 2, | 28 FOUND_EXISTING_FROM_IP_POOL = 2, |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 net_log.net_log())); | 94 net_log.net_log())); |
| 94 | 95 |
| 95 new_session->InitializeWithSocket(std::move(connection), this, is_secure, | 96 new_session->InitializeWithSocket(std::move(connection), this, is_secure, |
| 96 certificate_error_code); | 97 certificate_error_code); |
| 97 | 98 |
| 98 base::WeakPtr<SpdySession> available_session = new_session->GetWeakPtr(); | 99 base::WeakPtr<SpdySession> available_session = new_session->GetWeakPtr(); |
| 99 sessions_.insert(new_session.release()); | 100 sessions_.insert(new_session.release()); |
| 100 MapKeyToAvailableSession(key, available_session); | 101 MapKeyToAvailableSession(key, available_session); |
| 101 | 102 |
| 102 net_log.AddEvent( | 103 net_log.AddEvent( |
| 103 NetLog::TYPE_HTTP2_SESSION_POOL_IMPORTED_SESSION_FROM_SOCKET, | 104 NetLogEventType::HTTP2_SESSION_POOL_IMPORTED_SESSION_FROM_SOCKET, |
| 104 available_session->net_log().source().ToEventParametersCallback()); | 105 available_session->net_log().source().ToEventParametersCallback()); |
| 105 | 106 |
| 106 // Look up the IP address for this session so that we can match | 107 // Look up the IP address for this session so that we can match |
| 107 // future sessions (potentially to different domains) which can | 108 // future sessions (potentially to different domains) which can |
| 108 // potentially be pooled with this one. Because GetPeerAddress() | 109 // potentially be pooled with this one. Because GetPeerAddress() |
| 109 // reports the proxy's address instead of the origin server, check | 110 // reports the proxy's address instead of the origin server, check |
| 110 // to see if this is a direct connection. | 111 // to see if this is a direct connection. |
| 111 if (key.proxy_server().is_direct()) { | 112 if (key.proxy_server().is_direct()) { |
| 112 IPEndPoint address; | 113 IPEndPoint address; |
| 113 if (available_session->GetPeerAddress(&address) == OK) | 114 if (available_session->GetPeerAddress(&address) == OK) |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 if (url_it->second.empty()) { | 149 if (url_it->second.empty()) { |
| 149 unclaimed_pushed_streams_.erase(url_it); | 150 unclaimed_pushed_streams_.erase(url_it); |
| 150 } | 151 } |
| 151 } | 152 } |
| 152 | 153 |
| 153 AvailableSessionMap::iterator it = LookupAvailableSessionByKey(key); | 154 AvailableSessionMap::iterator it = LookupAvailableSessionByKey(key); |
| 154 if (it != available_sessions_.end()) { | 155 if (it != available_sessions_.end()) { |
| 155 UMA_HISTOGRAM_ENUMERATION( | 156 UMA_HISTOGRAM_ENUMERATION( |
| 156 "Net.SpdySessionGet", FOUND_EXISTING, SPDY_SESSION_GET_MAX); | 157 "Net.SpdySessionGet", FOUND_EXISTING, SPDY_SESSION_GET_MAX); |
| 157 net_log.AddEvent( | 158 net_log.AddEvent( |
| 158 NetLog::TYPE_HTTP2_SESSION_POOL_FOUND_EXISTING_SESSION, | 159 NetLogEventType::HTTP2_SESSION_POOL_FOUND_EXISTING_SESSION, |
| 159 it->second->net_log().source().ToEventParametersCallback()); | 160 it->second->net_log().source().ToEventParametersCallback()); |
| 160 return it->second; | 161 return it->second; |
| 161 } | 162 } |
| 162 | 163 |
| 163 // Look up the key's from the resolver's cache. | 164 // Look up the key's from the resolver's cache. |
| 164 HostResolver::RequestInfo resolve_info(key.host_port_pair()); | 165 HostResolver::RequestInfo resolve_info(key.host_port_pair()); |
| 165 AddressList addresses; | 166 AddressList addresses; |
| 166 int rv = resolver_->ResolveFromCache(resolve_info, &addresses, net_log); | 167 int rv = resolver_->ResolveFromCache(resolve_info, &addresses, net_log); |
| 167 DCHECK_NE(rv, ERR_IO_PENDING); | 168 DCHECK_NE(rv, ERR_IO_PENDING); |
| 168 if (rv != OK) | 169 if (rv != OK) |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 key.host_port_pair().host())) { | 202 key.host_port_pair().host())) { |
| 202 UMA_HISTOGRAM_ENUMERATION("Net.SpdyIPPoolDomainMatch", 0, 2); | 203 UMA_HISTOGRAM_ENUMERATION("Net.SpdyIPPoolDomainMatch", 0, 2); |
| 203 continue; | 204 continue; |
| 204 } | 205 } |
| 205 | 206 |
| 206 UMA_HISTOGRAM_ENUMERATION("Net.SpdyIPPoolDomainMatch", 1, 2); | 207 UMA_HISTOGRAM_ENUMERATION("Net.SpdyIPPoolDomainMatch", 1, 2); |
| 207 UMA_HISTOGRAM_ENUMERATION("Net.SpdySessionGet", | 208 UMA_HISTOGRAM_ENUMERATION("Net.SpdySessionGet", |
| 208 FOUND_EXISTING_FROM_IP_POOL, | 209 FOUND_EXISTING_FROM_IP_POOL, |
| 209 SPDY_SESSION_GET_MAX); | 210 SPDY_SESSION_GET_MAX); |
| 210 net_log.AddEvent( | 211 net_log.AddEvent( |
| 211 NetLog::TYPE_HTTP2_SESSION_POOL_FOUND_EXISTING_SESSION_FROM_IP_POOL, | 212 NetLogEventType::HTTP2_SESSION_POOL_FOUND_EXISTING_SESSION_FROM_IP_POOL, |
| 212 available_session->net_log().source().ToEventParametersCallback()); | 213 available_session->net_log().source().ToEventParametersCallback()); |
| 213 // Add this session to the map so that we can find it next time. | 214 // Add this session to the map so that we can find it next time. |
| 214 MapKeyToAvailableSession(key, available_session); | 215 MapKeyToAvailableSession(key, available_session); |
| 215 available_session->AddPooledAlias(key); | 216 available_session->AddPooledAlias(key); |
| 216 return available_session; | 217 return available_session; |
| 217 } | 218 } |
| 218 | 219 |
| 219 return base::WeakPtr<SpdySession>(); | 220 return base::WeakPtr<SpdySession>(); |
| 220 } | 221 } |
| 221 | 222 |
| 222 void SpdySessionPool::MakeSessionUnavailable( | 223 void SpdySessionPool::MakeSessionUnavailable( |
| 223 const base::WeakPtr<SpdySession>& available_session) { | 224 const base::WeakPtr<SpdySession>& available_session) { |
| 224 UnmapKey(available_session->spdy_session_key()); | 225 UnmapKey(available_session->spdy_session_key()); |
| 225 RemoveAliases(available_session->spdy_session_key()); | 226 RemoveAliases(available_session->spdy_session_key()); |
| 226 const std::set<SpdySessionKey>& aliases = available_session->pooled_aliases(); | 227 const std::set<SpdySessionKey>& aliases = available_session->pooled_aliases(); |
| 227 for (std::set<SpdySessionKey>::const_iterator it = aliases.begin(); | 228 for (std::set<SpdySessionKey>::const_iterator it = aliases.begin(); |
| 228 it != aliases.end(); ++it) { | 229 it != aliases.end(); ++it) { |
| 229 UnmapKey(*it); | 230 UnmapKey(*it); |
| 230 RemoveAliases(*it); | 231 RemoveAliases(*it); |
| 231 } | 232 } |
| 232 DCHECK(!IsSessionAvailable(available_session)); | 233 DCHECK(!IsSessionAvailable(available_session)); |
| 233 } | 234 } |
| 234 | 235 |
| 235 void SpdySessionPool::RemoveUnavailableSession( | 236 void SpdySessionPool::RemoveUnavailableSession( |
| 236 const base::WeakPtr<SpdySession>& unavailable_session) { | 237 const base::WeakPtr<SpdySession>& unavailable_session) { |
| 237 DCHECK(!IsSessionAvailable(unavailable_session)); | 238 DCHECK(!IsSessionAvailable(unavailable_session)); |
| 238 | 239 |
| 239 unavailable_session->net_log().AddEvent( | 240 unavailable_session->net_log().AddEvent( |
| 240 NetLog::TYPE_HTTP2_SESSION_POOL_REMOVE_SESSION, | 241 NetLogEventType::HTTP2_SESSION_POOL_REMOVE_SESSION, |
| 241 unavailable_session->net_log().source().ToEventParametersCallback()); | 242 unavailable_session->net_log().source().ToEventParametersCallback()); |
| 242 | 243 |
| 243 SessionSet::iterator it = sessions_.find(unavailable_session.get()); | 244 SessionSet::iterator it = sessions_.find(unavailable_session.get()); |
| 244 CHECK(it != sessions_.end()); | 245 CHECK(it != sessions_.end()); |
| 245 std::unique_ptr<SpdySession> owned_session(*it); | 246 std::unique_ptr<SpdySession> owned_session(*it); |
| 246 sessions_.erase(it); | 247 sessions_.erase(it); |
| 247 } | 248 } |
| 248 | 249 |
| 249 // Make a copy of |sessions_| in the Close* functions below to avoid | 250 // Make a copy of |sessions_| in the Close* functions below to avoid |
| 250 // reentrancy problems. Since arbitrary functions get called by close | 251 // reentrancy problems. Since arbitrary functions get called by close |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 | 438 |
| 438 if (idle_only && (*it)->is_active()) | 439 if (idle_only && (*it)->is_active()) |
| 439 continue; | 440 continue; |
| 440 | 441 |
| 441 (*it)->CloseSessionOnError(error, description); | 442 (*it)->CloseSessionOnError(error, description); |
| 442 DCHECK(!IsSessionAvailable(*it)); | 443 DCHECK(!IsSessionAvailable(*it)); |
| 443 } | 444 } |
| 444 } | 445 } |
| 445 | 446 |
| 446 } // namespace net | 447 } // namespace net |
| OLD | NEW |