[email protected] | 27a112c | 2011-01-06 04:19:30 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 4 | |
| 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. |
| 9 | |
[email protected] | 43530b3 | 2008-08-04 22:21:34 | [diff] [blame] | 10 | #ifndef NET_URL_REQUEST_URL_REQUEST_CONTEXT_H_ |
| 11 | #define NET_URL_REQUEST_URL_REQUEST_CONTEXT_H_ |
[email protected] | 32b76ef | 2010-07-26 23:08:24 | [diff] [blame] | 12 | #pragma once |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 13 | |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 14 | #include "base/memory/ref_counted.h" |
[email protected] | ede9666 | 2011-07-14 12:34:18 | [diff] [blame] | 15 | #include "base/memory/scoped_ptr.h" |
[email protected] | 18590f2 | 2011-07-29 16:41:28 | [diff] [blame] | 16 | #include "base/memory/weak_ptr.h" |
[email protected] | c917750 | 2011-01-01 04:48:49 | [diff] [blame] | 17 | #include "base/threading/non_thread_safe.h" |
[email protected] | 172da1b | 2011-08-12 15:52:26 | [diff] [blame] | 18 | #include "net/base/net_export.h" |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 19 | #include "net/base/net_log.h" |
[email protected] | db36938c | 2009-08-19 21:48:42 | [diff] [blame] | 20 | #include "net/base/ssl_config_service.h" |
[email protected] | 326e679 | 2009-12-11 21:04:42 | [diff] [blame] | 21 | #include "net/base/transport_security_state.h" |
[email protected] | 515838c | 2009-01-15 06:43:48 | [diff] [blame] | 22 | #include "net/ftp/ftp_auth_cache.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 23 | |
[email protected] | 8ac1a75 | 2008-07-31 19:40:37 | [diff] [blame] | 24 | namespace net { |
[email protected] | 822581d | 2010-12-16 17:27:15 | [diff] [blame] | 25 | class CertVerifier; |
[email protected] | 9349cfb | 2010-08-31 18:00:53 | [diff] [blame] | 26 | class CookieStore; |
[email protected] | 345c613b | 2010-11-22 19:33:18 | [diff] [blame] | 27 | class DnsCertProvenanceChecker; |
[email protected] | 2db58053 | 2010-10-08 14:32:37 | [diff] [blame] | 28 | class DnsRRResolver; |
[email protected] | b65ce094 | 2009-03-16 20:13:33 | [diff] [blame] | 29 | class FtpTransactionFactory; |
[email protected] | 9349cfb | 2010-08-31 18:00:53 | [diff] [blame] | 30 | class HostResolver; |
[email protected] | fa55e19 | 2010-02-15 14:25:50 | [diff] [blame] | 31 | class HttpAuthHandlerFactory; |
[email protected] | b65ce094 | 2009-03-16 20:13:33 | [diff] [blame] | 32 | class HttpTransactionFactory; |
[email protected] | 0651b81 | 2011-02-24 00:22:50 | [diff] [blame] | 33 | class NetworkDelegate; |
[email protected] | feb79bcd | 2011-07-21 16:55:17 | [diff] [blame] | 34 | class OriginBoundCertService; |
[email protected] | 6104ea5d | 2011-04-27 21:37:12 | [diff] [blame] | 35 | class ProxyService; |
[email protected] | eaadd905 | 2009-06-23 18:02:23 | [diff] [blame] | 36 | class URLRequest; |
[email protected] | a8c1e745 | 2011-05-14 06:17:07 | [diff] [blame] | 37 | class URLRequestJobFactory; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 38 | |
[email protected] | 27a112c | 2011-01-06 04:19:30 | [diff] [blame] | 39 | // Subclass to provide application-specific context for URLRequest |
[email protected] | 529623e | 2011-02-23 17:37:16 | [diff] [blame] | 40 | // instances. Note that URLRequestContext typically does not provide storage for |
| 41 | // these member variables, since they may be shared. For the ones that aren't |
| 42 | // shared, URLRequestContextStorage can be helpful in defining their storage. |
[email protected] | 172da1b | 2011-08-12 15:52:26 | [diff] [blame] | 43 | class NET_EXPORT URLRequestContext |
[email protected] | fe57c8c | 2010-07-12 18:29:43 | [diff] [blame] | 44 | : public base::RefCountedThreadSafe<URLRequestContext>, |
[email protected] | eb2b46a | 2011-05-20 19:01:49 | [diff] [blame] | 45 | NON_EXPORTED_BASE(public base::NonThreadSafe) { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 46 | public: |
[email protected] | 9349cfb | 2010-08-31 18:00:53 | [diff] [blame] | 47 | URLRequestContext(); |
[email protected] | db8f44c | 2008-12-13 04:52:01 | [diff] [blame] | 48 | |
[email protected] | 18590f2 | 2011-07-29 16:41:28 | [diff] [blame] | 49 | base::WeakPtr<URLRequestContext> GetWeakPtr() { |
| 50 | return weak_factory_.GetWeakPtr(); |
| 51 | } |
| 52 | |
[email protected] | d969667 | 2011-03-15 22:45:09 | [diff] [blame] | 53 | // Copies the state from |other| into this context. |
| 54 | void CopyFrom(URLRequestContext* other); |
| 55 | |
[email protected] | 27a112c | 2011-01-06 04:19:30 | [diff] [blame] | 56 | NetLog* net_log() const { |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 57 | return net_log_; |
| 58 | } |
| 59 | |
[email protected] | 27a112c | 2011-01-06 04:19:30 | [diff] [blame] | 60 | void set_net_log(NetLog* net_log) { |
[email protected] | 2fb62920 | 2010-12-23 23:52:57 | [diff] [blame] | 61 | net_log_ = net_log; |
| 62 | } |
| 63 | |
[email protected] | 27a112c | 2011-01-06 04:19:30 | [diff] [blame] | 64 | HostResolver* host_resolver() const { |
[email protected] | 8a00f00a | 2009-06-12 00:49:38 | [diff] [blame] | 65 | return host_resolver_; |
| 66 | } |
| 67 | |
[email protected] | 27a112c | 2011-01-06 04:19:30 | [diff] [blame] | 68 | void set_host_resolver(HostResolver* host_resolver) { |
[email protected] | 2fb62920 | 2010-12-23 23:52:57 | [diff] [blame] | 69 | host_resolver_ = host_resolver; |
| 70 | } |
| 71 | |
[email protected] | 27a112c | 2011-01-06 04:19:30 | [diff] [blame] | 72 | CertVerifier* cert_verifier() const { |
[email protected] | 822581d | 2010-12-16 17:27:15 | [diff] [blame] | 73 | return cert_verifier_; |
| 74 | } |
| 75 | |
[email protected] | 27a112c | 2011-01-06 04:19:30 | [diff] [blame] | 76 | void set_cert_verifier(CertVerifier* cert_verifier) { |
[email protected] | 2fb62920 | 2010-12-23 23:52:57 | [diff] [blame] | 77 | cert_verifier_ = cert_verifier; |
| 78 | } |
| 79 | |
[email protected] | feb79bcd | 2011-07-21 16:55:17 | [diff] [blame] | 80 | OriginBoundCertService* origin_bound_cert_service() const { |
| 81 | return origin_bound_cert_service_; |
| 82 | } |
[email protected] | 273e37d | 2011-08-11 01:49:12 | [diff] [blame] | 83 | |
[email protected] | feb79bcd | 2011-07-21 16:55:17 | [diff] [blame] | 84 | void set_origin_bound_cert_service( |
| 85 | OriginBoundCertService* origin_bound_cert_service) { |
| 86 | origin_bound_cert_service_ = origin_bound_cert_service; |
| 87 | } |
| 88 | |
[email protected] | 27a112c | 2011-01-06 04:19:30 | [diff] [blame] | 89 | DnsRRResolver* dnsrr_resolver() const { |
[email protected] | 2db58053 | 2010-10-08 14:32:37 | [diff] [blame] | 90 | return dnsrr_resolver_; |
| 91 | } |
| 92 | |
[email protected] | 27a112c | 2011-01-06 04:19:30 | [diff] [blame] | 93 | void set_dnsrr_resolver(DnsRRResolver* dnsrr_resolver) { |
[email protected] | 2fb62920 | 2010-12-23 23:52:57 | [diff] [blame] | 94 | dnsrr_resolver_ = dnsrr_resolver; |
| 95 | } |
| 96 | |
[email protected] | 27a112c | 2011-01-06 04:19:30 | [diff] [blame] | 97 | DnsCertProvenanceChecker* dns_cert_checker() const { |
[email protected] | f6c21cb | 2011-02-16 19:45:41 | [diff] [blame] | 98 | return dns_cert_checker_; |
| 99 | } |
[email protected] | 7461a40 | 2011-03-24 23:19:51 | [diff] [blame] | 100 | void set_dns_cert_checker(DnsCertProvenanceChecker* dns_cert_checker) { |
[email protected] | f6c21cb | 2011-02-16 19:45:41 | [diff] [blame] | 101 | dns_cert_checker_ = dns_cert_checker; |
[email protected] | 345c613b | 2010-11-22 19:33:18 | [diff] [blame] | 102 | } |
| 103 | |
[email protected] | 63de95b | 2008-12-10 04:11:27 | [diff] [blame] | 104 | // Get the proxy service for this context. |
[email protected] | f6c21cb | 2011-02-16 19:45:41 | [diff] [blame] | 105 | ProxyService* proxy_service() const { return proxy_service_; } |
[email protected] | 27a112c | 2011-01-06 04:19:30 | [diff] [blame] | 106 | void set_proxy_service(ProxyService* proxy_service) { |
[email protected] | 2fb62920 | 2010-12-23 23:52:57 | [diff] [blame] | 107 | proxy_service_ = proxy_service; |
| 108 | } |
| 109 | |
[email protected] | db36938c | 2009-08-19 21:48:42 | [diff] [blame] | 110 | // Get the ssl config service for this context. |
[email protected] | f6c21cb | 2011-02-16 19:45:41 | [diff] [blame] | 111 | SSLConfigService* ssl_config_service() const { return ssl_config_service_; } |
[email protected] | 7461a40 | 2011-03-24 23:19:51 | [diff] [blame] | 112 | void set_ssl_config_service(SSLConfigService* service) { |
[email protected] | f6c21cb | 2011-02-16 19:45:41 | [diff] [blame] | 113 | ssl_config_service_ = service; |
[email protected] | db36938c | 2009-08-19 21:48:42 | [diff] [blame] | 114 | } |
| 115 | |
[email protected] | 2fb62920 | 2010-12-23 23:52:57 | [diff] [blame] | 116 | // Gets the HTTP Authentication Handler Factory for this context. |
| 117 | // The factory is only valid for the lifetime of this URLRequestContext |
[email protected] | 27a112c | 2011-01-06 04:19:30 | [diff] [blame] | 118 | HttpAuthHandlerFactory* http_auth_handler_factory() { |
[email protected] | 2fb62920 | 2010-12-23 23:52:57 | [diff] [blame] | 119 | return http_auth_handler_factory_; |
| 120 | } |
[email protected] | 27a112c | 2011-01-06 04:19:30 | [diff] [blame] | 121 | void set_http_auth_handler_factory(HttpAuthHandlerFactory* factory) { |
[email protected] | 2fb62920 | 2010-12-23 23:52:57 | [diff] [blame] | 122 | http_auth_handler_factory_ = factory; |
| 123 | } |
| 124 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 125 | // Gets the http transaction factory for this context. |
[email protected] | 27a112c | 2011-01-06 04:19:30 | [diff] [blame] | 126 | HttpTransactionFactory* http_transaction_factory() const { |
[email protected] | db8f44c | 2008-12-13 04:52:01 | [diff] [blame] | 127 | return http_transaction_factory_; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 128 | } |
[email protected] | 27a112c | 2011-01-06 04:19:30 | [diff] [blame] | 129 | void set_http_transaction_factory(HttpTransactionFactory* factory) { |
[email protected] | 2fb62920 | 2010-12-23 23:52:57 | [diff] [blame] | 130 | http_transaction_factory_ = factory; |
| 131 | } |
| 132 | |
[email protected] | b65ce094 | 2009-03-16 20:13:33 | [diff] [blame] | 133 | // Gets the ftp transaction factory for this context. |
[email protected] | ede9666 | 2011-07-14 12:34:18 | [diff] [blame] | 134 | FtpTransactionFactory* ftp_transaction_factory() const { |
[email protected] | b65ce094 | 2009-03-16 20:13:33 | [diff] [blame] | 135 | return ftp_transaction_factory_; |
| 136 | } |
[email protected] | 7461a40 | 2011-03-24 23:19:51 | [diff] [blame] | 137 | void set_ftp_transaction_factory(FtpTransactionFactory* factory) { |
[email protected] | f6c21cb | 2011-02-16 19:45:41 | [diff] [blame] | 138 | ftp_transaction_factory_ = factory; |
| 139 | } |
[email protected] | b65ce094 | 2009-03-16 20:13:33 | [diff] [blame] | 140 | |
[email protected] | 0651b81 | 2011-02-24 00:22:50 | [diff] [blame] | 141 | void set_network_delegate(NetworkDelegate* network_delegate) { |
[email protected] | d05ef99c | 2011-02-01 21:38:16 | [diff] [blame] | 142 | network_delegate_ = network_delegate; |
| 143 | } |
[email protected] | 0651b81 | 2011-02-24 00:22:50 | [diff] [blame] | 144 | NetworkDelegate* network_delegate() const { return network_delegate_; } |
[email protected] | d05ef99c | 2011-02-01 21:38:16 | [diff] [blame] | 145 | |
[email protected] | be6fca6c | 2010-01-30 21:48:57 | [diff] [blame] | 146 | // Gets the cookie store for this context (may be null, in which case |
| 147 | // cookies are not stored). |
[email protected] | f6c21cb | 2011-02-16 19:45:41 | [diff] [blame] | 148 | CookieStore* cookie_store() const { return cookie_store_.get(); } |
[email protected] | 27a112c | 2011-01-06 04:19:30 | [diff] [blame] | 149 | void set_cookie_store(CookieStore* cookie_store); |
[email protected] | 2fb62920 | 2010-12-23 23:52:57 | [diff] [blame] | 150 | |
[email protected] | f6c21cb | 2011-02-16 19:45:41 | [diff] [blame] | 151 | TransportSecurityState* transport_security_state() const { |
| 152 | return transport_security_state_; |
| 153 | } |
| 154 | void set_transport_security_state( |
[email protected] | 7461a40 | 2011-03-24 23:19:51 | [diff] [blame] | 155 | TransportSecurityState* state) { |
[email protected] | f6c21cb | 2011-02-16 19:45:41 | [diff] [blame] | 156 | transport_security_state_ = state; |
| 157 | } |
[email protected] | a9cea754 | 2009-05-20 04:30:23 | [diff] [blame] | 158 | |
[email protected] | 515838c | 2009-01-15 06:43:48 | [diff] [blame] | 159 | // Gets the FTP authentication cache for this context. |
[email protected] | ede9666 | 2011-07-14 12:34:18 | [diff] [blame] | 160 | FtpAuthCache* ftp_auth_cache() const { return ftp_auth_cache_.get(); } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 161 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 162 | // Gets the value of 'Accept-Charset' header field. |
| 163 | const std::string& accept_charset() const { return accept_charset_; } |
[email protected] | f6c21cb | 2011-02-16 19:45:41 | [diff] [blame] | 164 | void set_accept_charset(const std::string& accept_charset) { |
| 165 | accept_charset_ = accept_charset; |
| 166 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 167 | |
| 168 | // Gets the value of 'Accept-Language' header field. |
| 169 | const std::string& accept_language() const { return accept_language_; } |
[email protected] | f6c21cb | 2011-02-16 19:45:41 | [diff] [blame] | 170 | void set_accept_language(const std::string& accept_language) { |
| 171 | accept_language_ = accept_language; |
| 172 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 173 | |
[email protected] | 6f681a4 | 2009-01-27 22:28:54 | [diff] [blame] | 174 | // Gets the UA string to use for the given URL. Pass an invalid URL (such as |
| 175 | // GURL()) to get the default UA string. Subclasses should override this |
| 176 | // method to provide a UA string. |
[email protected] | f1d8192 | 2010-07-31 17:47:09 | [diff] [blame] | 177 | virtual const std::string& GetUserAgent(const GURL& url) const; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 178 | |
[email protected] | c9825a4 | 2009-05-01 22:51:50 | [diff] [blame] | 179 | // In general, referrer_charset is not known when URLRequestContext is |
| 180 | // constructed. So, we need a setter. |
| 181 | const std::string& referrer_charset() const { return referrer_charset_; } |
| 182 | void set_referrer_charset(const std::string& charset) { |
| 183 | referrer_charset_ = charset; |
| 184 | } |
| 185 | |
[email protected] | a8c1e745 | 2011-05-14 06:17:07 | [diff] [blame] | 186 | const URLRequestJobFactory* job_factory() const { return job_factory_; } |
| 187 | void set_job_factory(const URLRequestJobFactory* job_factory) { |
| 188 | job_factory_ = job_factory; |
| 189 | } |
| 190 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 191 | protected: |
[email protected] | 6f681a4 | 2009-01-27 22:28:54 | [diff] [blame] | 192 | friend class base::RefCountedThreadSafe<URLRequestContext>; |
| 193 | |
[email protected] | 9349cfb | 2010-08-31 18:00:53 | [diff] [blame] | 194 | virtual ~URLRequestContext(); |
[email protected] | 6f681a4 | 2009-01-27 22:28:54 | [diff] [blame] | 195 | |
[email protected] | f6c21cb | 2011-02-16 19:45:41 | [diff] [blame] | 196 | private: |
[email protected] | 18590f2 | 2011-07-29 16:41:28 | [diff] [blame] | 197 | base::WeakPtrFactory<URLRequestContext> weak_factory_; |
| 198 | |
[email protected] | d969667 | 2011-03-15 22:45:09 | [diff] [blame] | 199 | // --------------------------------------------------------------------------- |
| 200 | // Important: When adding any new members below, consider whether they need to |
| 201 | // be added to CopyFrom. |
| 202 | // --------------------------------------------------------------------------- |
| 203 | |
[email protected] | f6c21cb | 2011-02-16 19:45:41 | [diff] [blame] | 204 | // Ownership for these members are not defined here. Clients should either |
| 205 | // provide storage elsewhere or have a subclass take ownership. |
[email protected] | 27a112c | 2011-01-06 04:19:30 | [diff] [blame] | 206 | NetLog* net_log_; |
| 207 | HostResolver* host_resolver_; |
| 208 | CertVerifier* cert_verifier_; |
[email protected] | feb79bcd | 2011-07-21 16:55:17 | [diff] [blame] | 209 | OriginBoundCertService* origin_bound_cert_service_; |
[email protected] | 27a112c | 2011-01-06 04:19:30 | [diff] [blame] | 210 | DnsRRResolver* dnsrr_resolver_; |
[email protected] | f6c21cb | 2011-02-16 19:45:41 | [diff] [blame] | 211 | DnsCertProvenanceChecker* dns_cert_checker_; |
| 212 | HttpAuthHandlerFactory* http_auth_handler_factory_; |
[email protected] | 6104ea5d | 2011-04-27 21:37:12 | [diff] [blame] | 213 | ProxyService* proxy_service_; |
[email protected] | 27a112c | 2011-01-06 04:19:30 | [diff] [blame] | 214 | scoped_refptr<SSLConfigService> ssl_config_service_; |
[email protected] | 0651b81 | 2011-02-24 00:22:50 | [diff] [blame] | 215 | NetworkDelegate* network_delegate_; |
[email protected] | 27a112c | 2011-01-06 04:19:30 | [diff] [blame] | 216 | scoped_refptr<CookieStore> cookie_store_; |
[email protected] | 27a112c | 2011-01-06 04:19:30 | [diff] [blame] | 217 | scoped_refptr<TransportSecurityState> transport_security_state_; |
[email protected] | ede9666 | 2011-07-14 12:34:18 | [diff] [blame] | 218 | scoped_ptr<FtpAuthCache> ftp_auth_cache_; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 219 | std::string accept_language_; |
| 220 | std::string accept_charset_; |
[email protected] | c9825a4 | 2009-05-01 22:51:50 | [diff] [blame] | 221 | // The charset of the referrer where this request comes from. It's not |
| 222 | // used in communication with a server but is used to construct a suggested |
| 223 | // filename for file download. |
| 224 | std::string referrer_charset_; |
[email protected] | f6c21cb | 2011-02-16 19:45:41 | [diff] [blame] | 225 | HttpTransactionFactory* http_transaction_factory_; |
| 226 | FtpTransactionFactory* ftp_transaction_factory_; |
[email protected] | a8c1e745 | 2011-05-14 06:17:07 | [diff] [blame] | 227 | const URLRequestJobFactory* job_factory_; |
[email protected] | 70b9234 | 2010-10-12 05:54:06 | [diff] [blame] | 228 | |
[email protected] | d969667 | 2011-03-15 22:45:09 | [diff] [blame] | 229 | // --------------------------------------------------------------------------- |
| 230 | // Important: When adding any new members below, consider whether they need to |
| 231 | // be added to CopyFrom. |
| 232 | // --------------------------------------------------------------------------- |
| 233 | |
[email protected] | 6f681a4 | 2009-01-27 22:28:54 | [diff] [blame] | 234 | DISALLOW_COPY_AND_ASSIGN(URLRequestContext); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 235 | }; |
| 236 | |
[email protected] | 27a112c | 2011-01-06 04:19:30 | [diff] [blame] | 237 | } // namespace net |
| 238 | |
[email protected] | 43530b3 | 2008-08-04 22:21:34 | [diff] [blame] | 239 | #endif // NET_URL_REQUEST_URL_REQUEST_CONTEXT_H_ |