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_
12 #include "base/basictypes.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/memory/weak_ptr.h"
15 #include "base/threading/non_thread_safe.h"
16 #include "net/base/host_port_pair.h"
17 #include "net/base/net_export.h"
18 #include "net/dns/host_resolver.h"
19 #include "net/http/http_auth_cache.h"
20 #include "net/http/http_stream_factory.h"
21 #include "net/quic/quic_stream_factory.h"
22 #include "net/socket/next_proto.h"
23 #include "net/spdy/spdy_session_pool.h"
24 #include "net/ssl/ssl_client_auth_cache.h"
33 class ChannelIDService
;
34 class ClientSocketFactory
;
35 class ClientSocketPoolManager
;
38 class HpackHuffmanAggregator
;
39 class HttpAuthHandlerFactory
;
40 class HttpNetworkSessionPeer
;
41 class HttpProxyClientSocketPool
;
42 class HttpResponseBodyDrainer
;
43 class HttpServerProperties
;
45 class NetworkDelegate
;
48 class QuicCryptoClientStreamFactory
;
49 class QuicServerInfoFactory
;
50 class SOCKSClientSocketPool
;
51 class SSLClientSocketPool
;
52 class SSLConfigService
;
53 class TransportClientSocketPool
;
54 class TransportSecurityState
;
56 // This class holds session objects used by HttpNetworkTransaction objects.
57 class NET_EXPORT HttpNetworkSession
58 : public base::RefCounted
<HttpNetworkSession
>,
59 NON_EXPORTED_BASE(public base::NonThreadSafe
) {
61 struct NET_EXPORT Params
{
65 ClientSocketFactory
* client_socket_factory
;
66 HostResolver
* host_resolver
;
67 CertVerifier
* cert_verifier
;
68 ChannelIDService
* channel_id_service
;
69 TransportSecurityState
* transport_security_state
;
70 CTVerifier
* cert_transparency_verifier
;
71 ProxyService
* proxy_service
;
72 std::string ssl_session_cache_shard
;
73 SSLConfigService
* ssl_config_service
;
74 HttpAuthHandlerFactory
* http_auth_handler_factory
;
75 NetworkDelegate
* network_delegate
;
76 base::WeakPtr
<HttpServerProperties
> http_server_properties
;
78 HostMappingRules
* host_mapping_rules
;
79 bool enable_ssl_connect_job_waiting
;
80 bool ignore_certificate_errors
;
81 uint16 testing_fixed_http_port
;
82 uint16 testing_fixed_https_port
;
84 bool force_spdy_single_domain
;
85 bool enable_spdy_compression
;
86 bool enable_spdy_ping_based_connection_checking
;
87 NextProto spdy_default_protocol
;
88 // The protocols supported by NPN (next protocol negotiation) during the
89 // SSL handshake as well as by HTTP Alternate-Protocol.
90 // TODO(mmenke): This is currently empty by default, and alternate
91 // protocols are disabled. We should use some reasonable
93 NextProtoVector next_protos
;
94 size_t spdy_stream_initial_recv_window_size
;
95 size_t spdy_initial_max_concurrent_streams
;
96 size_t spdy_max_concurrent_streams_limit
;
97 SpdySessionPool::TimeFunc time_func
;
98 std::string trusted_spdy_proxy
;
99 // Controls whether or not ssl is used when in SPDY mode.
100 bool force_spdy_over_ssl
;
101 // Controls whether or not SPDY is used without NPN.
102 bool force_spdy_always
;
103 // URLs to exclude from forced SPDY.
104 std::set
<HostPortPair
> forced_spdy_exclusions
;
105 // Noe: Using this in the case of NPN for HTTP only results in the browser
106 // trying SSL and then falling back to http.
107 bool use_alternate_protocols
;
108 double alternate_protocol_probability_threshold
;
109 bool enable_websocket_over_spdy
;
112 bool enable_quic_port_selection
;
113 bool enable_quic_time_based_loss_detection
;
114 HostPortPair origin_to_force_quic_on
;
115 QuicClock
* quic_clock
; // Will be owned by QuicStreamFactory.
116 QuicRandom
* quic_random
;
117 size_t quic_max_packet_length
;
118 std::string quic_user_agent_id
;
119 bool enable_user_alternate_protocol_ports
;
120 QuicCryptoClientStreamFactory
* quic_crypto_client_stream_factory
;
121 QuicVersionVector quic_supported_versions
;
122 QuicTagVector quic_connection_options
;
125 enum SocketPoolType
{
127 WEBSOCKET_SOCKET_POOL
,
128 NUM_SOCKET_POOL_TYPES
131 explicit HttpNetworkSession(const Params
& params
);
133 HttpAuthCache
* http_auth_cache() { return &http_auth_cache_
; }
134 SSLClientAuthCache
* ssl_client_auth_cache() {
135 return &ssl_client_auth_cache_
;
138 void AddResponseDrainer(HttpResponseBodyDrainer
* drainer
);
140 void RemoveResponseDrainer(HttpResponseBodyDrainer
* drainer
);
142 TransportClientSocketPool
* GetTransportSocketPool(SocketPoolType pool_type
);
143 SSLClientSocketPool
* GetSSLSocketPool(SocketPoolType pool_type
);
144 SOCKSClientSocketPool
* GetSocketPoolForSOCKSProxy(
145 SocketPoolType pool_type
,
146 const HostPortPair
& socks_proxy
);
147 HttpProxyClientSocketPool
* GetSocketPoolForHTTPProxy(
148 SocketPoolType pool_type
,
149 const HostPortPair
& http_proxy
);
150 SSLClientSocketPool
* GetSocketPoolForSSLWithProxy(
151 SocketPoolType pool_type
,
152 const HostPortPair
& proxy_server
);
154 CertVerifier
* cert_verifier() { return cert_verifier_
; }
155 ProxyService
* proxy_service() { return proxy_service_
; }
156 SSLConfigService
* ssl_config_service() { return ssl_config_service_
.get(); }
157 SpdySessionPool
* spdy_session_pool() { return &spdy_session_pool_
; }
158 QuicStreamFactory
* quic_stream_factory() { return &quic_stream_factory_
; }
159 HttpAuthHandlerFactory
* http_auth_handler_factory() {
160 return http_auth_handler_factory_
;
162 NetworkDelegate
* network_delegate() {
163 return network_delegate_
;
165 base::WeakPtr
<HttpServerProperties
> http_server_properties() {
166 return http_server_properties_
;
168 HttpStreamFactory
* http_stream_factory() {
169 return http_stream_factory_
.get();
171 HttpStreamFactory
* http_stream_factory_for_websocket() {
172 return http_stream_factory_for_websocket_
.get();
177 HpackHuffmanAggregator
* huffman_aggregator() {
178 return huffman_aggregator_
.get();
181 // Creates a Value summary of the state of the socket pools. The caller is
182 // responsible for deleting the returned value.
183 base::Value
* SocketPoolInfoToValue() const;
185 // Creates a Value summary of the state of the SPDY sessions. The caller is
186 // responsible for deleting the returned value.
187 base::Value
* SpdySessionPoolInfoToValue() const;
189 // Creates a Value summary of the state of the QUIC sessions and
190 // configuration. The caller is responsible for deleting the returned value.
191 base::Value
* QuicInfoToValue() const;
193 void CloseAllConnections();
194 void CloseIdleConnections();
196 // Returns the original Params used to construct this session.
197 const Params
& params() const { return params_
; }
199 bool IsProtocolEnabled(AlternateProtocol protocol
) const;
201 void GetNextProtos(std::vector
<std::string
>* next_protos
) const;
203 // Convenience function for searching through |params_| for
204 // |forced_spdy_exclusions|.
205 bool HasSpdyExclusion(HostPortPair host_port_pair
) const;
208 friend class base::RefCounted
<HttpNetworkSession
>;
209 friend class HttpNetworkSessionPeer
;
211 ~HttpNetworkSession();
213 ClientSocketPoolManager
* GetSocketPoolManager(SocketPoolType pool_type
);
215 NetLog
* const net_log_
;
216 NetworkDelegate
* const network_delegate_
;
217 const base::WeakPtr
<HttpServerProperties
> http_server_properties_
;
218 CertVerifier
* const cert_verifier_
;
219 HttpAuthHandlerFactory
* const http_auth_handler_factory_
;
221 // Not const since it's modified by HttpNetworkSessionPeer for testing.
222 ProxyService
* proxy_service_
;
223 const scoped_refptr
<SSLConfigService
> ssl_config_service_
;
225 HttpAuthCache http_auth_cache_
;
226 SSLClientAuthCache ssl_client_auth_cache_
;
227 scoped_ptr
<ClientSocketPoolManager
> normal_socket_pool_manager_
;
228 scoped_ptr
<ClientSocketPoolManager
> websocket_socket_pool_manager_
;
229 QuicStreamFactory quic_stream_factory_
;
230 SpdySessionPool spdy_session_pool_
;
231 scoped_ptr
<HttpStreamFactory
> http_stream_factory_
;
232 scoped_ptr
<HttpStreamFactory
> http_stream_factory_for_websocket_
;
233 std::set
<HttpResponseBodyDrainer
*> response_drainers_
;
235 // TODO(jgraettinger): Remove when Huffman collection is complete.
236 scoped_ptr
<HpackHuffmanAggregator
> huffman_aggregator_
;
238 std::vector
<std::string
> next_protos_
;
239 bool enabled_protocols_
[NUM_VALID_ALTERNATE_PROTOCOLS
];
246 #endif // NET_HTTP_HTTP_NETWORK_SESSION_H_