blob: ea8014307d906ef5c374ce2b93cbb345c95c9c9c [file] [log] [blame]
[email protected]27a112c2011-01-06 04:19:301// Copyright (c) 2011 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit586acc5fe2008-07-26 22:42:524
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]43530b32008-08-04 22:21:3410#ifndef NET_URL_REQUEST_URL_REQUEST_CONTEXT_H_
11#define NET_URL_REQUEST_URL_REQUEST_CONTEXT_H_
[email protected]32b76ef2010-07-26 23:08:2412#pragma once
initial.commit586acc5fe2008-07-26 22:42:5213
[email protected]3b63f8f42011-03-28 01:54:1514#include "base/memory/ref_counted.h"
[email protected]c9177502011-01-01 04:48:4915#include "base/threading/non_thread_safe.h"
[email protected]9e743cd2010-03-16 07:03:5316#include "net/base/net_log.h"
[email protected]db36938c2009-08-19 21:48:4217#include "net/base/ssl_config_service.h"
[email protected]326e6792009-12-11 21:04:4218#include "net/base/transport_security_state.h"
[email protected]515838c2009-01-15 06:43:4819#include "net/ftp/ftp_auth_cache.h"
[email protected]80d6524d2009-08-18 03:58:0920#include "net/proxy/proxy_service.h"
[email protected]345c613b2010-11-22 19:33:1821#include "net/socket/dns_cert_provenance_checker.h"
initial.commit586acc5fe2008-07-26 22:42:5222
[email protected]8ac1a752008-07-31 19:40:3723namespace net {
[email protected]822581d2010-12-16 17:27:1524class CertVerifier;
[email protected]cb370a0632010-01-30 08:24:1225class CookiePolicy;
[email protected]9349cfb2010-08-31 18:00:5326class CookieStore;
[email protected]345c613b2010-11-22 19:33:1827class DnsCertProvenanceChecker;
[email protected]2db580532010-10-08 14:32:3728class DnsRRResolver;
[email protected]b65ce0942009-03-16 20:13:3329class FtpTransactionFactory;
[email protected]9349cfb2010-08-31 18:00:5330class HostResolver;
[email protected]fa55e192010-02-15 14:25:5031class HttpAuthHandlerFactory;
[email protected]b65ce0942009-03-16 20:13:3332class HttpTransactionFactory;
[email protected]0651b812011-02-24 00:22:5033class NetworkDelegate;
[email protected]9349cfb2010-08-31 18:00:5334class SSLConfigService;
[email protected]eaadd9052009-06-23 18:02:2335class URLRequest;
initial.commit586acc5fe2008-07-26 22:42:5236
[email protected]27a112c2011-01-06 04:19:3037// Subclass to provide application-specific context for URLRequest
[email protected]529623e2011-02-23 17:37:1638// instances. Note that URLRequestContext typically does not provide storage for
39// these member variables, since they may be shared. For the ones that aren't
40// shared, URLRequestContextStorage can be helpful in defining their storage.
[email protected]483bf122010-05-04 20:41:2441class URLRequestContext
[email protected]fe57c8c2010-07-12 18:29:4342 : public base::RefCountedThreadSafe<URLRequestContext>,
[email protected]c9177502011-01-01 04:48:4943 public base::NonThreadSafe {
initial.commit586acc5fe2008-07-26 22:42:5244 public:
[email protected]9349cfb2010-08-31 18:00:5345 URLRequestContext();
[email protected]db8f44c2008-12-13 04:52:0146
[email protected]d9696672011-03-15 22:45:0947 // Copies the state from |other| into this context.
48 void CopyFrom(URLRequestContext* other);
49
[email protected]27a112c2011-01-06 04:19:3050 NetLog* net_log() const {
[email protected]9e743cd2010-03-16 07:03:5351 return net_log_;
52 }
53
[email protected]27a112c2011-01-06 04:19:3054 void set_net_log(NetLog* net_log) {
[email protected]2fb629202010-12-23 23:52:5755 net_log_ = net_log;
56 }
57
[email protected]27a112c2011-01-06 04:19:3058 HostResolver* host_resolver() const {
[email protected]8a00f00a2009-06-12 00:49:3859 return host_resolver_;
60 }
61
[email protected]27a112c2011-01-06 04:19:3062 void set_host_resolver(HostResolver* host_resolver) {
[email protected]2fb629202010-12-23 23:52:5763 host_resolver_ = host_resolver;
64 }
65
[email protected]27a112c2011-01-06 04:19:3066 CertVerifier* cert_verifier() const {
[email protected]822581d2010-12-16 17:27:1567 return cert_verifier_;
68 }
69
[email protected]27a112c2011-01-06 04:19:3070 void set_cert_verifier(CertVerifier* cert_verifier) {
[email protected]2fb629202010-12-23 23:52:5771 cert_verifier_ = cert_verifier;
72 }
73
[email protected]27a112c2011-01-06 04:19:3074 DnsRRResolver* dnsrr_resolver() const {
[email protected]2db580532010-10-08 14:32:3775 return dnsrr_resolver_;
76 }
77
[email protected]27a112c2011-01-06 04:19:3078 void set_dnsrr_resolver(DnsRRResolver* dnsrr_resolver) {
[email protected]2fb629202010-12-23 23:52:5779 dnsrr_resolver_ = dnsrr_resolver;
80 }
81
[email protected]27a112c2011-01-06 04:19:3082 DnsCertProvenanceChecker* dns_cert_checker() const {
[email protected]f6c21cb2011-02-16 19:45:4183 return dns_cert_checker_;
84 }
[email protected]7461a402011-03-24 23:19:5185 void set_dns_cert_checker(DnsCertProvenanceChecker* dns_cert_checker) {
[email protected]f6c21cb2011-02-16 19:45:4186 dns_cert_checker_ = dns_cert_checker;
[email protected]345c613b2010-11-22 19:33:1887 }
88
[email protected]63de95b2008-12-10 04:11:2789 // Get the proxy service for this context.
[email protected]f6c21cb2011-02-16 19:45:4190 ProxyService* proxy_service() const { return proxy_service_; }
[email protected]27a112c2011-01-06 04:19:3091 void set_proxy_service(ProxyService* proxy_service) {
[email protected]2fb629202010-12-23 23:52:5792 proxy_service_ = proxy_service;
93 }
94
[email protected]db36938c2009-08-19 21:48:4295 // Get the ssl config service for this context.
[email protected]f6c21cb2011-02-16 19:45:4196 SSLConfigService* ssl_config_service() const { return ssl_config_service_; }
[email protected]7461a402011-03-24 23:19:5197 void set_ssl_config_service(SSLConfigService* service) {
[email protected]f6c21cb2011-02-16 19:45:4198 ssl_config_service_ = service;
[email protected]db36938c2009-08-19 21:48:4299 }
100
[email protected]2fb629202010-12-23 23:52:57101 // Gets the HTTP Authentication Handler Factory for this context.
102 // The factory is only valid for the lifetime of this URLRequestContext
[email protected]27a112c2011-01-06 04:19:30103 HttpAuthHandlerFactory* http_auth_handler_factory() {
[email protected]2fb629202010-12-23 23:52:57104 return http_auth_handler_factory_;
105 }
[email protected]27a112c2011-01-06 04:19:30106 void set_http_auth_handler_factory(HttpAuthHandlerFactory* factory) {
[email protected]2fb629202010-12-23 23:52:57107 http_auth_handler_factory_ = factory;
108 }
109
initial.commit586acc5fe2008-07-26 22:42:52110 // Gets the http transaction factory for this context.
[email protected]27a112c2011-01-06 04:19:30111 HttpTransactionFactory* http_transaction_factory() const {
[email protected]db8f44c2008-12-13 04:52:01112 return http_transaction_factory_;
initial.commit586acc5fe2008-07-26 22:42:52113 }
[email protected]27a112c2011-01-06 04:19:30114 void set_http_transaction_factory(HttpTransactionFactory* factory) {
[email protected]2fb629202010-12-23 23:52:57115 http_transaction_factory_ = factory;
116 }
117
[email protected]b65ce0942009-03-16 20:13:33118 // Gets the ftp transaction factory for this context.
[email protected]27a112c2011-01-06 04:19:30119 FtpTransactionFactory* ftp_transaction_factory() {
[email protected]b65ce0942009-03-16 20:13:33120 return ftp_transaction_factory_;
121 }
[email protected]7461a402011-03-24 23:19:51122 void set_ftp_transaction_factory(FtpTransactionFactory* factory) {
[email protected]f6c21cb2011-02-16 19:45:41123 ftp_transaction_factory_ = factory;
124 }
[email protected]b65ce0942009-03-16 20:13:33125
[email protected]0651b812011-02-24 00:22:50126 void set_network_delegate(NetworkDelegate* network_delegate) {
[email protected]d05ef99c2011-02-01 21:38:16127 network_delegate_ = network_delegate;
128 }
[email protected]0651b812011-02-24 00:22:50129 NetworkDelegate* network_delegate() const { return network_delegate_; }
[email protected]d05ef99c2011-02-01 21:38:16130
[email protected]be6fca6c2010-01-30 21:48:57131 // Gets the cookie store for this context (may be null, in which case
132 // cookies are not stored).
[email protected]f6c21cb2011-02-16 19:45:41133 CookieStore* cookie_store() const { return cookie_store_.get(); }
[email protected]27a112c2011-01-06 04:19:30134 void set_cookie_store(CookieStore* cookie_store);
[email protected]2fb629202010-12-23 23:52:57135
[email protected]be6fca6c2010-01-30 21:48:57136 // Gets the cookie policy for this context (may be null, in which case
137 // cookies are allowed).
[email protected]f6c21cb2011-02-16 19:45:41138 CookiePolicy* cookie_policy() const { return cookie_policy_; }
139 void set_cookie_policy(CookiePolicy* cookie_policy) {
140 cookie_policy_ = cookie_policy;
141 }
initial.commit586acc5fe2008-07-26 22:42:52142
[email protected]f6c21cb2011-02-16 19:45:41143 TransportSecurityState* transport_security_state() const {
144 return transport_security_state_;
145 }
146 void set_transport_security_state(
[email protected]7461a402011-03-24 23:19:51147 TransportSecurityState* state) {
[email protected]f6c21cb2011-02-16 19:45:41148 transport_security_state_ = state;
149 }
[email protected]a9cea7542009-05-20 04:30:23150
[email protected]515838c2009-01-15 06:43:48151 // Gets the FTP authentication cache for this context.
[email protected]27a112c2011-01-06 04:19:30152 FtpAuthCache* ftp_auth_cache() { return &ftp_auth_cache_; }
initial.commit586acc5fe2008-07-26 22:42:52153
initial.commit586acc5fe2008-07-26 22:42:52154 // Gets the value of 'Accept-Charset' header field.
155 const std::string& accept_charset() const { return accept_charset_; }
[email protected]f6c21cb2011-02-16 19:45:41156 void set_accept_charset(const std::string& accept_charset) {
157 accept_charset_ = accept_charset;
158 }
initial.commit586acc5fe2008-07-26 22:42:52159
160 // Gets the value of 'Accept-Language' header field.
161 const std::string& accept_language() const { return accept_language_; }
[email protected]f6c21cb2011-02-16 19:45:41162 void set_accept_language(const std::string& accept_language) {
163 accept_language_ = accept_language;
164 }
initial.commit586acc5fe2008-07-26 22:42:52165
[email protected]6f681a42009-01-27 22:28:54166 // Gets the UA string to use for the given URL. Pass an invalid URL (such as
167 // GURL()) to get the default UA string. Subclasses should override this
168 // method to provide a UA string.
[email protected]f1d81922010-07-31 17:47:09169 virtual const std::string& GetUserAgent(const GURL& url) const;
initial.commit586acc5fe2008-07-26 22:42:52170
[email protected]c9825a42009-05-01 22:51:50171 // In general, referrer_charset is not known when URLRequestContext is
172 // constructed. So, we need a setter.
173 const std::string& referrer_charset() const { return referrer_charset_; }
174 void set_referrer_charset(const std::string& charset) {
175 referrer_charset_ = charset;
176 }
177
[email protected]70b92342010-10-12 05:54:06178 // Controls whether or not the URLRequestContext considers itself to be the
179 // "main" URLRequestContext.
180 bool is_main() const { return is_main_; }
181 void set_is_main(bool is_main) { is_main_ = is_main; }
182
initial.commit586acc5fe2008-07-26 22:42:52183 protected:
[email protected]6f681a42009-01-27 22:28:54184 friend class base::RefCountedThreadSafe<URLRequestContext>;
185
[email protected]9349cfb2010-08-31 18:00:53186 virtual ~URLRequestContext();
[email protected]6f681a42009-01-27 22:28:54187
[email protected]f6c21cb2011-02-16 19:45:41188 private:
[email protected]d9696672011-03-15 22:45:09189 // ---------------------------------------------------------------------------
190 // Important: When adding any new members below, consider whether they need to
191 // be added to CopyFrom.
192 // ---------------------------------------------------------------------------
193
[email protected]f6c21cb2011-02-16 19:45:41194 // Indicates whether or not this is the main URLRequestContext.
195 bool is_main_;
196
197 // Ownership for these members are not defined here. Clients should either
198 // provide storage elsewhere or have a subclass take ownership.
[email protected]27a112c2011-01-06 04:19:30199 NetLog* net_log_;
200 HostResolver* host_resolver_;
201 CertVerifier* cert_verifier_;
202 DnsRRResolver* dnsrr_resolver_;
[email protected]f6c21cb2011-02-16 19:45:41203 DnsCertProvenanceChecker* dns_cert_checker_;
204 HttpAuthHandlerFactory* http_auth_handler_factory_;
[email protected]27a112c2011-01-06 04:19:30205 scoped_refptr<ProxyService> proxy_service_;
206 scoped_refptr<SSLConfigService> ssl_config_service_;
[email protected]0651b812011-02-24 00:22:50207 NetworkDelegate* network_delegate_;
[email protected]27a112c2011-01-06 04:19:30208 scoped_refptr<CookieStore> cookie_store_;
209 CookiePolicy* cookie_policy_;
210 scoped_refptr<TransportSecurityState> transport_security_state_;
211 FtpAuthCache ftp_auth_cache_;
initial.commit586acc5fe2008-07-26 22:42:52212 std::string accept_language_;
213 std::string accept_charset_;
[email protected]c9825a42009-05-01 22:51:50214 // The charset of the referrer where this request comes from. It's not
215 // used in communication with a server but is used to construct a suggested
216 // filename for file download.
217 std::string referrer_charset_;
initial.commit586acc5fe2008-07-26 22:42:52218
[email protected]f6c21cb2011-02-16 19:45:41219 HttpTransactionFactory* http_transaction_factory_;
220 FtpTransactionFactory* ftp_transaction_factory_;
[email protected]70b92342010-10-12 05:54:06221
[email protected]d9696672011-03-15 22:45:09222 // ---------------------------------------------------------------------------
223 // Important: When adding any new members below, consider whether they need to
224 // be added to CopyFrom.
225 // ---------------------------------------------------------------------------
226
[email protected]6f681a42009-01-27 22:28:54227 DISALLOW_COPY_AND_ASSIGN(URLRequestContext);
initial.commit586acc5fe2008-07-26 22:42:52228};
229
[email protected]27a112c2011-01-06 04:19:30230} // namespace net
231
[email protected]43530b32008-08-04 22:21:34232#endif // NET_URL_REQUEST_URL_REQUEST_CONTEXT_H_