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/values.h" | 9 #include "base/values.h" |
10 #include "net/base/address_list.h" | 10 #include "net/base/address_list.h" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 default_protocol_ <= kProtoSPDYMaximumVersion); | 64 default_protocol_ <= kProtoSPDYMaximumVersion); |
65 NetworkChangeNotifier::AddIPAddressObserver(this); | 65 NetworkChangeNotifier::AddIPAddressObserver(this); |
66 if (ssl_config_service_.get()) | 66 if (ssl_config_service_.get()) |
67 ssl_config_service_->AddObserver(this); | 67 ssl_config_service_->AddObserver(this); |
68 CertDatabase::GetInstance()->AddObserver(this); | 68 CertDatabase::GetInstance()->AddObserver(this); |
69 } | 69 } |
70 | 70 |
71 SpdySessionPool::~SpdySessionPool() { | 71 SpdySessionPool::~SpdySessionPool() { |
72 CloseAllSessions(); | 72 CloseAllSessions(); |
73 | 73 |
| 74 while (!sessions_.empty()) { |
| 75 // Destroy sessions to enforce that lifetime is scoped to SpdySessionPool. |
| 76 // Write callbacks queued upon session drain are not invoked. |
| 77 RemoveUnavailableSession((*sessions_.begin())->GetWeakPtr()); |
| 78 } |
| 79 |
74 if (ssl_config_service_.get()) | 80 if (ssl_config_service_.get()) |
75 ssl_config_service_->RemoveObserver(this); | 81 ssl_config_service_->RemoveObserver(this); |
76 NetworkChangeNotifier::RemoveIPAddressObserver(this); | 82 NetworkChangeNotifier::RemoveIPAddressObserver(this); |
77 CertDatabase::GetInstance()->RemoveObserver(this); | 83 CertDatabase::GetInstance()->RemoveObserver(this); |
78 } | 84 } |
79 | 85 |
80 base::WeakPtr<SpdySession> SpdySessionPool::CreateAvailableSessionFromSocket( | 86 base::WeakPtr<SpdySession> SpdySessionPool::CreateAvailableSessionFromSocket( |
81 const SpdySessionKey& key, | 87 const SpdySessionKey& key, |
82 scoped_ptr<ClientSocketHandle> connection, | 88 scoped_ptr<ClientSocketHandle> connection, |
83 const BoundNetLog& net_log, | 89 const BoundNetLog& net_log, |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 CloseCurrentSessionsHelper(error, "Closing current sessions.", | 243 CloseCurrentSessionsHelper(error, "Closing current sessions.", |
238 false /* idle_only */); | 244 false /* idle_only */); |
239 } | 245 } |
240 | 246 |
241 void SpdySessionPool::CloseCurrentIdleSessions() { | 247 void SpdySessionPool::CloseCurrentIdleSessions() { |
242 CloseCurrentSessionsHelper(ERR_ABORTED, "Closing idle sessions.", | 248 CloseCurrentSessionsHelper(ERR_ABORTED, "Closing idle sessions.", |
243 true /* idle_only */); | 249 true /* idle_only */); |
244 } | 250 } |
245 | 251 |
246 void SpdySessionPool::CloseAllSessions() { | 252 void SpdySessionPool::CloseAllSessions() { |
247 while (!sessions_.empty()) { | 253 while (!available_sessions_.empty()) { |
248 CloseCurrentSessionsHelper(ERR_ABORTED, "Closing all sessions.", | 254 CloseCurrentSessionsHelper(ERR_ABORTED, "Closing all sessions.", |
249 false /* idle_only */); | 255 false /* idle_only */); |
250 } | 256 } |
251 } | 257 } |
252 | 258 |
253 base::Value* SpdySessionPool::SpdySessionPoolInfoToValue() const { | 259 base::Value* SpdySessionPool::SpdySessionPoolInfoToValue() const { |
254 base::ListValue* list = new base::ListValue(); | 260 base::ListValue* list = new base::ListValue(); |
255 | 261 |
256 for (AvailableSessionMap::const_iterator it = available_sessions_.begin(); | 262 for (AvailableSessionMap::const_iterator it = available_sessions_.begin(); |
257 it != available_sessions_.end(); ++it) { | 263 it != available_sessions_.end(); ++it) { |
(...skipping 15 matching lines...) Expand all Loading... |
273 continue; | 279 continue; |
274 | 280 |
275 // For OSs that terminate TCP connections upon relevant network changes | 281 // For OSs that terminate TCP connections upon relevant network changes |
276 // there is no need to explicitly close SpdySessions, instead simply mark | 282 // there is no need to explicitly close SpdySessions, instead simply mark |
277 // the sessions as deprecated so they aren't reused. | 283 // the sessions as deprecated so they aren't reused. |
278 #if defined(OS_ANDROID) || defined(OS_WIN) || defined(OS_IOS) | 284 #if defined(OS_ANDROID) || defined(OS_WIN) || defined(OS_IOS) |
279 (*it)->MakeUnavailable(); | 285 (*it)->MakeUnavailable(); |
280 #else | 286 #else |
281 (*it)->CloseSessionOnError(ERR_NETWORK_CHANGED, | 287 (*it)->CloseSessionOnError(ERR_NETWORK_CHANGED, |
282 "Closing current sessions."); | 288 "Closing current sessions."); |
283 DCHECK(!*it); | 289 DCHECK((*it)->IsDraining()); |
284 #endif // defined(OS_ANDROID) || defined(OS_WIN) || defined(OS_IOS) | 290 #endif // defined(OS_ANDROID) || defined(OS_WIN) || defined(OS_IOS) |
285 DCHECK(!IsSessionAvailable(*it)); | 291 DCHECK(!IsSessionAvailable(*it)); |
286 } | 292 } |
287 http_server_properties_->ClearAllSpdySettings(); | 293 http_server_properties_->ClearAllSpdySettings(); |
288 } | 294 } |
289 | 295 |
290 void SpdySessionPool::OnSSLConfigChanged() { | 296 void SpdySessionPool::OnSSLConfigChanged() { |
291 CloseCurrentSessions(ERR_NETWORK_CHANGED); | 297 CloseCurrentSessions(ERR_NETWORK_CHANGED); |
292 } | 298 } |
293 | 299 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 for (WeakSessionList::const_iterator it = current_sessions.begin(); | 388 for (WeakSessionList::const_iterator it = current_sessions.begin(); |
383 it != current_sessions.end(); ++it) { | 389 it != current_sessions.end(); ++it) { |
384 if (!*it) | 390 if (!*it) |
385 continue; | 391 continue; |
386 | 392 |
387 if (idle_only && (*it)->is_active()) | 393 if (idle_only && (*it)->is_active()) |
388 continue; | 394 continue; |
389 | 395 |
390 (*it)->CloseSessionOnError(error, description); | 396 (*it)->CloseSessionOnError(error, description); |
391 DCHECK(!IsSessionAvailable(*it)); | 397 DCHECK(!IsSessionAvailable(*it)); |
392 DCHECK(!*it); | |
393 } | 398 } |
394 } | 399 } |
395 | 400 |
396 } // namespace net | 401 } // namespace net |
OLD | NEW |