| 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 | 18 |
| 19 #include "base/basictypes.h" | 19 #include "base/basictypes.h" |
| 20 #include "base/file_path.h" | 20 #include "base/file_path.h" |
| 21 #include "base/memory/ref_counted.h" | 21 #include "base/memory/ref_counted.h" |
| 22 #include "base/memory/scoped_ptr.h" | 22 #include "base/memory/scoped_ptr.h" |
| 23 #include "build/build_config.h" | 23 #include "build/build_config.h" |
| 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 ProxyConfigService; | 29 class ProxyConfigService; |
| 29 class URLRequestContext; | 30 class URLRequestContext; |
| 30 | 31 |
| 31 class NET_EXPORT URLRequestContextBuilder { | 32 class NET_EXPORT URLRequestContextBuilder { |
| 32 public: | 33 public: |
| 33 struct NET_EXPORT HostResolverParams { | 34 struct NET_EXPORT HostResolverParams { |
| 34 HostResolverParams(); | 35 HostResolverParams(); |
| 35 ~HostResolverParams(); | 36 ~HostResolverParams(); |
| 36 | 37 |
| 37 // The limit on the number of parallel host resolutions. | 38 // The limit on the number of parallel host resolutions. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 55 Type type; | 56 Type type; |
| 56 | 57 |
| 57 // The max size of the cache in bytes. Default is algorithmically determined | 58 // The max size of the cache in bytes. Default is algorithmically determined |
| 58 // based off available disk space. | 59 // based off available disk space. |
| 59 int max_size; | 60 int max_size; |
| 60 | 61 |
| 61 // The cache path (when type is DISK). | 62 // The cache path (when type is DISK). |
| 62 FilePath path; | 63 FilePath path; |
| 63 }; | 64 }; |
| 64 | 65 |
| 66 struct NET_EXPORT HttpNetworkSessionParams { |
| 67 HttpNetworkSessionParams(); |
| 68 ~HttpNetworkSessionParams(); |
| 69 |
| 70 // These fields mirror those in net::HttpNetworkSession::Params; |
| 71 bool ignore_certificate_errors; |
| 72 HostMappingRules* host_mapping_rules; |
| 73 bool http_pipelining_enabled; |
| 74 uint16 testing_fixed_http_port; |
| 75 uint16 testing_fixed_https_port; |
| 76 std::string trusted_spdy_proxy; |
| 77 }; |
| 78 |
| 65 URLRequestContextBuilder(); | 79 URLRequestContextBuilder(); |
| 66 ~URLRequestContextBuilder(); | 80 ~URLRequestContextBuilder(); |
| 67 | 81 |
| 68 #if defined(OS_LINUX) | 82 #if defined(OS_LINUX) |
| 69 void set_proxy_config_service(ProxyConfigService* proxy_config_service); | 83 void set_proxy_config_service(ProxyConfigService* proxy_config_service); |
| 70 #endif // defined(OS_LINUX) | 84 #endif // defined(OS_LINUX) |
| 71 | 85 |
| 72 // Call this function to specify a hard-coded User-Agent for all requests that | 86 // Call this function to specify a hard-coded User-Agent for all requests that |
| 73 // don't have a User-Agent already set. | 87 // don't have a User-Agent already set. |
| 74 void set_user_agent(const std::string& user_agent) { | 88 void set_user_agent(const std::string& user_agent) { |
| 75 user_agent_ = user_agent; | 89 user_agent_ = user_agent; |
| 76 } | 90 } |
| 77 | 91 |
| 78 // Allows for overriding the default HostResolver params. | 92 // Allows for overriding the default HostResolver params. |
| 79 void set_host_resolver_params( | 93 void set_host_resolver_params( |
| 80 const HostResolverParams& host_resolver_params) { | 94 const HostResolverParams& host_resolver_params) { |
| 81 host_resolver_params_ = host_resolver_params; | 95 host_resolver_params_ = host_resolver_params; |
| 82 } | 96 } |
| 83 | 97 |
| 84 // By default it's disabled. | 98 // By default it's disabled. |
| 85 void set_ftp_enabled(bool enable) { | 99 void set_ftp_enabled(bool enable) { |
| 86 ftp_enabled_ = enable; | 100 ftp_enabled_ = enable; |
| 87 } | 101 } |
| 88 | 102 |
| 89 // By default HttpCache is enabled with a default constructed HttpCacheParams. | 103 // By default HttpCache is enabled with a default constructed HttpCacheParams. |
| 90 void EnableHttpCache(const HttpCacheParams& params); | 104 void EnableHttpCache(const HttpCacheParams& params); |
| 91 void DisableHttpCache(); | 105 void DisableHttpCache(); |
| 92 | 106 |
| 107 // Override default net::HttpNetworkSession::Params settings. |
| 108 void set_http_network_session_params( |
| 109 const HttpNetworkSessionParams& http_network_session_params) { |
| 110 http_network_session_params_ = http_network_session_params; |
| 111 } |
| 112 |
| 93 URLRequestContext* Build(); | 113 URLRequestContext* Build(); |
| 94 | 114 |
| 95 private: | 115 private: |
| 96 std::string user_agent_; | 116 std::string user_agent_; |
| 97 bool ftp_enabled_; | 117 bool ftp_enabled_; |
| 98 HostResolverParams host_resolver_params_; | 118 HostResolverParams host_resolver_params_; |
| 99 bool http_cache_enabled_; | 119 bool http_cache_enabled_; |
| 100 HttpCacheParams http_cache_params_; | 120 HttpCacheParams http_cache_params_; |
| 121 HttpNetworkSessionParams http_network_session_params_; |
| 101 #if defined(OS_LINUX) | 122 #if defined(OS_LINUX) |
| 102 scoped_ptr<ProxyConfigService> proxy_config_service_; | 123 scoped_ptr<ProxyConfigService> proxy_config_service_; |
| 103 #endif // defined(OS_LINUX) | 124 #endif // defined(OS_LINUX) |
| 104 | 125 |
| 105 DISALLOW_COPY_AND_ASSIGN(URLRequestContextBuilder); | 126 DISALLOW_COPY_AND_ASSIGN(URLRequestContextBuilder); |
| 106 }; | 127 }; |
| 107 | 128 |
| 108 } // namespace net | 129 } // namespace net |
| 109 | 130 |
| 110 #endif // NET_URL_REQUEST_URL_REQUEST_CONTEXT_BUILDER_H_ | 131 #endif // NET_URL_REQUEST_URL_REQUEST_CONTEXT_BUILDER_H_ |
| OLD | NEW |