[email protected] | cf4cae3 | 2014-05-27 00:39:10 | [diff] [blame] | 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. |
| 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 | |
| 26 | namespace base { |
| 27 | class Value; |
| 28 | } |
| 29 | |
| 30 | namespace net { |
| 31 | |
eranm | 6571b2b | 2014-12-03 15:53:23 | [diff] [blame] | 32 | class CertPolicyEnforcer; |
[email protected] | cf4cae3 | 2014-05-27 00:39:10 | [diff] [blame] | 33 | class CertVerifier; |
[email protected] | 6b8a3c74 | 2014-07-25 00:25:35 | [diff] [blame] | 34 | class ChannelIDService; |
[email protected] | cf4cae3 | 2014-05-27 00:39:10 | [diff] [blame] | 35 | class ClientSocketFactory; |
| 36 | class ClientSocketPoolManager; |
| 37 | class CTVerifier; |
| 38 | class HostResolver; |
[email protected] | cf4cae3 | 2014-05-27 00:39:10 | [diff] [blame] | 39 | class HttpAuthHandlerFactory; |
| 40 | class HttpNetworkSessionPeer; |
| 41 | class HttpProxyClientSocketPool; |
| 42 | class HttpResponseBodyDrainer; |
| 43 | class HttpServerProperties; |
| 44 | class NetLog; |
| 45 | class NetworkDelegate; |
bengr | 39e40610 | 2014-09-10 23:04:46 | [diff] [blame] | 46 | class ProxyDelegate; |
[email protected] | cf4cae3 | 2014-05-27 00:39:10 | [diff] [blame] | 47 | class ProxyService; |
| 48 | class QuicClock; |
| 49 | class QuicCryptoClientStreamFactory; |
| 50 | class QuicServerInfoFactory; |
tbansal | ba8f411 | 2015-09-03 21:57:19 | [diff] [blame] | 51 | class SocketPerformanceWatcherFactory; |
[email protected] | cf4cae3 | 2014-05-27 00:39:10 | [diff] [blame] | 52 | class SOCKSClientSocketPool; |
| 53 | class SSLClientSocketPool; |
| 54 | class SSLConfigService; |
| 55 | class TransportClientSocketPool; |
| 56 | class TransportSecurityState; |
| 57 | |
| 58 | // This class holds session objects used by HttpNetworkTransaction objects. |
| 59 | class NET_EXPORT HttpNetworkSession |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 60 | : NON_EXPORTED_BASE(public base::NonThreadSafe) { |
[email protected] | cf4cae3 | 2014-05-27 00:39:10 | [diff] [blame] | 61 | public: |
| 62 | struct NET_EXPORT Params { |
| 63 | Params(); |
| 64 | ~Params(); |
| 65 | |
| 66 | ClientSocketFactory* client_socket_factory; |
| 67 | HostResolver* host_resolver; |
| 68 | CertVerifier* cert_verifier; |
eranm | 6571b2b | 2014-12-03 15:53:23 | [diff] [blame] | 69 | CertPolicyEnforcer* cert_policy_enforcer; |
[email protected] | 6b8a3c74 | 2014-07-25 00:25:35 | [diff] [blame] | 70 | ChannelIDService* channel_id_service; |
[email protected] | cf4cae3 | 2014-05-27 00:39:10 | [diff] [blame] | 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; |
tbansal | ba8f411 | 2015-09-03 21:57:19 | [diff] [blame] | 81 | SocketPerformanceWatcherFactory* socket_performance_watcher_factory; |
[email protected] | cf4cae3 | 2014-05-27 00:39:10 | [diff] [blame] | 82 | bool ignore_certificate_errors; |
| 83 | uint16 testing_fixed_http_port; |
| 84 | uint16 testing_fixed_https_port; |
jri | f9b4bec | 2014-09-15 15:46:54 | [diff] [blame] | 85 | bool enable_tcp_fast_open_for_ssl; |
[email protected] | cf4cae3 | 2014-05-27 00:39:10 | [diff] [blame] | 86 | |
rch | d502a30 | 2015-10-16 03:57:21 | [diff] [blame^] | 87 | // Compress SPDY headers. |
[email protected] | cf4cae3 | 2014-05-27 00:39:10 | [diff] [blame] | 88 | bool enable_spdy_compression; |
rch | d502a30 | 2015-10-16 03:57:21 | [diff] [blame^] | 89 | // Use SPDY ping frames to test for connection health after idle. |
[email protected] | cf4cae3 | 2014-05-27 00:39:10 | [diff] [blame] | 90 | bool enable_spdy_ping_based_connection_checking; |
| 91 | NextProto spdy_default_protocol; |
| 92 | // The protocols supported by NPN (next protocol negotiation) during the |
| 93 | // SSL handshake as well as by HTTP Alternate-Protocol. |
| 94 | // TODO(mmenke): This is currently empty by default, and alternate |
| 95 | // protocols are disabled. We should use some reasonable |
| 96 | // defaults. |
| 97 | NextProtoVector next_protos; |
bnc | 8f0f3b6 | 2015-04-08 04:37:23 | [diff] [blame] | 98 | size_t spdy_session_max_recv_window_size; |
| 99 | size_t spdy_stream_max_recv_window_size; |
[email protected] | cf4cae3 | 2014-05-27 00:39:10 | [diff] [blame] | 100 | size_t spdy_initial_max_concurrent_streams; |
rch | d502a30 | 2015-10-16 03:57:21 | [diff] [blame^] | 101 | // Source of time for SPDY connections. |
[email protected] | cf4cae3 | 2014-05-27 00:39:10 | [diff] [blame] | 102 | SpdySessionPool::TimeFunc time_func; |
rch | d502a30 | 2015-10-16 03:57:21 | [diff] [blame^] | 103 | // This SPDY proxy is allowed to push resources from origins that are |
| 104 | // different from those of their associated streams. |
[email protected] | cf4cae3 | 2014-05-27 00:39:10 | [diff] [blame] | 105 | std::string trusted_spdy_proxy; |
[email protected] | cf4cae3 | 2014-05-27 00:39:10 | [diff] [blame] | 106 | // URLs to exclude from forced SPDY. |
| 107 | std::set<HostPortPair> forced_spdy_exclusions; |
rch | d502a30 | 2015-10-16 03:57:21 | [diff] [blame^] | 108 | // Process Alt-Svc headers. |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 109 | bool use_alternative_services; |
rch | d502a30 | 2015-10-16 03:57:21 | [diff] [blame^] | 110 | // Only honor alternative service entries which have a higher probability |
| 111 | // than this value. |
bnc | 62891a5 | 2015-04-27 14:14:12 | [diff] [blame] | 112 | double alternative_service_probability_threshold; |
[email protected] | cf4cae3 | 2014-05-27 00:39:10 | [diff] [blame] | 113 | |
rch | d502a30 | 2015-10-16 03:57:21 | [diff] [blame^] | 114 | // Enables QUIC support. |
[email protected] | cf4cae3 | 2014-05-27 00:39:10 | [diff] [blame] | 115 | bool enable_quic; |
rch | d502a30 | 2015-10-16 03:57:21 | [diff] [blame^] | 116 | // Enables insecure QUIC (http:// URLs) support, if enable_quic is true. |
rch | ff01212 | 2015-07-27 20:01:40 | [diff] [blame] | 117 | bool enable_insecure_quic; |
rch | d502a30 | 2015-10-16 03:57:21 | [diff] [blame^] | 118 | // Enables QUIC for proxies. |
tbansal | ed0aecc | 2015-02-20 03:44:18 | [diff] [blame] | 119 | bool enable_quic_for_proxies; |
rch | d502a30 | 2015-10-16 03:57:21 | [diff] [blame^] | 120 | // Instruct QUIC to use consistent ephemeral ports when talking to |
| 121 | // the same server. |
[email protected] | cf4cae3 | 2014-05-27 00:39:10 | [diff] [blame] | 122 | bool enable_quic_port_selection; |
rch | d502a30 | 2015-10-16 03:57:21 | [diff] [blame^] | 123 | // Disables QUIC's 0-RTT behavior. |
jri | 2b966f2 | 2014-09-02 22:25:36 | [diff] [blame] | 124 | bool quic_always_require_handshake_confirmation; |
rch | d502a30 | 2015-10-16 03:57:21 | [diff] [blame^] | 125 | // Disables QUIC connection pooling. |
jri | 584002d1 | 2014-09-09 00:51:28 | [diff] [blame] | 126 | bool quic_disable_connection_pooling; |
rch | d502a30 | 2015-10-16 03:57:21 | [diff] [blame^] | 127 | // If not zero, the task to load QUIC server configs from the disk cache |
| 128 | // will timeout after this value multiplied by the smoothed RTT for the |
| 129 | // server. |
rtenneti | 2912825c | 2015-01-06 01:19:46 | [diff] [blame] | 130 | float quic_load_server_info_timeout_srtt_multiplier; |
rch | d502a30 | 2015-10-16 03:57:21 | [diff] [blame^] | 131 | // Causes QUIC to race reading the server config from disk with |
| 132 | // sending an inchoate CHLO. |
rtenneti | 4f80997 | 2015-02-11 19:38:34 | [diff] [blame] | 133 | bool quic_enable_connection_racing; |
rch | d502a30 | 2015-10-16 03:57:21 | [diff] [blame^] | 134 | // Use non-blocking IO for UDP sockets. |
qyearsley | 3257b7de | 2015-02-28 06:59:03 | [diff] [blame] | 135 | bool quic_enable_non_blocking_io; |
rch | d502a30 | 2015-10-16 03:57:21 | [diff] [blame^] | 136 | // Disables using the disk cache to store QUIC server configs. |
rtenneti | 34dffe75 | 2015-02-24 23:27:32 | [diff] [blame] | 137 | bool quic_disable_disk_cache; |
rch | d502a30 | 2015-10-16 03:57:21 | [diff] [blame^] | 138 | // Prefer AES-GCM to ChaCha20 even if no hardware support is present. |
rch | 9976b0c | 2015-06-10 21:27:23 | [diff] [blame] | 139 | bool quic_prefer_aes; |
rch | d502a30 | 2015-10-16 03:57:21 | [diff] [blame^] | 140 | // Specifies the maximum number of connections with high packet loss in |
| 141 | // a row after which QUIC will be disabled. |
rtenneti | 85dcfac2 | 2015-03-27 20:22:19 | [diff] [blame] | 142 | int quic_max_number_of_lossy_connections; |
rch | d502a30 | 2015-10-16 03:57:21 | [diff] [blame^] | 143 | // Specifies packet loss rate in fraction after which a connection is |
| 144 | // closed and is considered as a lossy connection. |
rtenneti | 85dcfac2 | 2015-03-27 20:22:19 | [diff] [blame] | 145 | float quic_packet_loss_threshold; |
rch | d502a30 | 2015-10-16 03:57:21 | [diff] [blame^] | 146 | // Size in bytes of the QUIC DUP socket receive buffer. |
rch | c743357 | 2015-02-27 18:16:51 | [diff] [blame] | 147 | int quic_socket_receive_buffer_size; |
rch | d502a30 | 2015-10-16 03:57:21 | [diff] [blame^] | 148 | // Delay starting a TCP connection when QUIC believes it can speak |
| 149 | // 0-RTT to a server. |
rtenneti | 8332ba5 | 2015-09-17 19:33:41 | [diff] [blame] | 150 | bool quic_delay_tcp_race; |
rch | d502a30 | 2015-10-16 03:57:21 | [diff] [blame^] | 151 | // Store server configs in HttpServerProperties, instead of the disk cache. |
rtenneti | cd2aaa15b | 2015-10-10 20:29:33 | [diff] [blame] | 152 | bool quic_store_server_configs_in_properties; |
rch | d502a30 | 2015-10-16 03:57:21 | [diff] [blame^] | 153 | // If not empty, QUIC will be used for all connections to this origin. |
[email protected] | cf4cae3 | 2014-05-27 00:39:10 | [diff] [blame] | 154 | HostPortPair origin_to_force_quic_on; |
rch | d502a30 | 2015-10-16 03:57:21 | [diff] [blame^] | 155 | // Source of time for QUIC connections. Will be owned by QuicStreamFactory. |
| 156 | QuicClock* quic_clock; |
| 157 | // Source of entropy for QUIC connections. |
[email protected] | cf4cae3 | 2014-05-27 00:39:10 | [diff] [blame] | 158 | QuicRandom* quic_random; |
rch | d502a30 | 2015-10-16 03:57:21 | [diff] [blame^] | 159 | // Limit on the size of QUIC packets. |
[email protected] | cf4cae3 | 2014-05-27 00:39:10 | [diff] [blame] | 160 | size_t quic_max_packet_length; |
rch | d502a30 | 2015-10-16 03:57:21 | [diff] [blame^] | 161 | // User agent description to send in the QUIC handshake. |
[email protected] | 0c4017ca | 2014-06-06 03:30:45 | [diff] [blame] | 162 | std::string quic_user_agent_id; |
[email protected] | cf4cae3 | 2014-05-27 00:39:10 | [diff] [blame] | 163 | bool enable_user_alternate_protocol_ports; |
rch | d502a30 | 2015-10-16 03:57:21 | [diff] [blame^] | 164 | // Optional factory to use for creating QuicCryptoClientStreams. |
[email protected] | cf4cae3 | 2014-05-27 00:39:10 | [diff] [blame] | 165 | QuicCryptoClientStreamFactory* quic_crypto_client_stream_factory; |
rch | d502a30 | 2015-10-16 03:57:21 | [diff] [blame^] | 166 | // Versions of QUIC which may be used. |
[email protected] | cf4cae3 | 2014-05-27 00:39:10 | [diff] [blame] | 167 | QuicVersionVector quic_supported_versions; |
ckrasic | 1e53b64 | 2015-07-08 22:39:35 | [diff] [blame] | 168 | int quic_max_recent_disabled_reasons; |
| 169 | int quic_threshold_public_resets_post_handshake; |
| 170 | int quic_threshold_timeouts_streams_open; |
rch | d502a30 | 2015-10-16 03:57:21 | [diff] [blame^] | 171 | // Set of QUIC tags to send in the handshakes connection options. |
[email protected] | 488a0e25 | 2014-06-25 04:37:44 | [diff] [blame] | 172 | QuicTagVector quic_connection_options; |
bengr | 39e40610 | 2014-09-10 23:04:46 | [diff] [blame] | 173 | ProxyDelegate* proxy_delegate; |
[email protected] | cf4cae3 | 2014-05-27 00:39:10 | [diff] [blame] | 174 | }; |
| 175 | |
| 176 | enum SocketPoolType { |
| 177 | NORMAL_SOCKET_POOL, |
| 178 | WEBSOCKET_SOCKET_POOL, |
| 179 | NUM_SOCKET_POOL_TYPES |
| 180 | }; |
| 181 | |
| 182 | explicit HttpNetworkSession(const Params& params); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 183 | ~HttpNetworkSession(); |
[email protected] | cf4cae3 | 2014-05-27 00:39:10 | [diff] [blame] | 184 | |
| 185 | HttpAuthCache* http_auth_cache() { return &http_auth_cache_; } |
| 186 | SSLClientAuthCache* ssl_client_auth_cache() { |
| 187 | return &ssl_client_auth_cache_; |
| 188 | } |
| 189 | |
| 190 | void AddResponseDrainer(HttpResponseBodyDrainer* drainer); |
| 191 | |
| 192 | void RemoveResponseDrainer(HttpResponseBodyDrainer* drainer); |
| 193 | |
| 194 | TransportClientSocketPool* GetTransportSocketPool(SocketPoolType pool_type); |
| 195 | SSLClientSocketPool* GetSSLSocketPool(SocketPoolType pool_type); |
| 196 | SOCKSClientSocketPool* GetSocketPoolForSOCKSProxy( |
| 197 | SocketPoolType pool_type, |
| 198 | const HostPortPair& socks_proxy); |
| 199 | HttpProxyClientSocketPool* GetSocketPoolForHTTPProxy( |
| 200 | SocketPoolType pool_type, |
| 201 | const HostPortPair& http_proxy); |
| 202 | SSLClientSocketPool* GetSocketPoolForSSLWithProxy( |
| 203 | SocketPoolType pool_type, |
| 204 | const HostPortPair& proxy_server); |
| 205 | |
| 206 | CertVerifier* cert_verifier() { return cert_verifier_; } |
| 207 | ProxyService* proxy_service() { return proxy_service_; } |
| 208 | SSLConfigService* ssl_config_service() { return ssl_config_service_.get(); } |
| 209 | SpdySessionPool* spdy_session_pool() { return &spdy_session_pool_; } |
| 210 | QuicStreamFactory* quic_stream_factory() { return &quic_stream_factory_; } |
| 211 | HttpAuthHandlerFactory* http_auth_handler_factory() { |
| 212 | return http_auth_handler_factory_; |
| 213 | } |
| 214 | NetworkDelegate* network_delegate() { |
| 215 | return network_delegate_; |
| 216 | } |
| 217 | base::WeakPtr<HttpServerProperties> http_server_properties() { |
| 218 | return http_server_properties_; |
| 219 | } |
| 220 | HttpStreamFactory* http_stream_factory() { |
| 221 | return http_stream_factory_.get(); |
| 222 | } |
| 223 | HttpStreamFactory* http_stream_factory_for_websocket() { |
| 224 | return http_stream_factory_for_websocket_.get(); |
| 225 | } |
| 226 | NetLog* net_log() { |
| 227 | return net_log_; |
| 228 | } |
[email protected] | cf4cae3 | 2014-05-27 00:39:10 | [diff] [blame] | 229 | |
payal.pandey | 62a40029 | 2015-05-28 09:29:54 | [diff] [blame] | 230 | // Creates a Value summary of the state of the socket pools. |
| 231 | scoped_ptr<base::Value> SocketPoolInfoToValue() const; |
[email protected] | cf4cae3 | 2014-05-27 00:39:10 | [diff] [blame] | 232 | |
payal.pandey | 91cb231 | 2015-05-27 07:41:51 | [diff] [blame] | 233 | // Creates a Value summary of the state of the SPDY sessions. |
| 234 | scoped_ptr<base::Value> SpdySessionPoolInfoToValue() const; |
[email protected] | cf4cae3 | 2014-05-27 00:39:10 | [diff] [blame] | 235 | |
| 236 | // Creates a Value summary of the state of the QUIC sessions and |
payal.pandey | a18956a | 2015-05-27 05:57:55 | [diff] [blame] | 237 | // configuration. |
| 238 | scoped_ptr<base::Value> QuicInfoToValue() const; |
[email protected] | cf4cae3 | 2014-05-27 00:39:10 | [diff] [blame] | 239 | |
| 240 | void CloseAllConnections(); |
| 241 | void CloseIdleConnections(); |
| 242 | |
| 243 | // Returns the original Params used to construct this session. |
| 244 | const Params& params() const { return params_; } |
| 245 | |
| 246 | bool IsProtocolEnabled(AlternateProtocol protocol) const; |
| 247 | |
bnc | 0d23cf4 | 2014-12-11 14:09:46 | [diff] [blame] | 248 | // Populates |*next_protos| with protocols. |
| 249 | void GetNextProtos(NextProtoVector* next_protos) const; |
[email protected] | cf4cae3 | 2014-05-27 00:39:10 | [diff] [blame] | 250 | |
| 251 | // Convenience function for searching through |params_| for |
| 252 | // |forced_spdy_exclusions|. |
| 253 | bool HasSpdyExclusion(HostPortPair host_port_pair) const; |
| 254 | |
| 255 | private: |
[email protected] | cf4cae3 | 2014-05-27 00:39:10 | [diff] [blame] | 256 | friend class HttpNetworkSessionPeer; |
| 257 | |
[email protected] | cf4cae3 | 2014-05-27 00:39:10 | [diff] [blame] | 258 | ClientSocketPoolManager* GetSocketPoolManager(SocketPoolType pool_type); |
| 259 | |
| 260 | NetLog* const net_log_; |
| 261 | NetworkDelegate* const network_delegate_; |
| 262 | const base::WeakPtr<HttpServerProperties> http_server_properties_; |
| 263 | CertVerifier* const cert_verifier_; |
| 264 | HttpAuthHandlerFactory* const http_auth_handler_factory_; |
| 265 | |
| 266 | // Not const since it's modified by HttpNetworkSessionPeer for testing. |
| 267 | ProxyService* proxy_service_; |
| 268 | const scoped_refptr<SSLConfigService> ssl_config_service_; |
| 269 | |
| 270 | HttpAuthCache http_auth_cache_; |
| 271 | SSLClientAuthCache ssl_client_auth_cache_; |
| 272 | scoped_ptr<ClientSocketPoolManager> normal_socket_pool_manager_; |
| 273 | scoped_ptr<ClientSocketPoolManager> websocket_socket_pool_manager_; |
| 274 | QuicStreamFactory quic_stream_factory_; |
| 275 | SpdySessionPool spdy_session_pool_; |
| 276 | scoped_ptr<HttpStreamFactory> http_stream_factory_; |
| 277 | scoped_ptr<HttpStreamFactory> http_stream_factory_for_websocket_; |
| 278 | std::set<HttpResponseBodyDrainer*> response_drainers_; |
| 279 | |
bnc | 0d23cf4 | 2014-12-11 14:09:46 | [diff] [blame] | 280 | NextProtoVector next_protos_; |
[email protected] | cf4cae3 | 2014-05-27 00:39:10 | [diff] [blame] | 281 | bool enabled_protocols_[NUM_VALID_ALTERNATE_PROTOCOLS]; |
| 282 | |
| 283 | Params params_; |
| 284 | }; |
| 285 | |
| 286 | } // namespace net |
| 287 | |
| 288 | #endif // NET_HTTP_HTTP_NETWORK_SESSION_H_ |