Chromium Code Reviews| Index: net/url_request/url_request_context.h |
| diff --git a/net/url_request/url_request_context.h b/net/url_request/url_request_context.h |
| index cea9de5b1a657d2631d5a8e7f99a957500ef3a1d..3a7d69802536951eb6ad6185c5c63f34e19b3bbb 100644 |
| --- a/net/url_request/url_request_context.h |
| +++ b/net/url_request/url_request_context.h |
| @@ -40,6 +40,71 @@ class URLRequest; |
| class URLRequestJobFactory; |
| class URLRequestThrottlerManager; |
| +// A pure-virtual interface that provides the HTTP Accept-Language, |
| +// Accept-Charset and User-Agent header values. An instance of an |
| +// implementation of this interface can be used by calling |
| +// |URLRequestContext::set_http_user_agent_settings()|. |
| +class NET_EXPORT HttpUserAgentSettings { |
|
erikwright (departed)
2012/09/21 15:06:33
Move to http_user_agent_settings.h
|
| + public: |
| + // Gets the value of 'Accept-Language' header field. |
| + virtual const std::string& GetAcceptLanguage() = 0; |
| + // Gets the value of 'Accept-Charset' header field. |
| + virtual const std::string& GetAcceptCharset() = 0; |
| + // 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
|
| + // GURL()) to get the default UA string. |
| + virtual const std::string& GetUserAgent(const GURL& url) = 0; |
| + |
| + virtual ~HttpUserAgentSettings() {} |
| + |
| + protected: |
| + HttpUserAgentSettings() {} |
|
erikwright (departed)
2012/09/21 15:06:33
This can be public (no-one can call it because of
|
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(HttpUserAgentSettings); |
|
erikwright (departed)
2012/09/21 15:06:33
This can be omitted on pure-virtual classes becaus
|
| +}; |
| + |
| +// A partial implementation of |HttpUserAgentSettings| that always provides |
| +// the same constant values for the HTTP Accept-Language and Accept-Charset |
| +// headers. Implementors can inherit from this class and implement |
| +// |GetUserAgent()|. |
| +class NET_EXPORT ConstHttpAcceptLanguageAndCharset |
|
erikwright (departed)
2012/09/21 15:06:33
move to separate file.
|
| + : public HttpUserAgentSettings { |
| + public: |
| + virtual const std::string& GetAcceptLanguage() OVERRIDE; |
| + virtual const std::string& GetAcceptCharset() OVERRIDE; |
| + |
| + protected: |
| + ConstHttpAcceptLanguageAndCharset(const std::string& accept_language, |
| + const std::string& accept_charset); |
| + virtual ~ConstHttpAcceptLanguageAndCharset() {} |
| + |
| + private: |
| + const std::string accept_language_; |
| + const std::string accept_charset_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(ConstHttpAcceptLanguageAndCharset); |
| +}; |
| + |
| +// An implementation of |HttpUserAgentSettings| that always provides the |
| +// same constant values for the HTTP Accept-Language, Accept-Charset, and |
| +// User-Agent headers. |
| +class NET_EXPORT ConstHttpUserAgentSettings |
|
erikwright (departed)
2012/09/21 15:06:33
move to separate file.
|
| + : public ConstHttpAcceptLanguageAndCharset { |
| + public: |
| + ConstHttpUserAgentSettings(const std::string& accept_language, |
| + const std::string& accept_charset, |
| + const std::string& user_agent); |
| + virtual ~ConstHttpUserAgentSettings() {} |
| + |
| + virtual const std::string& GetUserAgent(const GURL& url) OVERRIDE; |
| + |
| + private: |
| + const std::string user_agent_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(ConstHttpUserAgentSettings); |
| +}; |
| + |
| + |
| // Subclass to provide application-specific context for URLRequest |
| // instances. Note that URLRequestContext typically does not provide storage for |
| // these member variables, since they may be shared. For the ones that aren't |
| @@ -173,21 +238,14 @@ class NET_EXPORT URLRequestContext |
| } |
| // Gets the value of 'Accept-Charset' header field. |
| - const std::string& accept_charset() const { return accept_charset_; } |
| - void set_accept_charset(const std::string& accept_charset) { |
| - accept_charset_ = accept_charset; |
| - } |
| + const std::string& accept_charset() const; |
|
erikwright (departed)
2012/09/21 15:06:33
Group these together with a single "Legacy accesso
|
| // Gets the value of 'Accept-Language' header field. |
| - const std::string& accept_language() const { return accept_language_; } |
| - void set_accept_language(const std::string& accept_language) { |
| - accept_language_ = accept_language; |
| - } |
| + const std::string& accept_language() const; |
| // Gets the UA string to use for the given URL. Pass an invalid URL (such as |
| - // GURL()) to get the default UA string. Subclasses should override this |
| - // method to provide a UA string. |
| - virtual const std::string& GetUserAgent(const GURL& url) const; |
| + // GURL()) to get the default UA string. |
| + const std::string& GetUserAgent(const GURL& url) const; |
| // In general, referrer_charset is not known when URLRequestContext is |
| // constructed. So, we need a setter. |
| @@ -217,6 +275,17 @@ class NET_EXPORT URLRequestContext |
| void AssertNoURLRequests() const; |
| + // Set the underlying |HttpUserAgentSettings| implementation that provides |
| + // 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
|
| + // are returned by |accept_language|, |accept_charset|, and |GetUserAgent|. |
| + // 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
|
| + // the responsibility of the caller of |set_http_user_agent_settings| to |
| + // ensure the implementation outlives the use of this |URLRequestContext|. |
| + void set_http_user_agent_settings( |
| + HttpUserAgentSettings* http_user_agent_settings) { |
| + http_user_agent_settings_ = http_user_agent_settings; |
| + } |
| + |
| private: |
| // --------------------------------------------------------------------------- |
| // Important: When adding any new members below, consider whether they need to |
| @@ -240,8 +309,6 @@ class NET_EXPORT URLRequestContext |
| #if !defined(DISABLE_FTP_SUPPORT) |
| scoped_ptr<FtpAuthCache> ftp_auth_cache_; |
| #endif |
| - std::string accept_language_; |
| - std::string accept_charset_; |
| // The charset of the referrer where this request comes from. It's not |
| // used in communication with a server but is used to construct a suggested |
| // filename for file download. |
| @@ -250,6 +317,7 @@ class NET_EXPORT URLRequestContext |
| FtpTransactionFactory* ftp_transaction_factory_; |
| const URLRequestJobFactory* job_factory_; |
| URLRequestThrottlerManager* throttler_manager_; |
| + HttpUserAgentSettings* http_user_agent_settings_; |
| // --------------------------------------------------------------------------- |
| // Important: When adding any new members below, consider whether they need to |