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/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 if (available_session->GetPeerAddress(&address) == OK) | 123 if (available_session->GetPeerAddress(&address) == OK) |
124 aliases_[address] = key; | 124 aliases_[address] = key; |
125 } | 125 } |
126 | 126 |
127 return available_session; | 127 return available_session; |
128 } | 128 } |
129 | 129 |
130 base::WeakPtr<SpdySession> SpdySessionPool::FindAvailableSession( | 130 base::WeakPtr<SpdySession> SpdySessionPool::FindAvailableSession( |
131 const SpdySessionKey& key, | 131 const SpdySessionKey& key, |
132 const GURL& url, | 132 const GURL& url, |
| 133 bool enable_ip_based_pooling, |
133 const NetLogWithSource& net_log) { | 134 const NetLogWithSource& net_log) { |
134 UnclaimedPushedStreamMap::iterator url_it = | 135 UnclaimedPushedStreamMap::iterator url_it = |
135 unclaimed_pushed_streams_.find(url); | 136 unclaimed_pushed_streams_.find(url); |
136 if (!url.is_empty() && url_it != unclaimed_pushed_streams_.end()) { | 137 if (!url.is_empty() && url_it != unclaimed_pushed_streams_.end()) { |
137 DCHECK(url.SchemeIsCryptographic()); | 138 DCHECK(url.SchemeIsCryptographic()); |
138 for (WeakSessionList::iterator it = url_it->second.begin(); | 139 for (WeakSessionList::iterator it = url_it->second.begin(); |
139 it != url_it->second.end();) { | 140 it != url_it->second.end();) { |
140 base::WeakPtr<SpdySession> spdy_session = *it; | 141 base::WeakPtr<SpdySession> spdy_session = *it; |
141 // Lazy deletion of destroyed SpdySessions. | 142 // Lazy deletion of destroyed SpdySessions. |
142 if (!spdy_session) { | 143 if (!spdy_session) { |
(...skipping 19 matching lines...) Expand all Loading... |
162 | 163 |
163 AvailableSessionMap::iterator it = LookupAvailableSessionByKey(key); | 164 AvailableSessionMap::iterator it = LookupAvailableSessionByKey(key); |
164 if (it != available_sessions_.end()) { | 165 if (it != available_sessions_.end()) { |
165 if (key.Equals(it->second->spdy_session_key())) { | 166 if (key.Equals(it->second->spdy_session_key())) { |
166 UMA_HISTOGRAM_ENUMERATION("Net.SpdySessionGet", FOUND_EXISTING, | 167 UMA_HISTOGRAM_ENUMERATION("Net.SpdySessionGet", FOUND_EXISTING, |
167 SPDY_SESSION_GET_MAX); | 168 SPDY_SESSION_GET_MAX); |
168 net_log.AddEvent( | 169 net_log.AddEvent( |
169 NetLogEventType::HTTP2_SESSION_POOL_FOUND_EXISTING_SESSION, | 170 NetLogEventType::HTTP2_SESSION_POOL_FOUND_EXISTING_SESSION, |
170 it->second->net_log().source().ToEventParametersCallback()); | 171 it->second->net_log().source().ToEventParametersCallback()); |
171 } else { | 172 } else { |
| 173 if (!enable_ip_based_pooling) { |
| 174 // Remove session from available sessions and from aliases, and remove |
| 175 // key from the session's pooled alias set, so that a new session can be |
| 176 // created with this |key|. |
| 177 it->second->RemovePooledAlias(key); |
| 178 UnmapKey(key); |
| 179 RemoveAliases(key); |
| 180 return base::WeakPtr<SpdySession>(); |
| 181 } |
| 182 |
172 UMA_HISTOGRAM_ENUMERATION("Net.SpdySessionGet", | 183 UMA_HISTOGRAM_ENUMERATION("Net.SpdySessionGet", |
173 FOUND_EXISTING_FROM_IP_POOL, | 184 FOUND_EXISTING_FROM_IP_POOL, |
174 SPDY_SESSION_GET_MAX); | 185 SPDY_SESSION_GET_MAX); |
175 net_log.AddEvent( | 186 net_log.AddEvent( |
176 NetLogEventType:: | 187 NetLogEventType:: |
177 HTTP2_SESSION_POOL_FOUND_EXISTING_SESSION_FROM_IP_POOL, | 188 HTTP2_SESSION_POOL_FOUND_EXISTING_SESSION_FROM_IP_POOL, |
178 it->second->net_log().source().ToEventParametersCallback()); | 189 it->second->net_log().source().ToEventParametersCallback()); |
179 } | 190 } |
180 return it->second; | 191 return it->second; |
181 } | 192 } |
182 | 193 |
| 194 if (!enable_ip_based_pooling) |
| 195 return base::WeakPtr<SpdySession>(); |
| 196 |
183 // Look up IP addresses from resolver cache. | 197 // Look up IP addresses from resolver cache. |
184 HostResolver::RequestInfo resolve_info(key.host_port_pair()); | 198 HostResolver::RequestInfo resolve_info(key.host_port_pair()); |
185 AddressList addresses; | 199 AddressList addresses; |
186 int rv = resolver_->ResolveFromCache(resolve_info, &addresses, net_log); | 200 int rv = resolver_->ResolveFromCache(resolve_info, &addresses, net_log); |
187 DCHECK_NE(rv, ERR_IO_PENDING); | 201 DCHECK_NE(rv, ERR_IO_PENDING); |
188 if (rv != OK) | 202 if (rv != OK) |
189 return base::WeakPtr<SpdySession>(); | 203 return base::WeakPtr<SpdySession>(); |
190 | 204 |
191 // Check if we have a session through a domain alias. | 205 // Check if we have a session through a domain alias. |
192 for (AddressList::const_iterator address_it = addresses.begin(); | 206 for (AddressList::const_iterator address_it = addresses.begin(); |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
493 | 507 |
494 if (idle_only && (*it)->is_active()) | 508 if (idle_only && (*it)->is_active()) |
495 continue; | 509 continue; |
496 | 510 |
497 (*it)->CloseSessionOnError(error, description); | 511 (*it)->CloseSessionOnError(error, description); |
498 DCHECK(!IsSessionAvailable(*it)); | 512 DCHECK(!IsSessionAvailable(*it)); |
499 } | 513 } |
500 } | 514 } |
501 | 515 |
502 } // namespace net | 516 } // namespace net |
OLD | NEW |