Revert 74344 - BackingStoreSkia: Use skia for painting in RenderWidgetHostViewViews.
[chromium-blink-merge.git] / net / url_request / url_request_context.h
blob18315dceab76331fa19d839cea00b51c2191f8c6
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.
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_
12 #pragma once
14 #include "base/ref_counted.h"
15 #include "base/threading/non_thread_safe.h"
16 #include "net/base/net_log.h"
17 #include "net/base/ssl_config_service.h"
18 #include "net/base/transport_security_state.h"
19 #include "net/ftp/ftp_auth_cache.h"
20 #include "net/proxy/proxy_service.h"
21 #include "net/socket/dns_cert_provenance_checker.h"
23 namespace net {
24 class CertVerifier;
25 class CookiePolicy;
26 class CookieStore;
27 class DnsCertProvenanceChecker;
28 class DnsRRResolver;
29 class FtpTransactionFactory;
30 class HostResolver;
31 class HttpAuthHandlerFactory;
32 class HttpNetworkDelegate;
33 class HttpTransactionFactory;
34 class SSLConfigService;
35 class URLRequest;
37 // Subclass to provide application-specific context for URLRequest
38 // instances.
39 class URLRequestContext
40 : public base::RefCountedThreadSafe<URLRequestContext>,
41 public base::NonThreadSafe {
42 public:
43 URLRequestContext();
45 NetLog* net_log() const {
46 return net_log_;
49 void set_net_log(NetLog* net_log) {
50 net_log_ = net_log;
53 HostResolver* host_resolver() const {
54 return host_resolver_;
57 void set_host_resolver(HostResolver* host_resolver) {
58 host_resolver_ = host_resolver;
61 CertVerifier* cert_verifier() const {
62 return cert_verifier_;
65 void set_cert_verifier(CertVerifier* cert_verifier) {
66 cert_verifier_ = cert_verifier;
69 DnsRRResolver* dnsrr_resolver() const {
70 return dnsrr_resolver_;
73 void set_dnsrr_resolver(DnsRRResolver* dnsrr_resolver) {
74 dnsrr_resolver_ = dnsrr_resolver;
77 DnsCertProvenanceChecker* dns_cert_checker() const {
78 return dns_cert_checker_.get();
81 // Get the proxy service for this context.
82 ProxyService* proxy_service() const {
83 return proxy_service_;
86 void set_proxy_service(ProxyService* proxy_service) {
87 proxy_service_ = proxy_service;
90 // Get the ssl config service for this context.
91 SSLConfigService* ssl_config_service() const {
92 return ssl_config_service_;
95 // Gets the HTTP Authentication Handler Factory for this context.
96 // The factory is only valid for the lifetime of this URLRequestContext
97 HttpAuthHandlerFactory* http_auth_handler_factory() {
98 return http_auth_handler_factory_;
100 void set_http_auth_handler_factory(HttpAuthHandlerFactory* factory) {
101 http_auth_handler_factory_ = factory;
104 // Gets the http transaction factory for this context.
105 HttpTransactionFactory* http_transaction_factory() const {
106 return http_transaction_factory_;
109 void set_http_transaction_factory(HttpTransactionFactory* factory) {
110 http_transaction_factory_ = factory;
113 // Gets the ftp transaction factory for this context.
114 FtpTransactionFactory* ftp_transaction_factory() {
115 return ftp_transaction_factory_;
118 void set_network_delegate(HttpNetworkDelegate* network_delegate) {
119 network_delegate_ = network_delegate;
121 HttpNetworkDelegate* network_delegate() { return network_delegate_; }
123 // Gets the cookie store for this context (may be null, in which case
124 // cookies are not stored).
125 CookieStore* cookie_store() { return cookie_store_.get(); }
127 void set_cookie_store(CookieStore* cookie_store);
129 // Gets the cookie policy for this context (may be null, in which case
130 // cookies are allowed).
131 CookiePolicy* cookie_policy() { return cookie_policy_; }
133 TransportSecurityState* transport_security_state() {
134 return transport_security_state_; }
136 // Gets the FTP authentication cache for this context.
137 FtpAuthCache* ftp_auth_cache() { return &ftp_auth_cache_; }
139 // Gets the value of 'Accept-Charset' header field.
140 const std::string& accept_charset() const { return accept_charset_; }
142 // Gets the value of 'Accept-Language' header field.
143 const std::string& accept_language() const { return accept_language_; }
145 // Gets the UA string to use for the given URL. Pass an invalid URL (such as
146 // GURL()) to get the default UA string. Subclasses should override this
147 // method to provide a UA string.
148 virtual const std::string& GetUserAgent(const GURL& url) const;
150 // In general, referrer_charset is not known when URLRequestContext is
151 // constructed. So, we need a setter.
152 const std::string& referrer_charset() const { return referrer_charset_; }
153 void set_referrer_charset(const std::string& charset) {
154 referrer_charset_ = charset;
157 // Controls whether or not the URLRequestContext considers itself to be the
158 // "main" URLRequestContext.
159 bool is_main() const { return is_main_; }
160 void set_is_main(bool is_main) { is_main_ = is_main; }
162 protected:
163 friend class base::RefCountedThreadSafe<URLRequestContext>;
165 virtual ~URLRequestContext();
167 // The following members are expected to be initialized and owned by
168 // subclasses.
169 NetLog* net_log_;
170 HostResolver* host_resolver_;
171 CertVerifier* cert_verifier_;
172 DnsRRResolver* dnsrr_resolver_;
173 scoped_ptr<DnsCertProvenanceChecker> dns_cert_checker_;
174 scoped_refptr<ProxyService> proxy_service_;
175 scoped_refptr<SSLConfigService> ssl_config_service_;
176 HttpTransactionFactory* http_transaction_factory_;
177 FtpTransactionFactory* ftp_transaction_factory_;
178 HttpAuthHandlerFactory* http_auth_handler_factory_;
179 HttpNetworkDelegate* network_delegate_;
180 scoped_refptr<CookieStore> cookie_store_;
181 CookiePolicy* cookie_policy_;
182 scoped_refptr<TransportSecurityState> transport_security_state_;
183 FtpAuthCache ftp_auth_cache_;
184 std::string accept_language_;
185 std::string accept_charset_;
186 // The charset of the referrer where this request comes from. It's not
187 // used in communication with a server but is used to construct a suggested
188 // filename for file download.
189 std::string referrer_charset_;
191 private:
192 // Indicates whether or not this is the main URLRequestContext.
193 bool is_main_;
195 DISALLOW_COPY_AND_ASSIGN(URLRequestContext);
198 } // namespace net
200 #endif // NET_URL_REQUEST_URL_REQUEST_CONTEXT_H_