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
3 // found in the LICENSE file.
5 #ifndef NET_HTTP_HTTP_NETWORK_SESSION_H_
6 #define NET_HTTP_HTTP_NETWORK_SESSION_H_
11 #include "base/basictypes.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/threading/non_thread_safe.h"
15 #include "net/base/host_port_pair.h"
16 #include "net/base/net_export.h"
17 #include "net/dns/host_resolver.h"
18 #include "net/http/http_auth_cache.h"
19 #include "net/http/http_stream_factory.h"
20 #include "net/quic/quic_stream_factory.h"
21 #include "net/spdy/spdy_session_pool.h"
22 #include "net/ssl/ssl_client_auth_cache.h"
31 class ClientSocketFactory
;
32 class ClientSocketPoolManager
;
34 class HttpAuthHandlerFactory
;
35 class HttpNetworkSessionPeer
;
36 class HttpProxyClientSocketPool
;
37 class HttpResponseBodyDrainer
;
38 class HttpServerProperties
;
40 class NetworkDelegate
;
41 class ServerBoundCertService
;
44 class QuicCryptoClientStreamFactory
;
45 class QuicServerInfoFactory
;
46 class SOCKSClientSocketPool
;
47 class SSLClientSocketPool
;
48 class SSLConfigService
;
49 class TransportClientSocketPool
;
50 class TransportSecurityState
;
52 // This class holds session objects used by HttpNetworkTransaction objects.
53 class NET_EXPORT HttpNetworkSession
54 : public base::RefCounted
<HttpNetworkSession
>,
55 NON_EXPORTED_BASE(public base::NonThreadSafe
) {
57 struct NET_EXPORT Params
{
61 ClientSocketFactory
* client_socket_factory
;
62 HostResolver
* host_resolver
;
63 CertVerifier
* cert_verifier
;
64 ServerBoundCertService
* server_bound_cert_service
;
65 TransportSecurityState
* transport_security_state
;
66 CTVerifier
* cert_transparency_verifier
;
67 ProxyService
* proxy_service
;
68 std::string ssl_session_cache_shard
;
69 SSLConfigService
* ssl_config_service
;
70 HttpAuthHandlerFactory
* http_auth_handler_factory
;
71 NetworkDelegate
* network_delegate
;
72 base::WeakPtr
<HttpServerProperties
> http_server_properties
;
74 HostMappingRules
* host_mapping_rules
;
75 bool force_http_pipelining
;
76 bool ignore_certificate_errors
;
77 bool http_pipelining_enabled
;
78 uint16 testing_fixed_http_port
;
79 uint16 testing_fixed_https_port
;
80 bool force_spdy_single_domain
;
81 bool enable_spdy_compression
;
82 bool enable_spdy_ping_based_connection_checking
;
83 NextProto spdy_default_protocol
;
84 size_t spdy_stream_initial_recv_window_size
;
85 size_t spdy_initial_max_concurrent_streams
;
86 size_t spdy_max_concurrent_streams_limit
;
87 SpdySessionPool::TimeFunc time_func
;
88 std::string trusted_spdy_proxy
;
90 bool enable_quic_https
;
91 bool enable_quic_port_selection
;
92 bool enable_quic_pacing
;
93 HostPortPair origin_to_force_quic_on
;
94 QuicClock
* quic_clock
; // Will be owned by QuicStreamFactory.
95 QuicRandom
* quic_random
;
96 size_t quic_max_packet_length
;
97 bool enable_user_alternate_protocol_ports
;
98 QuicCryptoClientStreamFactory
* quic_crypto_client_stream_factory
;
99 QuicVersionVector quic_supported_versions
;
102 enum SocketPoolType
{
104 WEBSOCKET_SOCKET_POOL
,
105 NUM_SOCKET_POOL_TYPES
108 explicit HttpNetworkSession(const Params
& params
);
110 HttpAuthCache
* http_auth_cache() { return &http_auth_cache_
; }
111 SSLClientAuthCache
* ssl_client_auth_cache() {
112 return &ssl_client_auth_cache_
;
115 void AddResponseDrainer(HttpResponseBodyDrainer
* drainer
);
117 void RemoveResponseDrainer(HttpResponseBodyDrainer
* drainer
);
119 TransportClientSocketPool
* GetTransportSocketPool(SocketPoolType pool_type
);
120 SSLClientSocketPool
* GetSSLSocketPool(SocketPoolType pool_type
);
121 SOCKSClientSocketPool
* GetSocketPoolForSOCKSProxy(
122 SocketPoolType pool_type
,
123 const HostPortPair
& socks_proxy
);
124 HttpProxyClientSocketPool
* GetSocketPoolForHTTPProxy(
125 SocketPoolType pool_type
,
126 const HostPortPair
& http_proxy
);
127 SSLClientSocketPool
* GetSocketPoolForSSLWithProxy(
128 SocketPoolType pool_type
,
129 const HostPortPair
& proxy_server
);
131 CertVerifier
* cert_verifier() { return cert_verifier_
; }
132 ProxyService
* proxy_service() { return proxy_service_
; }
133 SSLConfigService
* ssl_config_service() { return ssl_config_service_
.get(); }
134 SpdySessionPool
* spdy_session_pool() { return &spdy_session_pool_
; }
135 QuicStreamFactory
* quic_stream_factory() { return &quic_stream_factory_
; }
136 HttpAuthHandlerFactory
* http_auth_handler_factory() {
137 return http_auth_handler_factory_
;
139 NetworkDelegate
* network_delegate() {
140 return network_delegate_
;
142 base::WeakPtr
<HttpServerProperties
> http_server_properties() {
143 return http_server_properties_
;
145 HttpStreamFactory
* http_stream_factory() {
146 return http_stream_factory_
.get();
148 HttpStreamFactory
* http_stream_factory_for_websocket() {
149 return http_stream_factory_for_websocket_
.get();
155 // Creates a Value summary of the state of the socket pools. The caller is
156 // responsible for deleting the returned value.
157 base::Value
* SocketPoolInfoToValue() const;
159 // Creates a Value summary of the state of the SPDY sessions. The caller is
160 // responsible for deleting the returned value.
161 base::Value
* SpdySessionPoolInfoToValue() const;
163 // Creates a Value summary of the state of the QUIC sessions and
164 // configuration. The caller is responsible for deleting the returned value.
165 base::Value
* QuicInfoToValue() const;
167 void CloseAllConnections();
168 void CloseIdleConnections();
170 bool force_http_pipelining() const { return force_http_pipelining_
; }
172 // Returns the original Params used to construct this session.
173 const Params
& params() const { return params_
; }
175 void set_http_pipelining_enabled(bool enable
) {
176 params_
.http_pipelining_enabled
= enable
;
180 friend class base::RefCounted
<HttpNetworkSession
>;
181 friend class HttpNetworkSessionPeer
;
183 ~HttpNetworkSession();
185 ClientSocketPoolManager
* GetSocketPoolManager(SocketPoolType pool_type
);
187 NetLog
* const net_log_
;
188 NetworkDelegate
* const network_delegate_
;
189 const base::WeakPtr
<HttpServerProperties
> http_server_properties_
;
190 CertVerifier
* const cert_verifier_
;
191 HttpAuthHandlerFactory
* const http_auth_handler_factory_
;
192 bool force_http_pipelining_
;
194 // Not const since it's modified by HttpNetworkSessionPeer for testing.
195 ProxyService
* proxy_service_
;
196 const scoped_refptr
<SSLConfigService
> ssl_config_service_
;
198 HttpAuthCache http_auth_cache_
;
199 SSLClientAuthCache ssl_client_auth_cache_
;
200 scoped_ptr
<ClientSocketPoolManager
> normal_socket_pool_manager_
;
201 scoped_ptr
<ClientSocketPoolManager
> websocket_socket_pool_manager_
;
202 QuicStreamFactory quic_stream_factory_
;
203 SpdySessionPool spdy_session_pool_
;
204 scoped_ptr
<HttpStreamFactory
> http_stream_factory_
;
205 scoped_ptr
<HttpStreamFactory
> http_stream_factory_for_websocket_
;
206 std::set
<HttpResponseBodyDrainer
*> response_drainers_
;
213 #endif // NET_HTTP_HTTP_NETWORK_SESSION_H_