| 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 "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "base/profiler/scoped_tracker.h" | 9 #include "base/profiler/scoped_tracker.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 net_log.net_log())); | 119 net_log.net_log())); |
| 120 | 120 |
| 121 new_session->InitializeWithSocket( | 121 new_session->InitializeWithSocket( |
| 122 connection.Pass(), this, is_secure, certificate_error_code); | 122 connection.Pass(), this, is_secure, certificate_error_code); |
| 123 | 123 |
| 124 base::WeakPtr<SpdySession> available_session = new_session->GetWeakPtr(); | 124 base::WeakPtr<SpdySession> available_session = new_session->GetWeakPtr(); |
| 125 sessions_.insert(new_session.release()); | 125 sessions_.insert(new_session.release()); |
| 126 MapKeyToAvailableSession(key, available_session); | 126 MapKeyToAvailableSession(key, available_session); |
| 127 | 127 |
| 128 net_log.AddEvent( | 128 net_log.AddEvent( |
| 129 NetLog::TYPE_SPDY_SESSION_POOL_IMPORTED_SESSION_FROM_SOCKET, | 129 NetLog::TYPE_HTTP2_SESSION_POOL_IMPORTED_SESSION_FROM_SOCKET, |
| 130 available_session->net_log().source().ToEventParametersCallback()); | 130 available_session->net_log().source().ToEventParametersCallback()); |
| 131 | 131 |
| 132 // Look up the IP address for this session so that we can match | 132 // Look up the IP address for this session so that we can match |
| 133 // future sessions (potentially to different domains) which can | 133 // future sessions (potentially to different domains) which can |
| 134 // potentially be pooled with this one. Because GetPeerAddress() | 134 // potentially be pooled with this one. Because GetPeerAddress() |
| 135 // reports the proxy's address instead of the origin server, check | 135 // reports the proxy's address instead of the origin server, check |
| 136 // to see if this is a direct connection. | 136 // to see if this is a direct connection. |
| 137 if (key.proxy_server().is_direct()) { | 137 if (key.proxy_server().is_direct()) { |
| 138 IPEndPoint address; | 138 IPEndPoint address; |
| 139 if (available_session->GetPeerAddress(&address) == OK) | 139 if (available_session->GetPeerAddress(&address) == OK) |
| 140 aliases_[address] = key; | 140 aliases_[address] = key; |
| 141 } | 141 } |
| 142 | 142 |
| 143 return available_session; | 143 return available_session; |
| 144 } | 144 } |
| 145 | 145 |
| 146 base::WeakPtr<SpdySession> SpdySessionPool::FindAvailableSession( | 146 base::WeakPtr<SpdySession> SpdySessionPool::FindAvailableSession( |
| 147 const SpdySessionKey& key, | 147 const SpdySessionKey& key, |
| 148 const BoundNetLog& net_log) { | 148 const BoundNetLog& net_log) { |
| 149 AvailableSessionMap::iterator it = LookupAvailableSessionByKey(key); | 149 AvailableSessionMap::iterator it = LookupAvailableSessionByKey(key); |
| 150 if (it != available_sessions_.end()) { | 150 if (it != available_sessions_.end()) { |
| 151 UMA_HISTOGRAM_ENUMERATION( | 151 UMA_HISTOGRAM_ENUMERATION( |
| 152 "Net.SpdySessionGet", FOUND_EXISTING, SPDY_SESSION_GET_MAX); | 152 "Net.SpdySessionGet", FOUND_EXISTING, SPDY_SESSION_GET_MAX); |
| 153 net_log.AddEvent( | 153 net_log.AddEvent( |
| 154 NetLog::TYPE_SPDY_SESSION_POOL_FOUND_EXISTING_SESSION, | 154 NetLog::TYPE_HTTP2_SESSION_POOL_FOUND_EXISTING_SESSION, |
| 155 it->second->net_log().source().ToEventParametersCallback()); | 155 it->second->net_log().source().ToEventParametersCallback()); |
| 156 return it->second; | 156 return it->second; |
| 157 } | 157 } |
| 158 | 158 |
| 159 // Look up the key's from the resolver's cache. | 159 // Look up the key's from the resolver's cache. |
| 160 net::HostResolver::RequestInfo resolve_info(key.host_port_pair()); | 160 net::HostResolver::RequestInfo resolve_info(key.host_port_pair()); |
| 161 AddressList addresses; | 161 AddressList addresses; |
| 162 int rv = resolver_->ResolveFromCache(resolve_info, &addresses, net_log); | 162 int rv = resolver_->ResolveFromCache(resolve_info, &addresses, net_log); |
| 163 DCHECK_NE(rv, ERR_IO_PENDING); | 163 DCHECK_NE(rv, ERR_IO_PENDING); |
| 164 if (rv != OK) | 164 if (rv != OK) |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 key.host_port_pair().host())) { | 197 key.host_port_pair().host())) { |
| 198 UMA_HISTOGRAM_ENUMERATION("Net.SpdyIPPoolDomainMatch", 0, 2); | 198 UMA_HISTOGRAM_ENUMERATION("Net.SpdyIPPoolDomainMatch", 0, 2); |
| 199 continue; | 199 continue; |
| 200 } | 200 } |
| 201 | 201 |
| 202 UMA_HISTOGRAM_ENUMERATION("Net.SpdyIPPoolDomainMatch", 1, 2); | 202 UMA_HISTOGRAM_ENUMERATION("Net.SpdyIPPoolDomainMatch", 1, 2); |
| 203 UMA_HISTOGRAM_ENUMERATION("Net.SpdySessionGet", | 203 UMA_HISTOGRAM_ENUMERATION("Net.SpdySessionGet", |
| 204 FOUND_EXISTING_FROM_IP_POOL, | 204 FOUND_EXISTING_FROM_IP_POOL, |
| 205 SPDY_SESSION_GET_MAX); | 205 SPDY_SESSION_GET_MAX); |
| 206 net_log.AddEvent( | 206 net_log.AddEvent( |
| 207 NetLog::TYPE_SPDY_SESSION_POOL_FOUND_EXISTING_SESSION_FROM_IP_POOL, | 207 NetLog::TYPE_HTTP2_SESSION_POOL_FOUND_EXISTING_SESSION_FROM_IP_POOL, |
| 208 available_session->net_log().source().ToEventParametersCallback()); | 208 available_session->net_log().source().ToEventParametersCallback()); |
| 209 // Add this session to the map so that we can find it next time. | 209 // Add this session to the map so that we can find it next time. |
| 210 MapKeyToAvailableSession(key, available_session); | 210 MapKeyToAvailableSession(key, available_session); |
| 211 available_session->AddPooledAlias(key); | 211 available_session->AddPooledAlias(key); |
| 212 return available_session; | 212 return available_session; |
| 213 } | 213 } |
| 214 | 214 |
| 215 return base::WeakPtr<SpdySession>(); | 215 return base::WeakPtr<SpdySession>(); |
| 216 } | 216 } |
| 217 | 217 |
| 218 void SpdySessionPool::MakeSessionUnavailable( | 218 void SpdySessionPool::MakeSessionUnavailable( |
| 219 const base::WeakPtr<SpdySession>& available_session) { | 219 const base::WeakPtr<SpdySession>& available_session) { |
| 220 UnmapKey(available_session->spdy_session_key()); | 220 UnmapKey(available_session->spdy_session_key()); |
| 221 RemoveAliases(available_session->spdy_session_key()); | 221 RemoveAliases(available_session->spdy_session_key()); |
| 222 const std::set<SpdySessionKey>& aliases = available_session->pooled_aliases(); | 222 const std::set<SpdySessionKey>& aliases = available_session->pooled_aliases(); |
| 223 for (std::set<SpdySessionKey>::const_iterator it = aliases.begin(); | 223 for (std::set<SpdySessionKey>::const_iterator it = aliases.begin(); |
| 224 it != aliases.end(); ++it) { | 224 it != aliases.end(); ++it) { |
| 225 UnmapKey(*it); | 225 UnmapKey(*it); |
| 226 RemoveAliases(*it); | 226 RemoveAliases(*it); |
| 227 } | 227 } |
| 228 DCHECK(!IsSessionAvailable(available_session)); | 228 DCHECK(!IsSessionAvailable(available_session)); |
| 229 } | 229 } |
| 230 | 230 |
| 231 void SpdySessionPool::RemoveUnavailableSession( | 231 void SpdySessionPool::RemoveUnavailableSession( |
| 232 const base::WeakPtr<SpdySession>& unavailable_session) { | 232 const base::WeakPtr<SpdySession>& unavailable_session) { |
| 233 DCHECK(!IsSessionAvailable(unavailable_session)); | 233 DCHECK(!IsSessionAvailable(unavailable_session)); |
| 234 | 234 |
| 235 unavailable_session->net_log().AddEvent( | 235 unavailable_session->net_log().AddEvent( |
| 236 NetLog::TYPE_SPDY_SESSION_POOL_REMOVE_SESSION, | 236 NetLog::TYPE_HTTP2_SESSION_POOL_REMOVE_SESSION, |
| 237 unavailable_session->net_log().source().ToEventParametersCallback()); | 237 unavailable_session->net_log().source().ToEventParametersCallback()); |
| 238 | 238 |
| 239 SessionSet::iterator it = sessions_.find(unavailable_session.get()); | 239 SessionSet::iterator it = sessions_.find(unavailable_session.get()); |
| 240 CHECK(it != sessions_.end()); | 240 CHECK(it != sessions_.end()); |
| 241 scoped_ptr<SpdySession> owned_session(*it); | 241 scoped_ptr<SpdySession> owned_session(*it); |
| 242 sessions_.erase(it); | 242 sessions_.erase(it); |
| 243 } | 243 } |
| 244 | 244 |
| 245 // Make a copy of |sessions_| in the Close* functions below to avoid | 245 // Make a copy of |sessions_| in the Close* functions below to avoid |
| 246 // reentrancy problems. Since arbitrary functions get called by close | 246 // reentrancy problems. Since arbitrary functions get called by close |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 | 403 |
| 404 if (idle_only && (*it)->is_active()) | 404 if (idle_only && (*it)->is_active()) |
| 405 continue; | 405 continue; |
| 406 | 406 |
| 407 (*it)->CloseSessionOnError(error, description); | 407 (*it)->CloseSessionOnError(error, description); |
| 408 DCHECK(!IsSessionAvailable(*it)); | 408 DCHECK(!IsSessionAvailable(*it)); |
| 409 } | 409 } |
| 410 } | 410 } |
| 411 | 411 |
| 412 } // namespace net | 412 } // namespace net |
| OLD | NEW |