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