1 // Copyright (c) 2011 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 #pragma once 8 9 #include <set> 10 #include "base/memory/ref_counted.h" 11 #include "base/threading/non_thread_safe.h" 12 #include "net/base/host_port_pair.h" 13 #include "net/base/host_resolver.h" 14 #include "net/base/ssl_client_auth_cache.h" 15 #include "net/http/http_alternate_protocols.h" 16 #include "net/http/http_auth_cache.h" 17 #include "net/http/http_stream_factory.h" 18 #include "net/socket/client_socket_pool_manager.h" 19 #include "net/spdy/spdy_session_pool.h" 20 #include "net/spdy/spdy_settings_storage.h" 21 22 class Value; 23 24 namespace net { 25 26 class CertVerifier; 27 class ClientSocketFactory; 28 class DnsCertProvenanceChecker; 29 class DnsRRResolver; 30 class HostResolver; 31 class HttpAuthHandlerFactory; 32 class HttpNetworkSessionPeer; 33 class HttpProxyClientSocketPool; 34 class HttpResponseBodyDrainer; 35 class NetLog; 36 class NetworkDelegate; 37 class ProxyService; 38 class SSLConfigService; 39 class SSLHostInfoFactory; 40 41 // This class holds session objects used by HttpNetworkTransaction objects. 42 class HttpNetworkSession : public base::RefCounted<HttpNetworkSession>, 43 public base::NonThreadSafe { 44 public: 45 struct Params { ParamsParams46 Params() 47 : client_socket_factory(NULL), 48 host_resolver(NULL), 49 cert_verifier(NULL), 50 dnsrr_resolver(NULL), 51 dns_cert_checker(NULL), 52 proxy_service(NULL), 53 ssl_host_info_factory(NULL), 54 ssl_config_service(NULL), 55 http_auth_handler_factory(NULL), 56 network_delegate(NULL), 57 net_log(NULL) {} 58 59 ClientSocketFactory* client_socket_factory; 60 HostResolver* host_resolver; 61 CertVerifier* cert_verifier; 62 DnsRRResolver* dnsrr_resolver; 63 DnsCertProvenanceChecker* dns_cert_checker; 64 ProxyService* proxy_service; 65 SSLHostInfoFactory* ssl_host_info_factory; 66 SSLConfigService* ssl_config_service; 67 HttpAuthHandlerFactory* http_auth_handler_factory; 68 NetworkDelegate* network_delegate; 69 NetLog* net_log; 70 }; 71 72 explicit HttpNetworkSession(const Params& params); 73 http_auth_cache()74 HttpAuthCache* http_auth_cache() { return &http_auth_cache_; } ssl_client_auth_cache()75 SSLClientAuthCache* ssl_client_auth_cache() { 76 return &ssl_client_auth_cache_; 77 } 78 79 void AddResponseDrainer(HttpResponseBodyDrainer* drainer); 80 81 void RemoveResponseDrainer(HttpResponseBodyDrainer* drainer); 82 alternate_protocols()83 const HttpAlternateProtocols& alternate_protocols() const { 84 return alternate_protocols_; 85 } mutable_alternate_protocols()86 HttpAlternateProtocols* mutable_alternate_protocols() { 87 return &alternate_protocols_; 88 } 89 transport_socket_pool()90 TransportClientSocketPool* transport_socket_pool() { 91 return socket_pool_manager_.transport_socket_pool(); 92 } 93 ssl_socket_pool()94 SSLClientSocketPool* ssl_socket_pool() { 95 return socket_pool_manager_.ssl_socket_pool(); 96 } 97 GetSocketPoolForSOCKSProxy(const HostPortPair & socks_proxy)98 SOCKSClientSocketPool* GetSocketPoolForSOCKSProxy( 99 const HostPortPair& socks_proxy) { 100 return socket_pool_manager_.GetSocketPoolForSOCKSProxy(socks_proxy); 101 } 102 GetSocketPoolForHTTPProxy(const HostPortPair & http_proxy)103 HttpProxyClientSocketPool* GetSocketPoolForHTTPProxy( 104 const HostPortPair& http_proxy) { 105 return socket_pool_manager_.GetSocketPoolForHTTPProxy(http_proxy); 106 } 107 GetSocketPoolForSSLWithProxy(const HostPortPair & proxy_server)108 SSLClientSocketPool* GetSocketPoolForSSLWithProxy( 109 const HostPortPair& proxy_server) { 110 return socket_pool_manager_.GetSocketPoolForSSLWithProxy(proxy_server); 111 } 112 cert_verifier()113 CertVerifier* cert_verifier() { return cert_verifier_; } proxy_service()114 ProxyService* proxy_service() { return proxy_service_; } ssl_config_service()115 SSLConfigService* ssl_config_service() { return ssl_config_service_; } spdy_session_pool()116 SpdySessionPool* spdy_session_pool() { return &spdy_session_pool_; } http_auth_handler_factory()117 HttpAuthHandlerFactory* http_auth_handler_factory() { 118 return http_auth_handler_factory_; 119 } network_delegate()120 NetworkDelegate* network_delegate() { 121 return network_delegate_; 122 } 123 http_stream_factory()124 HttpStreamFactory* http_stream_factory() { 125 return http_stream_factory_.get(); 126 } 127 net_log()128 NetLog* net_log() { 129 return net_log_; 130 } 131 132 // Creates a Value summary of the state of the socket pools. The caller is 133 // responsible for deleting the returned value. SocketPoolInfoToValue()134 Value* SocketPoolInfoToValue() const { 135 return socket_pool_manager_.SocketPoolInfoToValue(); 136 } 137 138 // Creates a Value summary of the state of the SPDY sessions. The caller is 139 // responsible for deleting the returned value. 140 Value* SpdySessionPoolInfoToValue() const; 141 CloseAllConnections()142 void CloseAllConnections() { 143 socket_pool_manager_.FlushSocketPools(); 144 spdy_session_pool_.CloseCurrentSessions(); 145 } 146 CloseIdleConnections()147 void CloseIdleConnections() { 148 socket_pool_manager_.CloseIdleSockets(); 149 spdy_session_pool_.CloseIdleSessions(); 150 } 151 152 153 private: 154 friend class base::RefCounted<HttpNetworkSession>; 155 friend class HttpNetworkSessionPeer; 156 157 ~HttpNetworkSession(); 158 159 NetLog* const net_log_; 160 NetworkDelegate* const network_delegate_; 161 CertVerifier* const cert_verifier_; 162 HttpAuthHandlerFactory* const http_auth_handler_factory_; 163 164 // Not const since it's modified by HttpNetworkSessionPeer for testing. 165 scoped_refptr<ProxyService> proxy_service_; 166 const scoped_refptr<SSLConfigService> ssl_config_service_; 167 168 HttpAuthCache http_auth_cache_; 169 SSLClientAuthCache ssl_client_auth_cache_; 170 HttpAlternateProtocols alternate_protocols_; 171 ClientSocketPoolManager socket_pool_manager_; 172 SpdySessionPool spdy_session_pool_; 173 scoped_ptr<HttpStreamFactory> http_stream_factory_; 174 std::set<HttpResponseBodyDrainer*> response_drainers_; 175 }; 176 177 } // namespace net 178 179 #endif // NET_HTTP_HTTP_NETWORK_SESSION_H_ 180