Rewrite AndroidSyncSettings to be significantly simpler.
[chromium-blink-merge.git] / net / http / http_network_session.h
blobea1879dfe2cab18941827b09b982c18fae0e7b73
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_
8 #include <set>
9 #include <string>
10 #include <vector>
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"
26 namespace base {
27 class Value;
30 namespace net {
32 class CertPolicyEnforcer;
33 class CertVerifier;
34 class ChannelIDService;
35 class ClientSocketFactory;
36 class ClientSocketPoolManager;
37 class CTVerifier;
38 class HostResolver;
39 class HpackHuffmanAggregator;
40 class HttpAuthHandlerFactory;
41 class HttpNetworkSessionPeer;
42 class HttpProxyClientSocketPool;
43 class HttpResponseBodyDrainer;
44 class HttpServerProperties;
45 class NetLog;
46 class NetworkDelegate;
47 class ProxyDelegate;
48 class ProxyService;
49 class QuicClock;
50 class QuicCryptoClientStreamFactory;
51 class QuicServerInfoFactory;
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) {
62 public:
63 struct NET_EXPORT Params {
64 Params();
65 ~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;
80 NetLog* net_log;
81 HostMappingRules* host_mapping_rules;
82 bool enable_ssl_connect_job_waiting;
83 bool ignore_certificate_errors;
84 bool use_stale_while_revalidate;
85 uint16 testing_fixed_http_port;
86 uint16 testing_fixed_https_port;
87 bool enable_tcp_fast_open_for_ssl;
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;
113 double alternate_protocol_probability_threshold;
115 bool enable_quic;
116 bool enable_quic_for_proxies;
117 bool enable_quic_port_selection;
118 bool quic_always_require_handshake_confirmation;
119 bool quic_disable_connection_pooling;
120 int quic_load_server_info_timeout_ms;
121 float quic_load_server_info_timeout_srtt_multiplier;
122 bool quic_enable_truncated_connection_ids;
123 bool quic_enable_connection_racing;
124 bool quic_disable_disk_cache;
125 HostPortPair origin_to_force_quic_on;
126 QuicClock* quic_clock; // Will be owned by QuicStreamFactory.
127 QuicRandom* quic_random;
128 size_t quic_max_packet_length;
129 std::string quic_user_agent_id;
130 bool enable_user_alternate_protocol_ports;
131 QuicCryptoClientStreamFactory* quic_crypto_client_stream_factory;
132 QuicVersionVector quic_supported_versions;
133 QuicTagVector quic_connection_options;
134 ProxyDelegate* proxy_delegate;
137 enum SocketPoolType {
138 NORMAL_SOCKET_POOL,
139 WEBSOCKET_SOCKET_POOL,
140 NUM_SOCKET_POOL_TYPES
143 explicit HttpNetworkSession(const Params& params);
145 HttpAuthCache* http_auth_cache() { return &http_auth_cache_; }
146 SSLClientAuthCache* ssl_client_auth_cache() {
147 return &ssl_client_auth_cache_;
150 void AddResponseDrainer(HttpResponseBodyDrainer* drainer);
152 void RemoveResponseDrainer(HttpResponseBodyDrainer* drainer);
154 TransportClientSocketPool* GetTransportSocketPool(SocketPoolType pool_type);
155 SSLClientSocketPool* GetSSLSocketPool(SocketPoolType pool_type);
156 SOCKSClientSocketPool* GetSocketPoolForSOCKSProxy(
157 SocketPoolType pool_type,
158 const HostPortPair& socks_proxy);
159 HttpProxyClientSocketPool* GetSocketPoolForHTTPProxy(
160 SocketPoolType pool_type,
161 const HostPortPair& http_proxy);
162 SSLClientSocketPool* GetSocketPoolForSSLWithProxy(
163 SocketPoolType pool_type,
164 const HostPortPair& proxy_server);
166 CertVerifier* cert_verifier() { return cert_verifier_; }
167 ProxyService* proxy_service() { return proxy_service_; }
168 SSLConfigService* ssl_config_service() { return ssl_config_service_.get(); }
169 SpdySessionPool* spdy_session_pool() { return &spdy_session_pool_; }
170 QuicStreamFactory* quic_stream_factory() { return &quic_stream_factory_; }
171 HttpAuthHandlerFactory* http_auth_handler_factory() {
172 return http_auth_handler_factory_;
174 NetworkDelegate* network_delegate() {
175 return network_delegate_;
177 base::WeakPtr<HttpServerProperties> http_server_properties() {
178 return http_server_properties_;
180 HttpStreamFactory* http_stream_factory() {
181 return http_stream_factory_.get();
183 HttpStreamFactory* http_stream_factory_for_websocket() {
184 return http_stream_factory_for_websocket_.get();
186 NetLog* net_log() {
187 return net_log_;
189 HpackHuffmanAggregator* huffman_aggregator() {
190 return huffman_aggregator_.get();
193 // Creates a Value summary of the state of the socket pools. The caller is
194 // responsible for deleting the returned value.
195 base::Value* SocketPoolInfoToValue() const;
197 // Creates a Value summary of the state of the SPDY sessions. The caller is
198 // responsible for deleting the returned value.
199 base::Value* SpdySessionPoolInfoToValue() const;
201 // Creates a Value summary of the state of the QUIC sessions and
202 // configuration. The caller is responsible for deleting the returned value.
203 base::Value* QuicInfoToValue() const;
205 void CloseAllConnections();
206 void CloseIdleConnections();
208 // Returns the original Params used to construct this session.
209 const Params& params() const { return params_; }
211 bool IsProtocolEnabled(AlternateProtocol protocol) const;
213 // Populates |*next_protos| with protocols.
214 void GetNextProtos(NextProtoVector* next_protos) const;
216 // Convenience function for searching through |params_| for
217 // |forced_spdy_exclusions|.
218 bool HasSpdyExclusion(HostPortPair host_port_pair) const;
220 private:
221 friend class base::RefCounted<HttpNetworkSession>;
222 friend class HttpNetworkSessionPeer;
224 ~HttpNetworkSession();
226 ClientSocketPoolManager* GetSocketPoolManager(SocketPoolType pool_type);
228 NetLog* const net_log_;
229 NetworkDelegate* const network_delegate_;
230 const base::WeakPtr<HttpServerProperties> http_server_properties_;
231 CertVerifier* const cert_verifier_;
232 HttpAuthHandlerFactory* const http_auth_handler_factory_;
234 // Not const since it's modified by HttpNetworkSessionPeer for testing.
235 ProxyService* proxy_service_;
236 const scoped_refptr<SSLConfigService> ssl_config_service_;
238 HttpAuthCache http_auth_cache_;
239 SSLClientAuthCache ssl_client_auth_cache_;
240 scoped_ptr<ClientSocketPoolManager> normal_socket_pool_manager_;
241 scoped_ptr<ClientSocketPoolManager> websocket_socket_pool_manager_;
242 QuicStreamFactory quic_stream_factory_;
243 SpdySessionPool spdy_session_pool_;
244 scoped_ptr<HttpStreamFactory> http_stream_factory_;
245 scoped_ptr<HttpStreamFactory> http_stream_factory_for_websocket_;
246 std::set<HttpResponseBodyDrainer*> response_drainers_;
248 // TODO(jgraettinger): Remove when Huffman collection is complete.
249 scoped_ptr<HpackHuffmanAggregator> huffman_aggregator_;
251 NextProtoVector next_protos_;
252 bool enabled_protocols_[NUM_VALID_ALTERNATE_PROTOCOLS];
254 Params params_;
257 } // namespace net
259 #endif // NET_HTTP_HTTP_NETWORK_SESSION_H_