| 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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 | 70 |
| 71 SpdySessionPool::~SpdySessionPool() { | 71 SpdySessionPool::~SpdySessionPool() { |
| 72 CloseAllSessions(); | 72 CloseAllSessions(); |
| 73 | 73 |
| 74 if (ssl_config_service_.get()) | 74 if (ssl_config_service_.get()) |
| 75 ssl_config_service_->RemoveObserver(this); | 75 ssl_config_service_->RemoveObserver(this); |
| 76 NetworkChangeNotifier::RemoveIPAddressObserver(this); | 76 NetworkChangeNotifier::RemoveIPAddressObserver(this); |
| 77 CertDatabase::GetInstance()->RemoveObserver(this); | 77 CertDatabase::GetInstance()->RemoveObserver(this); |
| 78 } | 78 } |
| 79 | 79 |
| 80 base::WeakPtr<SpdySession> SpdySessionPool::CreateAvailableSessionFromSocket( | 80 net::Error SpdySessionPool::CreateAvailableSessionFromSocket( |
| 81 const SpdySessionKey& key, | 81 const SpdySessionKey& key, |
| 82 scoped_ptr<ClientSocketHandle> connection, | 82 scoped_ptr<ClientSocketHandle> connection, |
| 83 const BoundNetLog& net_log, | 83 const BoundNetLog& net_log, |
| 84 int certificate_error_code, | 84 int certificate_error_code, |
| 85 base::WeakPtr<SpdySession>* available_session, |
| 85 bool is_secure) { | 86 bool is_secure) { |
| 86 DCHECK_GE(default_protocol_, kProtoSPDYMinimumVersion); | 87 DCHECK_GE(default_protocol_, kProtoSPDYMinimumVersion); |
| 87 DCHECK_LE(default_protocol_, kProtoSPDYMaximumVersion); | 88 DCHECK_LE(default_protocol_, kProtoSPDYMaximumVersion); |
| 88 | 89 |
| 89 UMA_HISTOGRAM_ENUMERATION( | 90 UMA_HISTOGRAM_ENUMERATION( |
| 90 "Net.SpdySessionGet", IMPORTED_FROM_SOCKET, SPDY_SESSION_GET_MAX); | 91 "Net.SpdySessionGet", IMPORTED_FROM_SOCKET, SPDY_SESSION_GET_MAX); |
| 91 | 92 |
| 92 scoped_ptr<SpdySession> new_session( | 93 scoped_ptr<SpdySession> new_session( |
| 93 new SpdySession(key, | 94 new SpdySession(key, |
| 94 http_server_properties_, | 95 http_server_properties_, |
| 95 verify_domain_authentication_, | 96 verify_domain_authentication_, |
| 96 enable_sending_initial_data_, | 97 enable_sending_initial_data_, |
| 97 enable_compression_, | 98 enable_compression_, |
| 98 enable_ping_based_connection_checking_, | 99 enable_ping_based_connection_checking_, |
| 99 default_protocol_, | 100 default_protocol_, |
| 100 stream_initial_recv_window_size_, | 101 stream_initial_recv_window_size_, |
| 101 initial_max_concurrent_streams_, | 102 initial_max_concurrent_streams_, |
| 102 max_concurrent_streams_limit_, | 103 max_concurrent_streams_limit_, |
| 103 time_func_, | 104 time_func_, |
| 104 trusted_spdy_proxy_, | 105 trusted_spdy_proxy_, |
| 105 net_log.net_log())); | 106 net_log.net_log())); |
| 106 | 107 |
| 107 new_session->InitializeWithSocket( | 108 Error error = new_session->InitializeWithSocket( |
| 108 connection.Pass(), this, is_secure, certificate_error_code); | 109 connection.Pass(), this, is_secure, certificate_error_code); |
| 110 DCHECK_NE(error, ERR_IO_PENDING); |
| 109 | 111 |
| 110 base::WeakPtr<SpdySession> available_session = new_session->GetWeakPtr(); | 112 if (error != OK) { |
| 113 available_session->reset(); |
| 114 return error; |
| 115 } |
| 116 |
| 117 *available_session = new_session->GetWeakPtr(); |
| 111 sessions_.insert(new_session.release()); | 118 sessions_.insert(new_session.release()); |
| 112 MapKeyToAvailableSession(key, available_session); | 119 MapKeyToAvailableSession(key, *available_session); |
| 113 | 120 |
| 114 net_log.AddEvent( | 121 net_log.AddEvent( |
| 115 NetLog::TYPE_SPDY_SESSION_POOL_IMPORTED_SESSION_FROM_SOCKET, | 122 NetLog::TYPE_SPDY_SESSION_POOL_IMPORTED_SESSION_FROM_SOCKET, |
| 116 available_session->net_log().source().ToEventParametersCallback()); | 123 (*available_session)->net_log().source().ToEventParametersCallback()); |
| 117 | 124 |
| 118 // Look up the IP address for this session so that we can match | 125 // Look up the IP address for this session so that we can match |
| 119 // future sessions (potentially to different domains) which can | 126 // future sessions (potentially to different domains) which can |
| 120 // potentially be pooled with this one. Because GetPeerAddress() | 127 // potentially be pooled with this one. Because GetPeerAddress() |
| 121 // reports the proxy's address instead of the origin server, check | 128 // reports the proxy's address instead of the origin server, check |
| 122 // to see if this is a direct connection. | 129 // to see if this is a direct connection. |
| 123 if (key.proxy_server().is_direct()) { | 130 if (key.proxy_server().is_direct()) { |
| 124 IPEndPoint address; | 131 IPEndPoint address; |
| 125 if (available_session->GetPeerAddress(&address) == OK) | 132 if ((*available_session)->GetPeerAddress(&address) == OK) |
| 126 aliases_[address] = key; | 133 aliases_[address] = key; |
| 127 } | 134 } |
| 128 | 135 |
| 129 return available_session; | 136 return error; |
| 130 } | 137 } |
| 131 | 138 |
| 132 base::WeakPtr<SpdySession> SpdySessionPool::FindAvailableSession( | 139 base::WeakPtr<SpdySession> SpdySessionPool::FindAvailableSession( |
| 133 const SpdySessionKey& key, | 140 const SpdySessionKey& key, |
| 134 const BoundNetLog& net_log) { | 141 const BoundNetLog& net_log) { |
| 135 AvailableSessionMap::iterator it = LookupAvailableSessionByKey(key); | 142 AvailableSessionMap::iterator it = LookupAvailableSessionByKey(key); |
| 136 if (it != available_sessions_.end()) { | 143 if (it != available_sessions_.end()) { |
| 137 UMA_HISTOGRAM_ENUMERATION( | 144 UMA_HISTOGRAM_ENUMERATION( |
| 138 "Net.SpdySessionGet", FOUND_EXISTING, SPDY_SESSION_GET_MAX); | 145 "Net.SpdySessionGet", FOUND_EXISTING, SPDY_SESSION_GET_MAX); |
| 139 net_log.AddEvent( | 146 net_log.AddEvent( |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 if (idle_only && (*it)->is_active()) | 394 if (idle_only && (*it)->is_active()) |
| 388 continue; | 395 continue; |
| 389 | 396 |
| 390 (*it)->CloseSessionOnError(error, description); | 397 (*it)->CloseSessionOnError(error, description); |
| 391 DCHECK(!IsSessionAvailable(*it)); | 398 DCHECK(!IsSessionAvailable(*it)); |
| 392 DCHECK(!*it); | 399 DCHECK(!*it); |
| 393 } | 400 } |
| 394 } | 401 } |
| 395 | 402 |
| 396 } // namespace net | 403 } // namespace net |
| OLD | NEW |