Update optimize_png_files.sh to work on msysgit bash.
[chromium-blink-merge.git] / net / url_request / url_request_context_builder.h
blob5d4296c1da1c2cd5187b82682ce200f0b5e86501
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
3 // found in the LICENSE file.
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
7 // any configuration params, and when done, invoke Build() to construct the
8 // URLRequestContext. This URLRequestContext will own all its own storage.
9 //
10 // URLRequestContextBuilder and its associated params classes are initially
11 // populated with "sane" default values. Read through the comments to figure out
12 // what these are.
14 #ifndef NET_URL_REQUEST_URL_REQUEST_CONTEXT_BUILDER_H_
15 #define NET_URL_REQUEST_URL_REQUEST_CONTEXT_BUILDER_H_
17 #include <string>
18 #include <vector>
20 #include "base/basictypes.h"
21 #include "base/files/file_path.h"
22 #include "base/memory/ref_counted.h"
23 #include "base/memory/scoped_ptr.h"
24 #include "build/build_config.h"
25 #include "net/base/net_export.h"
27 namespace net {
29 class FtpTransactionFactory;
30 class HostResolver;
31 class HostMappingRules;
32 class HttpAuthHandlerFactory;
33 class ProxyConfigService;
34 class URLRequestContext;
35 class NetworkDelegate;
37 class NET_EXPORT URLRequestContextBuilder {
38 public:
39 struct NET_EXPORT HttpCacheParams {
40 enum Type {
41 IN_MEMORY,
42 DISK,
45 HttpCacheParams();
46 ~HttpCacheParams();
48 // The type of HTTP cache. Default is IN_MEMORY.
49 Type type;
51 // The max size of the cache in bytes. Default is algorithmically determined
52 // based off available disk space.
53 int max_size;
55 // The cache path (when type is DISK).
56 base::FilePath path;
59 struct NET_EXPORT HttpNetworkSessionParams {
60 HttpNetworkSessionParams();
61 ~HttpNetworkSessionParams();
63 // These fields mirror those in net::HttpNetworkSession::Params;
64 bool ignore_certificate_errors;
65 HostMappingRules* host_mapping_rules;
66 bool http_pipelining_enabled;
67 uint16 testing_fixed_http_port;
68 uint16 testing_fixed_https_port;
69 std::string trusted_spdy_proxy;
72 URLRequestContextBuilder();
73 ~URLRequestContextBuilder();
75 void set_proxy_config_service(ProxyConfigService* proxy_config_service);
77 // Call these functions to specify hard-coded Accept-Language
78 // or User-Agent header values for all requests that don't
79 // have the headers already set.
80 void set_accept_language(const std::string& accept_language) {
81 accept_language_ = accept_language;
83 void set_user_agent(const std::string& user_agent) {
84 user_agent_ = user_agent;
87 // Control support for data:// requests. By default it's disabled.
88 void set_data_enabled(bool enable) {
89 data_enabled_ = enable;
92 #if !defined(DISABLE_FILE_SUPPORT)
93 // Control support for file:// requests. By default it's disabled.
94 void set_file_enabled(bool enable) {
95 file_enabled_ = enable;
97 #endif
99 #if !defined(DISABLE_FTP_SUPPORT)
100 // Control support for ftp:// requests. By default it's disabled.
101 void set_ftp_enabled(bool enable) {
102 ftp_enabled_ = enable;
104 #endif
106 // By default host_resolver is constructed with CreateDefaultResolver.
107 void set_host_resolver(HostResolver* host_resolver) {
108 host_resolver_.reset(host_resolver);
111 // Uses BasicNetworkDelegate by default. Note that calling Build will unset
112 // any custom delegate in builder, so this must be called each time before
113 // Build is called.
114 void set_network_delegate(NetworkDelegate* delegate) {
115 network_delegate_.reset(delegate);
119 // Adds additional auth handler factories to be used in addition to what is
120 // provided in the default |HttpAuthHandlerRegistryFactory|. The auth |scheme|
121 // and |factory| are provided. The builder takes ownership of the factory and
122 // Build() must be called after this method.
123 void add_http_auth_handler_factory(const std::string& scheme,
124 net::HttpAuthHandlerFactory* factory) {
125 extra_http_auth_handlers_.push_back(SchemeFactory(scheme, factory));
128 // By default HttpCache is enabled with a default constructed HttpCacheParams.
129 void EnableHttpCache(const HttpCacheParams& params) {
130 http_cache_enabled_ = true;
131 http_cache_params_ = params;
134 void DisableHttpCache() {
135 http_cache_enabled_ = false;
136 http_cache_params_ = HttpCacheParams();
139 // Override default net::HttpNetworkSession::Params settings.
140 void set_http_network_session_params(
141 const HttpNetworkSessionParams& http_network_session_params) {
142 http_network_session_params_ = http_network_session_params;
145 URLRequestContext* Build();
147 private:
148 struct SchemeFactory {
149 SchemeFactory(const std::string& scheme,
150 net::HttpAuthHandlerFactory* factory);
151 ~SchemeFactory();
153 std::string scheme;
154 net::HttpAuthHandlerFactory* factory;
157 std::string accept_language_;
158 std::string user_agent_;
159 // Include support for data:// requests.
160 bool data_enabled_;
161 #if !defined(DISABLE_FILE_SUPPORT)
162 // Include support for file:// requests.
163 bool file_enabled_;
164 #endif
165 #if !defined(DISABLE_FTP_SUPPORT)
166 // Include support for ftp:// requests.
167 bool ftp_enabled_;
168 #endif
169 bool http_cache_enabled_;
170 HttpCacheParams http_cache_params_;
171 HttpNetworkSessionParams http_network_session_params_;
172 scoped_ptr<HostResolver> host_resolver_;
173 scoped_ptr<ProxyConfigService> proxy_config_service_;
174 scoped_ptr<NetworkDelegate> network_delegate_;
175 scoped_ptr<FtpTransactionFactory> ftp_transaction_factory_;
176 std::vector<SchemeFactory> extra_http_auth_handlers_;
178 DISALLOW_COPY_AND_ASSIGN(URLRequestContextBuilder);
181 } // namespace net
183 #endif // NET_URL_REQUEST_URL_REQUEST_CONTEXT_BUILDER_H_