| OLD | NEW |
| 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 is useful for building a simple URLRequestContext. Most creators | 5 // This class is useful for building a simple URLRequestContext. Most creators |
| 6 // of new URLRequestContexts should use this helper class to construct it. Call | 6 // of new URLRequestContexts should use this helper class to construct it. Call |
| 7 // any configuration params, and when done, invoke Build() to construct the | 7 // any configuration params, and when done, invoke Build() to construct the |
| 8 // URLRequestContext. This URLRequestContext will own all its own storage. | 8 // URLRequestContext. This URLRequestContext will own all its own storage. |
| 9 // | 9 // |
| 10 // URLRequestContextBuilder and its associated params classes are initially | 10 // URLRequestContextBuilder and its associated params classes are initially |
| 11 // populated with "sane" default values. Read through the comments to figure out | 11 // populated with "sane" default values. Read through the comments to figure out |
| 12 // what these are. | 12 // what these are. |
| 13 | 13 |
| 14 #ifndef NET_URL_REQUEST_URL_REQUEST_CONTEXT_BUILDER_H_ | 14 #ifndef NET_URL_REQUEST_URL_REQUEST_CONTEXT_BUILDER_H_ |
| 15 #define NET_URL_REQUEST_URL_REQUEST_CONTEXT_BUILDER_H_ | 15 #define NET_URL_REQUEST_URL_REQUEST_CONTEXT_BUILDER_H_ |
| 16 | 16 |
| 17 #include <string> | 17 #include <string> |
| 18 #include <vector> | 18 #include <vector> |
| 19 | 19 |
| 20 #include "base/basictypes.h" | 20 #include "base/basictypes.h" |
| 21 #include "base/files/file_path.h" | 21 #include "base/files/file_path.h" |
| 22 #include "base/memory/ref_counted.h" | 22 #include "base/memory/ref_counted.h" |
| 23 #include "base/memory/scoped_ptr.h" | 23 #include "base/memory/scoped_ptr.h" |
| 24 #include "build/build_config.h" | 24 #include "build/build_config.h" |
| 25 #include "net/base/net_export.h" | 25 #include "net/base/net_export.h" |
| 26 #include "net/base/network_delegate.h" | 26 #include "net/base/network_delegate.h" |
| 27 #include "net/dns/host_resolver.h" | 27 #include "net/dns/host_resolver.h" |
| 28 #include "net/proxy/proxy_config_service.h" |
| 29 #include "net/proxy/proxy_service.h" |
| 28 #include "net/socket/next_proto.h" | 30 #include "net/socket/next_proto.h" |
| 29 | 31 |
| 30 namespace net { | 32 namespace net { |
| 31 | 33 |
| 32 class FtpTransactionFactory; | 34 class FtpTransactionFactory; |
| 33 class HostMappingRules; | 35 class HostMappingRules; |
| 34 class HttpAuthHandlerFactory; | 36 class HttpAuthHandlerFactory; |
| 35 class ProxyConfigService; | 37 class ProxyConfigService; |
| 36 class URLRequestContext; | 38 class URLRequestContext; |
| 37 | 39 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 67 uint16 testing_fixed_http_port; | 69 uint16 testing_fixed_http_port; |
| 68 uint16 testing_fixed_https_port; | 70 uint16 testing_fixed_https_port; |
| 69 NextProtoVector next_protos; | 71 NextProtoVector next_protos; |
| 70 std::string trusted_spdy_proxy; | 72 std::string trusted_spdy_proxy; |
| 71 bool use_alternate_protocols; | 73 bool use_alternate_protocols; |
| 72 }; | 74 }; |
| 73 | 75 |
| 74 URLRequestContextBuilder(); | 76 URLRequestContextBuilder(); |
| 75 ~URLRequestContextBuilder(); | 77 ~URLRequestContextBuilder(); |
| 76 | 78 |
| 77 void set_proxy_config_service(ProxyConfigService* proxy_config_service); | 79 // These functions are mutually exclusive. The ProxyConfigService, if |
| 80 // set, will be used to construct a ProxyService. |
| 81 void set_proxy_config_service(ProxyConfigService* proxy_config_service) { |
| 82 proxy_config_service_.reset(proxy_config_service); |
| 83 } |
| 84 void set_proxy_service(ProxyService* proxy_service) { |
| 85 proxy_service_.reset(proxy_service); |
| 86 } |
| 78 | 87 |
| 79 // Call these functions to specify hard-coded Accept-Language | 88 // Call these functions to specify hard-coded Accept-Language |
| 80 // or User-Agent header values for all requests that don't | 89 // or User-Agent header values for all requests that don't |
| 81 // have the headers already set. | 90 // have the headers already set. |
| 82 void set_accept_language(const std::string& accept_language) { | 91 void set_accept_language(const std::string& accept_language) { |
| 83 accept_language_ = accept_language; | 92 accept_language_ = accept_language; |
| 84 } | 93 } |
| 85 void set_user_agent(const std::string& user_agent) { | 94 void set_user_agent(const std::string& user_agent) { |
| 86 user_agent_ = user_agent; | 95 user_agent_ = user_agent; |
| 87 } | 96 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 98 } | 107 } |
| 99 #endif | 108 #endif |
| 100 | 109 |
| 101 #if !defined(DISABLE_FTP_SUPPORT) | 110 #if !defined(DISABLE_FTP_SUPPORT) |
| 102 // Control support for ftp:// requests. By default it's disabled. | 111 // Control support for ftp:// requests. By default it's disabled. |
| 103 void set_ftp_enabled(bool enable) { | 112 void set_ftp_enabled(bool enable) { |
| 104 ftp_enabled_ = enable; | 113 ftp_enabled_ = enable; |
| 105 } | 114 } |
| 106 #endif | 115 #endif |
| 107 | 116 |
| 117 // TODO(mmenke): Probably makes sense to get rid of this, and have consumers |
| 118 // set their own NetLog::Observers instead. |
| 119 void set_net_log(NetLog* net_log) { |
| 120 net_log_.reset(net_log); |
| 121 } |
| 122 |
| 108 // By default host_resolver is constructed with CreateDefaultResolver. | 123 // By default host_resolver is constructed with CreateDefaultResolver. |
| 109 void set_host_resolver(HostResolver* host_resolver) { | 124 void set_host_resolver(HostResolver* host_resolver) { |
| 110 host_resolver_.reset(host_resolver); | 125 host_resolver_.reset(host_resolver); |
| 111 } | 126 } |
| 112 | 127 |
| 113 // Uses BasicNetworkDelegate by default. Note that calling Build will unset | 128 // Uses BasicNetworkDelegate by default. Note that calling Build will unset |
| 114 // any custom delegate in builder, so this must be called each time before | 129 // any custom delegate in builder, so this must be called each time before |
| 115 // Build is called. | 130 // Build is called. |
| 116 void set_network_delegate(NetworkDelegate* delegate) { | 131 void set_network_delegate(NetworkDelegate* delegate) { |
| 117 network_delegate_.reset(delegate); | 132 network_delegate_.reset(delegate); |
| 118 } | 133 } |
| 119 | 134 |
| 120 | 135 |
| 121 // Adds additional auth handler factories to be used in addition to what is | 136 // Adds additional auth handler factories to be used in addition to what is |
| 122 // provided in the default |HttpAuthHandlerRegistryFactory|. The auth |scheme| | 137 // provided in the default |HttpAuthHandlerRegistryFactory|. The auth |scheme| |
| 123 // and |factory| are provided. The builder takes ownership of the factory and | 138 // and |factory| are provided. The builder takes ownership of the factory and |
| 124 // Build() must be called after this method. | 139 // Build() must be called after this method. |
| 125 void add_http_auth_handler_factory(const std::string& scheme, | 140 void add_http_auth_handler_factory(const std::string& scheme, |
| 126 net::HttpAuthHandlerFactory* factory) { | 141 net::HttpAuthHandlerFactory* factory) { |
| 127 extra_http_auth_handlers_.push_back(SchemeFactory(scheme, factory)); | 142 extra_http_auth_handlers_.push_back(SchemeFactory(scheme, factory)); |
| 128 } | 143 } |
| 129 | 144 |
| 130 // By default HttpCache is enabled with a default constructed HttpCacheParams. | 145 // By default HttpCache is enabled with a default constructed HttpCacheParams. |
| 131 void EnableHttpCache(const HttpCacheParams& params) { | 146 void EnableHttpCache(const HttpCacheParams& params); |
| 132 http_cache_enabled_ = true; | 147 void DisableHttpCache(); |
| 133 http_cache_params_ = params; | |
| 134 } | |
| 135 | |
| 136 void DisableHttpCache() { | |
| 137 http_cache_enabled_ = false; | |
| 138 http_cache_params_ = HttpCacheParams(); | |
| 139 } | |
| 140 | 148 |
| 141 // Override default net::HttpNetworkSession::Params settings. | 149 // Override default net::HttpNetworkSession::Params settings. |
| 142 void set_http_network_session_params( | 150 void set_http_network_session_params( |
| 143 const HttpNetworkSessionParams& http_network_session_params) { | 151 const HttpNetworkSessionParams& http_network_session_params) { |
| 144 http_network_session_params_ = http_network_session_params; | 152 http_network_session_params_ = http_network_session_params; |
| 145 } | 153 } |
| 146 | 154 |
| 155 void set_transport_security_persister_path( |
| 156 const base::FilePath& transport_security_persister_path) { |
| 157 transport_security_persister_path_ = transport_security_persister_path; |
| 158 } |
| 159 |
| 147 // Adjust |http_network_session_params_.next_protos| to enable SPDY and QUIC. | 160 // Adjust |http_network_session_params_.next_protos| to enable SPDY and QUIC. |
| 148 void SetSpdyAndQuicEnabled(bool spdy_enabled, | 161 void SetSpdyAndQuicEnabled(bool spdy_enabled, |
| 149 bool quic_enabled); | 162 bool quic_enabled); |
| 150 | 163 |
| 164 void set_throttling_enabled(bool throttling_enabled) { |
| 165 throttling_enabled_ = throttling_enabled; |
| 166 } |
| 167 |
| 151 URLRequestContext* Build(); | 168 URLRequestContext* Build(); |
| 152 | 169 |
| 153 private: | 170 private: |
| 154 struct SchemeFactory { | 171 struct SchemeFactory { |
| 155 SchemeFactory(const std::string& scheme, | 172 SchemeFactory(const std::string& scheme, |
| 156 net::HttpAuthHandlerFactory* factory); | 173 net::HttpAuthHandlerFactory* factory); |
| 157 ~SchemeFactory(); | 174 ~SchemeFactory(); |
| 158 | 175 |
| 159 std::string scheme; | 176 std::string scheme; |
| 160 net::HttpAuthHandlerFactory* factory; | 177 net::HttpAuthHandlerFactory* factory; |
| 161 }; | 178 }; |
| 162 | 179 |
| 163 std::string accept_language_; | 180 std::string accept_language_; |
| 164 std::string user_agent_; | 181 std::string user_agent_; |
| 165 // Include support for data:// requests. | 182 // Include support for data:// requests. |
| 166 bool data_enabled_; | 183 bool data_enabled_; |
| 167 #if !defined(DISABLE_FILE_SUPPORT) | 184 #if !defined(DISABLE_FILE_SUPPORT) |
| 168 // Include support for file:// requests. | 185 // Include support for file:// requests. |
| 169 bool file_enabled_; | 186 bool file_enabled_; |
| 170 #endif | 187 #endif |
| 171 #if !defined(DISABLE_FTP_SUPPORT) | 188 #if !defined(DISABLE_FTP_SUPPORT) |
| 172 // Include support for ftp:// requests. | 189 // Include support for ftp:// requests. |
| 173 bool ftp_enabled_; | 190 bool ftp_enabled_; |
| 174 #endif | 191 #endif |
| 175 bool http_cache_enabled_; | 192 bool http_cache_enabled_; |
| 193 bool throttling_enabled_; |
| 194 |
| 176 HttpCacheParams http_cache_params_; | 195 HttpCacheParams http_cache_params_; |
| 177 HttpNetworkSessionParams http_network_session_params_; | 196 HttpNetworkSessionParams http_network_session_params_; |
| 197 base::FilePath transport_security_persister_path_; |
| 198 scoped_ptr<NetLog> net_log_; |
| 178 scoped_ptr<HostResolver> host_resolver_; | 199 scoped_ptr<HostResolver> host_resolver_; |
| 179 scoped_ptr<ProxyConfigService> proxy_config_service_; | 200 scoped_ptr<ProxyConfigService> proxy_config_service_; |
| 201 scoped_ptr<ProxyService> proxy_service_; |
| 180 scoped_ptr<NetworkDelegate> network_delegate_; | 202 scoped_ptr<NetworkDelegate> network_delegate_; |
| 181 scoped_ptr<FtpTransactionFactory> ftp_transaction_factory_; | 203 scoped_ptr<FtpTransactionFactory> ftp_transaction_factory_; |
| 182 std::vector<SchemeFactory> extra_http_auth_handlers_; | 204 std::vector<SchemeFactory> extra_http_auth_handlers_; |
| 183 | 205 |
| 184 DISALLOW_COPY_AND_ASSIGN(URLRequestContextBuilder); | 206 DISALLOW_COPY_AND_ASSIGN(URLRequestContextBuilder); |
| 185 }; | 207 }; |
| 186 | 208 |
| 187 } // namespace net | 209 } // namespace net |
| 188 | 210 |
| 189 #endif // NET_URL_REQUEST_URL_REQUEST_CONTEXT_BUILDER_H_ | 211 #endif // NET_URL_REQUEST_URL_REQUEST_CONTEXT_BUILDER_H_ |
| OLD | NEW |