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 #ifndef NET_SPDY_SPDY_SESSION_POOL_H_ | 5 #ifndef NET_SPDY_SPDY_SESSION_POOL_H_ |
6 #define NET_SPDY_SPDY_SESSION_POOL_H_ | 6 #define NET_SPDY_SPDY_SESSION_POOL_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <list> | 9 #include <list> |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/gtest_prod_util.h" | 13 #include "base/gtest_prod_util.h" |
14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
15 #include "net/base/cert_database.h" | 15 #include "net/base/cert_database.h" |
16 #include "net/base/host_port_pair.h" | 16 #include "net/base/host_port_pair.h" |
17 #include "net/base/ip_endpoint.h" | 17 #include "net/base/ip_endpoint.h" |
18 #include "net/base/net_errors.h" | 18 #include "net/base/net_errors.h" |
19 #include "net/base/net_export.h" | 19 #include "net/base/net_export.h" |
20 #include "net/base/network_change_notifier.h" | 20 #include "net/base/network_change_notifier.h" |
21 #include "net/base/ssl_config_service.h" | 21 #include "net/base/ssl_config_service.h" |
22 #include "net/proxy/proxy_config.h" | 22 #include "net/proxy/proxy_config.h" |
23 #include "net/proxy/proxy_server.h" | 23 #include "net/proxy/proxy_server.h" |
| 24 #include "net/socket/next_proto.h" |
24 | 25 |
25 namespace net { | 26 namespace net { |
26 | 27 |
27 class AddressList; | 28 class AddressList; |
28 class BoundNetLog; | 29 class BoundNetLog; |
29 class ClientSocketHandle; | 30 class ClientSocketHandle; |
30 class HostResolver; | 31 class HostResolver; |
31 class HttpServerProperties; | 32 class HttpServerProperties; |
32 class SpdySession; | 33 class SpdySession; |
33 | 34 |
34 namespace test_spdy2 { | 35 namespace test_spdy2 { |
35 class SpdySessionPoolPeer; | 36 class SpdySessionPoolPeer; |
36 } // namespace test_spdy | 37 } // namespace test_spdy |
37 | 38 |
38 namespace test_spdy3 { | 39 namespace test_spdy3 { |
39 class SpdySessionPoolPeer; | 40 class SpdySessionPoolPeer; |
40 } // namespace test_spdy | 41 } // namespace test_spdy |
41 | 42 |
42 // This is a very simple pool for open SpdySessions. | 43 // This is a very simple pool for open SpdySessions. |
43 class NET_EXPORT SpdySessionPool | 44 class NET_EXPORT SpdySessionPool |
44 : public NetworkChangeNotifier::IPAddressObserver, | 45 : public NetworkChangeNotifier::IPAddressObserver, |
45 public SSLConfigService::Observer, | 46 public SSLConfigService::Observer, |
46 public CertDatabase::Observer { | 47 public CertDatabase::Observer { |
47 public: | 48 public: |
| 49 typedef base::TimeTicks (*TimeFunc)(void); |
| 50 |
48 SpdySessionPool(HostResolver* host_resolver, | 51 SpdySessionPool(HostResolver* host_resolver, |
49 SSLConfigService* ssl_config_service, | 52 SSLConfigService* ssl_config_service, |
50 HttpServerProperties* http_server_properties, | 53 HttpServerProperties* http_server_properties, |
| 54 size_t max_sessions_per_domain, |
| 55 bool force_single_domain, |
| 56 bool enable_ip_pooling, |
| 57 bool enable_credential_frames, |
| 58 bool enable_compression, |
| 59 bool enable_ping_based_connection_checking, |
| 60 NextProto default_protocol, |
| 61 size_t default_initial_recv_window_size, |
| 62 size_t initial_max_concurrent_streams, |
| 63 size_t max_concurrent_streams_limit, |
| 64 SpdySessionPool::TimeFunc time_func, |
51 const std::string& trusted_spdy_proxy); | 65 const std::string& trusted_spdy_proxy); |
52 virtual ~SpdySessionPool(); | 66 virtual ~SpdySessionPool(); |
53 | 67 |
54 // Either returns an existing SpdySession or creates a new SpdySession for | 68 // Either returns an existing SpdySession or creates a new SpdySession for |
55 // use. | 69 // use. |
56 scoped_refptr<SpdySession> Get( | 70 scoped_refptr<SpdySession> Get( |
57 const HostPortProxyPair& host_port_proxy_pair, | 71 const HostPortProxyPair& host_port_proxy_pair, |
58 const BoundNetLog& net_log); | 72 const BoundNetLog& net_log); |
59 | 73 |
60 // Only returns a SpdySession if it already exists. | 74 // Only returns a SpdySession if it already exists. |
61 scoped_refptr<SpdySession> GetIfExists( | 75 scoped_refptr<SpdySession> GetIfExists( |
62 const HostPortProxyPair& host_port_proxy_pair, | 76 const HostPortProxyPair& host_port_proxy_pair, |
63 const BoundNetLog& net_log); | 77 const BoundNetLog& net_log); |
64 | 78 |
65 // Set the maximum concurrent sessions per domain. | |
66 static void set_max_sessions_per_domain(int max) { | |
67 if (max >= 1) | |
68 g_max_sessions_per_domain = max; | |
69 } | |
70 | |
71 // Builds a SpdySession from an existing SSL socket. Users should try | 79 // Builds a SpdySession from an existing SSL socket. Users should try |
72 // calling Get() first to use an existing SpdySession so we don't get | 80 // calling Get() first to use an existing SpdySession so we don't get |
73 // multiple SpdySessions per domain. Note that ownership of |connection| is | 81 // multiple SpdySessions per domain. Note that ownership of |connection| is |
74 // transferred from the caller to the SpdySession. | 82 // transferred from the caller to the SpdySession. |
75 // |certificate_error_code| is used to indicate the certificate error | 83 // |certificate_error_code| is used to indicate the certificate error |
76 // encountered when connecting the SSL socket. OK means there was no error. | 84 // encountered when connecting the SSL socket. OK means there was no error. |
77 // For testing, setting is_secure to false allows Spdy to connect with a | 85 // For testing, setting is_secure to false allows Spdy to connect with a |
78 // pre-existing TCP socket. | 86 // pre-existing TCP socket. |
79 // Returns OK on success, and the |spdy_session| will be provided. | 87 // Returns OK on success, and the |spdy_session| will be provided. |
80 // Returns an error on failure, and |spdy_session| will be NULL. | 88 // Returns an error on failure, and |spdy_session| will be NULL. |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 // We flush all idle sessions and release references to the active ones so | 127 // We flush all idle sessions and release references to the active ones so |
120 // they won't get re-used. The active ones will either complete successfully | 128 // they won't get re-used. The active ones will either complete successfully |
121 // or error out due to the IP address change. | 129 // or error out due to the IP address change. |
122 virtual void OnIPAddressChanged() OVERRIDE; | 130 virtual void OnIPAddressChanged() OVERRIDE; |
123 | 131 |
124 // SSLConfigService::Observer methods: | 132 // SSLConfigService::Observer methods: |
125 | 133 |
126 // We perform the same flushing as described above when SSL settings change. | 134 // We perform the same flushing as described above when SSL settings change. |
127 virtual void OnSSLConfigChanged() OVERRIDE; | 135 virtual void OnSSLConfigChanged() OVERRIDE; |
128 | 136 |
129 // A debugging mode where we compress all accesses through a single domain. | |
130 static void ForceSingleDomain() { g_force_single_domain = true; } | |
131 | |
132 // Controls whether the pool allows use of a common session for domains | |
133 // which share IP address resolutions. | |
134 static void enable_ip_pooling(bool value) { g_enable_ip_pooling = value; } | |
135 | |
136 // CertDatabase::Observer methods: | 137 // CertDatabase::Observer methods: |
137 virtual void OnCertAdded(const X509Certificate* cert) OVERRIDE; | 138 virtual void OnCertAdded(const X509Certificate* cert) OVERRIDE; |
138 virtual void OnCertTrustChanged(const X509Certificate* cert) OVERRIDE; | 139 virtual void OnCertTrustChanged(const X509Certificate* cert) OVERRIDE; |
139 | 140 |
140 private: | 141 private: |
141 friend class test_spdy2::SpdySessionPoolPeer; // For testing. | 142 friend class test_spdy2::SpdySessionPoolPeer; // For testing. |
142 friend class test_spdy3::SpdySessionPoolPeer; // For testing. | 143 friend class test_spdy3::SpdySessionPoolPeer; // For testing. |
143 friend class SpdyNetworkTransactionSpdy2Test; // For testing. | 144 friend class SpdyNetworkTransactionSpdy2Test; // For testing. |
144 friend class SpdyNetworkTransactionSpdy3Test; // For testing. | 145 friend class SpdyNetworkTransactionSpdy3Test; // For testing. |
145 FRIEND_TEST_ALL_PREFIXES(SpdyNetworkTransactionSpdy2Test, | 146 FRIEND_TEST_ALL_PREFIXES(SpdyNetworkTransactionSpdy2Test, |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 bool RemoveFromSessionList(const scoped_refptr<SpdySession>& session, | 191 bool RemoveFromSessionList(const scoped_refptr<SpdySession>& session, |
191 const HostPortProxyPair& pair); | 192 const HostPortProxyPair& pair); |
192 | 193 |
193 HttpServerProperties* const http_server_properties_; | 194 HttpServerProperties* const http_server_properties_; |
194 | 195 |
195 // This is our weak session pool - one session per domain. | 196 // This is our weak session pool - one session per domain. |
196 SpdySessionsMap sessions_; | 197 SpdySessionsMap sessions_; |
197 // A map of IPEndPoint aliases for sessions. | 198 // A map of IPEndPoint aliases for sessions. |
198 SpdyAliasMap aliases_; | 199 SpdyAliasMap aliases_; |
199 | 200 |
200 static size_t g_max_sessions_per_domain; | |
201 static bool g_force_single_domain; | 201 static bool g_force_single_domain; |
202 static bool g_enable_ip_pooling; | |
203 | 202 |
204 const scoped_refptr<SSLConfigService> ssl_config_service_; | 203 const scoped_refptr<SSLConfigService> ssl_config_service_; |
205 HostResolver* const resolver_; | 204 HostResolver* const resolver_; |
206 | 205 |
207 // Defaults to true. May be controlled via SpdySessionPoolPeer for tests. | 206 // Defaults to true. May be controlled via SpdySessionPoolPeer for tests. |
208 bool verify_domain_authentication_; | 207 bool verify_domain_authentication_; |
209 | |
210 bool enable_sending_initial_settings_; | 208 bool enable_sending_initial_settings_; |
| 209 size_t max_sessions_per_domain_; |
| 210 bool force_single_domain_; |
| 211 bool enable_ip_pooling_; |
| 212 bool enable_credential_frames_; |
| 213 bool enable_compression_; |
| 214 bool enable_ping_based_connection_checking_; |
| 215 NextProto default_protocol_; |
| 216 size_t initial_recv_window_size_; |
| 217 size_t initial_max_concurrent_streams_; |
| 218 size_t max_concurrent_streams_limit_; |
| 219 TimeFunc time_func_; |
211 | 220 |
212 // This SPDY proxy is allowed to push resources from origins that are | 221 // This SPDY proxy is allowed to push resources from origins that are |
213 // different from those of their associated streams. | 222 // different from those of their associated streams. |
214 HostPortPair trusted_spdy_proxy_; | 223 HostPortPair trusted_spdy_proxy_; |
215 | 224 |
216 DISALLOW_COPY_AND_ASSIGN(SpdySessionPool); | 225 DISALLOW_COPY_AND_ASSIGN(SpdySessionPool); |
217 }; | 226 }; |
218 | 227 |
219 } // namespace net | 228 } // namespace net |
220 | 229 |
221 #endif // NET_SPDY_SPDY_SESSION_POOL_H_ | 230 #endif // NET_SPDY_SPDY_SESSION_POOL_H_ |
OLD | NEW |