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