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 11 #include "base/basictypes.h" 12 #include "base/memory/ref_counted.h" 13 #include "base/memory/weak_ptr.h" 14 #include "base/threading/non_thread_safe.h" 15 #include "net/base/host_port_pair.h" 16 #include "net/base/net_export.h" 17 #include "net/dns/host_resolver.h" 18 #include "net/http/http_auth_cache.h" 19 #include "net/http/http_stream_factory.h" 20 #include "net/quic/quic_stream_factory.h" 21 #include "net/spdy/spdy_session_pool.h" 22 #include "net/ssl/ssl_client_auth_cache.h" 23 24 namespace base { 25 class Value; 26 } 27 28 namespace net { 29 30 class CertVerifier; 31 class ClientSocketFactory; 32 class ClientSocketPoolManager; 33 class HostResolver; 34 class HttpAuthHandlerFactory; 35 class HttpNetworkSessionPeer; 36 class HttpProxyClientSocketPool; 37 class HttpResponseBodyDrainer; 38 class HttpServerProperties; 39 class NetLog; 40 class NetworkDelegate; 41 class ServerBoundCertService; 42 class ProxyService; 43 class QuicClock; 44 class QuicCryptoClientStreamFactory; 45 class SOCKSClientSocketPool; 46 class SSLClientSocketPool; 47 class SSLConfigService; 48 class TransportClientSocketPool; 49 class TransportSecurityState; 50 51 // This class holds session objects used by HttpNetworkTransaction objects. 52 class NET_EXPORT HttpNetworkSession 53 : public base::RefCounted<HttpNetworkSession>, 54 NON_EXPORTED_BASE(public base::NonThreadSafe) { 55 public: 56 struct NET_EXPORT Params { 57 Params(); 58 ~Params(); 59 60 ClientSocketFactory* client_socket_factory; 61 HostResolver* host_resolver; 62 CertVerifier* cert_verifier; 63 ServerBoundCertService* server_bound_cert_service; 64 TransportSecurityState* transport_security_state; 65 ProxyService* proxy_service; 66 std::string ssl_session_cache_shard; 67 SSLConfigService* ssl_config_service; 68 HttpAuthHandlerFactory* http_auth_handler_factory; 69 NetworkDelegate* network_delegate; 70 base::WeakPtr<HttpServerProperties> http_server_properties; 71 NetLog* net_log; 72 HostMappingRules* host_mapping_rules; 73 bool force_http_pipelining; 74 bool ignore_certificate_errors; 75 bool http_pipelining_enabled; 76 uint16 testing_fixed_http_port; 77 uint16 testing_fixed_https_port; 78 bool force_spdy_single_domain; 79 bool enable_spdy_ip_pooling; 80 bool enable_spdy_credential_frames; 81 bool enable_spdy_compression; 82 bool enable_spdy_ping_based_connection_checking; 83 NextProto spdy_default_protocol; 84 size_t spdy_stream_initial_recv_window_size; 85 size_t spdy_initial_max_concurrent_streams; 86 size_t spdy_max_concurrent_streams_limit; 87 SpdySessionPool::TimeFunc time_func; 88 std::string trusted_spdy_proxy; 89 bool enable_quic; 90 bool enable_quic_https; 91 HostPortPair origin_to_force_quic_on; 92 QuicClock* quic_clock; // Will be owned by QuicStreamFactory. 93 QuicRandom* quic_random; 94 bool enable_user_alternate_protocol_ports; 95 QuicCryptoClientStreamFactory* quic_crypto_client_stream_factory; 96 }; 97 98 enum SocketPoolType { 99 NORMAL_SOCKET_POOL, 100 WEBSOCKET_SOCKET_POOL, 101 NUM_SOCKET_POOL_TYPES 102 }; 103 104 explicit HttpNetworkSession(const Params& params); 105 106 HttpAuthCache* http_auth_cache() { return &http_auth_cache_; } 107 SSLClientAuthCache* ssl_client_auth_cache() { 108 return &ssl_client_auth_cache_; 109 } 110 111 void AddResponseDrainer(HttpResponseBodyDrainer* drainer); 112 113 void RemoveResponseDrainer(HttpResponseBodyDrainer* drainer); 114 115 TransportClientSocketPool* GetTransportSocketPool(SocketPoolType pool_type); 116 SSLClientSocketPool* GetSSLSocketPool(SocketPoolType pool_type); 117 SOCKSClientSocketPool* GetSocketPoolForSOCKSProxy( 118 SocketPoolType pool_type, 119 const HostPortPair& socks_proxy); 120 HttpProxyClientSocketPool* GetSocketPoolForHTTPProxy( 121 SocketPoolType pool_type, 122 const HostPortPair& http_proxy); 123 SSLClientSocketPool* GetSocketPoolForSSLWithProxy( 124 SocketPoolType pool_type, 125 const HostPortPair& proxy_server); 126 127 CertVerifier* cert_verifier() { return cert_verifier_; } 128 ProxyService* proxy_service() { return proxy_service_; } 129 SSLConfigService* ssl_config_service() { return ssl_config_service_.get(); } 130 SpdySessionPool* spdy_session_pool() { return &spdy_session_pool_; } 131 QuicStreamFactory* quic_stream_factory() { return &quic_stream_factory_; } 132 HttpAuthHandlerFactory* http_auth_handler_factory() { 133 return http_auth_handler_factory_; 134 } 135 NetworkDelegate* network_delegate() { 136 return network_delegate_; 137 } 138 base::WeakPtr<HttpServerProperties> http_server_properties() { 139 return http_server_properties_; 140 } 141 HttpStreamFactory* http_stream_factory() { 142 return http_stream_factory_.get(); 143 } 144 HttpStreamFactory* websocket_stream_factory() { 145 return websocket_stream_factory_.get(); 146 } 147 NetLog* net_log() { 148 return net_log_; 149 } 150 151 // Creates a Value summary of the state of the socket pools. The caller is 152 // responsible for deleting the returned value. 153 base::Value* SocketPoolInfoToValue() const; 154 155 // Creates a Value summary of the state of the SPDY sessions. The caller is 156 // responsible for deleting the returned value. 157 base::Value* SpdySessionPoolInfoToValue() const; 158 159 // Creates a Value summary of the state of the QUIC sessions and 160 // configuration. The caller is responsible for deleting the returned value. 161 base::Value* QuicInfoToValue() const; 162 163 void CloseAllConnections(); 164 void CloseIdleConnections(); 165 166 bool force_http_pipelining() const { return force_http_pipelining_; } 167 168 // Returns the original Params used to construct this session. 169 const Params& params() const { return params_; } 170 171 void set_http_pipelining_enabled(bool enable) { 172 params_.http_pipelining_enabled = enable; 173 } 174 175 private: 176 friend class base::RefCounted<HttpNetworkSession>; 177 friend class HttpNetworkSessionPeer; 178 179 ~HttpNetworkSession(); 180 181 ClientSocketPoolManager* GetSocketPoolManager(SocketPoolType pool_type); 182 183 NetLog* const net_log_; 184 NetworkDelegate* const network_delegate_; 185 const base::WeakPtr<HttpServerProperties> http_server_properties_; 186 CertVerifier* const cert_verifier_; 187 HttpAuthHandlerFactory* const http_auth_handler_factory_; 188 bool force_http_pipelining_; 189 190 // Not const since it's modified by HttpNetworkSessionPeer for testing. 191 ProxyService* proxy_service_; 192 const scoped_refptr<SSLConfigService> ssl_config_service_; 193 194 HttpAuthCache http_auth_cache_; 195 SSLClientAuthCache ssl_client_auth_cache_; 196 scoped_ptr<ClientSocketPoolManager> normal_socket_pool_manager_; 197 scoped_ptr<ClientSocketPoolManager> websocket_socket_pool_manager_; 198 QuicStreamFactory quic_stream_factory_; 199 SpdySessionPool spdy_session_pool_; 200 scoped_ptr<HttpStreamFactory> http_stream_factory_; 201 scoped_ptr<HttpStreamFactory> websocket_stream_factory_; 202 std::set<HttpResponseBodyDrainer*> response_drainers_; 203 204 Params params_; 205 }; 206 207 } // namespace net 208 209 #endif // NET_HTTP_HTTP_NETWORK_SESSION_H_ 210