blob: cea9de5b1a657d2631d5a8e7f99a957500ef3a1d [file] [log] [blame]
[email protected]9c4eff22012-03-20 22:42:291// Copyright (c) 2012 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_
initial.commit586acc5fe2008-07-26 22:42:5212
[email protected]7c52ed92012-04-06 15:42:4013#include <set>
14
[email protected]3b63f8f42011-03-28 01:54:1515#include "base/memory/ref_counted.h"
[email protected]ede96662011-07-14 12:34:1816#include "base/memory/scoped_ptr.h"
[email protected]18590f22011-07-29 16:41:2817#include "base/memory/weak_ptr.h"
[email protected]c9177502011-01-01 04:48:4918#include "base/threading/non_thread_safe.h"
[email protected]172da1b2011-08-12 15:52:2619#include "net/base/net_export.h"
[email protected]9e743cd2010-03-16 07:03:5320#include "net/base/net_log.h"
[email protected]db36938c2009-08-19 21:48:4221#include "net/base/ssl_config_service.h"
[email protected]326e6792009-12-11 21:04:4222#include "net/base/transport_security_state.h"
[email protected]c2dad292012-09-07 21:27:3523#include "net/http/http_network_session.h"
[email protected]db96a882011-10-09 02:01:5424#include "net/http/http_server_properties.h"
[email protected]515838c2009-01-15 06:43:4825#include "net/ftp/ftp_auth_cache.h"
[email protected]8a26ff62012-08-24 21:49:2026#include "net/url_request/url_request.h"
initial.commit586acc5fe2008-07-26 22:42:5227
[email protected]8ac1a752008-07-31 19:40:3728namespace net {
[email protected]822581d2010-12-16 17:27:1529class CertVerifier;
[email protected]9349cfb2010-08-31 18:00:5330class CookieStore;
[email protected]b97d7702011-10-16 01:11:0731class FraudulentCertificateReporter;
[email protected]b65ce0942009-03-16 20:13:3332class FtpTransactionFactory;
[email protected]9349cfb2010-08-31 18:00:5333class HostResolver;
[email protected]fa55e192010-02-15 14:25:5034class HttpAuthHandlerFactory;
[email protected]b65ce0942009-03-16 20:13:3335class HttpTransactionFactory;
[email protected]0651b812011-02-24 00:22:5036class NetworkDelegate;
[email protected]9c4eff22012-03-20 22:42:2937class ServerBoundCertService;
[email protected]6104ea5d2011-04-27 21:37:1238class ProxyService;
[email protected]eaadd9052009-06-23 18:02:2339class URLRequest;
[email protected]a8c1e7452011-05-14 06:17:0740class URLRequestJobFactory;
[email protected]a73a2802012-05-02 19:20:1541class URLRequestThrottlerManager;
initial.commit586acc5fe2008-07-26 22:42:5242
[email protected]27a112c2011-01-06 04:19:3043// Subclass to provide application-specific context for URLRequest
[email protected]529623e2011-02-23 17:37:1644// instances. Note that URLRequestContext typically does not provide storage for
45// these member variables, since they may be shared. For the ones that aren't
46// shared, URLRequestContextStorage can be helpful in defining their storage.
[email protected]172da1b2011-08-12 15:52:2647class NET_EXPORT URLRequestContext
[email protected]ef2bf422012-05-11 03:27:0948 : NON_EXPORTED_BASE(public base::NonThreadSafe) {
initial.commit586acc5fe2008-07-26 22:42:5249 public:
[email protected]9349cfb2010-08-31 18:00:5350 URLRequestContext();
[email protected]ef2bf422012-05-11 03:27:0951 virtual ~URLRequestContext();
[email protected]18590f22011-07-29 16:41:2852
[email protected]d9696672011-03-15 22:45:0953 // Copies the state from |other| into this context.
[email protected]fa22a6f12012-05-11 17:19:5954 void CopyFrom(const URLRequestContext* other);
[email protected]d9696672011-03-15 22:45:0955
[email protected]c2dad292012-09-07 21:27:3556 // May return NULL if this context doesn't have an associated network session.
57 const HttpNetworkSession::Params* GetNetworkSessionParams() const;
58
[email protected]8a26ff62012-08-24 21:49:2059 URLRequest* CreateRequest(
60 const GURL& url, URLRequest::Delegate* delegate) const;
61
[email protected]27a112c2011-01-06 04:19:3062 NetLog* net_log() const {
[email protected]9e743cd2010-03-16 07:03:5363 return net_log_;
64 }
65
[email protected]27a112c2011-01-06 04:19:3066 void set_net_log(NetLog* net_log) {
[email protected]2fb629202010-12-23 23:52:5767 net_log_ = net_log;
68 }
69
[email protected]27a112c2011-01-06 04:19:3070 HostResolver* host_resolver() const {
[email protected]8a00f00a2009-06-12 00:49:3871 return host_resolver_;
72 }
73
[email protected]27a112c2011-01-06 04:19:3074 void set_host_resolver(HostResolver* host_resolver) {
[email protected]2fb629202010-12-23 23:52:5775 host_resolver_ = host_resolver;
76 }
77
[email protected]27a112c2011-01-06 04:19:3078 CertVerifier* cert_verifier() const {
[email protected]822581d2010-12-16 17:27:1579 return cert_verifier_;
80 }
81
[email protected]27a112c2011-01-06 04:19:3082 void set_cert_verifier(CertVerifier* cert_verifier) {
[email protected]2fb629202010-12-23 23:52:5783 cert_verifier_ = cert_verifier;
84 }
85
[email protected]9c4eff22012-03-20 22:42:2986 ServerBoundCertService* server_bound_cert_service() const {
87 return server_bound_cert_service_;
[email protected]feb79bcd2011-07-21 16:55:1788 }
[email protected]273e37d2011-08-11 01:49:1289
[email protected]9c4eff22012-03-20 22:42:2990 void set_server_bound_cert_service(
91 ServerBoundCertService* server_bound_cert_service) {
92 server_bound_cert_service_ = server_bound_cert_service;
[email protected]feb79bcd2011-07-21 16:55:1793 }
94
[email protected]b97d7702011-10-16 01:11:0795 FraudulentCertificateReporter* fraudulent_certificate_reporter() const {
96 return fraudulent_certificate_reporter_;
97 }
98 void set_fraudulent_certificate_reporter(
99 FraudulentCertificateReporter* fraudulent_certificate_reporter) {
100 fraudulent_certificate_reporter_ = fraudulent_certificate_reporter;
101 }
102
[email protected]63de95b2008-12-10 04:11:27103 // Get the proxy service for this context.
[email protected]f6c21cb2011-02-16 19:45:41104 ProxyService* proxy_service() const { return proxy_service_; }
[email protected]27a112c2011-01-06 04:19:30105 void set_proxy_service(ProxyService* proxy_service) {
[email protected]2fb629202010-12-23 23:52:57106 proxy_service_ = proxy_service;
107 }
108
[email protected]db36938c2009-08-19 21:48:42109 // Get the ssl config service for this context.
[email protected]f6c21cb2011-02-16 19:45:41110 SSLConfigService* ssl_config_service() const { return ssl_config_service_; }
[email protected]7461a402011-03-24 23:19:51111 void set_ssl_config_service(SSLConfigService* service) {
[email protected]f6c21cb2011-02-16 19:45:41112 ssl_config_service_ = service;
[email protected]db36938c2009-08-19 21:48:42113 }
114
[email protected]2fb629202010-12-23 23:52:57115 // Gets the HTTP Authentication Handler Factory for this context.
116 // The factory is only valid for the lifetime of this URLRequestContext
[email protected]ef2bf422012-05-11 03:27:09117 HttpAuthHandlerFactory* http_auth_handler_factory() const {
[email protected]2fb629202010-12-23 23:52:57118 return http_auth_handler_factory_;
119 }
[email protected]27a112c2011-01-06 04:19:30120 void set_http_auth_handler_factory(HttpAuthHandlerFactory* factory) {
[email protected]2fb629202010-12-23 23:52:57121 http_auth_handler_factory_ = factory;
122 }
123
initial.commit586acc5fe2008-07-26 22:42:52124 // Gets the http transaction factory for this context.
[email protected]27a112c2011-01-06 04:19:30125 HttpTransactionFactory* http_transaction_factory() const {
[email protected]db8f44c2008-12-13 04:52:01126 return http_transaction_factory_;
initial.commit586acc5fe2008-07-26 22:42:52127 }
[email protected]27a112c2011-01-06 04:19:30128 void set_http_transaction_factory(HttpTransactionFactory* factory) {
[email protected]2fb629202010-12-23 23:52:57129 http_transaction_factory_ = factory;
130 }
131
[email protected]b65ce0942009-03-16 20:13:33132 // Gets the ftp transaction factory for this context.
[email protected]ede96662011-07-14 12:34:18133 FtpTransactionFactory* ftp_transaction_factory() const {
[email protected]b65ce0942009-03-16 20:13:33134 return ftp_transaction_factory_;
135 }
[email protected]7461a402011-03-24 23:19:51136 void set_ftp_transaction_factory(FtpTransactionFactory* factory) {
[email protected]f6c21cb2011-02-16 19:45:41137 ftp_transaction_factory_ = factory;
138 }
[email protected]b65ce0942009-03-16 20:13:33139
[email protected]0651b812011-02-24 00:22:50140 void set_network_delegate(NetworkDelegate* network_delegate) {
[email protected]d05ef99c2011-02-01 21:38:16141 network_delegate_ = network_delegate;
142 }
[email protected]0651b812011-02-24 00:22:50143 NetworkDelegate* network_delegate() const { return network_delegate_; }
[email protected]d05ef99c2011-02-01 21:38:16144
[email protected]db96a882011-10-09 02:01:54145 void set_http_server_properties(
146 HttpServerProperties* http_server_properties) {
147 http_server_properties_ = http_server_properties;
148 }
149 HttpServerProperties* http_server_properties() const {
150 return http_server_properties_;
151 }
152
[email protected]be6fca6c2010-01-30 21:48:57153 // Gets the cookie store for this context (may be null, in which case
154 // cookies are not stored).
[email protected]f6c21cb2011-02-16 19:45:41155 CookieStore* cookie_store() const { return cookie_store_.get(); }
[email protected]27a112c2011-01-06 04:19:30156 void set_cookie_store(CookieStore* cookie_store);
[email protected]2fb629202010-12-23 23:52:57157
[email protected]f6c21cb2011-02-16 19:45:41158 TransportSecurityState* transport_security_state() const {
159 return transport_security_state_;
160 }
161 void set_transport_security_state(
[email protected]7461a402011-03-24 23:19:51162 TransportSecurityState* state) {
[email protected]f6c21cb2011-02-16 19:45:41163 transport_security_state_ = state;
164 }
[email protected]a9cea7542009-05-20 04:30:23165
[email protected]515838c2009-01-15 06:43:48166 // Gets the FTP authentication cache for this context.
[email protected]9bfe0ab2012-08-30 13:18:11167 FtpAuthCache* ftp_auth_cache() const {
168#if !defined(DISABLE_FTP_SUPPORT)
169 return ftp_auth_cache_.get();
170#else
171 return NULL;
172#endif
173 }
initial.commit586acc5fe2008-07-26 22:42:52174
initial.commit586acc5fe2008-07-26 22:42:52175 // Gets the value of 'Accept-Charset' header field.
176 const std::string& accept_charset() const { return accept_charset_; }
[email protected]f6c21cb2011-02-16 19:45:41177 void set_accept_charset(const std::string& accept_charset) {
178 accept_charset_ = accept_charset;
179 }
initial.commit586acc5fe2008-07-26 22:42:52180
181 // Gets the value of 'Accept-Language' header field.
182 const std::string& accept_language() const { return accept_language_; }
[email protected]f6c21cb2011-02-16 19:45:41183 void set_accept_language(const std::string& accept_language) {
184 accept_language_ = accept_language;
185 }
initial.commit586acc5fe2008-07-26 22:42:52186
[email protected]6f681a42009-01-27 22:28:54187 // Gets the UA string to use for the given URL. Pass an invalid URL (such as
188 // GURL()) to get the default UA string. Subclasses should override this
189 // method to provide a UA string.
[email protected]f1d81922010-07-31 17:47:09190 virtual const std::string& GetUserAgent(const GURL& url) const;
initial.commit586acc5fe2008-07-26 22:42:52191
[email protected]c9825a42009-05-01 22:51:50192 // In general, referrer_charset is not known when URLRequestContext is
193 // constructed. So, we need a setter.
194 const std::string& referrer_charset() const { return referrer_charset_; }
195 void set_referrer_charset(const std::string& charset) {
196 referrer_charset_ = charset;
197 }
198
[email protected]a8c1e7452011-05-14 06:17:07199 const URLRequestJobFactory* job_factory() const { return job_factory_; }
200 void set_job_factory(const URLRequestJobFactory* job_factory) {
201 job_factory_ = job_factory;
202 }
203
[email protected]a73a2802012-05-02 19:20:15204 // May be NULL.
205 URLRequestThrottlerManager* throttler_manager() const {
206 return throttler_manager_;
207 }
208 void set_throttler_manager(URLRequestThrottlerManager* throttler_manager) {
209 throttler_manager_ = throttler_manager;
210 }
211
[email protected]7c52ed92012-04-06 15:42:40212 // Gets the URLRequest objects that hold a reference to this
213 // URLRequestContext.
214 std::set<const URLRequest*>* url_requests() const {
215 return url_requests_.get();
216 }
217
[email protected]1e714bba2012-04-10 17:01:05218 void AssertNoURLRequests() const;
219
[email protected]f6c21cb2011-02-16 19:45:41220 private:
[email protected]d9696672011-03-15 22:45:09221 // ---------------------------------------------------------------------------
222 // Important: When adding any new members below, consider whether they need to
223 // be added to CopyFrom.
224 // ---------------------------------------------------------------------------
225
[email protected]f6c21cb2011-02-16 19:45:41226 // Ownership for these members are not defined here. Clients should either
227 // provide storage elsewhere or have a subclass take ownership.
[email protected]27a112c2011-01-06 04:19:30228 NetLog* net_log_;
229 HostResolver* host_resolver_;
230 CertVerifier* cert_verifier_;
[email protected]9c4eff22012-03-20 22:42:29231 ServerBoundCertService* server_bound_cert_service_;
[email protected]b97d7702011-10-16 01:11:07232 FraudulentCertificateReporter* fraudulent_certificate_reporter_;
[email protected]f6c21cb2011-02-16 19:45:41233 HttpAuthHandlerFactory* http_auth_handler_factory_;
[email protected]6104ea5d2011-04-27 21:37:12234 ProxyService* proxy_service_;
[email protected]27a112c2011-01-06 04:19:30235 scoped_refptr<SSLConfigService> ssl_config_service_;
[email protected]0651b812011-02-24 00:22:50236 NetworkDelegate* network_delegate_;
[email protected]db96a882011-10-09 02:01:54237 HttpServerProperties* http_server_properties_;
[email protected]27a112c2011-01-06 04:19:30238 scoped_refptr<CookieStore> cookie_store_;
[email protected]edbc4f92011-09-27 21:04:49239 TransportSecurityState* transport_security_state_;
[email protected]9bfe0ab2012-08-30 13:18:11240#if !defined(DISABLE_FTP_SUPPORT)
[email protected]ede96662011-07-14 12:34:18241 scoped_ptr<FtpAuthCache> ftp_auth_cache_;
[email protected]9bfe0ab2012-08-30 13:18:11242#endif
initial.commit586acc5fe2008-07-26 22:42:52243 std::string accept_language_;
244 std::string accept_charset_;
[email protected]c9825a42009-05-01 22:51:50245 // The charset of the referrer where this request comes from. It's not
246 // used in communication with a server but is used to construct a suggested
247 // filename for file download.
248 std::string referrer_charset_;
[email protected]f6c21cb2011-02-16 19:45:41249 HttpTransactionFactory* http_transaction_factory_;
250 FtpTransactionFactory* ftp_transaction_factory_;
[email protected]a8c1e7452011-05-14 06:17:07251 const URLRequestJobFactory* job_factory_;
[email protected]a73a2802012-05-02 19:20:15252 URLRequestThrottlerManager* throttler_manager_;
[email protected]70b92342010-10-12 05:54:06253
[email protected]d9696672011-03-15 22:45:09254 // ---------------------------------------------------------------------------
255 // Important: When adding any new members below, consider whether they need to
256 // be added to CopyFrom.
257 // ---------------------------------------------------------------------------
258
[email protected]7c52ed92012-04-06 15:42:40259 scoped_ptr<std::set<const URLRequest*> > url_requests_;
260
[email protected]6f681a42009-01-27 22:28:54261 DISALLOW_COPY_AND_ASSIGN(URLRequestContext);
initial.commit586acc5fe2008-07-26 22:42:52262};
263
[email protected]27a112c2011-01-06 04:19:30264} // namespace net
265
[email protected]43530b32008-08-04 22:21:34266#endif // NET_URL_REQUEST_URL_REQUEST_CONTEXT_H_