| 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 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 #include "net/base/net_export.h" | 24 #include "net/base/net_export.h" |
| 25 | 25 |
| 26 namespace net { | 26 namespace net { |
| 27 | 27 |
| 28 class HostMappingRules; | 28 class HostMappingRules; |
| 29 class ProxyConfigService; | 29 class ProxyConfigService; |
| 30 class URLRequestContext; | 30 class URLRequestContext; |
| 31 | 31 |
| 32 class NET_EXPORT URLRequestContextBuilder { | 32 class NET_EXPORT URLRequestContextBuilder { |
| 33 public: | 33 public: |
| 34 struct NET_EXPORT HostResolverParams { | |
| 35 HostResolverParams(); | |
| 36 ~HostResolverParams(); | |
| 37 | |
| 38 // The limit on the number of parallel host resolutions. | |
| 39 size_t parallelism; | |
| 40 | |
| 41 // When the host resolution is taking too long, we'll retry this many times, | |
| 42 // in a backing off manner. | |
| 43 size_t retry_attempts; | |
| 44 }; | |
| 45 | |
| 46 struct NET_EXPORT HttpCacheParams { | 34 struct NET_EXPORT HttpCacheParams { |
| 47 enum Type { | 35 enum Type { |
| 48 IN_MEMORY, | 36 IN_MEMORY, |
| 49 DISK, | 37 DISK, |
| 50 }; | 38 }; |
| 51 | 39 |
| 52 HttpCacheParams(); | 40 HttpCacheParams(); |
| 53 ~HttpCacheParams(); | 41 ~HttpCacheParams(); |
| 54 | 42 |
| 55 // The type of HTTP cache. Default is IN_MEMORY. | 43 // The type of HTTP cache. Default is IN_MEMORY. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 82 #if defined(OS_LINUX) | 70 #if defined(OS_LINUX) |
| 83 void set_proxy_config_service(ProxyConfigService* proxy_config_service); | 71 void set_proxy_config_service(ProxyConfigService* proxy_config_service); |
| 84 #endif // defined(OS_LINUX) | 72 #endif // defined(OS_LINUX) |
| 85 | 73 |
| 86 // Call this function to specify a hard-coded User-Agent for all requests that | 74 // Call this function to specify a hard-coded User-Agent for all requests that |
| 87 // don't have a User-Agent already set. | 75 // don't have a User-Agent already set. |
| 88 void set_user_agent(const std::string& user_agent) { | 76 void set_user_agent(const std::string& user_agent) { |
| 89 user_agent_ = user_agent; | 77 user_agent_ = user_agent; |
| 90 } | 78 } |
| 91 | 79 |
| 92 // Allows for overriding the default HostResolver params. | |
| 93 void set_host_resolver_params( | |
| 94 const HostResolverParams& host_resolver_params) { | |
| 95 host_resolver_params_ = host_resolver_params; | |
| 96 } | |
| 97 | |
| 98 // By default it's disabled. | 80 // By default it's disabled. |
| 99 void set_ftp_enabled(bool enable) { | 81 void set_ftp_enabled(bool enable) { |
| 100 ftp_enabled_ = enable; | 82 ftp_enabled_ = enable; |
| 101 } | 83 } |
| 102 | 84 |
| 103 // By default HttpCache is enabled with a default constructed HttpCacheParams. | 85 // By default HttpCache is enabled with a default constructed HttpCacheParams. |
| 104 void EnableHttpCache(const HttpCacheParams& params); | 86 void EnableHttpCache(const HttpCacheParams& params); |
| 105 void DisableHttpCache(); | 87 void DisableHttpCache(); |
| 106 | 88 |
| 107 // Override default net::HttpNetworkSession::Params settings. | 89 // Override default net::HttpNetworkSession::Params settings. |
| 108 void set_http_network_session_params( | 90 void set_http_network_session_params( |
| 109 const HttpNetworkSessionParams& http_network_session_params) { | 91 const HttpNetworkSessionParams& http_network_session_params) { |
| 110 http_network_session_params_ = http_network_session_params; | 92 http_network_session_params_ = http_network_session_params; |
| 111 } | 93 } |
| 112 | 94 |
| 113 URLRequestContext* Build(); | 95 URLRequestContext* Build(); |
| 114 | 96 |
| 115 private: | 97 private: |
| 116 std::string user_agent_; | 98 std::string user_agent_; |
| 117 bool ftp_enabled_; | 99 bool ftp_enabled_; |
| 118 HostResolverParams host_resolver_params_; | |
| 119 bool http_cache_enabled_; | 100 bool http_cache_enabled_; |
| 120 HttpCacheParams http_cache_params_; | 101 HttpCacheParams http_cache_params_; |
| 121 HttpNetworkSessionParams http_network_session_params_; | 102 HttpNetworkSessionParams http_network_session_params_; |
| 122 #if defined(OS_LINUX) | 103 #if defined(OS_LINUX) |
| 123 scoped_ptr<ProxyConfigService> proxy_config_service_; | 104 scoped_ptr<ProxyConfigService> proxy_config_service_; |
| 124 #endif // defined(OS_LINUX) | 105 #endif // defined(OS_LINUX) |
| 125 | 106 |
| 126 DISALLOW_COPY_AND_ASSIGN(URLRequestContextBuilder); | 107 DISALLOW_COPY_AND_ASSIGN(URLRequestContextBuilder); |
| 127 }; | 108 }; |
| 128 | 109 |
| 129 } // namespace net | 110 } // namespace net |
| 130 | 111 |
| 131 #endif // NET_URL_REQUEST_URL_REQUEST_CONTEXT_BUILDER_H_ | 112 #endif // NET_URL_REQUEST_URL_REQUEST_CONTEXT_BUILDER_H_ |
| OLD | NEW |