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"
32 class CertPolicyEnforcer
;
34 class ChannelIDService
;
35 class ClientSocketFactory
;
36 class ClientSocketPoolManager
;
39 class HttpAuthHandlerFactory
;
40 class HttpNetworkSessionPeer
;
41 class HttpProxyClientSocketPool
;
42 class HttpResponseBodyDrainer
;
43 class HttpServerProperties
;
45 class NetworkDelegate
;
49 class QuicCryptoClientStreamFactory
;
50 class QuicServerInfoFactory
;
51 class SocketPerformanceWatcherFactory
;
52 class SOCKSClientSocketPool
;
53 class SSLClientSocketPool
;
54 class SSLConfigService
;
55 class TransportClientSocketPool
;
56 class TransportSecurityState
;
58 // This class holds session objects used by HttpNetworkTransaction objects.
59 class NET_EXPORT HttpNetworkSession
60 : public base::RefCounted
<HttpNetworkSession
>,
61 NON_EXPORTED_BASE(public base::NonThreadSafe
) {
63 struct NET_EXPORT Params
{
67 ClientSocketFactory
* client_socket_factory
;
68 HostResolver
* host_resolver
;
69 CertVerifier
* cert_verifier
;
70 CertPolicyEnforcer
* cert_policy_enforcer
;
71 ChannelIDService
* channel_id_service
;
72 TransportSecurityState
* transport_security_state
;
73 CTVerifier
* cert_transparency_verifier
;
74 ProxyService
* proxy_service
;
75 std::string ssl_session_cache_shard
;
76 SSLConfigService
* ssl_config_service
;
77 HttpAuthHandlerFactory
* http_auth_handler_factory
;
78 NetworkDelegate
* network_delegate
;
79 base::WeakPtr
<HttpServerProperties
> http_server_properties
;
81 HostMappingRules
* host_mapping_rules
;
82 SocketPerformanceWatcherFactory
* socket_performance_watcher_factory
;
83 bool ignore_certificate_errors
;
84 uint16 testing_fixed_http_port
;
85 uint16 testing_fixed_https_port
;
86 bool enable_tcp_fast_open_for_ssl
;
88 bool enable_spdy_compression
;
89 bool enable_spdy_ping_based_connection_checking
;
90 NextProto spdy_default_protocol
;
91 // The protocols supported by NPN (next protocol negotiation) during the
92 // SSL handshake as well as by HTTP Alternate-Protocol.
93 // TODO(mmenke): This is currently empty by default, and alternate
94 // protocols are disabled. We should use some reasonable
96 NextProtoVector next_protos
;
97 size_t spdy_session_max_recv_window_size
;
98 size_t spdy_stream_max_recv_window_size
;
99 size_t spdy_initial_max_concurrent_streams
;
100 SpdySessionPool::TimeFunc time_func
;
101 std::string trusted_spdy_proxy
;
102 // URLs to exclude from forced SPDY.
103 std::set
<HostPortPair
> forced_spdy_exclusions
;
104 bool use_alternative_services
;
105 double alternative_service_probability_threshold
;
108 bool enable_insecure_quic
;
109 bool enable_quic_for_proxies
;
110 bool enable_quic_port_selection
;
111 bool quic_always_require_handshake_confirmation
;
112 bool quic_disable_connection_pooling
;
113 float quic_load_server_info_timeout_srtt_multiplier
;
114 bool quic_enable_connection_racing
;
115 bool quic_enable_non_blocking_io
;
116 bool quic_disable_disk_cache
;
117 bool quic_prefer_aes
;
118 int quic_max_number_of_lossy_connections
;
119 float quic_packet_loss_threshold
;
120 int quic_socket_receive_buffer_size
;
121 HostPortPair origin_to_force_quic_on
;
122 QuicClock
* quic_clock
; // Will be owned by QuicStreamFactory.
123 QuicRandom
* quic_random
;
124 size_t quic_max_packet_length
;
125 std::string quic_user_agent_id
;
126 bool enable_user_alternate_protocol_ports
;
127 QuicCryptoClientStreamFactory
* quic_crypto_client_stream_factory
;
128 QuicVersionVector quic_supported_versions
;
129 int quic_max_recent_disabled_reasons
;
130 int quic_threshold_public_resets_post_handshake
;
131 int quic_threshold_timeouts_streams_open
;
132 QuicTagVector quic_connection_options
;
133 ProxyDelegate
* proxy_delegate
;
136 enum SocketPoolType
{
138 WEBSOCKET_SOCKET_POOL
,
139 NUM_SOCKET_POOL_TYPES
142 explicit HttpNetworkSession(const Params
& params
);
144 HttpAuthCache
* http_auth_cache() { return &http_auth_cache_
; }
145 SSLClientAuthCache
* ssl_client_auth_cache() {
146 return &ssl_client_auth_cache_
;
149 void AddResponseDrainer(HttpResponseBodyDrainer
* drainer
);
151 void RemoveResponseDrainer(HttpResponseBodyDrainer
* drainer
);
153 TransportClientSocketPool
* GetTransportSocketPool(SocketPoolType pool_type
);
154 SSLClientSocketPool
* GetSSLSocketPool(SocketPoolType pool_type
);
155 SOCKSClientSocketPool
* GetSocketPoolForSOCKSProxy(
156 SocketPoolType pool_type
,
157 const HostPortPair
& socks_proxy
);
158 HttpProxyClientSocketPool
* GetSocketPoolForHTTPProxy(
159 SocketPoolType pool_type
,
160 const HostPortPair
& http_proxy
);
161 SSLClientSocketPool
* GetSocketPoolForSSLWithProxy(
162 SocketPoolType pool_type
,
163 const HostPortPair
& proxy_server
);
165 CertVerifier
* cert_verifier() { return cert_verifier_
; }
166 ProxyService
* proxy_service() { return proxy_service_
; }
167 SSLConfigService
* ssl_config_service() { return ssl_config_service_
.get(); }
168 SpdySessionPool
* spdy_session_pool() { return &spdy_session_pool_
; }
169 QuicStreamFactory
* quic_stream_factory() { return &quic_stream_factory_
; }
170 HttpAuthHandlerFactory
* http_auth_handler_factory() {
171 return http_auth_handler_factory_
;
173 NetworkDelegate
* network_delegate() {
174 return network_delegate_
;
176 base::WeakPtr
<HttpServerProperties
> http_server_properties() {
177 return http_server_properties_
;
179 HttpStreamFactory
* http_stream_factory() {
180 return http_stream_factory_
.get();
182 HttpStreamFactory
* http_stream_factory_for_websocket() {
183 return http_stream_factory_for_websocket_
.get();
189 // Creates a Value summary of the state of the socket pools.
190 scoped_ptr
<base::Value
> SocketPoolInfoToValue() const;
192 // Creates a Value summary of the state of the SPDY sessions.
193 scoped_ptr
<base::Value
> SpdySessionPoolInfoToValue() const;
195 // Creates a Value summary of the state of the QUIC sessions and
197 scoped_ptr
<base::Value
> QuicInfoToValue() const;
199 void CloseAllConnections();
200 void CloseIdleConnections();
202 // Returns the original Params used to construct this session.
203 const Params
& params() const { return params_
; }
205 bool IsProtocolEnabled(AlternateProtocol protocol
) const;
207 // Populates |*next_protos| with protocols.
208 void GetNextProtos(NextProtoVector
* next_protos
) const;
210 // Convenience function for searching through |params_| for
211 // |forced_spdy_exclusions|.
212 bool HasSpdyExclusion(HostPortPair host_port_pair
) const;
215 friend class base::RefCounted
<HttpNetworkSession
>;
216 friend class HttpNetworkSessionPeer
;
218 ~HttpNetworkSession();
220 ClientSocketPoolManager
* GetSocketPoolManager(SocketPoolType pool_type
);
222 NetLog
* const net_log_
;
223 NetworkDelegate
* const network_delegate_
;
224 const base::WeakPtr
<HttpServerProperties
> http_server_properties_
;
225 CertVerifier
* const cert_verifier_
;
226 HttpAuthHandlerFactory
* const http_auth_handler_factory_
;
228 // Not const since it's modified by HttpNetworkSessionPeer for testing.
229 ProxyService
* proxy_service_
;
230 const scoped_refptr
<SSLConfigService
> ssl_config_service_
;
232 HttpAuthCache http_auth_cache_
;
233 SSLClientAuthCache ssl_client_auth_cache_
;
234 scoped_ptr
<ClientSocketPoolManager
> normal_socket_pool_manager_
;
235 scoped_ptr
<ClientSocketPoolManager
> websocket_socket_pool_manager_
;
236 QuicStreamFactory quic_stream_factory_
;
237 SpdySessionPool spdy_session_pool_
;
238 scoped_ptr
<HttpStreamFactory
> http_stream_factory_
;
239 scoped_ptr
<HttpStreamFactory
> http_stream_factory_for_websocket_
;
240 std::set
<HttpResponseBodyDrainer
*> response_drainers_
;
242 NextProtoVector next_protos_
;
243 bool enabled_protocols_
[NUM_VALID_ALTERNATE_PROTOCOLS
];
250 #endif // NET_HTTP_HTTP_NETWORK_SESSION_H_