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