Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(78)

Side by Side Diff: net/spdy/spdy_session_pool.cc

Issue 266243004: Clang format slam. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/values.h" 9 #include "base/values.h"
10 #include "net/base/address_list.h" 10 #include "net/base/address_list.h"
11 #include "net/http/http_network_session.h" 11 #include "net/http/http_network_session.h"
12 #include "net/http/http_server_properties.h" 12 #include "net/http/http_server_properties.h"
13 #include "net/spdy/spdy_session.h" 13 #include "net/spdy/spdy_session.h"
14 14
15
16 namespace net { 15 namespace net {
17 16
18 namespace { 17 namespace {
19 18
20 enum SpdySessionGetTypes { 19 enum SpdySessionGetTypes {
21 CREATED_NEW = 0, 20 CREATED_NEW = 0,
22 FOUND_EXISTING = 1, 21 FOUND_EXISTING = 1,
23 FOUND_EXISTING_FROM_IP_POOL = 2, 22 FOUND_EXISTING_FROM_IP_POOL = 2,
24 IMPORTED_FROM_SOCKET = 3, 23 IMPORTED_FROM_SOCKET = 3,
25 SPDY_SESSION_GET_MAX = 4 24 SPDY_SESSION_GET_MAX = 4
26 }; 25 };
27 26
28 } // namespace 27 } // namespace
29 28
30 SpdySessionPool::SpdySessionPool( 29 SpdySessionPool::SpdySessionPool(
31 HostResolver* resolver, 30 HostResolver* resolver,
32 SSLConfigService* ssl_config_service, 31 SSLConfigService* ssl_config_service,
33 const base::WeakPtr<HttpServerProperties>& http_server_properties, 32 const base::WeakPtr<HttpServerProperties>& http_server_properties,
34 bool force_single_domain, 33 bool force_single_domain,
35 bool enable_compression, 34 bool enable_compression,
36 bool enable_ping_based_connection_checking, 35 bool enable_ping_based_connection_checking,
37 NextProto default_protocol, 36 NextProto default_protocol,
38 size_t stream_initial_recv_window_size, 37 size_t stream_initial_recv_window_size,
39 size_t initial_max_concurrent_streams, 38 size_t initial_max_concurrent_streams,
40 size_t max_concurrent_streams_limit, 39 size_t max_concurrent_streams_limit,
41 SpdySessionPool::TimeFunc time_func, 40 SpdySessionPool::TimeFunc time_func,
42 const std::string& trusted_spdy_proxy) 41 const std::string& trusted_spdy_proxy)
43 : http_server_properties_(http_server_properties), 42 : http_server_properties_(http_server_properties),
44 ssl_config_service_(ssl_config_service), 43 ssl_config_service_(ssl_config_service),
45 resolver_(resolver), 44 resolver_(resolver),
46 verify_domain_authentication_(true), 45 verify_domain_authentication_(true),
47 enable_sending_initial_data_(true), 46 enable_sending_initial_data_(true),
48 force_single_domain_(force_single_domain), 47 force_single_domain_(force_single_domain),
49 enable_compression_(enable_compression), 48 enable_compression_(enable_compression),
50 enable_ping_based_connection_checking_( 49 enable_ping_based_connection_checking_(
51 enable_ping_based_connection_checking), 50 enable_ping_based_connection_checking),
52 // TODO(akalin): Force callers to have a valid value of 51 // TODO(akalin): Force callers to have a valid value of
53 // |default_protocol_|. 52 // |default_protocol_|.
54 default_protocol_( 53 default_protocol_((default_protocol == kProtoUnknown) ? kProtoSPDY3
55 (default_protocol == kProtoUnknown) ? 54 : default_protocol),
56 kProtoSPDY3 : default_protocol),
57 stream_initial_recv_window_size_(stream_initial_recv_window_size), 55 stream_initial_recv_window_size_(stream_initial_recv_window_size),
58 initial_max_concurrent_streams_(initial_max_concurrent_streams), 56 initial_max_concurrent_streams_(initial_max_concurrent_streams),
59 max_concurrent_streams_limit_(max_concurrent_streams_limit), 57 max_concurrent_streams_limit_(max_concurrent_streams_limit),
60 time_func_(time_func), 58 time_func_(time_func),
61 trusted_spdy_proxy_( 59 trusted_spdy_proxy_(HostPortPair::FromString(trusted_spdy_proxy)) {
62 HostPortPair::FromString(trusted_spdy_proxy)) {
63 DCHECK(default_protocol_ >= kProtoSPDYMinimumVersion && 60 DCHECK(default_protocol_ >= kProtoSPDYMinimumVersion &&
64 default_protocol_ <= kProtoSPDYMaximumVersion); 61 default_protocol_ <= kProtoSPDYMaximumVersion);
65 NetworkChangeNotifier::AddIPAddressObserver(this); 62 NetworkChangeNotifier::AddIPAddressObserver(this);
66 if (ssl_config_service_.get()) 63 if (ssl_config_service_.get())
67 ssl_config_service_->AddObserver(this); 64 ssl_config_service_->AddObserver(this);
68 CertDatabase::GetInstance()->AddObserver(this); 65 CertDatabase::GetInstance()->AddObserver(this);
69 } 66 }
70 67
71 SpdySessionPool::~SpdySessionPool() { 68 SpdySessionPool::~SpdySessionPool() {
72 CloseAllSessions(); 69 CloseAllSessions();
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 197
201 return base::WeakPtr<SpdySession>(); 198 return base::WeakPtr<SpdySession>();
202 } 199 }
203 200
204 void SpdySessionPool::MakeSessionUnavailable( 201 void SpdySessionPool::MakeSessionUnavailable(
205 const base::WeakPtr<SpdySession>& available_session) { 202 const base::WeakPtr<SpdySession>& available_session) {
206 UnmapKey(available_session->spdy_session_key()); 203 UnmapKey(available_session->spdy_session_key());
207 RemoveAliases(available_session->spdy_session_key()); 204 RemoveAliases(available_session->spdy_session_key());
208 const std::set<SpdySessionKey>& aliases = available_session->pooled_aliases(); 205 const std::set<SpdySessionKey>& aliases = available_session->pooled_aliases();
209 for (std::set<SpdySessionKey>::const_iterator it = aliases.begin(); 206 for (std::set<SpdySessionKey>::const_iterator it = aliases.begin();
210 it != aliases.end(); ++it) { 207 it != aliases.end();
208 ++it) {
211 UnmapKey(*it); 209 UnmapKey(*it);
212 RemoveAliases(*it); 210 RemoveAliases(*it);
213 } 211 }
214 DCHECK(!IsSessionAvailable(available_session)); 212 DCHECK(!IsSessionAvailable(available_session));
215 } 213 }
216 214
217 void SpdySessionPool::RemoveUnavailableSession( 215 void SpdySessionPool::RemoveUnavailableSession(
218 const base::WeakPtr<SpdySession>& unavailable_session) { 216 const base::WeakPtr<SpdySession>& unavailable_session) {
219 DCHECK(!IsSessionAvailable(unavailable_session)); 217 DCHECK(!IsSessionAvailable(unavailable_session));
220 218
221 unavailable_session->net_log().AddEvent( 219 unavailable_session->net_log().AddEvent(
222 NetLog::TYPE_SPDY_SESSION_POOL_REMOVE_SESSION, 220 NetLog::TYPE_SPDY_SESSION_POOL_REMOVE_SESSION,
223 unavailable_session->net_log().source().ToEventParametersCallback()); 221 unavailable_session->net_log().source().ToEventParametersCallback());
224 222
225 SessionSet::iterator it = sessions_.find(unavailable_session.get()); 223 SessionSet::iterator it = sessions_.find(unavailable_session.get());
226 CHECK(it != sessions_.end()); 224 CHECK(it != sessions_.end());
227 scoped_ptr<SpdySession> owned_session(*it); 225 scoped_ptr<SpdySession> owned_session(*it);
228 sessions_.erase(it); 226 sessions_.erase(it);
229 } 227 }
230 228
231 // Make a copy of |sessions_| in the Close* functions below to avoid 229 // Make a copy of |sessions_| in the Close* functions below to avoid
232 // reentrancy problems. Since arbitrary functions get called by close 230 // reentrancy problems. Since arbitrary functions get called by close
233 // handlers, it doesn't suffice to simply increment the iterator 231 // handlers, it doesn't suffice to simply increment the iterator
234 // before closing. 232 // before closing.
235 233
236 void SpdySessionPool::CloseCurrentSessions(net::Error error) { 234 void SpdySessionPool::CloseCurrentSessions(net::Error error) {
237 CloseCurrentSessionsHelper(error, "Closing current sessions.", 235 CloseCurrentSessionsHelper(
238 false /* idle_only */); 236 error, "Closing current sessions.", false /* idle_only */);
239 } 237 }
240 238
241 void SpdySessionPool::CloseCurrentIdleSessions() { 239 void SpdySessionPool::CloseCurrentIdleSessions() {
242 CloseCurrentSessionsHelper(ERR_ABORTED, "Closing idle sessions.", 240 CloseCurrentSessionsHelper(
243 true /* idle_only */); 241 ERR_ABORTED, "Closing idle sessions.", true /* idle_only */);
244 } 242 }
245 243
246 void SpdySessionPool::CloseAllSessions() { 244 void SpdySessionPool::CloseAllSessions() {
247 while (!sessions_.empty()) { 245 while (!sessions_.empty()) {
248 CloseCurrentSessionsHelper(ERR_ABORTED, "Closing all sessions.", 246 CloseCurrentSessionsHelper(
249 false /* idle_only */); 247 ERR_ABORTED, "Closing all sessions.", false /* idle_only */);
250 } 248 }
251 } 249 }
252 250
253 base::Value* SpdySessionPool::SpdySessionPoolInfoToValue() const { 251 base::Value* SpdySessionPool::SpdySessionPoolInfoToValue() const {
254 base::ListValue* list = new base::ListValue(); 252 base::ListValue* list = new base::ListValue();
255 253
256 for (AvailableSessionMap::const_iterator it = available_sessions_.begin(); 254 for (AvailableSessionMap::const_iterator it = available_sessions_.begin();
257 it != available_sessions_.end(); ++it) { 255 it != available_sessions_.end();
256 ++it) {
258 // Only add the session if the key in the map matches the main 257 // Only add the session if the key in the map matches the main
259 // host_port_proxy_pair (not an alias). 258 // host_port_proxy_pair (not an alias).
260 const SpdySessionKey& key = it->first; 259 const SpdySessionKey& key = it->first;
261 const SpdySessionKey& session_key = it->second->spdy_session_key(); 260 const SpdySessionKey& session_key = it->second->spdy_session_key();
262 if (key.Equals(session_key)) 261 if (key.Equals(session_key))
263 list->Append(it->second->GetInfoAsValue()); 262 list->Append(it->second->GetInfoAsValue());
264 } 263 }
265 return list; 264 return list;
266 } 265 }
267 266
268 void SpdySessionPool::OnIPAddressChanged() { 267 void SpdySessionPool::OnIPAddressChanged() {
269 WeakSessionList current_sessions = GetCurrentSessions(); 268 WeakSessionList current_sessions = GetCurrentSessions();
270 for (WeakSessionList::const_iterator it = current_sessions.begin(); 269 for (WeakSessionList::const_iterator it = current_sessions.begin();
271 it != current_sessions.end(); ++it) { 270 it != current_sessions.end();
271 ++it) {
272 if (!*it) 272 if (!*it)
273 continue; 273 continue;
274 274
275 // For OSs that terminate TCP connections upon relevant network changes 275 // For OSs that terminate TCP connections upon relevant network changes
276 // there is no need to explicitly close SpdySessions, instead simply mark 276 // there is no need to explicitly close SpdySessions, instead simply mark
277 // the sessions as deprecated so they aren't reused. 277 // the sessions as deprecated so they aren't reused.
278 #if defined(OS_ANDROID) || defined(OS_WIN) || defined(OS_IOS) 278 #if defined(OS_ANDROID) || defined(OS_WIN) || defined(OS_IOS)
279 (*it)->MakeUnavailable(); 279 (*it)->MakeUnavailable();
280 #else 280 #else
281 (*it)->CloseSessionOnError(ERR_NETWORK_CHANGED, 281 (*it)
282 "Closing current sessions."); 282 ->CloseSessionOnError(ERR_NETWORK_CHANGED, "Closing current sessions.");
283 DCHECK(!*it); 283 DCHECK(!*it);
284 #endif // defined(OS_ANDROID) || defined(OS_WIN) || defined(OS_IOS) 284 #endif // defined(OS_ANDROID) || defined(OS_WIN) || defined(OS_IOS)
285 DCHECK(!IsSessionAvailable(*it)); 285 DCHECK(!IsSessionAvailable(*it));
286 } 286 }
287 http_server_properties_->ClearAllSpdySettings(); 287 http_server_properties_->ClearAllSpdySettings();
288 } 288 }
289 289
290 void SpdySessionPool::OnSSLConfigChanged() { 290 void SpdySessionPool::OnSSLConfigChanged() {
291 CloseCurrentSessions(ERR_NETWORK_CHANGED); 291 CloseCurrentSessions(ERR_NETWORK_CHANGED);
292 } 292 }
293 293
294 void SpdySessionPool::OnCertAdded(const X509Certificate* cert) { 294 void SpdySessionPool::OnCertAdded(const X509Certificate* cert) {
295 CloseCurrentSessions(ERR_CERT_DATABASE_CHANGED); 295 CloseCurrentSessions(ERR_CERT_DATABASE_CHANGED);
296 } 296 }
297 297
298 void SpdySessionPool::OnCACertChanged(const X509Certificate* cert) { 298 void SpdySessionPool::OnCACertChanged(const X509Certificate* cert) {
299 // Per wtc, we actually only need to CloseCurrentSessions when trust is 299 // Per wtc, we actually only need to CloseCurrentSessions when trust is
300 // reduced. CloseCurrentSessions now because OnCACertChanged does not 300 // reduced. CloseCurrentSessions now because OnCACertChanged does not
301 // tell us this. 301 // tell us this.
302 // See comments in ClientSocketPoolManager::OnCACertChanged. 302 // See comments in ClientSocketPoolManager::OnCACertChanged.
303 CloseCurrentSessions(ERR_CERT_DATABASE_CHANGED); 303 CloseCurrentSessions(ERR_CERT_DATABASE_CHANGED);
304 } 304 }
305 305
306 bool SpdySessionPool::IsSessionAvailable( 306 bool SpdySessionPool::IsSessionAvailable(
307 const base::WeakPtr<SpdySession>& session) const { 307 const base::WeakPtr<SpdySession>& session) const {
308 for (AvailableSessionMap::const_iterator it = available_sessions_.begin(); 308 for (AvailableSessionMap::const_iterator it = available_sessions_.begin();
309 it != available_sessions_.end(); ++it) { 309 it != available_sessions_.end();
310 ++it) {
310 if (it->second.get() == session.get()) 311 if (it->second.get() == session.get())
311 return true; 312 return true;
312 } 313 }
313 return false; 314 return false;
314 } 315 }
315 316
316 const SpdySessionKey& SpdySessionPool::NormalizeListKey( 317 const SpdySessionKey& SpdySessionPool::NormalizeListKey(
317 const SpdySessionKey& key) const { 318 const SpdySessionKey& key) const {
318 if (!force_single_domain_) 319 if (!force_single_domain_)
319 return key; 320 return key;
320 321
321 static SpdySessionKey* single_domain_key = NULL; 322 static SpdySessionKey* single_domain_key = NULL;
322 if (!single_domain_key) { 323 if (!single_domain_key) {
323 HostPortPair single_domain = HostPortPair("singledomain.com", 80); 324 HostPortPair single_domain = HostPortPair("singledomain.com", 80);
324 single_domain_key = new SpdySessionKey(single_domain, 325 single_domain_key = new SpdySessionKey(
325 ProxyServer::Direct(), 326 single_domain, ProxyServer::Direct(), PRIVACY_MODE_DISABLED);
326 PRIVACY_MODE_DISABLED);
327 } 327 }
328 return *single_domain_key; 328 return *single_domain_key;
329 } 329 }
330 330
331 void SpdySessionPool::MapKeyToAvailableSession( 331 void SpdySessionPool::MapKeyToAvailableSession(
332 const SpdySessionKey& key, 332 const SpdySessionKey& key,
333 const base::WeakPtr<SpdySession>& session) { 333 const base::WeakPtr<SpdySession>& session) {
334 DCHECK(ContainsKey(sessions_, session.get())); 334 DCHECK(ContainsKey(sessions_, session.get()));
335 const SpdySessionKey& normalized_key = NormalizeListKey(key); 335 const SpdySessionKey& normalized_key = NormalizeListKey(key);
336 std::pair<AvailableSessionMap::iterator, bool> result = 336 std::pair<AvailableSessionMap::iterator, bool> result =
337 available_sessions_.insert(std::make_pair(normalized_key, session)); 337 available_sessions_.insert(std::make_pair(normalized_key, session));
338 CHECK(result.second); 338 CHECK(result.second);
339 } 339 }
340 340
341 SpdySessionPool::AvailableSessionMap::iterator 341 SpdySessionPool::AvailableSessionMap::iterator
342 SpdySessionPool::LookupAvailableSessionByKey( 342 SpdySessionPool::LookupAvailableSessionByKey(const SpdySessionKey& key) {
343 const SpdySessionKey& key) {
344 const SpdySessionKey& normalized_key = NormalizeListKey(key); 343 const SpdySessionKey& normalized_key = NormalizeListKey(key);
345 return available_sessions_.find(normalized_key); 344 return available_sessions_.find(normalized_key);
346 } 345 }
347 346
348 void SpdySessionPool::UnmapKey(const SpdySessionKey& key) { 347 void SpdySessionPool::UnmapKey(const SpdySessionKey& key) {
349 AvailableSessionMap::iterator it = LookupAvailableSessionByKey(key); 348 AvailableSessionMap::iterator it = LookupAvailableSessionByKey(key);
350 CHECK(it != available_sessions_.end()); 349 CHECK(it != available_sessions_.end());
351 available_sessions_.erase(it); 350 available_sessions_.erase(it);
352 } 351 }
353 352
354 void SpdySessionPool::RemoveAliases(const SpdySessionKey& key) { 353 void SpdySessionPool::RemoveAliases(const SpdySessionKey& key) {
355 // Walk the aliases map, find references to this pair. 354 // Walk the aliases map, find references to this pair.
356 // TODO(mbelshe): Figure out if this is too expensive. 355 // TODO(mbelshe): Figure out if this is too expensive.
357 for (AliasMap::iterator it = aliases_.begin(); it != aliases_.end(); ) { 356 for (AliasMap::iterator it = aliases_.begin(); it != aliases_.end();) {
358 if (it->second.Equals(key)) { 357 if (it->second.Equals(key)) {
359 AliasMap::iterator old_it = it; 358 AliasMap::iterator old_it = it;
360 ++it; 359 ++it;
361 aliases_.erase(old_it); 360 aliases_.erase(old_it);
362 } else { 361 } else {
363 ++it; 362 ++it;
364 } 363 }
365 } 364 }
366 } 365 }
367 366
368 SpdySessionPool::WeakSessionList SpdySessionPool::GetCurrentSessions() const { 367 SpdySessionPool::WeakSessionList SpdySessionPool::GetCurrentSessions() const {
369 WeakSessionList current_sessions; 368 WeakSessionList current_sessions;
370 for (SessionSet::const_iterator it = sessions_.begin(); 369 for (SessionSet::const_iterator it = sessions_.begin(); it != sessions_.end();
371 it != sessions_.end(); ++it) { 370 ++it) {
372 current_sessions.push_back((*it)->GetWeakPtr()); 371 current_sessions.push_back((*it)->GetWeakPtr());
373 } 372 }
374 return current_sessions; 373 return current_sessions;
375 } 374 }
376 375
377 void SpdySessionPool::CloseCurrentSessionsHelper( 376 void SpdySessionPool::CloseCurrentSessionsHelper(Error error,
378 Error error, 377 const std::string& description,
379 const std::string& description, 378 bool idle_only) {
380 bool idle_only) {
381 WeakSessionList current_sessions = GetCurrentSessions(); 379 WeakSessionList current_sessions = GetCurrentSessions();
382 for (WeakSessionList::const_iterator it = current_sessions.begin(); 380 for (WeakSessionList::const_iterator it = current_sessions.begin();
383 it != current_sessions.end(); ++it) { 381 it != current_sessions.end();
382 ++it) {
384 if (!*it) 383 if (!*it)
385 continue; 384 continue;
386 385
387 if (idle_only && (*it)->is_active()) 386 if (idle_only && (*it)->is_active())
388 continue; 387 continue;
389 388
390 (*it)->CloseSessionOnError(error, description); 389 (*it)->CloseSessionOnError(error, description);
391 DCHECK(!IsSessionAvailable(*it)); 390 DCHECK(!IsSessionAvailable(*it));
392 DCHECK(!*it); 391 DCHECK(!*it);
393 } 392 }
394 } 393 }
395 394
396 } // namespace net 395 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698