blob: fca0ea593086a453f9b1d4edf96472537914e63e [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]eb2b46a2011-05-20 19:01:4916#include "net/base/net_api.h"
[email protected]9e743cd2010-03-16 07:03:5317#include "net/base/net_log.h"
[email protected]db36938c2009-08-19 21:48:4218#include "net/base/ssl_config_service.h"
[email protected]326e6792009-12-11 21:04:4219#include "net/base/transport_security_state.h"
[email protected]515838c2009-01-15 06:43:4820#include "net/ftp/ftp_auth_cache.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]9349cfb2010-08-31 18:00:5325class CookieStore;
[email protected]345c613b2010-11-22 19:33:1826class DnsCertProvenanceChecker;
[email protected]2db580532010-10-08 14:32:3727class DnsRRResolver;
[email protected]b65ce0942009-03-16 20:13:3328class FtpTransactionFactory;
[email protected]9349cfb2010-08-31 18:00:5329class HostResolver;
[email protected]fa55e192010-02-15 14:25:5030class HttpAuthHandlerFactory;
[email protected]b65ce0942009-03-16 20:13:3331class HttpTransactionFactory;
[email protected]0651b812011-02-24 00:22:5032class NetworkDelegate;
[email protected]6104ea5d2011-04-27 21:37:1233class ProxyService;
[email protected]9349cfb2010-08-31 18:00:5334class SSLConfigService;
[email protected]eaadd9052009-06-23 18:02:2335class URLRequest;
[email protected]a8c1e7452011-05-14 06:17:0736class URLRequestJobFactory;
initial.commit586acc5fe2008-07-26 22:42:5237
[email protected]27a112c2011-01-06 04:19:3038// Subclass to provide application-specific context for URLRequest
[email protected]529623e2011-02-23 17:37:1639// instances. Note that URLRequestContext typically does not provide storage for
40// these member variables, since they may be shared. For the ones that aren't
41// shared, URLRequestContextStorage can be helpful in defining their storage.
[email protected]eb2b46a2011-05-20 19:01:4942class NET_API URLRequestContext
[email protected]fe57c8c2010-07-12 18:29:4343 : public base::RefCountedThreadSafe<URLRequestContext>,
[email protected]eb2b46a2011-05-20 19:01:4944 NON_EXPORTED_BASE(public base::NonThreadSafe) {
initial.commit586acc5fe2008-07-26 22:42:5245 public:
[email protected]9349cfb2010-08-31 18:00:5346 URLRequestContext();
[email protected]db8f44c2008-12-13 04:52:0147
[email protected]d9696672011-03-15 22:45:0948 // Copies the state from |other| into this context.
49 void CopyFrom(URLRequestContext* other);
50
[email protected]27a112c2011-01-06 04:19:3051 NetLog* net_log() const {
[email protected]9e743cd2010-03-16 07:03:5352 return net_log_;
53 }
54
[email protected]27a112c2011-01-06 04:19:3055 void set_net_log(NetLog* net_log) {
[email protected]2fb629202010-12-23 23:52:5756 net_log_ = net_log;
57 }
58
[email protected]27a112c2011-01-06 04:19:3059 HostResolver* host_resolver() const {
[email protected]8a00f00a2009-06-12 00:49:3860 return host_resolver_;
61 }
62
[email protected]27a112c2011-01-06 04:19:3063 void set_host_resolver(HostResolver* host_resolver) {
[email protected]2fb629202010-12-23 23:52:5764 host_resolver_ = host_resolver;
65 }
66
[email protected]27a112c2011-01-06 04:19:3067 CertVerifier* cert_verifier() const {
[email protected]822581d2010-12-16 17:27:1568 return cert_verifier_;
69 }
70
[email protected]27a112c2011-01-06 04:19:3071 void set_cert_verifier(CertVerifier* cert_verifier) {
[email protected]2fb629202010-12-23 23:52:5772 cert_verifier_ = cert_verifier;
73 }
74
[email protected]27a112c2011-01-06 04:19:3075 DnsRRResolver* dnsrr_resolver() const {
[email protected]2db580532010-10-08 14:32:3776 return dnsrr_resolver_;
77 }
78
[email protected]27a112c2011-01-06 04:19:3079 void set_dnsrr_resolver(DnsRRResolver* dnsrr_resolver) {
[email protected]2fb629202010-12-23 23:52:5780 dnsrr_resolver_ = dnsrr_resolver;
81 }
82
[email protected]27a112c2011-01-06 04:19:3083 DnsCertProvenanceChecker* dns_cert_checker() const {
[email protected]f6c21cb2011-02-16 19:45:4184 return dns_cert_checker_;
85 }
[email protected]7461a402011-03-24 23:19:5186 void set_dns_cert_checker(DnsCertProvenanceChecker* dns_cert_checker) {
[email protected]f6c21cb2011-02-16 19:45:4187 dns_cert_checker_ = dns_cert_checker;
[email protected]345c613b2010-11-22 19:33:1888 }
89
[email protected]63de95b2008-12-10 04:11:2790 // Get the proxy service for this context.
[email protected]f6c21cb2011-02-16 19:45:4191 ProxyService* proxy_service() const { return proxy_service_; }
[email protected]27a112c2011-01-06 04:19:3092 void set_proxy_service(ProxyService* proxy_service) {
[email protected]2fb629202010-12-23 23:52:5793 proxy_service_ = proxy_service;
94 }
95
[email protected]db36938c2009-08-19 21:48:4296 // Get the ssl config service for this context.
[email protected]f6c21cb2011-02-16 19:45:4197 SSLConfigService* ssl_config_service() const { return ssl_config_service_; }
[email protected]7461a402011-03-24 23:19:5198 void set_ssl_config_service(SSLConfigService* service) {
[email protected]f6c21cb2011-02-16 19:45:4199 ssl_config_service_ = service;
[email protected]db36938c2009-08-19 21:48:42100 }
101
[email protected]2fb629202010-12-23 23:52:57102 // Gets the HTTP Authentication Handler Factory for this context.
103 // The factory is only valid for the lifetime of this URLRequestContext
[email protected]27a112c2011-01-06 04:19:30104 HttpAuthHandlerFactory* http_auth_handler_factory() {
[email protected]2fb629202010-12-23 23:52:57105 return http_auth_handler_factory_;
106 }
[email protected]27a112c2011-01-06 04:19:30107 void set_http_auth_handler_factory(HttpAuthHandlerFactory* factory) {
[email protected]2fb629202010-12-23 23:52:57108 http_auth_handler_factory_ = factory;
109 }
110
initial.commit586acc5fe2008-07-26 22:42:52111 // Gets the http transaction factory for this context.
[email protected]27a112c2011-01-06 04:19:30112 HttpTransactionFactory* http_transaction_factory() const {
[email protected]db8f44c2008-12-13 04:52:01113 return http_transaction_factory_;
initial.commit586acc5fe2008-07-26 22:42:52114 }
[email protected]27a112c2011-01-06 04:19:30115 void set_http_transaction_factory(HttpTransactionFactory* factory) {
[email protected]2fb629202010-12-23 23:52:57116 http_transaction_factory_ = factory;
117 }
118
[email protected]b65ce0942009-03-16 20:13:33119 // Gets the ftp transaction factory for this context.
[email protected]27a112c2011-01-06 04:19:30120 FtpTransactionFactory* ftp_transaction_factory() {
[email protected]b65ce0942009-03-16 20:13:33121 return ftp_transaction_factory_;
122 }
[email protected]7461a402011-03-24 23:19:51123 void set_ftp_transaction_factory(FtpTransactionFactory* factory) {
[email protected]f6c21cb2011-02-16 19:45:41124 ftp_transaction_factory_ = factory;
125 }
[email protected]b65ce0942009-03-16 20:13:33126
[email protected]0651b812011-02-24 00:22:50127 void set_network_delegate(NetworkDelegate* network_delegate) {
[email protected]d05ef99c2011-02-01 21:38:16128 network_delegate_ = network_delegate;
129 }
[email protected]0651b812011-02-24 00:22:50130 NetworkDelegate* network_delegate() const { return network_delegate_; }
[email protected]d05ef99c2011-02-01 21:38:16131
[email protected]be6fca6c2010-01-30 21:48:57132 // Gets the cookie store for this context (may be null, in which case
133 // cookies are not stored).
[email protected]f6c21cb2011-02-16 19:45:41134 CookieStore* cookie_store() const { return cookie_store_.get(); }
[email protected]27a112c2011-01-06 04:19:30135 void set_cookie_store(CookieStore* cookie_store);
[email protected]2fb629202010-12-23 23:52:57136
[email protected]f6c21cb2011-02-16 19:45:41137 TransportSecurityState* transport_security_state() const {
138 return transport_security_state_;
139 }
140 void set_transport_security_state(
[email protected]7461a402011-03-24 23:19:51141 TransportSecurityState* state) {
[email protected]f6c21cb2011-02-16 19:45:41142 transport_security_state_ = state;
143 }
[email protected]a9cea7542009-05-20 04:30:23144
[email protected]515838c2009-01-15 06:43:48145 // Gets the FTP authentication cache for this context.
[email protected]27a112c2011-01-06 04:19:30146 FtpAuthCache* ftp_auth_cache() { return &ftp_auth_cache_; }
initial.commit586acc5fe2008-07-26 22:42:52147
initial.commit586acc5fe2008-07-26 22:42:52148 // Gets the value of 'Accept-Charset' header field.
149 const std::string& accept_charset() const { return accept_charset_; }
[email protected]f6c21cb2011-02-16 19:45:41150 void set_accept_charset(const std::string& accept_charset) {
151 accept_charset_ = accept_charset;
152 }
initial.commit586acc5fe2008-07-26 22:42:52153
154 // Gets the value of 'Accept-Language' header field.
155 const std::string& accept_language() const { return accept_language_; }
[email protected]f6c21cb2011-02-16 19:45:41156 void set_accept_language(const std::string& accept_language) {
157 accept_language_ = accept_language;
158 }
initial.commit586acc5fe2008-07-26 22:42:52159
[email protected]6f681a42009-01-27 22:28:54160 // Gets the UA string to use for the given URL. Pass an invalid URL (such as
161 // GURL()) to get the default UA string. Subclasses should override this
162 // method to provide a UA string.
[email protected]f1d81922010-07-31 17:47:09163 virtual const std::string& GetUserAgent(const GURL& url) const;
initial.commit586acc5fe2008-07-26 22:42:52164
[email protected]c9825a42009-05-01 22:51:50165 // In general, referrer_charset is not known when URLRequestContext is
166 // constructed. So, we need a setter.
167 const std::string& referrer_charset() const { return referrer_charset_; }
168 void set_referrer_charset(const std::string& charset) {
169 referrer_charset_ = charset;
170 }
171
[email protected]a8c1e7452011-05-14 06:17:07172 const URLRequestJobFactory* job_factory() const { return job_factory_; }
173 void set_job_factory(const URLRequestJobFactory* job_factory) {
174 job_factory_ = job_factory;
175 }
176
initial.commit586acc5fe2008-07-26 22:42:52177 protected:
[email protected]6f681a42009-01-27 22:28:54178 friend class base::RefCountedThreadSafe<URLRequestContext>;
179
[email protected]9349cfb2010-08-31 18:00:53180 virtual ~URLRequestContext();
[email protected]6f681a42009-01-27 22:28:54181
[email protected]f6c21cb2011-02-16 19:45:41182 private:
[email protected]d9696672011-03-15 22:45:09183 // ---------------------------------------------------------------------------
184 // Important: When adding any new members below, consider whether they need to
185 // be added to CopyFrom.
186 // ---------------------------------------------------------------------------
187
[email protected]f6c21cb2011-02-16 19:45:41188 // Ownership for these members are not defined here. Clients should either
189 // provide storage elsewhere or have a subclass take ownership.
[email protected]27a112c2011-01-06 04:19:30190 NetLog* net_log_;
191 HostResolver* host_resolver_;
192 CertVerifier* cert_verifier_;
193 DnsRRResolver* dnsrr_resolver_;
[email protected]f6c21cb2011-02-16 19:45:41194 DnsCertProvenanceChecker* dns_cert_checker_;
195 HttpAuthHandlerFactory* http_auth_handler_factory_;
[email protected]6104ea5d2011-04-27 21:37:12196 ProxyService* proxy_service_;
[email protected]27a112c2011-01-06 04:19:30197 scoped_refptr<SSLConfigService> ssl_config_service_;
[email protected]0651b812011-02-24 00:22:50198 NetworkDelegate* network_delegate_;
[email protected]27a112c2011-01-06 04:19:30199 scoped_refptr<CookieStore> cookie_store_;
[email protected]27a112c2011-01-06 04:19:30200 scoped_refptr<TransportSecurityState> transport_security_state_;
201 FtpAuthCache ftp_auth_cache_;
initial.commit586acc5fe2008-07-26 22:42:52202 std::string accept_language_;
203 std::string accept_charset_;
[email protected]c9825a42009-05-01 22:51:50204 // The charset of the referrer where this request comes from. It's not
205 // used in communication with a server but is used to construct a suggested
206 // filename for file download.
207 std::string referrer_charset_;
[email protected]f6c21cb2011-02-16 19:45:41208 HttpTransactionFactory* http_transaction_factory_;
209 FtpTransactionFactory* ftp_transaction_factory_;
[email protected]a8c1e7452011-05-14 06:17:07210 const URLRequestJobFactory* job_factory_;
[email protected]70b92342010-10-12 05:54:06211
[email protected]d9696672011-03-15 22:45:09212 // ---------------------------------------------------------------------------
213 // Important: When adding any new members below, consider whether they need to
214 // be added to CopyFrom.
215 // ---------------------------------------------------------------------------
216
[email protected]6f681a42009-01-27 22:28:54217 DISALLOW_COPY_AND_ASSIGN(URLRequestContext);
initial.commit586acc5fe2008-07-26 22:42:52218};
219
[email protected]27a112c2011-01-06 04:19:30220} // namespace net
221
[email protected]43530b32008-08-04 22:21:34222#endif // NET_URL_REQUEST_URL_REQUEST_CONTEXT_H_