Lots of random cleanups, mostly for native_theme_win.cc:
[chromium-blink-merge.git] / net / http / http_network_session.h
blobe265a9146896df98e860372c8fe63e3734773071
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 CertVerifier;
33 class ClientSocketFactory;
34 class ClientSocketPoolManager;
35 class CTVerifier;
36 class HostResolver;
37 class HpackHuffmanAggregator;
38 class HttpAuthHandlerFactory;
39 class HttpNetworkSessionPeer;
40 class HttpProxyClientSocketPool;
41 class HttpResponseBodyDrainer;
42 class HttpServerProperties;
43 class NetLog;
44 class NetworkDelegate;
45 class ServerBoundCertService;
46 class ProxyService;
47 class QuicClock;
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) {
60 public:
61 struct NET_EXPORT Params {
62 Params();
63 ~Params();
65 ClientSocketFactory* client_socket_factory;
66 HostResolver* host_resolver;
67 CertVerifier* cert_verifier;
68 ServerBoundCertService* server_bound_cert_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;
77 NetLog* net_log;
78 HostMappingRules* host_mapping_rules;
79 bool ignore_certificate_errors;
80 uint16 testing_fixed_http_port;
81 uint16 testing_fixed_https_port;
83 bool force_spdy_single_domain;
84 bool enable_spdy_compression;
85 bool enable_spdy_ping_based_connection_checking;
86 NextProto spdy_default_protocol;
87 // The protocols supported by NPN (next protocol negotiation) during the
88 // SSL handshake as well as by HTTP Alternate-Protocol.
89 // TODO(mmenke): This is currently empty by default, and alternate
90 // protocols are disabled. We should use some reasonable
91 // defaults.
92 NextProtoVector next_protos;
93 size_t spdy_stream_initial_recv_window_size;
94 size_t spdy_initial_max_concurrent_streams;
95 size_t spdy_max_concurrent_streams_limit;
96 SpdySessionPool::TimeFunc time_func;
97 std::string trusted_spdy_proxy;
98 // Controls whether or not ssl is used when in SPDY mode.
99 bool force_spdy_over_ssl;
100 // Controls whether or not SPDY is used without NPN.
101 bool force_spdy_always;
102 // URLs to exclude from forced SPDY.
103 std::set<HostPortPair> forced_spdy_exclusions;
104 // Noe: Using this in the case of NPN for HTTP only results in the browser
105 // trying SSL and then falling back to http.
106 bool use_alternate_protocols;
107 double alternate_protocol_probability_threshold;
108 bool enable_websocket_over_spdy;
110 bool enable_quic;
111 bool enable_quic_port_selection;
112 bool enable_quic_pacing;
113 bool enable_quic_time_based_loss_detection;
114 bool enable_quic_persist_server_info;
115 HostPortPair origin_to_force_quic_on;
116 QuicClock* quic_clock; // Will be owned by QuicStreamFactory.
117 QuicRandom* quic_random;
118 size_t quic_max_packet_length;
119 std::string quic_user_agent_id;
120 bool enable_user_alternate_protocol_ports;
121 QuicCryptoClientStreamFactory* quic_crypto_client_stream_factory;
122 QuicVersionVector quic_supported_versions;
123 QuicTagVector quic_connection_options;
126 enum SocketPoolType {
127 NORMAL_SOCKET_POOL,
128 WEBSOCKET_SOCKET_POOL,
129 NUM_SOCKET_POOL_TYPES
132 explicit HttpNetworkSession(const Params& params);
134 HttpAuthCache* http_auth_cache() { return &http_auth_cache_; }
135 SSLClientAuthCache* ssl_client_auth_cache() {
136 return &ssl_client_auth_cache_;
139 void AddResponseDrainer(HttpResponseBodyDrainer* drainer);
141 void RemoveResponseDrainer(HttpResponseBodyDrainer* drainer);
143 TransportClientSocketPool* GetTransportSocketPool(SocketPoolType pool_type);
144 SSLClientSocketPool* GetSSLSocketPool(SocketPoolType pool_type);
145 SOCKSClientSocketPool* GetSocketPoolForSOCKSProxy(
146 SocketPoolType pool_type,
147 const HostPortPair& socks_proxy);
148 HttpProxyClientSocketPool* GetSocketPoolForHTTPProxy(
149 SocketPoolType pool_type,
150 const HostPortPair& http_proxy);
151 SSLClientSocketPool* GetSocketPoolForSSLWithProxy(
152 SocketPoolType pool_type,
153 const HostPortPair& proxy_server);
155 CertVerifier* cert_verifier() { return cert_verifier_; }
156 ProxyService* proxy_service() { return proxy_service_; }
157 SSLConfigService* ssl_config_service() { return ssl_config_service_.get(); }
158 SpdySessionPool* spdy_session_pool() { return &spdy_session_pool_; }
159 QuicStreamFactory* quic_stream_factory() { return &quic_stream_factory_; }
160 HttpAuthHandlerFactory* http_auth_handler_factory() {
161 return http_auth_handler_factory_;
163 NetworkDelegate* network_delegate() {
164 return network_delegate_;
166 base::WeakPtr<HttpServerProperties> http_server_properties() {
167 return http_server_properties_;
169 HttpStreamFactory* http_stream_factory() {
170 return http_stream_factory_.get();
172 HttpStreamFactory* http_stream_factory_for_websocket() {
173 return http_stream_factory_for_websocket_.get();
175 NetLog* net_log() {
176 return net_log_;
178 HpackHuffmanAggregator* huffman_aggregator() {
179 return huffman_aggregator_.get();
182 // Creates a Value summary of the state of the socket pools. The caller is
183 // responsible for deleting the returned value.
184 base::Value* SocketPoolInfoToValue() const;
186 // Creates a Value summary of the state of the SPDY sessions. The caller is
187 // responsible for deleting the returned value.
188 base::Value* SpdySessionPoolInfoToValue() const;
190 // Creates a Value summary of the state of the QUIC sessions and
191 // configuration. The caller is responsible for deleting the returned value.
192 base::Value* QuicInfoToValue() const;
194 void CloseAllConnections();
195 void CloseIdleConnections();
197 // Returns the original Params used to construct this session.
198 const Params& params() const { return params_; }
200 bool IsProtocolEnabled(AlternateProtocol protocol) const;
202 void GetNextProtos(std::vector<std::string>* next_protos) const;
204 // Convenience function for searching through |params_| for
205 // |forced_spdy_exclusions|.
206 bool HasSpdyExclusion(HostPortPair host_port_pair) const;
208 private:
209 friend class base::RefCounted<HttpNetworkSession>;
210 friend class HttpNetworkSessionPeer;
212 ~HttpNetworkSession();
214 ClientSocketPoolManager* GetSocketPoolManager(SocketPoolType pool_type);
216 NetLog* const net_log_;
217 NetworkDelegate* const network_delegate_;
218 const base::WeakPtr<HttpServerProperties> http_server_properties_;
219 CertVerifier* const cert_verifier_;
220 HttpAuthHandlerFactory* const http_auth_handler_factory_;
222 // Not const since it's modified by HttpNetworkSessionPeer for testing.
223 ProxyService* proxy_service_;
224 const scoped_refptr<SSLConfigService> ssl_config_service_;
226 HttpAuthCache http_auth_cache_;
227 SSLClientAuthCache ssl_client_auth_cache_;
228 scoped_ptr<ClientSocketPoolManager> normal_socket_pool_manager_;
229 scoped_ptr<ClientSocketPoolManager> websocket_socket_pool_manager_;
230 QuicStreamFactory quic_stream_factory_;
231 SpdySessionPool spdy_session_pool_;
232 scoped_ptr<HttpStreamFactory> http_stream_factory_;
233 scoped_ptr<HttpStreamFactory> http_stream_factory_for_websocket_;
234 std::set<HttpResponseBodyDrainer*> response_drainers_;
236 // TODO(jgraettinger): Remove when Huffman collection is complete.
237 scoped_ptr<HpackHuffmanAggregator> huffman_aggregator_;
239 std::vector<std::string> next_protos_;
240 bool enabled_protocols_[NUM_VALID_ALTERNATE_PROTOCOLS];
242 Params params_;
245 } // namespace net
247 #endif // NET_HTTP_HTTP_NETWORK_SESSION_H_