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.
5 #ifndef NET_HTTP_HTTP_NETWORK_SESSION_H_
6 #define NET_HTTP_HTTP_NETWORK_SESSION_H_
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"
31 class ClientSocketFactory;
32 class ClientSocketPoolManager;
34 class HttpAuthHandlerFactory;
35 class HttpNetworkSessionPeer;
36 class HttpProxyClientSocketPool;
37 class HttpResponseBodyDrainer;
38 class HttpServerProperties;
40 class NetworkDelegate;
41 class ServerBoundCertService;
44 class QuicCryptoClientStreamFactory;
45 class SOCKSClientSocketPool;
46 class SSLClientSocketPool;
47 class SSLConfigService;
48 class TransportClientSocketPool;
49 class TransportSecurityState;
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) {
56 struct NET_EXPORT Params {
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;
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_compression;
81 bool enable_spdy_ping_based_connection_checking;
82 NextProto spdy_default_protocol;
83 size_t spdy_stream_initial_recv_window_size;
84 size_t spdy_initial_max_concurrent_streams;
85 size_t spdy_max_concurrent_streams_limit;
86 SpdySessionPool::TimeFunc time_func;
87 std::string trusted_spdy_proxy;
89 bool enable_quic_https;
90 HostPortPair origin_to_force_quic_on;
91 QuicClock* quic_clock; // Will be owned by QuicStreamFactory.
92 QuicRandom* quic_random;
93 bool enable_user_alternate_protocol_ports;
94 QuicCryptoClientStreamFactory* quic_crypto_client_stream_factory;
99 WEBSOCKET_SOCKET_POOL,
100 NUM_SOCKET_POOL_TYPES
103 explicit HttpNetworkSession(const Params& params);
105 HttpAuthCache* http_auth_cache() { return &http_auth_cache_; }
106 SSLClientAuthCache* ssl_client_auth_cache() {
107 return &ssl_client_auth_cache_;
110 void AddResponseDrainer(HttpResponseBodyDrainer* drainer);
112 void RemoveResponseDrainer(HttpResponseBodyDrainer* drainer);
114 TransportClientSocketPool* GetTransportSocketPool(SocketPoolType pool_type);
115 SSLClientSocketPool* GetSSLSocketPool(SocketPoolType pool_type);
116 SOCKSClientSocketPool* GetSocketPoolForSOCKSProxy(
117 SocketPoolType pool_type,
118 const HostPortPair& socks_proxy);
119 HttpProxyClientSocketPool* GetSocketPoolForHTTPProxy(
120 SocketPoolType pool_type,
121 const HostPortPair& http_proxy);
122 SSLClientSocketPool* GetSocketPoolForSSLWithProxy(
123 SocketPoolType pool_type,
124 const HostPortPair& proxy_server);
126 CertVerifier* cert_verifier() { return cert_verifier_; }
127 ProxyService* proxy_service() { return proxy_service_; }
128 SSLConfigService* ssl_config_service() { return ssl_config_service_.get(); }
129 SpdySessionPool* spdy_session_pool() { return &spdy_session_pool_; }
130 QuicStreamFactory* quic_stream_factory() { return &quic_stream_factory_; }
131 HttpAuthHandlerFactory* http_auth_handler_factory() {
132 return http_auth_handler_factory_;
134 NetworkDelegate* network_delegate() {
135 return network_delegate_;
137 base::WeakPtr<HttpServerProperties> http_server_properties() {
138 return http_server_properties_;
140 HttpStreamFactory* http_stream_factory() {
141 return http_stream_factory_.get();
143 HttpStreamFactory* websocket_handshake_stream_factory() {
144 return websocket_handshake_stream_factory_.get();
150 // Creates a Value summary of the state of the socket pools. The caller is
151 // responsible for deleting the returned value.
152 base::Value* SocketPoolInfoToValue() const;
154 // Creates a Value summary of the state of the SPDY sessions. The caller is
155 // responsible for deleting the returned value.
156 base::Value* SpdySessionPoolInfoToValue() const;
158 // Creates a Value summary of the state of the QUIC sessions and
159 // configuration. The caller is responsible for deleting the returned value.
160 base::Value* QuicInfoToValue() const;
162 void CloseAllConnections();
163 void CloseIdleConnections();
165 bool force_http_pipelining() const { return force_http_pipelining_; }
167 // Returns the original Params used to construct this session.
168 const Params& params() const { return params_; }
170 void set_http_pipelining_enabled(bool enable) {
171 params_.http_pipelining_enabled = enable;
175 friend class base::RefCounted<HttpNetworkSession>;
176 friend class HttpNetworkSessionPeer;
178 ~HttpNetworkSession();
180 ClientSocketPoolManager* GetSocketPoolManager(SocketPoolType pool_type);
182 NetLog* const net_log_;
183 NetworkDelegate* const network_delegate_;
184 const base::WeakPtr<HttpServerProperties> http_server_properties_;
185 CertVerifier* const cert_verifier_;
186 HttpAuthHandlerFactory* const http_auth_handler_factory_;
187 bool force_http_pipelining_;
189 // Not const since it's modified by HttpNetworkSessionPeer for testing.
190 ProxyService* proxy_service_;
191 const scoped_refptr<SSLConfigService> ssl_config_service_;
193 HttpAuthCache http_auth_cache_;
194 SSLClientAuthCache ssl_client_auth_cache_;
195 scoped_ptr<ClientSocketPoolManager> normal_socket_pool_manager_;
196 scoped_ptr<ClientSocketPoolManager> websocket_socket_pool_manager_;
197 QuicStreamFactory quic_stream_factory_;
198 SpdySessionPool spdy_session_pool_;
199 scoped_ptr<HttpStreamFactory> http_stream_factory_;
200 scoped_ptr<HttpStreamFactory> websocket_handshake_stream_factory_;
201 std::set<HttpResponseBodyDrainer*> response_drainers_;
208 #endif // NET_HTTP_HTTP_NETWORK_SESSION_H_