| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_ |
| 11 #define NET_URL_REQUEST_URL_REQUEST_CONTEXT_H_ | 11 #define NET_URL_REQUEST_URL_REQUEST_CONTEXT_H_ |
| 12 | 12 |
| 13 #include "base/ref_counted.h" | 13 #include "base/ref_counted.h" |
| 14 #include "base/string_util.h" | 14 #include "base/string_util.h" |
| 15 #include "net/base/cookie_store.h" | 15 #include "net/base/cookie_store.h" |
| 16 #include "net/base/host_resolver.h" | 16 #include "net/base/host_resolver.h" |
| 17 #include "net/base/net_log.h" |
| 17 #include "net/base/ssl_config_service.h" | 18 #include "net/base/ssl_config_service.h" |
| 18 #include "net/base/transport_security_state.h" | 19 #include "net/base/transport_security_state.h" |
| 19 #include "net/ftp/ftp_auth_cache.h" | 20 #include "net/ftp/ftp_auth_cache.h" |
| 20 #include "net/proxy/proxy_service.h" | 21 #include "net/proxy/proxy_service.h" |
| 21 #include "net/url_request/request_tracker.h" | |
| 22 | 22 |
| 23 namespace net { | 23 namespace net { |
| 24 class CookiePolicy; | 24 class CookiePolicy; |
| 25 class FtpTransactionFactory; | 25 class FtpTransactionFactory; |
| 26 class HttpAuthHandlerFactory; | 26 class HttpAuthHandlerFactory; |
| 27 class HttpTransactionFactory; | 27 class HttpTransactionFactory; |
| 28 class SocketStream; | 28 class SocketStream; |
| 29 } | 29 } |
| 30 class URLRequest; | 30 class URLRequest; |
| 31 | 31 |
| 32 // Subclass to provide application-specific context for URLRequest instances. | 32 // Subclass to provide application-specific context for URLRequest instances. |
| 33 class URLRequestContext : | 33 class URLRequestContext : |
| 34 public base::RefCountedThreadSafe<URLRequestContext> { | 34 public base::RefCountedThreadSafe<URLRequestContext> { |
| 35 public: | 35 public: |
| 36 URLRequestContext() | 36 URLRequestContext() |
| 37 : http_transaction_factory_(NULL), | 37 : net_log_(NULL), |
| 38 http_transaction_factory_(NULL), |
| 38 ftp_transaction_factory_(NULL), | 39 ftp_transaction_factory_(NULL), |
| 39 cookie_policy_(NULL), | 40 cookie_policy_(NULL), |
| 40 transport_security_state_(NULL) { | 41 transport_security_state_(NULL) { |
| 41 } | 42 } |
| 42 | 43 |
| 44 net::NetLog* net_log() const { |
| 45 return net_log_; |
| 46 } |
| 47 |
| 43 net::HostResolver* host_resolver() const { | 48 net::HostResolver* host_resolver() const { |
| 44 return host_resolver_; | 49 return host_resolver_; |
| 45 } | 50 } |
| 46 | 51 |
| 47 // Get the proxy service for this context. | 52 // Get the proxy service for this context. |
| 48 net::ProxyService* proxy_service() const { | 53 net::ProxyService* proxy_service() const { |
| 49 return proxy_service_; | 54 return proxy_service_; |
| 50 } | 55 } |
| 51 | 56 |
| 52 // Get the ssl config service for this context. | 57 // Get the ssl config service for this context. |
| (...skipping 30 matching lines...) Expand all Loading... |
| 83 net::HttpAuthHandlerFactory* http_auth_handler_factory() { | 88 net::HttpAuthHandlerFactory* http_auth_handler_factory() { |
| 84 return http_auth_handler_factory_; | 89 return http_auth_handler_factory_; |
| 85 } | 90 } |
| 86 | 91 |
| 87 // Gets the value of 'Accept-Charset' header field. | 92 // Gets the value of 'Accept-Charset' header field. |
| 88 const std::string& accept_charset() const { return accept_charset_; } | 93 const std::string& accept_charset() const { return accept_charset_; } |
| 89 | 94 |
| 90 // Gets the value of 'Accept-Language' header field. | 95 // Gets the value of 'Accept-Language' header field. |
| 91 const std::string& accept_language() const { return accept_language_; } | 96 const std::string& accept_language() const { return accept_language_; } |
| 92 | 97 |
| 93 // Gets the tracker for URLRequests associated with this context. | |
| 94 RequestTracker<URLRequest>* url_request_tracker() { | |
| 95 return &url_request_tracker_; | |
| 96 } | |
| 97 | |
| 98 // Gets the tracker for SocketStreams associated with this context. | |
| 99 RequestTracker<net::SocketStream>* socket_stream_tracker() { | |
| 100 return &socket_stream_tracker_; | |
| 101 } | |
| 102 | |
| 103 // Gets the UA string to use for the given URL. Pass an invalid URL (such as | 98 // Gets the UA string to use for the given URL. Pass an invalid URL (such as |
| 104 // GURL()) to get the default UA string. Subclasses should override this | 99 // GURL()) to get the default UA string. Subclasses should override this |
| 105 // method to provide a UA string. | 100 // method to provide a UA string. |
| 106 virtual const std::string& GetUserAgent(const GURL& url) const { | 101 virtual const std::string& GetUserAgent(const GURL& url) const { |
| 107 return EmptyString(); | 102 return EmptyString(); |
| 108 } | 103 } |
| 109 | 104 |
| 110 // In general, referrer_charset is not known when URLRequestContext is | 105 // In general, referrer_charset is not known when URLRequestContext is |
| 111 // constructed. So, we need a setter. | 106 // constructed. So, we need a setter. |
| 112 const std::string& referrer_charset() const { return referrer_charset_; } | 107 const std::string& referrer_charset() const { return referrer_charset_; } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 128 return true; | 123 return true; |
| 129 } | 124 } |
| 130 | 125 |
| 131 protected: | 126 protected: |
| 132 friend class base::RefCountedThreadSafe<URLRequestContext>; | 127 friend class base::RefCountedThreadSafe<URLRequestContext>; |
| 133 | 128 |
| 134 virtual ~URLRequestContext() {} | 129 virtual ~URLRequestContext() {} |
| 135 | 130 |
| 136 // The following members are expected to be initialized and owned by | 131 // The following members are expected to be initialized and owned by |
| 137 // subclasses. | 132 // subclasses. |
| 133 net::NetLog* net_log_; |
| 138 scoped_refptr<net::HostResolver> host_resolver_; | 134 scoped_refptr<net::HostResolver> host_resolver_; |
| 139 scoped_refptr<net::ProxyService> proxy_service_; | 135 scoped_refptr<net::ProxyService> proxy_service_; |
| 140 scoped_refptr<net::SSLConfigService> ssl_config_service_; | 136 scoped_refptr<net::SSLConfigService> ssl_config_service_; |
| 141 net::HttpTransactionFactory* http_transaction_factory_; | 137 net::HttpTransactionFactory* http_transaction_factory_; |
| 142 net::FtpTransactionFactory* ftp_transaction_factory_; | 138 net::FtpTransactionFactory* ftp_transaction_factory_; |
| 143 net::HttpAuthHandlerFactory* http_auth_handler_factory_; | 139 net::HttpAuthHandlerFactory* http_auth_handler_factory_; |
| 144 scoped_refptr<net::CookieStore> cookie_store_; | 140 scoped_refptr<net::CookieStore> cookie_store_; |
| 145 net::CookiePolicy* cookie_policy_; | 141 net::CookiePolicy* cookie_policy_; |
| 146 scoped_refptr<net::TransportSecurityState> transport_security_state_; | 142 scoped_refptr<net::TransportSecurityState> transport_security_state_; |
| 147 net::FtpAuthCache ftp_auth_cache_; | 143 net::FtpAuthCache ftp_auth_cache_; |
| 148 std::string accept_language_; | 144 std::string accept_language_; |
| 149 std::string accept_charset_; | 145 std::string accept_charset_; |
| 150 // The charset of the referrer where this request comes from. It's not | 146 // The charset of the referrer where this request comes from. It's not |
| 151 // used in communication with a server but is used to construct a suggested | 147 // used in communication with a server but is used to construct a suggested |
| 152 // filename for file download. | 148 // filename for file download. |
| 153 std::string referrer_charset_; | 149 std::string referrer_charset_; |
| 154 | 150 |
| 155 // Tracks the requests associated with this context. | |
| 156 RequestTracker<URLRequest> url_request_tracker_; | |
| 157 | |
| 158 // Trakcs the socket streams associated with this context. | |
| 159 RequestTracker<net::SocketStream> socket_stream_tracker_; | |
| 160 | |
| 161 private: | 151 private: |
| 162 DISALLOW_COPY_AND_ASSIGN(URLRequestContext); | 152 DISALLOW_COPY_AND_ASSIGN(URLRequestContext); |
| 163 }; | 153 }; |
| 164 | 154 |
| 165 #endif // NET_URL_REQUEST_URL_REQUEST_CONTEXT_H_ | 155 #endif // NET_URL_REQUEST_URL_REQUEST_CONTEXT_H_ |
| OLD | NEW |