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/callback.h" | 7 #include "base/callback.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 enable_ping_based_connection_checking_( | 62 enable_ping_based_connection_checking_( |
63 enable_ping_based_connection_checking), | 63 enable_ping_based_connection_checking), |
64 default_protocol_(default_protocol), | 64 default_protocol_(default_protocol), |
65 stream_initial_recv_window_size_(stream_initial_recv_window_size), | 65 stream_initial_recv_window_size_(stream_initial_recv_window_size), |
66 initial_max_concurrent_streams_(initial_max_concurrent_streams), | 66 initial_max_concurrent_streams_(initial_max_concurrent_streams), |
67 max_concurrent_streams_limit_(max_concurrent_streams_limit), | 67 max_concurrent_streams_limit_(max_concurrent_streams_limit), |
68 time_func_(time_func), | 68 time_func_(time_func), |
69 trusted_spdy_proxy_( | 69 trusted_spdy_proxy_( |
70 HostPortPair::FromString(trusted_spdy_proxy)) { | 70 HostPortPair::FromString(trusted_spdy_proxy)) { |
71 NetworkChangeNotifier::AddIPAddressObserver(this); | 71 NetworkChangeNotifier::AddIPAddressObserver(this); |
72 if (ssl_config_service_) | 72 if (ssl_config_service_.get()) |
73 ssl_config_service_->AddObserver(this); | 73 ssl_config_service_->AddObserver(this); |
74 CertDatabase::GetInstance()->AddObserver(this); | 74 CertDatabase::GetInstance()->AddObserver(this); |
75 } | 75 } |
76 | 76 |
77 SpdySessionPool::~SpdySessionPool() { | 77 SpdySessionPool::~SpdySessionPool() { |
78 CloseAllSessions(); | 78 CloseAllSessions(); |
79 | 79 |
80 if (ssl_config_service_) | 80 if (ssl_config_service_.get()) |
81 ssl_config_service_->RemoveObserver(this); | 81 ssl_config_service_->RemoveObserver(this); |
82 NetworkChangeNotifier::RemoveIPAddressObserver(this); | 82 NetworkChangeNotifier::RemoveIPAddressObserver(this); |
83 CertDatabase::GetInstance()->RemoveObserver(this); | 83 CertDatabase::GetInstance()->RemoveObserver(this); |
84 } | 84 } |
85 | 85 |
86 scoped_refptr<SpdySession> SpdySessionPool::Get( | 86 scoped_refptr<SpdySession> SpdySessionPool::Get( |
87 const SpdySessionKey& spdy_session_key, | 87 const SpdySessionKey& spdy_session_key, |
88 const BoundNetLog& net_log) { | 88 const BoundNetLog& net_log) { |
89 return GetInternal(spdy_session_key, net_log, false); | 89 return GetInternal(spdy_session_key, net_log, false); |
90 } | 90 } |
91 | 91 |
92 scoped_refptr<SpdySession> SpdySessionPool::GetIfExists( | 92 scoped_refptr<SpdySession> SpdySessionPool::GetIfExists( |
93 const SpdySessionKey& spdy_session_key, | 93 const SpdySessionKey& spdy_session_key, |
94 const BoundNetLog& net_log) { | 94 const BoundNetLog& net_log) { |
95 return GetInternal(spdy_session_key, net_log, true); | 95 return GetInternal(spdy_session_key, net_log, true); |
96 } | 96 } |
97 | 97 |
98 scoped_refptr<SpdySession> SpdySessionPool::GetInternal( | 98 scoped_refptr<SpdySession> SpdySessionPool::GetInternal( |
99 const SpdySessionKey& spdy_session_key, | 99 const SpdySessionKey& spdy_session_key, |
100 const BoundNetLog& net_log, | 100 const BoundNetLog& net_log, |
101 bool only_use_existing_sessions) { | 101 bool only_use_existing_sessions) { |
102 scoped_refptr<SpdySession> spdy_session; | 102 scoped_refptr<SpdySession> spdy_session; |
103 SpdySessionList* list = GetSessionList(spdy_session_key); | 103 SpdySessionList* list = GetSessionList(spdy_session_key); |
104 if (!list) { | 104 if (!list) { |
105 // Check if we have a Session through a domain alias. | 105 // Check if we have a Session through a domain alias. |
106 spdy_session = GetFromAlias(spdy_session_key, net_log, true); | 106 spdy_session = GetFromAlias(spdy_session_key, net_log, true); |
107 if (spdy_session) { | 107 if (spdy_session.get()) { |
108 UMA_HISTOGRAM_ENUMERATION("Net.SpdySessionGet", | 108 UMA_HISTOGRAM_ENUMERATION("Net.SpdySessionGet", |
109 FOUND_EXISTING_FROM_IP_POOL, | 109 FOUND_EXISTING_FROM_IP_POOL, |
110 SPDY_SESSION_GET_MAX); | 110 SPDY_SESSION_GET_MAX); |
111 net_log.AddEvent( | 111 net_log.AddEvent( |
112 NetLog::TYPE_SPDY_SESSION_POOL_FOUND_EXISTING_SESSION_FROM_IP_POOL, | 112 NetLog::TYPE_SPDY_SESSION_POOL_FOUND_EXISTING_SESSION_FROM_IP_POOL, |
113 spdy_session->net_log().source().ToEventParametersCallback()); | 113 spdy_session->net_log().source().ToEventParametersCallback()); |
114 // Add this session to the map so that we can find it next time. | 114 // Add this session to the map so that we can find it next time. |
115 list = AddSessionList(spdy_session_key); | 115 list = AddSessionList(spdy_session_key); |
116 list->push_back(spdy_session); | 116 list->push_back(spdy_session); |
117 spdy_session->AddPooledAlias(spdy_session_key); | 117 spdy_session->AddPooledAlias(spdy_session_key); |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
432 } | 432 } |
433 ++alias_it; | 433 ++alias_it; |
434 } | 434 } |
435 } | 435 } |
436 | 436 |
437 void SpdySessionPool::CloseAllSessions() { | 437 void SpdySessionPool::CloseAllSessions() { |
438 while (!sessions_.empty()) { | 438 while (!sessions_.empty()) { |
439 SpdySessionList* list = sessions_.begin()->second; | 439 SpdySessionList* list = sessions_.begin()->second; |
440 CHECK(list); | 440 CHECK(list); |
441 const scoped_refptr<SpdySession>& session = list->front(); | 441 const scoped_refptr<SpdySession>& session = list->front(); |
442 CHECK(session); | 442 CHECK(session.get()); |
443 // This call takes care of removing the session from the pool, as well as | 443 // This call takes care of removing the session from the pool, as well as |
444 // removing the session list if the list is empty. | 444 // removing the session list if the list is empty. |
445 session->CloseSessionOnError( | 445 session->CloseSessionOnError( |
446 net::ERR_ABORTED, true, "Closing all sessions."); | 446 net::ERR_ABORTED, true, "Closing all sessions."); |
447 } | 447 } |
448 } | 448 } |
449 | 449 |
450 void SpdySessionPool::CloseCurrentSessions(net::Error error) { | 450 void SpdySessionPool::CloseCurrentSessions(net::Error error) { |
451 SpdySessionsMap old_map; | 451 SpdySessionsMap old_map; |
452 old_map.swap(sessions_); | 452 old_map.swap(sessions_); |
453 for (SpdySessionsMap::const_iterator it = old_map.begin(); | 453 for (SpdySessionsMap::const_iterator it = old_map.begin(); |
454 it != old_map.end(); ++it) { | 454 it != old_map.end(); ++it) { |
455 SpdySessionList* list = it->second; | 455 SpdySessionList* list = it->second; |
456 CHECK(list); | 456 CHECK(list); |
457 const scoped_refptr<SpdySession>& session = list->front(); | 457 const scoped_refptr<SpdySession>& session = list->front(); |
458 CHECK(session); | 458 CHECK(session.get()); |
459 session->set_spdy_session_pool(NULL); | 459 session->set_spdy_session_pool(NULL); |
460 } | 460 } |
461 | 461 |
462 while (!old_map.empty()) { | 462 while (!old_map.empty()) { |
463 SpdySessionList* list = old_map.begin()->second; | 463 SpdySessionList* list = old_map.begin()->second; |
464 CHECK(list); | 464 CHECK(list); |
465 const scoped_refptr<SpdySession>& session = list->front(); | 465 const scoped_refptr<SpdySession>& session = list->front(); |
466 CHECK(session); | 466 CHECK(session.get()); |
467 session->CloseSessionOnError(error, false, "Closing current sessions."); | 467 session->CloseSessionOnError(error, false, "Closing current sessions."); |
468 list->pop_front(); | 468 list->pop_front(); |
469 if (list->empty()) { | 469 if (list->empty()) { |
470 delete list; | 470 delete list; |
471 RemoveAliases(old_map.begin()->first); | 471 RemoveAliases(old_map.begin()->first); |
472 old_map.erase(old_map.begin()->first); | 472 old_map.erase(old_map.begin()->first); |
473 } | 473 } |
474 } | 474 } |
475 DCHECK(sessions_.empty()); | 475 DCHECK(sessions_.empty()); |
476 DCHECK(aliases_.empty()); | 476 DCHECK(aliases_.empty()); |
477 } | 477 } |
478 | 478 |
479 void SpdySessionPool::CloseIdleSessions() { | 479 void SpdySessionPool::CloseIdleSessions() { |
480 SpdySessionsMap::const_iterator map_it = sessions_.begin(); | 480 SpdySessionsMap::const_iterator map_it = sessions_.begin(); |
481 while (map_it != sessions_.end()) { | 481 while (map_it != sessions_.end()) { |
482 SpdySessionList* list = map_it->second; | 482 SpdySessionList* list = map_it->second; |
483 CHECK(list); | 483 CHECK(list); |
484 | 484 |
485 // Assumes there is only 1 element in the list. | 485 // Assumes there is only 1 element in the list. |
486 SpdySessionList::iterator session_it = list->begin(); | 486 SpdySessionList::iterator session_it = list->begin(); |
487 const scoped_refptr<SpdySession>& session = *session_it; | 487 const scoped_refptr<SpdySession>& session = *session_it; |
488 CHECK(session); | 488 CHECK(session.get()); |
489 if (session->is_active()) { | 489 if (session->is_active()) { |
490 ++map_it; | 490 ++map_it; |
491 continue; | 491 continue; |
492 } | 492 } |
493 | 493 |
494 SpdySessionKey key(map_it->first); | 494 SpdySessionKey key(map_it->first); |
495 session->CloseSessionOnError( | 495 session->CloseSessionOnError( |
496 net::ERR_ABORTED, true, "Closing idle sessions."); | 496 net::ERR_ABORTED, true, "Closing idle sessions."); |
497 // CloseSessionOnError can invalidate the iterator. | 497 // CloseSessionOnError can invalidate the iterator. |
498 map_it = sessions_.lower_bound(key); | 498 map_it = sessions_.lower_bound(key); |
499 } | 499 } |
500 } | 500 } |
501 | 501 |
502 } // namespace net | 502 } // namespace net |
OLD | NEW |