[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; |
| 51 | class SOCKSClientSocketPool; |
| 52 | class SSLClientSocketPool; |
| 53 | class SSLConfigService; |
| 54 | class TransportClientSocketPool; |
| 55 | class TransportSecurityState; |
| 56 | |
| 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(); |
| 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; |
[email protected] | cf4cae3 | 2014-05-27 00:39:10 | [diff] [blame] | 81 | bool ignore_certificate_errors; |
ricea | 64c07d79 | 2014-10-08 03:37:00 | [diff] [blame] | 82 | bool use_stale_while_revalidate; |
[email protected] | cf4cae3 | 2014-05-27 00:39:10 | [diff] [blame] | 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 | |
[email protected] | cf4cae3 | 2014-05-27 00:39:10 | [diff] [blame] | 87 | bool enable_spdy_compression; |
| 88 | bool enable_spdy_ping_based_connection_checking; |
| 89 | NextProto spdy_default_protocol; |
| 90 | // The protocols supported by NPN (next protocol negotiation) during the |
| 91 | // SSL handshake as well as by HTTP Alternate-Protocol. |
| 92 | // TODO(mmenke): This is currently empty by default, and alternate |
| 93 | // protocols are disabled. We should use some reasonable |
| 94 | // defaults. |
| 95 | NextProtoVector next_protos; |
bnc | 8f0f3b6 | 2015-04-08 04:37:23 | [diff] [blame] | 96 | size_t spdy_session_max_recv_window_size; |
| 97 | size_t spdy_stream_max_recv_window_size; |
[email protected] | cf4cae3 | 2014-05-27 00:39:10 | [diff] [blame] | 98 | size_t spdy_initial_max_concurrent_streams; |
[email protected] | cf4cae3 | 2014-05-27 00:39:10 | [diff] [blame] | 99 | SpdySessionPool::TimeFunc time_func; |
| 100 | std::string trusted_spdy_proxy; |
[email protected] | cf4cae3 | 2014-05-27 00:39:10 | [diff] [blame] | 101 | // URLs to exclude from forced SPDY. |
| 102 | std::set<HostPortPair> forced_spdy_exclusions; |
| 103 | // Noe: Using this in the case of NPN for HTTP only results in the browser |
| 104 | // trying SSL and then falling back to http. |
| 105 | bool use_alternate_protocols; |
bnc | 62891a5 | 2015-04-27 14:14:12 | [diff] [blame] | 106 | double alternative_service_probability_threshold; |
[email protected] | cf4cae3 | 2014-05-27 00:39:10 | [diff] [blame] | 107 | |
| 108 | bool enable_quic; |
rch | 405ed7a | 2015-05-12 01:10:16 | [diff] [blame] | 109 | bool disable_insecure_quic; |
tbansal | ed0aecc | 2015-02-20 03:44:18 | [diff] [blame] | 110 | bool enable_quic_for_proxies; |
[email protected] | cf4cae3 | 2014-05-27 00:39:10 | [diff] [blame] | 111 | bool enable_quic_port_selection; |
jri | 2b966f2 | 2014-09-02 22:25:36 | [diff] [blame] | 112 | bool quic_always_require_handshake_confirmation; |
jri | 584002d1 | 2014-09-09 00:51:28 | [diff] [blame] | 113 | bool quic_disable_connection_pooling; |
rtenneti | 2912825c | 2015-01-06 01:19:46 | [diff] [blame] | 114 | float quic_load_server_info_timeout_srtt_multiplier; |
rtenneti | 4f80997 | 2015-02-11 19:38:34 | [diff] [blame] | 115 | bool quic_enable_connection_racing; |
qyearsley | 3257b7de | 2015-02-28 06:59:03 | [diff] [blame] | 116 | bool quic_enable_non_blocking_io; |
rtenneti | 34dffe75 | 2015-02-24 23:27:32 | [diff] [blame] | 117 | bool quic_disable_disk_cache; |
rtenneti | 85dcfac2 | 2015-03-27 20:22:19 | [diff] [blame] | 118 | int quic_max_number_of_lossy_connections; |
| 119 | float quic_packet_loss_threshold; |
rch | c743357 | 2015-02-27 18:16:51 | [diff] [blame] | 120 | int quic_socket_receive_buffer_size; |
[email protected] | cf4cae3 | 2014-05-27 00:39:10 | [diff] [blame] | 121 | HostPortPair origin_to_force_quic_on; |
| 122 | QuicClock* quic_clock; // Will be owned by QuicStreamFactory. |
| 123 | QuicRandom* quic_random; |
| 124 | size_t quic_max_packet_length; |
[email protected] | 0c4017ca | 2014-06-06 03:30:45 | [diff] [blame] | 125 | std::string quic_user_agent_id; |
[email protected] | cf4cae3 | 2014-05-27 00:39:10 | [diff] [blame] | 126 | bool enable_user_alternate_protocol_ports; |
| 127 | QuicCryptoClientStreamFactory* quic_crypto_client_stream_factory; |
| 128 | QuicVersionVector quic_supported_versions; |
[email protected] | 488a0e25 | 2014-06-25 04:37:44 | [diff] [blame] | 129 | QuicTagVector quic_connection_options; |
bengr | 39e40610 | 2014-09-10 23:04:46 | [diff] [blame] | 130 | ProxyDelegate* proxy_delegate; |
[email protected] | cf4cae3 | 2014-05-27 00:39:10 | [diff] [blame] | 131 | }; |
| 132 | |
| 133 | enum SocketPoolType { |
| 134 | NORMAL_SOCKET_POOL, |
| 135 | WEBSOCKET_SOCKET_POOL, |
| 136 | NUM_SOCKET_POOL_TYPES |
| 137 | }; |
| 138 | |
| 139 | explicit HttpNetworkSession(const Params& params); |
| 140 | |
| 141 | HttpAuthCache* http_auth_cache() { return &http_auth_cache_; } |
| 142 | SSLClientAuthCache* ssl_client_auth_cache() { |
| 143 | return &ssl_client_auth_cache_; |
| 144 | } |
| 145 | |
| 146 | void AddResponseDrainer(HttpResponseBodyDrainer* drainer); |
| 147 | |
| 148 | void RemoveResponseDrainer(HttpResponseBodyDrainer* drainer); |
| 149 | |
| 150 | TransportClientSocketPool* GetTransportSocketPool(SocketPoolType pool_type); |
| 151 | SSLClientSocketPool* GetSSLSocketPool(SocketPoolType pool_type); |
| 152 | SOCKSClientSocketPool* GetSocketPoolForSOCKSProxy( |
| 153 | SocketPoolType pool_type, |
| 154 | const HostPortPair& socks_proxy); |
| 155 | HttpProxyClientSocketPool* GetSocketPoolForHTTPProxy( |
| 156 | SocketPoolType pool_type, |
| 157 | const HostPortPair& http_proxy); |
| 158 | SSLClientSocketPool* GetSocketPoolForSSLWithProxy( |
| 159 | SocketPoolType pool_type, |
| 160 | const HostPortPair& proxy_server); |
| 161 | |
| 162 | CertVerifier* cert_verifier() { return cert_verifier_; } |
| 163 | ProxyService* proxy_service() { return proxy_service_; } |
| 164 | SSLConfigService* ssl_config_service() { return ssl_config_service_.get(); } |
| 165 | SpdySessionPool* spdy_session_pool() { return &spdy_session_pool_; } |
| 166 | QuicStreamFactory* quic_stream_factory() { return &quic_stream_factory_; } |
| 167 | HttpAuthHandlerFactory* http_auth_handler_factory() { |
| 168 | return http_auth_handler_factory_; |
| 169 | } |
| 170 | NetworkDelegate* network_delegate() { |
| 171 | return network_delegate_; |
| 172 | } |
| 173 | base::WeakPtr<HttpServerProperties> http_server_properties() { |
| 174 | return http_server_properties_; |
| 175 | } |
| 176 | HttpStreamFactory* http_stream_factory() { |
| 177 | return http_stream_factory_.get(); |
| 178 | } |
| 179 | HttpStreamFactory* http_stream_factory_for_websocket() { |
| 180 | return http_stream_factory_for_websocket_.get(); |
| 181 | } |
| 182 | NetLog* net_log() { |
| 183 | return net_log_; |
| 184 | } |
[email protected] | cf4cae3 | 2014-05-27 00:39:10 | [diff] [blame] | 185 | |
| 186 | // Creates a Value summary of the state of the socket pools. The caller is |
| 187 | // responsible for deleting the returned value. |
| 188 | base::Value* SocketPoolInfoToValue() const; |
| 189 | |
payal.pandey | 91cb231 | 2015-05-27 07:41:51 | [diff] [blame^] | 190 | // Creates a Value summary of the state of the SPDY sessions. |
| 191 | scoped_ptr<base::Value> SpdySessionPoolInfoToValue() const; |
[email protected] | cf4cae3 | 2014-05-27 00:39:10 | [diff] [blame] | 192 | |
| 193 | // Creates a Value summary of the state of the QUIC sessions and |
payal.pandey | a18956a | 2015-05-27 05:57:55 | [diff] [blame] | 194 | // configuration. |
| 195 | scoped_ptr<base::Value> QuicInfoToValue() const; |
[email protected] | cf4cae3 | 2014-05-27 00:39:10 | [diff] [blame] | 196 | |
| 197 | void CloseAllConnections(); |
| 198 | void CloseIdleConnections(); |
| 199 | |
| 200 | // Returns the original Params used to construct this session. |
| 201 | const Params& params() const { return params_; } |
| 202 | |
| 203 | bool IsProtocolEnabled(AlternateProtocol protocol) const; |
| 204 | |
bnc | 0d23cf4 | 2014-12-11 14:09:46 | [diff] [blame] | 205 | // Populates |*next_protos| with protocols. |
| 206 | void GetNextProtos(NextProtoVector* next_protos) const; |
[email protected] | cf4cae3 | 2014-05-27 00:39:10 | [diff] [blame] | 207 | |
| 208 | // Convenience function for searching through |params_| for |
| 209 | // |forced_spdy_exclusions|. |
| 210 | bool HasSpdyExclusion(HostPortPair host_port_pair) const; |
| 211 | |
| 212 | private: |
| 213 | friend class base::RefCounted<HttpNetworkSession>; |
| 214 | friend class HttpNetworkSessionPeer; |
| 215 | |
| 216 | ~HttpNetworkSession(); |
| 217 | |
| 218 | ClientSocketPoolManager* GetSocketPoolManager(SocketPoolType pool_type); |
| 219 | |
| 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_; |
| 225 | |
| 226 | // Not const since it's modified by HttpNetworkSessionPeer for testing. |
| 227 | ProxyService* proxy_service_; |
| 228 | const scoped_refptr<SSLConfigService> ssl_config_service_; |
| 229 | |
| 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_; |
| 239 | |
bnc | 0d23cf4 | 2014-12-11 14:09:46 | [diff] [blame] | 240 | NextProtoVector next_protos_; |
[email protected] | cf4cae3 | 2014-05-27 00:39:10 | [diff] [blame] | 241 | bool enabled_protocols_[NUM_VALID_ALTERNATE_PROTOCOLS]; |
| 242 | |
| 243 | Params params_; |
| 244 | }; |
| 245 | |
| 246 | } // namespace net |
| 247 | |
| 248 | #endif // NET_HTTP_HTTP_NETWORK_SESSION_H_ |