| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "net/spdy/spdy_session.h" | 8 #include "net/spdy/spdy_session.h" |
| 9 | 9 |
| 10 namespace net { | 10 namespace net { |
| 11 | 11 |
| 12 // The maximum number of sessions to open to a single domain. | 12 // The maximum number of sessions to open to a single domain. |
| 13 static const size_t kMaxSessionsPerDomain = 1; | 13 static const size_t kMaxSessionsPerDomain = 1; |
| 14 | 14 |
| 15 int SpdySessionPool::g_max_sessions_per_domain = kMaxSessionsPerDomain; | 15 int SpdySessionPool::g_max_sessions_per_domain = kMaxSessionsPerDomain; |
| 16 | 16 |
| 17 SpdySessionPool::SpdySessionPool(NetworkChangeNotifier* notifier) | 17 SpdySessionPool::SpdySessionPool() { |
| 18 : network_change_notifier_(notifier) { | 18 NetworkChangeNotifier::AddObserver(this); |
| 19 if (network_change_notifier_) | |
| 20 network_change_notifier_->AddObserver(this); | |
| 21 } | 19 } |
| 22 | 20 |
| 23 SpdySessionPool::~SpdySessionPool() { | 21 SpdySessionPool::~SpdySessionPool() { |
| 24 CloseAllSessions(); | 22 CloseAllSessions(); |
| 25 | 23 |
| 26 if (network_change_notifier_) | 24 NetworkChangeNotifier::RemoveObserver(this); |
| 27 network_change_notifier_->RemoveObserver(this); | |
| 28 } | 25 } |
| 29 | 26 |
| 30 scoped_refptr<SpdySession> SpdySessionPool::Get( | 27 scoped_refptr<SpdySession> SpdySessionPool::Get( |
| 31 const HostPortPair& host_port_pair, HttpNetworkSession* session, | 28 const HostPortPair& host_port_pair, HttpNetworkSession* session, |
| 32 const BoundNetLog& net_log) { | 29 const BoundNetLog& net_log) { |
| 33 scoped_refptr<SpdySession> spdy_session; | 30 scoped_refptr<SpdySession> spdy_session; |
| 34 SpdySessionList* list = GetSessionList(host_port_pair); | 31 SpdySessionList* list = GetSessionList(host_port_pair); |
| 35 if (list) { | 32 if (list) { |
| 36 if (list->size() >= static_cast<unsigned int>(g_max_sessions_per_domain)) { | 33 if (list->size() >= static_cast<unsigned int>(g_max_sessions_per_domain)) { |
| 37 spdy_session = list->front(); | 34 spdy_session = list->front(); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 void SpdySessionPool::Remove(const scoped_refptr<SpdySession>& session) { | 75 void SpdySessionPool::Remove(const scoped_refptr<SpdySession>& session) { |
| 79 SpdySessionList* list = GetSessionList(session->host_port_pair()); | 76 SpdySessionList* list = GetSessionList(session->host_port_pair()); |
| 80 DCHECK(list); // We really shouldn't remove if we've already been removed. | 77 DCHECK(list); // We really shouldn't remove if we've already been removed. |
| 81 if (!list) | 78 if (!list) |
| 82 return; | 79 return; |
| 83 list->remove(session); | 80 list->remove(session); |
| 84 if (list->empty()) | 81 if (list->empty()) |
| 85 RemoveSessionList(session->host_port_pair()); | 82 RemoveSessionList(session->host_port_pair()); |
| 86 } | 83 } |
| 87 | 84 |
| 85 void SpdySessionPool::OnIPAddressChanged() { |
| 86 ClearSessions(); |
| 87 } |
| 88 |
| 88 SpdySessionPool::SpdySessionList* | 89 SpdySessionPool::SpdySessionList* |
| 89 SpdySessionPool::AddSessionList(const HostPortPair& host_port_pair) { | 90 SpdySessionPool::AddSessionList(const HostPortPair& host_port_pair) { |
| 90 DCHECK(sessions_.find(host_port_pair) == sessions_.end()); | 91 DCHECK(sessions_.find(host_port_pair) == sessions_.end()); |
| 91 SpdySessionPool::SpdySessionList* list = new SpdySessionList(); | 92 SpdySessionPool::SpdySessionList* list = new SpdySessionList(); |
| 92 sessions_[host_port_pair] = list; | 93 sessions_[host_port_pair] = list; |
| 93 return list; | 94 return list; |
| 94 } | 95 } |
| 95 | 96 |
| 96 SpdySessionPool::SpdySessionList* | 97 SpdySessionPool::SpdySessionList* |
| 97 SpdySessionPool::GetSessionList(const HostPortPair& host_port_pair) { | 98 SpdySessionPool::GetSessionList(const HostPortPair& host_port_pair) { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 128 scoped_refptr<SpdySession> session = list->front(); | 129 scoped_refptr<SpdySession> session = list->front(); |
| 129 list->pop_front(); | 130 list->pop_front(); |
| 130 if (close) | 131 if (close) |
| 131 session->CloseAllStreams(net::ERR_ABORTED); | 132 session->CloseAllStreams(net::ERR_ABORTED); |
| 132 } | 133 } |
| 133 delete list; | 134 delete list; |
| 134 } | 135 } |
| 135 } | 136 } |
| 136 | 137 |
| 137 } // namespace net | 138 } // namespace net |
| OLD | NEW |