ChildAccountService: get service flags from AccountTrackerService instead of fetching...
[chromium-blink-merge.git] / net / url_request / url_request_context.h
blob54bded29140cc909b8622ff6fa88124c0c876cba
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 FraudulentCertificateReporter;
35 class HostResolver;
36 class HttpAuthHandlerFactory;
37 class HttpTransactionFactory;
38 class HttpUserAgentSettings;
39 class NetworkDelegate;
40 class NetworkQualityEstimator;
41 class SdchManager;
42 class ProxyService;
43 class URLRequest;
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 FraudulentCertificateReporter* fraudulent_certificate_reporter() const {
102 return fraudulent_certificate_reporter_;
104 void set_fraudulent_certificate_reporter(
105 FraudulentCertificateReporter* fraudulent_certificate_reporter) {
106 fraudulent_certificate_reporter_ = fraudulent_certificate_reporter;
109 // Get the proxy service for this context.
110 ProxyService* proxy_service() const { return proxy_service_; }
111 void set_proxy_service(ProxyService* proxy_service) {
112 proxy_service_ = proxy_service;
115 // Get the ssl config service for this context.
116 SSLConfigService* ssl_config_service() const {
117 return ssl_config_service_.get();
119 void set_ssl_config_service(SSLConfigService* service) {
120 ssl_config_service_ = service;
123 // Gets the HTTP Authentication Handler Factory for this context.
124 // The factory is only valid for the lifetime of this URLRequestContext
125 HttpAuthHandlerFactory* http_auth_handler_factory() const {
126 return http_auth_handler_factory_;
128 void set_http_auth_handler_factory(HttpAuthHandlerFactory* factory) {
129 http_auth_handler_factory_ = factory;
132 // Gets the http transaction factory for this context.
133 HttpTransactionFactory* http_transaction_factory() const {
134 return http_transaction_factory_;
136 void set_http_transaction_factory(HttpTransactionFactory* factory) {
137 http_transaction_factory_ = factory;
140 void set_network_delegate(NetworkDelegate* network_delegate) {
141 network_delegate_ = network_delegate;
143 NetworkDelegate* network_delegate() const { return network_delegate_; }
145 void set_http_server_properties(
146 const base::WeakPtr<HttpServerProperties>& http_server_properties) {
147 http_server_properties_ = http_server_properties;
149 base::WeakPtr<HttpServerProperties> http_server_properties() const {
150 return http_server_properties_;
153 // Gets the cookie store for this context (may be null, in which case
154 // cookies are not stored).
155 CookieStore* cookie_store() const { return cookie_store_.get(); }
156 void set_cookie_store(CookieStore* cookie_store);
158 TransportSecurityState* transport_security_state() const {
159 return transport_security_state_;
161 void set_transport_security_state(
162 TransportSecurityState* state) {
163 transport_security_state_ = state;
166 CTVerifier* cert_transparency_verifier() const {
167 return cert_transparency_verifier_;
169 void set_cert_transparency_verifier(CTVerifier* verifier) {
170 cert_transparency_verifier_ = verifier;
173 const URLRequestJobFactory* job_factory() const { return job_factory_; }
174 void set_job_factory(const URLRequestJobFactory* job_factory) {
175 job_factory_ = job_factory;
178 // May return nullptr.
179 URLRequestThrottlerManager* throttler_manager() const {
180 return throttler_manager_;
182 void set_throttler_manager(URLRequestThrottlerManager* throttler_manager) {
183 throttler_manager_ = throttler_manager;
186 // May return nullptr.
187 SdchManager* sdch_manager() const { return sdch_manager_; }
188 void set_sdch_manager(SdchManager* sdch_manager) {
189 sdch_manager_ = sdch_manager;
192 // Gets the URLRequest objects that hold a reference to this
193 // URLRequestContext.
194 std::set<const URLRequest*>* url_requests() const {
195 return url_requests_.get();
198 // CHECKs that no URLRequests using this context remain. Subclasses should
199 // additionally call AssertNoURLRequests() within their own destructor,
200 // prior to implicit destruction of subclass-owned state.
201 void AssertNoURLRequests() const;
203 // Get the underlying |HttpUserAgentSettings| implementation that provides
204 // the HTTP Accept-Language and User-Agent header values.
205 const HttpUserAgentSettings* http_user_agent_settings() const {
206 return http_user_agent_settings_;
208 void set_http_user_agent_settings(
209 HttpUserAgentSettings* http_user_agent_settings) {
210 http_user_agent_settings_ = http_user_agent_settings;
213 // Gets the NetworkQualityEstimator associated with this context.
214 // May return nullptr.
215 NetworkQualityEstimator* network_quality_estimator() const {
216 return network_quality_estimator_;
218 void set_network_quality_estimator(
219 NetworkQualityEstimator* network_quality_estimator) {
220 network_quality_estimator_ = network_quality_estimator;
223 private:
224 // ---------------------------------------------------------------------------
225 // Important: When adding any new members below, consider whether they need to
226 // be added to CopyFrom.
227 // ---------------------------------------------------------------------------
229 // Ownership for these members are not defined here. Clients should either
230 // provide storage elsewhere or have a subclass take ownership.
231 NetLog* net_log_;
232 HostResolver* host_resolver_;
233 CertVerifier* cert_verifier_;
234 ChannelIDService* channel_id_service_;
235 FraudulentCertificateReporter* fraudulent_certificate_reporter_;
236 HttpAuthHandlerFactory* http_auth_handler_factory_;
237 ProxyService* proxy_service_;
238 scoped_refptr<SSLConfigService> ssl_config_service_;
239 NetworkDelegate* network_delegate_;
240 base::WeakPtr<HttpServerProperties> http_server_properties_;
241 HttpUserAgentSettings* http_user_agent_settings_;
242 scoped_refptr<CookieStore> cookie_store_;
243 TransportSecurityState* transport_security_state_;
244 CTVerifier* cert_transparency_verifier_;
245 HttpTransactionFactory* http_transaction_factory_;
246 const URLRequestJobFactory* job_factory_;
247 URLRequestThrottlerManager* throttler_manager_;
248 SdchManager* sdch_manager_;
249 NetworkQualityEstimator* network_quality_estimator_;
251 // ---------------------------------------------------------------------------
252 // Important: When adding any new members below, consider whether they need to
253 // be added to CopyFrom.
254 // ---------------------------------------------------------------------------
256 scoped_ptr<std::set<const URLRequest*> > url_requests_;
258 DISALLOW_COPY_AND_ASSIGN(URLRequestContext);
261 } // namespace net
263 #endif // NET_URL_REQUEST_URL_REQUEST_CONTEXT_H_