blob: f290f55e6dd274d8cccacc7ec2205d0bc42be76e [file] [log] [blame]
[email protected]cf4cae32014-05-27 00:39:101// 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.
4
5#ifndef NET_HTTP_HTTP_NETWORK_SESSION_H_
6#define NET_HTTP_HTTP_NETWORK_SESSION_H_
7
8#include <set>
9#include <string>
10#include <vector>
11
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"
25
26namespace base {
27class Value;
28}
29
30namespace net {
31
eranm6571b2b2014-12-03 15:53:2332class CertPolicyEnforcer;
[email protected]cf4cae32014-05-27 00:39:1033class CertVerifier;
[email protected]6b8a3c742014-07-25 00:25:3534class ChannelIDService;
[email protected]cf4cae32014-05-27 00:39:1035class ClientSocketFactory;
36class ClientSocketPoolManager;
37class CTVerifier;
38class HostResolver;
39class HpackHuffmanAggregator;
40class HttpAuthHandlerFactory;
41class HttpNetworkSessionPeer;
42class HttpProxyClientSocketPool;
43class HttpResponseBodyDrainer;
44class HttpServerProperties;
45class NetLog;
46class NetworkDelegate;
bengr39e406102014-09-10 23:04:4647class ProxyDelegate;
[email protected]cf4cae32014-05-27 00:39:1048class ProxyService;
49class QuicClock;
50class QuicCryptoClientStreamFactory;
51class QuicServerInfoFactory;
52class SOCKSClientSocketPool;
53class SSLClientSocketPool;
54class SSLConfigService;
55class TransportClientSocketPool;
56class TransportSecurityState;
57
58// This class holds session objects used by HttpNetworkTransaction objects.
59class NET_EXPORT HttpNetworkSession
60 : public base::RefCounted<HttpNetworkSession>,
61 NON_EXPORTED_BASE(public base::NonThreadSafe) {
62 public:
63 struct NET_EXPORT Params {
64 Params();
65 ~Params();
66
67 ClientSocketFactory* client_socket_factory;
68 HostResolver* host_resolver;
69 CertVerifier* cert_verifier;
eranm6571b2b2014-12-03 15:53:2370 CertPolicyEnforcer* cert_policy_enforcer;
[email protected]6b8a3c742014-07-25 00:25:3571 ChannelIDService* channel_id_service;
[email protected]cf4cae32014-05-27 00:39:1072 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;
80 NetLog* net_log;
81 HostMappingRules* host_mapping_rules;
[email protected]8e458552014-08-05 00:02:1582 bool enable_ssl_connect_job_waiting;
[email protected]cf4cae32014-05-27 00:39:1083 bool ignore_certificate_errors;
ricea64c07d792014-10-08 03:37:0084 bool use_stale_while_revalidate;
[email protected]cf4cae32014-05-27 00:39:1085 uint16 testing_fixed_http_port;
86 uint16 testing_fixed_https_port;
jrif9b4bec2014-09-15 15:46:5487 bool enable_tcp_fast_open_for_ssl;
[email protected]cf4cae32014-05-27 00:39:1088
89 bool force_spdy_single_domain;
90 bool enable_spdy_compression;
91 bool enable_spdy_ping_based_connection_checking;
92 NextProto spdy_default_protocol;
93 // The protocols supported by NPN (next protocol negotiation) during the
94 // SSL handshake as well as by HTTP Alternate-Protocol.
95 // TODO(mmenke): This is currently empty by default, and alternate
96 // protocols are disabled. We should use some reasonable
97 // defaults.
98 NextProtoVector next_protos;
99 size_t spdy_stream_initial_recv_window_size;
100 size_t spdy_initial_max_concurrent_streams;
101 size_t spdy_max_concurrent_streams_limit;
102 SpdySessionPool::TimeFunc time_func;
103 std::string trusted_spdy_proxy;
104 // Controls whether or not ssl is used when in SPDY mode.
105 bool force_spdy_over_ssl;
106 // Controls whether or not SPDY is used without NPN.
107 bool force_spdy_always;
108 // URLs to exclude from forced SPDY.
109 std::set<HostPortPair> forced_spdy_exclusions;
110 // Noe: Using this in the case of NPN for HTTP only results in the browser
111 // trying SSL and then falling back to http.
112 bool use_alternate_protocols;
[email protected]287d9412014-07-08 23:01:00113 double alternate_protocol_probability_threshold;
[email protected]cf4cae32014-05-27 00:39:10114
115 bool enable_quic;
tbansaled0aecc2015-02-20 03:44:18116 bool enable_quic_for_proxies;
[email protected]cf4cae32014-05-27 00:39:10117 bool enable_quic_port_selection;
jri2b966f22014-09-02 22:25:36118 bool quic_always_require_handshake_confirmation;
jri584002d12014-09-09 00:51:28119 bool quic_disable_connection_pooling;
rtenneti38f5cd52014-10-28 20:28:28120 int quic_load_server_info_timeout_ms;
rtenneti2912825c2015-01-06 01:19:46121 float quic_load_server_info_timeout_srtt_multiplier;
rtenneti6a4cf3b2015-01-09 03:41:15122 bool quic_enable_truncated_connection_ids;
rtenneti4f809972015-02-11 19:38:34123 bool quic_enable_connection_racing;
[email protected]cf4cae32014-05-27 00:39:10124 HostPortPair origin_to_force_quic_on;
125 QuicClock* quic_clock; // Will be owned by QuicStreamFactory.
126 QuicRandom* quic_random;
127 size_t quic_max_packet_length;
[email protected]0c4017ca2014-06-06 03:30:45128 std::string quic_user_agent_id;
[email protected]cf4cae32014-05-27 00:39:10129 bool enable_user_alternate_protocol_ports;
130 QuicCryptoClientStreamFactory* quic_crypto_client_stream_factory;
131 QuicVersionVector quic_supported_versions;
[email protected]488a0e252014-06-25 04:37:44132 QuicTagVector quic_connection_options;
bengr39e406102014-09-10 23:04:46133 ProxyDelegate* proxy_delegate;
[email protected]cf4cae32014-05-27 00:39:10134 };
135
136 enum SocketPoolType {
137 NORMAL_SOCKET_POOL,
138 WEBSOCKET_SOCKET_POOL,
139 NUM_SOCKET_POOL_TYPES
140 };
141
142 explicit HttpNetworkSession(const Params& params);
143
144 HttpAuthCache* http_auth_cache() { return &http_auth_cache_; }
145 SSLClientAuthCache* ssl_client_auth_cache() {
146 return &ssl_client_auth_cache_;
147 }
148
149 void AddResponseDrainer(HttpResponseBodyDrainer* drainer);
150
151 void RemoveResponseDrainer(HttpResponseBodyDrainer* drainer);
152
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);
164
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_;
172 }
173 NetworkDelegate* network_delegate() {
174 return network_delegate_;
175 }
176 base::WeakPtr<HttpServerProperties> http_server_properties() {
177 return http_server_properties_;
178 }
179 HttpStreamFactory* http_stream_factory() {
180 return http_stream_factory_.get();
181 }
182 HttpStreamFactory* http_stream_factory_for_websocket() {
183 return http_stream_factory_for_websocket_.get();
184 }
185 NetLog* net_log() {
186 return net_log_;
187 }
188 HpackHuffmanAggregator* huffman_aggregator() {
189 return huffman_aggregator_.get();
190 }
191
192 // Creates a Value summary of the state of the socket pools. The caller is
193 // responsible for deleting the returned value.
194 base::Value* SocketPoolInfoToValue() const;
195
196 // Creates a Value summary of the state of the SPDY sessions. The caller is
197 // responsible for deleting the returned value.
198 base::Value* SpdySessionPoolInfoToValue() const;
199
200 // Creates a Value summary of the state of the QUIC sessions and
201 // configuration. The caller is responsible for deleting the returned value.
202 base::Value* QuicInfoToValue() const;
203
204 void CloseAllConnections();
205 void CloseIdleConnections();
206
207 // Returns the original Params used to construct this session.
208 const Params& params() const { return params_; }
209
210 bool IsProtocolEnabled(AlternateProtocol protocol) const;
211
bnc0d23cf42014-12-11 14:09:46212 // Populates |*next_protos| with protocols.
213 void GetNextProtos(NextProtoVector* next_protos) const;
[email protected]cf4cae32014-05-27 00:39:10214
215 // Convenience function for searching through |params_| for
216 // |forced_spdy_exclusions|.
217 bool HasSpdyExclusion(HostPortPair host_port_pair) const;
218
219 private:
220 friend class base::RefCounted<HttpNetworkSession>;
221 friend class HttpNetworkSessionPeer;
222
223 ~HttpNetworkSession();
224
225 ClientSocketPoolManager* GetSocketPoolManager(SocketPoolType pool_type);
226
227 NetLog* const net_log_;
228 NetworkDelegate* const network_delegate_;
229 const base::WeakPtr<HttpServerProperties> http_server_properties_;
230 CertVerifier* const cert_verifier_;
231 HttpAuthHandlerFactory* const http_auth_handler_factory_;
232
233 // Not const since it's modified by HttpNetworkSessionPeer for testing.
234 ProxyService* proxy_service_;
235 const scoped_refptr<SSLConfigService> ssl_config_service_;
236
237 HttpAuthCache http_auth_cache_;
238 SSLClientAuthCache ssl_client_auth_cache_;
239 scoped_ptr<ClientSocketPoolManager> normal_socket_pool_manager_;
240 scoped_ptr<ClientSocketPoolManager> websocket_socket_pool_manager_;
241 QuicStreamFactory quic_stream_factory_;
242 SpdySessionPool spdy_session_pool_;
243 scoped_ptr<HttpStreamFactory> http_stream_factory_;
244 scoped_ptr<HttpStreamFactory> http_stream_factory_for_websocket_;
245 std::set<HttpResponseBodyDrainer*> response_drainers_;
246
247 // TODO(jgraettinger): Remove when Huffman collection is complete.
248 scoped_ptr<HpackHuffmanAggregator> huffman_aggregator_;
249
bnc0d23cf42014-12-11 14:09:46250 NextProtoVector next_protos_;
[email protected]cf4cae32014-05-27 00:39:10251 bool enabled_protocols_[NUM_VALID_ALTERNATE_PROTOCOLS];
252
253 Params params_;
254};
255
256} // namespace net
257
258#endif // NET_HTTP_HTTP_NETWORK_SESSION_H_