Remove redundant Tab constructors.
[chromium-blink-merge.git] / net / url_request / url_request_context.h
blobb9f1276d6b77bd5220ef5d08b83903fda3bdb8d9
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 // This class represents contextual information (cookies, cache, etc.)
6 // that's useful when processing resource requests.
7 // The class is reference-counted so that it can be cleaned up after any
8 // requests that are using it have been completed.
10 #ifndef NET_URL_REQUEST_URL_REQUEST_CONTEXT_H_
11 #define NET_URL_REQUEST_URL_REQUEST_CONTEXT_H_
13 #include <set>
14 #include <string>
16 #include "base/memory/ref_counted.h"
17 #include "base/memory/scoped_ptr.h"
18 #include "base/memory/weak_ptr.h"
19 #include "base/threading/non_thread_safe.h"
20 #include "net/base/net_export.h"
21 #include "net/base/request_priority.h"
22 #include "net/http/http_network_session.h"
23 #include "net/http/http_server_properties.h"
24 #include "net/http/transport_security_state.h"
25 #include "net/log/net_log.h"
26 #include "net/ssl/ssl_config_service.h"
27 #include "net/url_request/url_request.h"
29 namespace net {
30 class CertVerifier;
31 class ChannelIDService;
32 class CookieStore;
33 class CTVerifier;
34 class HostResolver;
35 class HttpAuthHandlerFactory;
36 class HttpTransactionFactory;
37 class HttpUserAgentSettings;
38 class NetworkDelegate;
39 class NetworkQualityEstimator;
40 class SdchManager;
41 class ProxyService;
42 class URLRequest;
43 class URLRequestBackoffManager;
44 class URLRequestJobFactory;
45 class URLRequestThrottlerManager;
47 // Subclass to provide application-specific context for URLRequest
48 // instances. Note that URLRequestContext typically does not provide storage for
49 // these member variables, since they may be shared. For the ones that aren't
50 // shared, URLRequestContextStorage can be helpful in defining their storage.
51 class NET_EXPORT URLRequestContext
52 : NON_EXPORTED_BASE(public base::NonThreadSafe) {
53 public:
54 URLRequestContext();
55 virtual ~URLRequestContext();
57 // Copies the state from |other| into this context.
58 void CopyFrom(const URLRequestContext* other);
60 // May return nullptr if this context doesn't have an associated network
61 // session.
62 const HttpNetworkSession::Params* GetNetworkSessionParams() const;
64 scoped_ptr<URLRequest> CreateRequest(const GURL& url,
65 RequestPriority priority,
66 URLRequest::Delegate* delegate) const;
68 NetLog* net_log() const {
69 return net_log_;
72 void set_net_log(NetLog* net_log) {
73 net_log_ = net_log;
76 HostResolver* host_resolver() const {
77 return host_resolver_;
80 void set_host_resolver(HostResolver* host_resolver) {
81 host_resolver_ = host_resolver;
84 CertVerifier* cert_verifier() const {
85 return cert_verifier_;
88 void set_cert_verifier(CertVerifier* cert_verifier) {
89 cert_verifier_ = cert_verifier;
92 ChannelIDService* channel_id_service() const {
93 return channel_id_service_;
96 void set_channel_id_service(
97 ChannelIDService* channel_id_service) {
98 channel_id_service_ = channel_id_service;
101 // Get the proxy service for this context.
102 ProxyService* proxy_service() const { return proxy_service_; }
103 void set_proxy_service(ProxyService* proxy_service) {
104 proxy_service_ = proxy_service;
107 // Get the ssl config service for this context.
108 SSLConfigService* ssl_config_service() const {
109 return ssl_config_service_.get();
111 void set_ssl_config_service(SSLConfigService* service) {
112 ssl_config_service_ = service;
115 // Gets the HTTP Authentication Handler Factory for this context.
116 // The factory is only valid for the lifetime of this URLRequestContext
117 HttpAuthHandlerFactory* http_auth_handler_factory() const {
118 return http_auth_handler_factory_;
120 void set_http_auth_handler_factory(HttpAuthHandlerFactory* factory) {
121 http_auth_handler_factory_ = factory;
124 // Gets the http transaction factory for this context.
125 HttpTransactionFactory* http_transaction_factory() const {
126 return http_transaction_factory_;
128 void set_http_transaction_factory(HttpTransactionFactory* factory) {
129 http_transaction_factory_ = factory;
132 void set_network_delegate(NetworkDelegate* network_delegate) {
133 network_delegate_ = network_delegate;
135 NetworkDelegate* network_delegate() const { return network_delegate_; }
137 void set_http_server_properties(
138 const base::WeakPtr<HttpServerProperties>& http_server_properties) {
139 http_server_properties_ = http_server_properties;
141 base::WeakPtr<HttpServerProperties> http_server_properties() const {
142 return http_server_properties_;
145 // Gets the cookie store for this context (may be null, in which case
146 // cookies are not stored).
147 CookieStore* cookie_store() const { return cookie_store_.get(); }
148 void set_cookie_store(CookieStore* cookie_store);
150 TransportSecurityState* transport_security_state() const {
151 return transport_security_state_;
153 void set_transport_security_state(
154 TransportSecurityState* state) {
155 transport_security_state_ = state;
158 CTVerifier* cert_transparency_verifier() const {
159 return cert_transparency_verifier_;
161 void set_cert_transparency_verifier(CTVerifier* verifier) {
162 cert_transparency_verifier_ = verifier;
165 const URLRequestJobFactory* job_factory() const { return job_factory_; }
166 void set_job_factory(const URLRequestJobFactory* job_factory) {
167 job_factory_ = job_factory;
170 // May return nullptr.
171 URLRequestThrottlerManager* throttler_manager() const {
172 return throttler_manager_;
174 void set_throttler_manager(URLRequestThrottlerManager* throttler_manager) {
175 throttler_manager_ = throttler_manager;
178 // May return nullptr.
179 URLRequestBackoffManager* backoff_manager() const { return backoff_manager_; }
180 void set_backoff_manager(URLRequestBackoffManager* backoff_manager) {
181 backoff_manager_ = backoff_manager;
184 // May return nullptr.
185 SdchManager* sdch_manager() const { return sdch_manager_; }
186 void set_sdch_manager(SdchManager* sdch_manager) {
187 sdch_manager_ = sdch_manager;
190 // Gets the URLRequest objects that hold a reference to this
191 // URLRequestContext.
192 std::set<const URLRequest*>* url_requests() const {
193 return url_requests_.get();
196 // CHECKs that no URLRequests using this context remain. Subclasses should
197 // additionally call AssertNoURLRequests() within their own destructor,
198 // prior to implicit destruction of subclass-owned state.
199 void AssertNoURLRequests() const;
201 // Get the underlying |HttpUserAgentSettings| implementation that provides
202 // the HTTP Accept-Language and User-Agent header values.
203 const HttpUserAgentSettings* http_user_agent_settings() const {
204 return http_user_agent_settings_;
206 void set_http_user_agent_settings(
207 HttpUserAgentSettings* http_user_agent_settings) {
208 http_user_agent_settings_ = http_user_agent_settings;
211 // Gets the NetworkQualityEstimator associated with this context.
212 // May return nullptr.
213 NetworkQualityEstimator* network_quality_estimator() const {
214 return network_quality_estimator_;
216 void set_network_quality_estimator(
217 NetworkQualityEstimator* network_quality_estimator) {
218 network_quality_estimator_ = network_quality_estimator;
221 private:
222 // ---------------------------------------------------------------------------
223 // Important: When adding any new members below, consider whether they need to
224 // be added to CopyFrom.
225 // ---------------------------------------------------------------------------
227 // Ownership for these members are not defined here. Clients should either
228 // provide storage elsewhere or have a subclass take ownership.
229 NetLog* net_log_;
230 HostResolver* host_resolver_;
231 CertVerifier* cert_verifier_;
232 ChannelIDService* channel_id_service_;
233 HttpAuthHandlerFactory* http_auth_handler_factory_;
234 ProxyService* proxy_service_;
235 scoped_refptr<SSLConfigService> ssl_config_service_;
236 NetworkDelegate* network_delegate_;
237 base::WeakPtr<HttpServerProperties> http_server_properties_;
238 HttpUserAgentSettings* http_user_agent_settings_;
239 scoped_refptr<CookieStore> cookie_store_;
240 TransportSecurityState* transport_security_state_;
241 CTVerifier* cert_transparency_verifier_;
242 HttpTransactionFactory* http_transaction_factory_;
243 const URLRequestJobFactory* job_factory_;
244 URLRequestThrottlerManager* throttler_manager_;
245 URLRequestBackoffManager* backoff_manager_;
246 SdchManager* sdch_manager_;
247 NetworkQualityEstimator* network_quality_estimator_;
249 // ---------------------------------------------------------------------------
250 // Important: When adding any new members below, consider whether they need to
251 // be added to CopyFrom.
252 // ---------------------------------------------------------------------------
254 scoped_ptr<std::set<const URLRequest*> > url_requests_;
256 DISALLOW_COPY_AND_ASSIGN(URLRequestContext);
259 } // namespace net
261 #endif // NET_URL_REQUEST_URL_REQUEST_CONTEXT_H_