blob: 3ef5159a37480df1548faa822d191593c2486cc8 [file] [log] [blame]
[email protected]94de3e02014-06-17 00:09:511// Copyright 2014 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.
4
5#ifndef COMPONENTS_CRONET_URL_REQUEST_CONTEXT_CONFIG_H_
6#define COMPONENTS_CRONET_URL_REQUEST_CONTEXT_CONFIG_H_
7
dchengfe3745e6242016-04-21 23:49:588#include <memory>
[email protected]94de3e02014-06-17 00:09:519#include <string>
10
mefc71361c2014-09-16 14:48:5611#include "base/macros.h"
xunjielida7f77022016-03-28 16:36:3612#include "base/memory/ref_counted.h"
mefc71361c2014-09-16 14:48:5613#include "base/memory/scoped_vector.h"
kapishnikovdf5ccab2015-12-03 18:38:5014#include "base/time/time.h"
pauljensen9041eb3c2015-12-09 12:29:0115#include "net/base/hash_value.h"
lilyhoughton14e2a1f12017-01-11 14:50:2716#include "net/cert/cert_verifier.h"
[email protected]94de3e02014-06-17 00:09:5117
xunjielida7f77022016-03-28 16:36:3618namespace base {
19class SequencedTaskRunner;
20} // namespace base
21
[email protected]94de3e02014-06-17 00:09:5122namespace net {
xunjieli013145f2015-10-20 23:20:1123class CertVerifier;
pauljensene92c4092015-12-09 19:13:4824class NetLog;
[email protected]94de3e02014-06-17 00:09:5125class URLRequestContextBuilder;
26} // namespace net
27
28namespace cronet {
29
30// Common configuration parameters used by Cronet to configure
pauljensen9041eb3c2015-12-09 12:29:0131// URLRequestContext.
[email protected]94de3e02014-06-17 00:09:5132struct URLRequestContextConfig {
pauljensen9041eb3c2015-12-09 12:29:0133 // Type of HTTP cache.
kapishnikovaa8f338c2016-10-28 16:17:3234 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.net.impl
pauljensen9041eb3c2015-12-09 12:29:0135 enum HttpCacheType {
36 // No HTTP cache.
37 DISABLED,
38 // HTTP cache persisted to disk.
39 DISK,
40 // HTTP cache kept in memory.
41 MEMORY,
42 };
43
mefc71361c2014-09-16 14:48:5644 // App-provided hint that server supports QUIC.
45 struct QuicHint {
pauljensen9041eb3c2015-12-09 12:29:0146 QuicHint(const std::string& host, int port, int alternate_port);
mefc71361c2014-09-16 14:48:5647 ~QuicHint();
48
mefc71361c2014-09-16 14:48:5649 // Host name of the server that supports QUIC.
pauljensen9041eb3c2015-12-09 12:29:0150 const std::string host;
mefc71361c2014-09-16 14:48:5651 // Port of the server that supports QUIC.
pauljensen9041eb3c2015-12-09 12:29:0152 const int port;
mefc71361c2014-09-16 14:48:5653 // Alternate protocol port.
pauljensen9041eb3c2015-12-09 12:29:0154 const int alternate_port;
mefc71361c2014-09-16 14:48:5655
56 private:
57 DISALLOW_COPY_AND_ASSIGN(QuicHint);
58 };
59
kapishnikovdf5ccab2015-12-03 18:38:5060 // Public-Key-Pinning configuration structure.
61 struct Pkp {
pauljensen9041eb3c2015-12-09 12:29:0162 Pkp(const std::string& host,
63 bool include_subdomains,
64 const base::Time& expiration_date);
kapishnikovdf5ccab2015-12-03 18:38:5065 ~Pkp();
66
kapishnikovdf5ccab2015-12-03 18:38:5067 // Host name.
pauljensen9041eb3c2015-12-09 12:29:0168 const std::string host;
kapishnikovdf5ccab2015-12-03 18:38:5069 // Pin hashes (currently SHA256 only).
pauljensen9041eb3c2015-12-09 12:29:0170 net::HashValueVector pin_hashes;
kapishnikovdf5ccab2015-12-03 18:38:5071 // Indicates whether the pinning should apply to the pinned host subdomains.
pauljensen9041eb3c2015-12-09 12:29:0172 const bool include_subdomains;
kapishnikovdf5ccab2015-12-03 18:38:5073 // Expiration date for the pins.
pauljensen9041eb3c2015-12-09 12:29:0174 const base::Time expiration_date;
kapishnikovdf5ccab2015-12-03 18:38:5075
76 private:
77 DISALLOW_COPY_AND_ASSIGN(Pkp);
78 };
79
pauljensen9041eb3c2015-12-09 12:29:0180 URLRequestContextConfig(
81 // Enable QUIC.
82 bool enable_quic,
mefc5da5712016-02-09 20:14:2383 // QUIC User Agent ID.
84 const std::string& quic_user_agent_id,
pauljensen9041eb3c2015-12-09 12:29:0185 // Enable SPDY.
86 bool enable_spdy,
87 // Enable SDCH.
88 bool enable_sdch,
89 // Type of http cache.
90 HttpCacheType http_cache,
91 // Max size of http cache in bytes.
92 int http_cache_max_size,
93 // Disable caching for HTTP responses. Other information may be stored in
94 // the cache.
95 bool load_disable_cache,
96 // Storage path for http cache and cookie storage.
97 const std::string& storage_path,
98 // User-Agent request header field.
99 const std::string& user_agent,
100 // JSON encoded experimental options.
101 const std::string& experimental_options,
102 // Data reduction proxy key.
103 const std::string& data_reduction_proxy_key,
104 // Data reduction proxy.
105 const std::string& data_reduction_primary_proxy,
106 // Fallback data reduction proxy.
107 const std::string& data_reduction_fallback_proxy,
108 // Data reduction proxy secure proxy check URL.
109 const std::string& data_reduction_secure_proxy_check_url,
110 // MockCertVerifier to use for testing purposes.
tbansal7018e2a2016-06-25 00:40:39111 std::unique_ptr<net::CertVerifier> mock_cert_verifier,
112 // Enable network quality estimator.
kapishnikov385aa422016-07-01 20:53:02113 bool enable_network_quality_estimator,
114 // Enable bypassing of public key pinning for local trust anchors
rtenneti121f9fa2016-07-07 23:49:28115 bool bypass_public_key_pinning_for_local_trust_anchors,
116 // Certificate verifier cache data.
117 const std::string& cert_verifier_data);
[email protected]94de3e02014-06-17 00:09:51118 ~URLRequestContextConfig();
119
120 // Configure |context_builder| based on |this|.
121 void ConfigureURLRequestContextBuilder(
pauljensene92c4092015-12-09 19:13:48122 net::URLRequestContextBuilder* context_builder,
xunjielida7f77022016-03-28 16:36:36123 net::NetLog* net_log,
124 const scoped_refptr<base::SequencedTaskRunner>& file_task_runner);
[email protected]94de3e02014-06-17 00:09:51125
[email protected]94de3e02014-06-17 00:09:51126 // Enable QUIC.
pauljensen9041eb3c2015-12-09 12:29:01127 const bool enable_quic;
mefc5da5712016-02-09 20:14:23128 // QUIC User Agent ID.
129 const std::string quic_user_agent_id;
[email protected]94de3e02014-06-17 00:09:51130 // Enable SPDY.
pauljensen9041eb3c2015-12-09 12:29:01131 const bool enable_spdy;
xunjielib8a6d56f2015-04-29 17:36:14132 // Enable SDCH.
pauljensen9041eb3c2015-12-09 12:29:01133 const bool enable_sdch;
134 // Type of http cache.
135 const HttpCacheType http_cache;
[email protected]94de3e02014-06-17 00:09:51136 // Max size of http cache in bytes.
pauljensen9041eb3c2015-12-09 12:29:01137 const int http_cache_max_size;
mefbb4f45c2015-01-12 18:03:25138 // Disable caching for HTTP responses. Other information may be stored in
139 // the cache.
pauljensen9041eb3c2015-12-09 12:29:01140 const bool load_disable_cache;
[email protected]94de3e02014-06-17 00:09:51141 // Storage path for http cache and cookie storage.
pauljensen9041eb3c2015-12-09 12:29:01142 const std::string storage_path;
mefd1907102014-11-07 17:46:48143 // User-Agent request header field.
pauljensen9041eb3c2015-12-09 12:29:01144 const std::string user_agent;
xunjieli61b1eaa2015-11-17 22:44:55145 // Experimental options encoded as a string in a JSON format containing
146 // experiments and their corresponding configuration options. The format
147 // is a JSON object with the name of the experiment as the key, and the
148 // configuration options as the value. An example:
149 // {"experiment1": {"option1": "option_value1", "option2": "option_value2",
150 // ...}, "experiment2: {"option3", "option_value3", ...}, ...}
pauljensen9041eb3c2015-12-09 12:29:01151 const std::string experimental_options;
bengr59cb6962015-05-13 17:55:58152 // Enable Data Reduction Proxy with authentication key.
pauljensen9041eb3c2015-12-09 12:29:01153 const std::string data_reduction_proxy_key;
154 const std::string data_reduction_primary_proxy;
155 const std::string data_reduction_fallback_proxy;
156 const std::string data_reduction_secure_proxy_check_url;
mefc71361c2014-09-16 14:48:56157
xunjieli013145f2015-10-20 23:20:11158 // Certificate verifier for testing.
dchengfe3745e6242016-04-21 23:49:58159 std::unique_ptr<net::CertVerifier> mock_cert_verifier;
xunjieli013145f2015-10-20 23:20:11160
tbansal7018e2a2016-06-25 00:40:39161 // Enable network quality estimator.
162 const bool enable_network_quality_estimator;
163
kapishnikov385aa422016-07-01 20:53:02164 // Enable public key pinning bypass for local trust anchors.
165 const bool bypass_public_key_pinning_for_local_trust_anchors;
166
rtenneti121f9fa2016-07-07 23:49:28167 // Data to populte CertVerifierCache.
168 const std::string cert_verifier_data;
169
pauljensen9041eb3c2015-12-09 12:29:01170 // App-provided list of servers that support QUIC.
171 ScopedVector<QuicHint> quic_hints;
172
173 // The list of public key pins.
174 ScopedVector<Pkp> pkp_list;
175
mefc71361c2014-09-16 14:48:56176 private:
177 DISALLOW_COPY_AND_ASSIGN(URLRequestContextConfig);
[email protected]94de3e02014-06-17 00:09:51178};
179
lilyhoughton14e2a1f12017-01-11 14:50:27180// Stores intermediate state for URLRequestContextConfig. Initializes with
181// (mostly) sane defaults, then the appropriate member variables can be
182// modified, and it can be finalized with Build().
183struct URLRequestContextConfigBuilder {
184 URLRequestContextConfigBuilder();
185 ~URLRequestContextConfigBuilder();
186
187 // Finalize state into a URLRequestContextConfig. Must only be called once,
188 // as once |mock_cert_verifier| is moved into a URLRequestContextConfig, it
189 // cannot be used again.
190 std::unique_ptr<URLRequestContextConfig> Build();
191
192 // Enable QUIC.
193 bool enable_quic = false;
194 // QUIC User Agent ID.
195 std::string quic_user_agent_id = "";
196 // Enable SPDY.
197 bool enable_spdy = true;
198 // Enable SDCH.
199 bool enable_sdch = false;
200 // Type of http cache.
201 URLRequestContextConfig::HttpCacheType http_cache =
202 URLRequestContextConfig::DISABLED;
203 // Max size of http cache in bytes.
204 int http_cache_max_size = 0;
205 // Disable caching for HTTP responses. Other information may be stored in
206 // the cache.
207 bool load_disable_cache = false;
208 // Storage path for http cache and cookie storage.
209 std::string storage_path = "";
210 // User-Agent request header field.
211 std::string user_agent = "";
212 // Experimental options encoded as a string in a JSON format containing
213 // experiments and their corresponding configuration options. The format
214 // is a JSON object with the name of the experiment as the key, and the
215 // configuration options as the value. An example:
216 // {"experiment1": {"option1": "option_value1", "option2": "option_value2",
217 // ...}, "experiment2: {"option3", "option_value3", ...}, ...}
218 std::string experimental_options = "{}";
219 // Enable Data Reduction Proxy with authentication key.
220 std::string data_reduction_proxy_key = "";
221 std::string data_reduction_primary_proxy = "";
222 std::string data_reduction_fallback_proxy = "";
223 std::string data_reduction_secure_proxy_check_url = "";
224
225 // Certificate verifier for testing.
226 std::unique_ptr<net::CertVerifier> mock_cert_verifier = nullptr;
227
228 // Enable network quality estimator.
229 bool enable_network_quality_estimator = false;
230
231 // Enable public key pinning bypass for local trust anchors.
232 bool bypass_public_key_pinning_for_local_trust_anchors = true;
233
234 // Data to populate CertVerifierCache.
235 std::string cert_verifier_data = "";
236
237 private:
238 DISALLOW_COPY_AND_ASSIGN(URLRequestContextConfigBuilder);
239};
240
[email protected]94de3e02014-06-17 00:09:51241} // namespace cronet
242
243#endif // COMPONENTS_CRONET_URL_REQUEST_CONTEXT_CONFIG_H_