Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(690)

Side by Side Diff: net/url_request/url_request_context.h

Issue 10918279: Provide mutable members of UrlRequestContext via pure-virtual interface (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // This class represents contextual information (cookies, cache, etc.) 5 // This class represents contextual information (cookies, cache, etc.)
6 // that's useful when processing resource requests. 6 // that's useful when processing resource requests.
7 // The class is reference-counted so that it can be cleaned up after any 7 // The class is reference-counted so that it can be cleaned up after any
8 // requests that are using it have been completed. 8 // requests that are using it have been completed.
9 9
10 #ifndef NET_URL_REQUEST_URL_REQUEST_CONTEXT_H_ 10 #ifndef NET_URL_REQUEST_URL_REQUEST_CONTEXT_H_
(...skipping 22 matching lines...) Expand all
33 class HostResolver; 33 class HostResolver;
34 class HttpAuthHandlerFactory; 34 class HttpAuthHandlerFactory;
35 class HttpTransactionFactory; 35 class HttpTransactionFactory;
36 class NetworkDelegate; 36 class NetworkDelegate;
37 class ServerBoundCertService; 37 class ServerBoundCertService;
38 class ProxyService; 38 class ProxyService;
39 class URLRequest; 39 class URLRequest;
40 class URLRequestJobFactory; 40 class URLRequestJobFactory;
41 class URLRequestThrottlerManager; 41 class URLRequestThrottlerManager;
42 42
43 // A pure-virtual interface that provides the HTTP Accept-Language,
44 // Accept-Charset and User-Agent header values. An instance of an
45 // implementation of this interface can be used by calling
46 // |URLRequestContext::set_http_user_agent_settings()|.
47 class NET_EXPORT HttpUserAgentSettings {
erikwright (departed) 2012/09/21 15:06:33 Move to http_user_agent_settings.h
48 public:
49 // Gets the value of 'Accept-Language' header field.
50 virtual const std::string& GetAcceptLanguage() = 0;
51 // Gets the value of 'Accept-Charset' header field.
52 virtual const std::string& GetAcceptCharset() = 0;
53 // Gets the UA string to use for the given URL. Pass an invalid URL (such as
erikwright (departed) 2012/09/21 15:06:33 "Pass an invalid URL (such as GURL())" -> Pass an
54 // GURL()) to get the default UA string.
55 virtual const std::string& GetUserAgent(const GURL& url) = 0;
56
57 virtual ~HttpUserAgentSettings() {}
58
59 protected:
60 HttpUserAgentSettings() {}
erikwright (departed) 2012/09/21 15:06:33 This can be public (no-one can call it because of
61
62 private:
63 DISALLOW_COPY_AND_ASSIGN(HttpUserAgentSettings);
erikwright (departed) 2012/09/21 15:06:33 This can be omitted on pure-virtual classes becaus
64 };
65
66 // A partial implementation of |HttpUserAgentSettings| that always provides
67 // the same constant values for the HTTP Accept-Language and Accept-Charset
68 // headers. Implementors can inherit from this class and implement
69 // |GetUserAgent()|.
70 class NET_EXPORT ConstHttpAcceptLanguageAndCharset
erikwright (departed) 2012/09/21 15:06:33 move to separate file.
71 : public HttpUserAgentSettings {
72 public:
73 virtual const std::string& GetAcceptLanguage() OVERRIDE;
74 virtual const std::string& GetAcceptCharset() OVERRIDE;
75
76 protected:
77 ConstHttpAcceptLanguageAndCharset(const std::string& accept_language,
78 const std::string& accept_charset);
79 virtual ~ConstHttpAcceptLanguageAndCharset() {}
80
81 private:
82 const std::string accept_language_;
83 const std::string accept_charset_;
84
85 DISALLOW_COPY_AND_ASSIGN(ConstHttpAcceptLanguageAndCharset);
86 };
87
88 // An implementation of |HttpUserAgentSettings| that always provides the
89 // same constant values for the HTTP Accept-Language, Accept-Charset, and
90 // User-Agent headers.
91 class NET_EXPORT ConstHttpUserAgentSettings
erikwright (departed) 2012/09/21 15:06:33 move to separate file.
92 : public ConstHttpAcceptLanguageAndCharset {
93 public:
94 ConstHttpUserAgentSettings(const std::string& accept_language,
95 const std::string& accept_charset,
96 const std::string& user_agent);
97 virtual ~ConstHttpUserAgentSettings() {}
98
99 virtual const std::string& GetUserAgent(const GURL& url) OVERRIDE;
100
101 private:
102 const std::string user_agent_;
103
104 DISALLOW_COPY_AND_ASSIGN(ConstHttpUserAgentSettings);
105 };
106
107
43 // Subclass to provide application-specific context for URLRequest 108 // Subclass to provide application-specific context for URLRequest
44 // instances. Note that URLRequestContext typically does not provide storage for 109 // 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 110 // these member variables, since they may be shared. For the ones that aren't
46 // shared, URLRequestContextStorage can be helpful in defining their storage. 111 // shared, URLRequestContextStorage can be helpful in defining their storage.
47 class NET_EXPORT URLRequestContext 112 class NET_EXPORT URLRequestContext
48 : NON_EXPORTED_BASE(public base::NonThreadSafe) { 113 : NON_EXPORTED_BASE(public base::NonThreadSafe) {
49 public: 114 public:
50 URLRequestContext(); 115 URLRequestContext();
51 virtual ~URLRequestContext(); 116 virtual ~URLRequestContext();
52 117
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 // Gets the FTP authentication cache for this context. 231 // Gets the FTP authentication cache for this context.
167 FtpAuthCache* ftp_auth_cache() const { 232 FtpAuthCache* ftp_auth_cache() const {
168 #if !defined(DISABLE_FTP_SUPPORT) 233 #if !defined(DISABLE_FTP_SUPPORT)
169 return ftp_auth_cache_.get(); 234 return ftp_auth_cache_.get();
170 #else 235 #else
171 return NULL; 236 return NULL;
172 #endif 237 #endif
173 } 238 }
174 239
175 // Gets the value of 'Accept-Charset' header field. 240 // Gets the value of 'Accept-Charset' header field.
176 const std::string& accept_charset() const { return accept_charset_; } 241 const std::string& accept_charset() const;
erikwright (departed) 2012/09/21 15:06:33 Group these together with a single "Legacy accesso
177 void set_accept_charset(const std::string& accept_charset) {
178 accept_charset_ = accept_charset;
179 }
180 242
181 // Gets the value of 'Accept-Language' header field. 243 // Gets the value of 'Accept-Language' header field.
182 const std::string& accept_language() const { return accept_language_; } 244 const std::string& accept_language() const;
183 void set_accept_language(const std::string& accept_language) {
184 accept_language_ = accept_language;
185 }
186 245
187 // Gets the UA string to use for the given URL. Pass an invalid URL (such as 246 // 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 247 // GURL()) to get the default UA string.
189 // method to provide a UA string. 248 const std::string& GetUserAgent(const GURL& url) const;
190 virtual const std::string& GetUserAgent(const GURL& url) const;
191 249
192 // In general, referrer_charset is not known when URLRequestContext is 250 // In general, referrer_charset is not known when URLRequestContext is
193 // constructed. So, we need a setter. 251 // constructed. So, we need a setter.
194 const std::string& referrer_charset() const { return referrer_charset_; } 252 const std::string& referrer_charset() const { return referrer_charset_; }
195 void set_referrer_charset(const std::string& charset) { 253 void set_referrer_charset(const std::string& charset) {
196 referrer_charset_ = charset; 254 referrer_charset_ = charset;
197 } 255 }
198 256
199 const URLRequestJobFactory* job_factory() const { return job_factory_; } 257 const URLRequestJobFactory* job_factory() const { return job_factory_; }
200 void set_job_factory(const URLRequestJobFactory* job_factory) { 258 void set_job_factory(const URLRequestJobFactory* job_factory) {
201 job_factory_ = job_factory; 259 job_factory_ = job_factory;
202 } 260 }
203 261
204 // May be NULL. 262 // May be NULL.
205 URLRequestThrottlerManager* throttler_manager() const { 263 URLRequestThrottlerManager* throttler_manager() const {
206 return throttler_manager_; 264 return throttler_manager_;
207 } 265 }
208 void set_throttler_manager(URLRequestThrottlerManager* throttler_manager) { 266 void set_throttler_manager(URLRequestThrottlerManager* throttler_manager) {
209 throttler_manager_ = throttler_manager; 267 throttler_manager_ = throttler_manager;
210 } 268 }
211 269
212 // Gets the URLRequest objects that hold a reference to this 270 // Gets the URLRequest objects that hold a reference to this
213 // URLRequestContext. 271 // URLRequestContext.
214 std::set<const URLRequest*>* url_requests() const { 272 std::set<const URLRequest*>* url_requests() const {
215 return url_requests_.get(); 273 return url_requests_.get();
216 } 274 }
217 275
218 void AssertNoURLRequests() const; 276 void AssertNoURLRequests() const;
219 277
278 // Set the underlying |HttpUserAgentSettings| implementation that provides
279 // the HTTP Accept-Language, Accept-Charset and User-Agent header values that
erikwright (departed) 2012/09/21 15:06:33 Clients should actually access HttpUserAgentSettin
280 // are returned by |accept_language|, |accept_charset|, and |GetUserAgent|.
281 // Note: This implementation is not owned by |URLRequestContext|, so it is
erikwright (departed) 2012/09/21 15:06:33 The "Note" is not required since it's the same as
282 // the responsibility of the caller of |set_http_user_agent_settings| to
283 // ensure the implementation outlives the use of this |URLRequestContext|.
284 void set_http_user_agent_settings(
285 HttpUserAgentSettings* http_user_agent_settings) {
286 http_user_agent_settings_ = http_user_agent_settings;
287 }
288
220 private: 289 private:
221 // --------------------------------------------------------------------------- 290 // ---------------------------------------------------------------------------
222 // Important: When adding any new members below, consider whether they need to 291 // Important: When adding any new members below, consider whether they need to
223 // be added to CopyFrom. 292 // be added to CopyFrom.
224 // --------------------------------------------------------------------------- 293 // ---------------------------------------------------------------------------
225 294
226 // Ownership for these members are not defined here. Clients should either 295 // Ownership for these members are not defined here. Clients should either
227 // provide storage elsewhere or have a subclass take ownership. 296 // provide storage elsewhere or have a subclass take ownership.
228 NetLog* net_log_; 297 NetLog* net_log_;
229 HostResolver* host_resolver_; 298 HostResolver* host_resolver_;
230 CertVerifier* cert_verifier_; 299 CertVerifier* cert_verifier_;
231 ServerBoundCertService* server_bound_cert_service_; 300 ServerBoundCertService* server_bound_cert_service_;
232 FraudulentCertificateReporter* fraudulent_certificate_reporter_; 301 FraudulentCertificateReporter* fraudulent_certificate_reporter_;
233 HttpAuthHandlerFactory* http_auth_handler_factory_; 302 HttpAuthHandlerFactory* http_auth_handler_factory_;
234 ProxyService* proxy_service_; 303 ProxyService* proxy_service_;
235 scoped_refptr<SSLConfigService> ssl_config_service_; 304 scoped_refptr<SSLConfigService> ssl_config_service_;
236 NetworkDelegate* network_delegate_; 305 NetworkDelegate* network_delegate_;
237 HttpServerProperties* http_server_properties_; 306 HttpServerProperties* http_server_properties_;
238 scoped_refptr<CookieStore> cookie_store_; 307 scoped_refptr<CookieStore> cookie_store_;
239 TransportSecurityState* transport_security_state_; 308 TransportSecurityState* transport_security_state_;
240 #if !defined(DISABLE_FTP_SUPPORT) 309 #if !defined(DISABLE_FTP_SUPPORT)
241 scoped_ptr<FtpAuthCache> ftp_auth_cache_; 310 scoped_ptr<FtpAuthCache> ftp_auth_cache_;
242 #endif 311 #endif
243 std::string accept_language_;
244 std::string accept_charset_;
245 // The charset of the referrer where this request comes from. It's not 312 // 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 313 // used in communication with a server but is used to construct a suggested
247 // filename for file download. 314 // filename for file download.
248 std::string referrer_charset_; 315 std::string referrer_charset_;
249 HttpTransactionFactory* http_transaction_factory_; 316 HttpTransactionFactory* http_transaction_factory_;
250 FtpTransactionFactory* ftp_transaction_factory_; 317 FtpTransactionFactory* ftp_transaction_factory_;
251 const URLRequestJobFactory* job_factory_; 318 const URLRequestJobFactory* job_factory_;
252 URLRequestThrottlerManager* throttler_manager_; 319 URLRequestThrottlerManager* throttler_manager_;
320 HttpUserAgentSettings* http_user_agent_settings_;
253 321
254 // --------------------------------------------------------------------------- 322 // ---------------------------------------------------------------------------
255 // Important: When adding any new members below, consider whether they need to 323 // Important: When adding any new members below, consider whether they need to
256 // be added to CopyFrom. 324 // be added to CopyFrom.
257 // --------------------------------------------------------------------------- 325 // ---------------------------------------------------------------------------
258 326
259 scoped_ptr<std::set<const URLRequest*> > url_requests_; 327 scoped_ptr<std::set<const URLRequest*> > url_requests_;
260 328
261 DISALLOW_COPY_AND_ASSIGN(URLRequestContext); 329 DISALLOW_COPY_AND_ASSIGN(URLRequestContext);
262 }; 330 };
263 331
264 } // namespace net 332 } // namespace net
265 333
266 #endif // NET_URL_REQUEST_URL_REQUEST_CONTEXT_H_ 334 #endif // NET_URL_REQUEST_URL_REQUEST_CONTEXT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698