Revert "Fix broken channel icon in chrome://help on CrOS" and try again
[chromium-blink-merge.git] / net / http / http_network_session.h
blob50c319d37c4e3c3948afa56ecd12ab02428b7e44
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 HttpAuthHandlerFactory;
40 class HttpNetworkSessionPeer;
41 class HttpProxyClientSocketPool;
42 class HttpResponseBodyDrainer;
43 class HttpServerProperties;
44 class NetLog;
45 class NetworkDelegate;
46 class ProxyDelegate;
47 class ProxyService;
48 class QuicClock;
49 class QuicCryptoClientStreamFactory;
50 class QuicServerInfoFactory;
51 class SOCKSClientSocketPool;
52 class SSLClientSocketPool;
53 class SSLConfigService;
54 class TransportClientSocketPool;
55 class TransportSecurityState;
57 // This class holds session objects used by HttpNetworkTransaction objects.
58 class NET_EXPORT HttpNetworkSession
59 : public base::RefCounted<HttpNetworkSession>,
60 NON_EXPORTED_BASE(public base::NonThreadSafe) {
61 public:
62 struct NET_EXPORT Params {
63 Params();
64 ~Params();
66 ClientSocketFactory* client_socket_factory;
67 HostResolver* host_resolver;
68 CertVerifier* cert_verifier;
69 CertPolicyEnforcer* cert_policy_enforcer;
70 ChannelIDService* channel_id_service;
71 TransportSecurityState* transport_security_state;
72 CTVerifier* cert_transparency_verifier;
73 ProxyService* proxy_service;
74 std::string ssl_session_cache_shard;
75 SSLConfigService* ssl_config_service;
76 HttpAuthHandlerFactory* http_auth_handler_factory;
77 NetworkDelegate* network_delegate;
78 base::WeakPtr<HttpServerProperties> http_server_properties;
79 NetLog* net_log;
80 HostMappingRules* host_mapping_rules;
81 bool ignore_certificate_errors;
82 uint16 testing_fixed_http_port;
83 uint16 testing_fixed_https_port;
84 bool enable_tcp_fast_open_for_ssl;
86 bool enable_spdy_compression;
87 bool enable_spdy_ping_based_connection_checking;
88 NextProto spdy_default_protocol;
89 // The protocols supported by NPN (next protocol negotiation) during the
90 // SSL handshake as well as by HTTP Alternate-Protocol.
91 // TODO(mmenke): This is currently empty by default, and alternate
92 // protocols are disabled. We should use some reasonable
93 // defaults.
94 NextProtoVector next_protos;
95 size_t spdy_session_max_recv_window_size;
96 size_t spdy_stream_max_recv_window_size;
97 size_t spdy_initial_max_concurrent_streams;
98 SpdySessionPool::TimeFunc time_func;
99 std::string trusted_spdy_proxy;
100 // URLs to exclude from forced SPDY.
101 std::set<HostPortPair> forced_spdy_exclusions;
102 bool use_alternative_services;
103 double alternative_service_probability_threshold;
105 bool enable_quic;
106 bool enable_insecure_quic;
107 bool enable_quic_for_proxies;
108 bool enable_quic_port_selection;
109 bool quic_always_require_handshake_confirmation;
110 bool quic_disable_connection_pooling;
111 float quic_load_server_info_timeout_srtt_multiplier;
112 bool quic_enable_connection_racing;
113 bool quic_enable_non_blocking_io;
114 bool quic_disable_disk_cache;
115 bool quic_prefer_aes;
116 int quic_max_number_of_lossy_connections;
117 float quic_packet_loss_threshold;
118 int quic_socket_receive_buffer_size;
119 HostPortPair origin_to_force_quic_on;
120 QuicClock* quic_clock; // Will be owned by QuicStreamFactory.
121 QuicRandom* quic_random;
122 size_t quic_max_packet_length;
123 std::string quic_user_agent_id;
124 bool enable_user_alternate_protocol_ports;
125 QuicCryptoClientStreamFactory* quic_crypto_client_stream_factory;
126 QuicVersionVector quic_supported_versions;
127 int quic_max_recent_disabled_reasons;
128 int quic_threshold_public_resets_post_handshake;
129 int quic_threshold_timeouts_streams_open;
130 QuicTagVector quic_connection_options;
131 ProxyDelegate* proxy_delegate;
134 enum SocketPoolType {
135 NORMAL_SOCKET_POOL,
136 WEBSOCKET_SOCKET_POOL,
137 NUM_SOCKET_POOL_TYPES
140 explicit HttpNetworkSession(const Params& params);
142 HttpAuthCache* http_auth_cache() { return &http_auth_cache_; }
143 SSLClientAuthCache* ssl_client_auth_cache() {
144 return &ssl_client_auth_cache_;
147 void AddResponseDrainer(HttpResponseBodyDrainer* drainer);
149 void RemoveResponseDrainer(HttpResponseBodyDrainer* drainer);
151 TransportClientSocketPool* GetTransportSocketPool(SocketPoolType pool_type);
152 SSLClientSocketPool* GetSSLSocketPool(SocketPoolType pool_type);
153 SOCKSClientSocketPool* GetSocketPoolForSOCKSProxy(
154 SocketPoolType pool_type,
155 const HostPortPair& socks_proxy);
156 HttpProxyClientSocketPool* GetSocketPoolForHTTPProxy(
157 SocketPoolType pool_type,
158 const HostPortPair& http_proxy);
159 SSLClientSocketPool* GetSocketPoolForSSLWithProxy(
160 SocketPoolType pool_type,
161 const HostPortPair& proxy_server);
163 CertVerifier* cert_verifier() { return cert_verifier_; }
164 ProxyService* proxy_service() { return proxy_service_; }
165 SSLConfigService* ssl_config_service() { return ssl_config_service_.get(); }
166 SpdySessionPool* spdy_session_pool() { return &spdy_session_pool_; }
167 QuicStreamFactory* quic_stream_factory() { return &quic_stream_factory_; }
168 HttpAuthHandlerFactory* http_auth_handler_factory() {
169 return http_auth_handler_factory_;
171 NetworkDelegate* network_delegate() {
172 return network_delegate_;
174 base::WeakPtr<HttpServerProperties> http_server_properties() {
175 return http_server_properties_;
177 HttpStreamFactory* http_stream_factory() {
178 return http_stream_factory_.get();
180 HttpStreamFactory* http_stream_factory_for_websocket() {
181 return http_stream_factory_for_websocket_.get();
183 NetLog* net_log() {
184 return net_log_;
187 // Creates a Value summary of the state of the socket pools.
188 scoped_ptr<base::Value> SocketPoolInfoToValue() const;
190 // Creates a Value summary of the state of the SPDY sessions.
191 scoped_ptr<base::Value> SpdySessionPoolInfoToValue() const;
193 // Creates a Value summary of the state of the QUIC sessions and
194 // configuration.
195 scoped_ptr<base::Value> QuicInfoToValue() const;
197 void CloseAllConnections();
198 void CloseIdleConnections();
200 // Returns the original Params used to construct this session.
201 const Params& params() const { return params_; }
203 bool IsProtocolEnabled(AlternateProtocol protocol) const;
205 // Populates |*next_protos| with protocols.
206 void GetNextProtos(NextProtoVector* next_protos) const;
208 // Convenience function for searching through |params_| for
209 // |forced_spdy_exclusions|.
210 bool HasSpdyExclusion(HostPortPair host_port_pair) const;
212 private:
213 friend class base::RefCounted<HttpNetworkSession>;
214 friend class HttpNetworkSessionPeer;
216 ~HttpNetworkSession();
218 ClientSocketPoolManager* GetSocketPoolManager(SocketPoolType pool_type);
220 NetLog* const net_log_;
221 NetworkDelegate* const network_delegate_;
222 const base::WeakPtr<HttpServerProperties> http_server_properties_;
223 CertVerifier* const cert_verifier_;
224 HttpAuthHandlerFactory* const http_auth_handler_factory_;
226 // Not const since it's modified by HttpNetworkSessionPeer for testing.
227 ProxyService* proxy_service_;
228 const scoped_refptr<SSLConfigService> ssl_config_service_;
230 HttpAuthCache http_auth_cache_;
231 SSLClientAuthCache ssl_client_auth_cache_;
232 scoped_ptr<ClientSocketPoolManager> normal_socket_pool_manager_;
233 scoped_ptr<ClientSocketPoolManager> websocket_socket_pool_manager_;
234 QuicStreamFactory quic_stream_factory_;
235 SpdySessionPool spdy_session_pool_;
236 scoped_ptr<HttpStreamFactory> http_stream_factory_;
237 scoped_ptr<HttpStreamFactory> http_stream_factory_for_websocket_;
238 std::set<HttpResponseBodyDrainer*> response_drainers_;
240 NextProtoVector next_protos_;
241 bool enabled_protocols_[NUM_VALID_ALTERNATE_PROTOCOLS];
243 Params params_;
246 } // namespace net
248 #endif // NET_HTTP_HTTP_NETWORK_SESSION_H_