blob: eb2f61fb2a450c56e58dfe7274d036c67afd81a0 [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]ede96662011-07-14 12:34:1815#include "base/memory/scoped_ptr.h"
[email protected]18590f22011-07-29 16:41:2816#include "base/memory/weak_ptr.h"
[email protected]c9177502011-01-01 04:48:4917#include "base/threading/non_thread_safe.h"
[email protected]172da1b2011-08-12 15:52:2618#include "net/base/net_export.h"
[email protected]9e743cd2010-03-16 07:03:5319#include "net/base/net_log.h"
[email protected]db36938c2009-08-19 21:48:4220#include "net/base/ssl_config_service.h"
[email protected]326e6792009-12-11 21:04:4221#include "net/base/transport_security_state.h"
[email protected]515838c2009-01-15 06:43:4822#include "net/ftp/ftp_auth_cache.h"
initial.commit586acc5fe2008-07-26 22:42:5223
[email protected]8ac1a752008-07-31 19:40:3724namespace net {
[email protected]822581d2010-12-16 17:27:1525class CertVerifier;
[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]feb79bcd2011-07-21 16:55:1734class OriginBoundCertService;
[email protected]6104ea5d2011-04-27 21:37:1235class ProxyService;
[email protected]eaadd9052009-06-23 18:02:2336class URLRequest;
[email protected]a8c1e7452011-05-14 06:17:0737class URLRequestJobFactory;
initial.commit586acc5fe2008-07-26 22:42:5238
[email protected]27a112c2011-01-06 04:19:3039// Subclass to provide application-specific context for URLRequest
[email protected]529623e2011-02-23 17:37:1640// 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]172da1b2011-08-12 15:52:2643class NET_EXPORT URLRequestContext
[email protected]fe57c8c2010-07-12 18:29:4344 : public base::RefCountedThreadSafe<URLRequestContext>,
[email protected]eb2b46a2011-05-20 19:01:4945 NON_EXPORTED_BASE(public base::NonThreadSafe) {
initial.commit586acc5fe2008-07-26 22:42:5246 public:
[email protected]9349cfb2010-08-31 18:00:5347 URLRequestContext();
[email protected]db8f44c2008-12-13 04:52:0148
[email protected]18590f22011-07-29 16:41:2849 base::WeakPtr<URLRequestContext> GetWeakPtr() {
50 return weak_factory_.GetWeakPtr();
51 }
52
[email protected]d9696672011-03-15 22:45:0953 // Copies the state from |other| into this context.
54 void CopyFrom(URLRequestContext* other);
55
[email protected]27a112c2011-01-06 04:19:3056 NetLog* net_log() const {
[email protected]9e743cd2010-03-16 07:03:5357 return net_log_;
58 }
59
[email protected]27a112c2011-01-06 04:19:3060 void set_net_log(NetLog* net_log) {
[email protected]2fb629202010-12-23 23:52:5761 net_log_ = net_log;
62 }
63
[email protected]27a112c2011-01-06 04:19:3064 HostResolver* host_resolver() const {
[email protected]8a00f00a2009-06-12 00:49:3865 return host_resolver_;
66 }
67
[email protected]27a112c2011-01-06 04:19:3068 void set_host_resolver(HostResolver* host_resolver) {
[email protected]2fb629202010-12-23 23:52:5769 host_resolver_ = host_resolver;
70 }
71
[email protected]27a112c2011-01-06 04:19:3072 CertVerifier* cert_verifier() const {
[email protected]822581d2010-12-16 17:27:1573 return cert_verifier_;
74 }
75
[email protected]27a112c2011-01-06 04:19:3076 void set_cert_verifier(CertVerifier* cert_verifier) {
[email protected]2fb629202010-12-23 23:52:5777 cert_verifier_ = cert_verifier;
78 }
79
[email protected]feb79bcd2011-07-21 16:55:1780 OriginBoundCertService* origin_bound_cert_service() const {
81 return origin_bound_cert_service_;
82 }
[email protected]273e37d2011-08-11 01:49:1283
[email protected]feb79bcd2011-07-21 16:55:1784 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]27a112c2011-01-06 04:19:3089 DnsRRResolver* dnsrr_resolver() const {
[email protected]2db580532010-10-08 14:32:3790 return dnsrr_resolver_;
91 }
92
[email protected]27a112c2011-01-06 04:19:3093 void set_dnsrr_resolver(DnsRRResolver* dnsrr_resolver) {
[email protected]2fb629202010-12-23 23:52:5794 dnsrr_resolver_ = dnsrr_resolver;
95 }
96
[email protected]27a112c2011-01-06 04:19:3097 DnsCertProvenanceChecker* dns_cert_checker() const {
[email protected]f6c21cb2011-02-16 19:45:4198 return dns_cert_checker_;
99 }
[email protected]7461a402011-03-24 23:19:51100 void set_dns_cert_checker(DnsCertProvenanceChecker* dns_cert_checker) {
[email protected]f6c21cb2011-02-16 19:45:41101 dns_cert_checker_ = dns_cert_checker;
[email protected]345c613b2010-11-22 19:33:18102 }
103
[email protected]63de95b2008-12-10 04:11:27104 // Get the proxy service for this context.
[email protected]f6c21cb2011-02-16 19:45:41105 ProxyService* proxy_service() const { return proxy_service_; }
[email protected]27a112c2011-01-06 04:19:30106 void set_proxy_service(ProxyService* proxy_service) {
[email protected]2fb629202010-12-23 23:52:57107 proxy_service_ = proxy_service;
108 }
109
[email protected]db36938c2009-08-19 21:48:42110 // Get the ssl config service for this context.
[email protected]f6c21cb2011-02-16 19:45:41111 SSLConfigService* ssl_config_service() const { return ssl_config_service_; }
[email protected]7461a402011-03-24 23:19:51112 void set_ssl_config_service(SSLConfigService* service) {
[email protected]f6c21cb2011-02-16 19:45:41113 ssl_config_service_ = service;
[email protected]db36938c2009-08-19 21:48:42114 }
115
[email protected]2fb629202010-12-23 23:52:57116 // Gets the HTTP Authentication Handler Factory for this context.
117 // The factory is only valid for the lifetime of this URLRequestContext
[email protected]27a112c2011-01-06 04:19:30118 HttpAuthHandlerFactory* http_auth_handler_factory() {
[email protected]2fb629202010-12-23 23:52:57119 return http_auth_handler_factory_;
120 }
[email protected]27a112c2011-01-06 04:19:30121 void set_http_auth_handler_factory(HttpAuthHandlerFactory* factory) {
[email protected]2fb629202010-12-23 23:52:57122 http_auth_handler_factory_ = factory;
123 }
124
initial.commit586acc5fe2008-07-26 22:42:52125 // Gets the http transaction factory for this context.
[email protected]27a112c2011-01-06 04:19:30126 HttpTransactionFactory* http_transaction_factory() const {
[email protected]db8f44c2008-12-13 04:52:01127 return http_transaction_factory_;
initial.commit586acc5fe2008-07-26 22:42:52128 }
[email protected]27a112c2011-01-06 04:19:30129 void set_http_transaction_factory(HttpTransactionFactory* factory) {
[email protected]2fb629202010-12-23 23:52:57130 http_transaction_factory_ = factory;
131 }
132
[email protected]b65ce0942009-03-16 20:13:33133 // Gets the ftp transaction factory for this context.
[email protected]ede96662011-07-14 12:34:18134 FtpTransactionFactory* ftp_transaction_factory() const {
[email protected]b65ce0942009-03-16 20:13:33135 return ftp_transaction_factory_;
136 }
[email protected]7461a402011-03-24 23:19:51137 void set_ftp_transaction_factory(FtpTransactionFactory* factory) {
[email protected]f6c21cb2011-02-16 19:45:41138 ftp_transaction_factory_ = factory;
139 }
[email protected]b65ce0942009-03-16 20:13:33140
[email protected]0651b812011-02-24 00:22:50141 void set_network_delegate(NetworkDelegate* network_delegate) {
[email protected]d05ef99c2011-02-01 21:38:16142 network_delegate_ = network_delegate;
143 }
[email protected]0651b812011-02-24 00:22:50144 NetworkDelegate* network_delegate() const { return network_delegate_; }
[email protected]d05ef99c2011-02-01 21:38:16145
[email protected]be6fca6c2010-01-30 21:48:57146 // Gets the cookie store for this context (may be null, in which case
147 // cookies are not stored).
[email protected]f6c21cb2011-02-16 19:45:41148 CookieStore* cookie_store() const { return cookie_store_.get(); }
[email protected]27a112c2011-01-06 04:19:30149 void set_cookie_store(CookieStore* cookie_store);
[email protected]2fb629202010-12-23 23:52:57150
[email protected]f6c21cb2011-02-16 19:45:41151 TransportSecurityState* transport_security_state() const {
152 return transport_security_state_;
153 }
154 void set_transport_security_state(
[email protected]7461a402011-03-24 23:19:51155 TransportSecurityState* state) {
[email protected]f6c21cb2011-02-16 19:45:41156 transport_security_state_ = state;
157 }
[email protected]a9cea7542009-05-20 04:30:23158
[email protected]515838c2009-01-15 06:43:48159 // Gets the FTP authentication cache for this context.
[email protected]ede96662011-07-14 12:34:18160 FtpAuthCache* ftp_auth_cache() const { return ftp_auth_cache_.get(); }
initial.commit586acc5fe2008-07-26 22:42:52161
initial.commit586acc5fe2008-07-26 22:42:52162 // Gets the value of 'Accept-Charset' header field.
163 const std::string& accept_charset() const { return accept_charset_; }
[email protected]f6c21cb2011-02-16 19:45:41164 void set_accept_charset(const std::string& accept_charset) {
165 accept_charset_ = accept_charset;
166 }
initial.commit586acc5fe2008-07-26 22:42:52167
168 // Gets the value of 'Accept-Language' header field.
169 const std::string& accept_language() const { return accept_language_; }
[email protected]f6c21cb2011-02-16 19:45:41170 void set_accept_language(const std::string& accept_language) {
171 accept_language_ = accept_language;
172 }
initial.commit586acc5fe2008-07-26 22:42:52173
[email protected]6f681a42009-01-27 22:28:54174 // 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]f1d81922010-07-31 17:47:09177 virtual const std::string& GetUserAgent(const GURL& url) const;
initial.commit586acc5fe2008-07-26 22:42:52178
[email protected]c9825a42009-05-01 22:51:50179 // 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]a8c1e7452011-05-14 06:17:07186 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.commit586acc5fe2008-07-26 22:42:52191 protected:
[email protected]6f681a42009-01-27 22:28:54192 friend class base::RefCountedThreadSafe<URLRequestContext>;
193
[email protected]9349cfb2010-08-31 18:00:53194 virtual ~URLRequestContext();
[email protected]6f681a42009-01-27 22:28:54195
[email protected]f6c21cb2011-02-16 19:45:41196 private:
[email protected]18590f22011-07-29 16:41:28197 base::WeakPtrFactory<URLRequestContext> weak_factory_;
198
[email protected]d9696672011-03-15 22:45:09199 // ---------------------------------------------------------------------------
200 // Important: When adding any new members below, consider whether they need to
201 // be added to CopyFrom.
202 // ---------------------------------------------------------------------------
203
[email protected]f6c21cb2011-02-16 19:45:41204 // Ownership for these members are not defined here. Clients should either
205 // provide storage elsewhere or have a subclass take ownership.
[email protected]27a112c2011-01-06 04:19:30206 NetLog* net_log_;
207 HostResolver* host_resolver_;
208 CertVerifier* cert_verifier_;
[email protected]feb79bcd2011-07-21 16:55:17209 OriginBoundCertService* origin_bound_cert_service_;
[email protected]27a112c2011-01-06 04:19:30210 DnsRRResolver* dnsrr_resolver_;
[email protected]f6c21cb2011-02-16 19:45:41211 DnsCertProvenanceChecker* dns_cert_checker_;
212 HttpAuthHandlerFactory* http_auth_handler_factory_;
[email protected]6104ea5d2011-04-27 21:37:12213 ProxyService* proxy_service_;
[email protected]27a112c2011-01-06 04:19:30214 scoped_refptr<SSLConfigService> ssl_config_service_;
[email protected]0651b812011-02-24 00:22:50215 NetworkDelegate* network_delegate_;
[email protected]27a112c2011-01-06 04:19:30216 scoped_refptr<CookieStore> cookie_store_;
[email protected]27a112c2011-01-06 04:19:30217 scoped_refptr<TransportSecurityState> transport_security_state_;
[email protected]ede96662011-07-14 12:34:18218 scoped_ptr<FtpAuthCache> ftp_auth_cache_;
initial.commit586acc5fe2008-07-26 22:42:52219 std::string accept_language_;
220 std::string accept_charset_;
[email protected]c9825a42009-05-01 22:51:50221 // 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]f6c21cb2011-02-16 19:45:41225 HttpTransactionFactory* http_transaction_factory_;
226 FtpTransactionFactory* ftp_transaction_factory_;
[email protected]a8c1e7452011-05-14 06:17:07227 const URLRequestJobFactory* job_factory_;
[email protected]70b92342010-10-12 05:54:06228
[email protected]d9696672011-03-15 22:45:09229 // ---------------------------------------------------------------------------
230 // Important: When adding any new members below, consider whether they need to
231 // be added to CopyFrom.
232 // ---------------------------------------------------------------------------
233
[email protected]6f681a42009-01-27 22:28:54234 DISALLOW_COPY_AND_ASSIGN(URLRequestContext);
initial.commit586acc5fe2008-07-26 22:42:52235};
236
[email protected]27a112c2011-01-06 04:19:30237} // namespace net
238
[email protected]43530b32008-08-04 22:21:34239#endif // NET_URL_REQUEST_URL_REQUEST_CONTEXT_H_