blob: 7c19ee0765f5ac3b3faf0373c9f76faa3d75a1a4 [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>
Donna Wu7ea51c22017-06-20 08:34:5210#include <vector>
[email protected]94de3e02014-06-17 00:09:5111
mefc71361c2014-09-16 14:48:5612#include "base/macros.h"
xunjielida7f77022016-03-28 16:36:3613#include "base/memory/ref_counted.h"
tbansale11aa362017-07-04 15:59:3614#include "base/optional.h"
kapishnikovdf5ccab2015-12-03 18:38:5015#include "base/time/time.h"
mgershcc6ae892017-06-20 22:33:5316#include "base/values.h"
pauljensen9041eb3c2015-12-09 12:29:0117#include "net/base/hash_value.h"
lilyhoughton14e2a1f12017-01-11 14:50:2718#include "net/cert/cert_verifier.h"
mmenkecf3cb2a2017-07-07 20:48:4419#include "net/http/http_network_session.h"
tbansale11aa362017-07-04 15:59:3620#include "net/nqe/effective_connection_type.h"
[email protected]94de3e02014-06-17 00:09:5121
22namespace net {
xunjieli013145f2015-10-20 23:20:1123class CertVerifier;
[email protected]94de3e02014-06-17 00:09:5124class URLRequestContextBuilder;
25} // namespace net
26
27namespace cronet {
28
29// Common configuration parameters used by Cronet to configure
pauljensen9041eb3c2015-12-09 12:29:0130// URLRequestContext.
mgershcc6ae892017-06-20 22:33:5331// TODO(mgersh): This shouldn't be a struct, and experimental option parsing
32// should be kept more separate from applying the configuration.
[email protected]94de3e02014-06-17 00:09:5133struct URLRequestContextConfig {
pauljensen9041eb3c2015-12-09 12:29:0134 // Type of HTTP cache.
kapishnikovaa8f338c2016-10-28 16:17:3235 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.net.impl
pauljensen9041eb3c2015-12-09 12:29:0136 enum HttpCacheType {
37 // No HTTP cache.
38 DISABLED,
39 // HTTP cache persisted to disk.
40 DISK,
41 // HTTP cache kept in memory.
42 MEMORY,
43 };
44
mefc71361c2014-09-16 14:48:5645 // App-provided hint that server supports QUIC.
46 struct QuicHint {
pauljensen9041eb3c2015-12-09 12:29:0147 QuicHint(const std::string& host, int port, int alternate_port);
mefc71361c2014-09-16 14:48:5648 ~QuicHint();
49
mefc71361c2014-09-16 14:48:5650 // Host name of the server that supports QUIC.
pauljensen9041eb3c2015-12-09 12:29:0151 const std::string host;
mefc71361c2014-09-16 14:48:5652 // Port of the server that supports QUIC.
pauljensen9041eb3c2015-12-09 12:29:0153 const int port;
mefc71361c2014-09-16 14:48:5654 // Alternate protocol port.
pauljensen9041eb3c2015-12-09 12:29:0155 const int alternate_port;
mefc71361c2014-09-16 14:48:5656
57 private:
58 DISALLOW_COPY_AND_ASSIGN(QuicHint);
59 };
60
kapishnikovdf5ccab2015-12-03 18:38:5061 // Public-Key-Pinning configuration structure.
62 struct Pkp {
pauljensen9041eb3c2015-12-09 12:29:0163 Pkp(const std::string& host,
64 bool include_subdomains,
65 const base::Time& expiration_date);
kapishnikovdf5ccab2015-12-03 18:38:5066 ~Pkp();
67
kapishnikovdf5ccab2015-12-03 18:38:5068 // Host name.
pauljensen9041eb3c2015-12-09 12:29:0169 const std::string host;
kapishnikovdf5ccab2015-12-03 18:38:5070 // Pin hashes (currently SHA256 only).
pauljensen9041eb3c2015-12-09 12:29:0171 net::HashValueVector pin_hashes;
kapishnikovdf5ccab2015-12-03 18:38:5072 // Indicates whether the pinning should apply to the pinned host subdomains.
pauljensen9041eb3c2015-12-09 12:29:0173 const bool include_subdomains;
kapishnikovdf5ccab2015-12-03 18:38:5074 // Expiration date for the pins.
pauljensen9041eb3c2015-12-09 12:29:0175 const base::Time expiration_date;
kapishnikovdf5ccab2015-12-03 18:38:5076
77 private:
78 DISALLOW_COPY_AND_ASSIGN(Pkp);
79 };
80
Douglas Creagera220947e2018-08-23 20:08:5381 // Simulated headers, used to preconfigure the Reporting API and Network Error
82 // Logging before receiving those actual configuration headers from the
83 // origins.
84 struct PreloadedNelAndReportingHeader {
85 PreloadedNelAndReportingHeader(const url::Origin& origin,
86 std::string value);
87 ~PreloadedNelAndReportingHeader();
88
89 // Origin that is "sending" this header.
90 const url::Origin origin;
91
92 // Value of the header that is "sent".
93 const std::string value;
94 };
95
pauljensen9041eb3c2015-12-09 12:29:0196 URLRequestContextConfig(
97 // Enable QUIC.
98 bool enable_quic,
mefc5da5712016-02-09 20:14:2399 // QUIC User Agent ID.
100 const std::string& quic_user_agent_id,
pauljensen9041eb3c2015-12-09 12:29:01101 // Enable SPDY.
102 bool enable_spdy,
xunjieli186d2bf2017-04-18 13:45:47103 // Enable Brotli.
104 bool enable_brotli,
pauljensen9041eb3c2015-12-09 12:29:01105 // Type of http cache.
106 HttpCacheType http_cache,
107 // Max size of http cache in bytes.
108 int http_cache_max_size,
109 // Disable caching for HTTP responses. Other information may be stored in
110 // the cache.
111 bool load_disable_cache,
112 // Storage path for http cache and cookie storage.
113 const std::string& storage_path,
Misha Efimovd4ab38302018-01-30 23:56:42114 // Accept-Language request header field.
115 const std::string& accept_language,
pauljensen9041eb3c2015-12-09 12:29:01116 // User-Agent request header field.
117 const std::string& user_agent,
118 // JSON encoded experimental options.
119 const std::string& experimental_options,
pauljensen9041eb3c2015-12-09 12:29:01120 // MockCertVerifier to use for testing purposes.
tbansal7018e2a2016-06-25 00:40:39121 std::unique_ptr<net::CertVerifier> mock_cert_verifier,
122 // Enable network quality estimator.
kapishnikov385aa422016-07-01 20:53:02123 bool enable_network_quality_estimator,
124 // Enable bypassing of public key pinning for local trust anchors
Paul Jensen6a1ea3a2018-08-24 14:46:41125 bool bypass_public_key_pinning_for_local_trust_anchors,
126 // Optional network thread priority.
127 // On Android, corresponds to android.os.Process.setThreadPriority()
128 // values. On iOS, corresponds to NSThread::setThreadPriority values. Do
129 // not specify for other targets.
130 base::Optional<double> network_thread_priority);
[email protected]94de3e02014-06-17 00:09:51131 ~URLRequestContextConfig();
132
xunjielid67295e2017-03-16 21:05:41133 // Configures |context_builder| based on |this|.
[email protected]94de3e02014-06-17 00:09:51134 void ConfigureURLRequestContextBuilder(
Matt Muellerde5dadf2019-11-27 20:11:58135 net::URLRequestContextBuilder* context_builder);
[email protected]94de3e02014-06-17 00:09:51136
[email protected]94de3e02014-06-17 00:09:51137 // Enable QUIC.
pauljensen9041eb3c2015-12-09 12:29:01138 const bool enable_quic;
mefc5da5712016-02-09 20:14:23139 // QUIC User Agent ID.
140 const std::string quic_user_agent_id;
[email protected]94de3e02014-06-17 00:09:51141 // Enable SPDY.
pauljensen9041eb3c2015-12-09 12:29:01142 const bool enable_spdy;
xunjieli186d2bf2017-04-18 13:45:47143 // Enable Brotli.
144 const bool enable_brotli;
pauljensen9041eb3c2015-12-09 12:29:01145 // Type of http cache.
146 const HttpCacheType http_cache;
[email protected]94de3e02014-06-17 00:09:51147 // Max size of http cache in bytes.
pauljensen9041eb3c2015-12-09 12:29:01148 const int http_cache_max_size;
mefbb4f45c2015-01-12 18:03:25149 // Disable caching for HTTP responses. Other information may be stored in
150 // the cache.
pauljensen9041eb3c2015-12-09 12:29:01151 const bool load_disable_cache;
[email protected]94de3e02014-06-17 00:09:51152 // Storage path for http cache and cookie storage.
pauljensen9041eb3c2015-12-09 12:29:01153 const std::string storage_path;
Misha Efimovd4ab38302018-01-30 23:56:42154 // Accept-Language request header field.
155 const std::string accept_language;
mefd1907102014-11-07 17:46:48156 // User-Agent request header field.
pauljensen9041eb3c2015-12-09 12:29:01157 const std::string user_agent;
mefc71361c2014-09-16 14:48:56158
xunjieli013145f2015-10-20 23:20:11159 // Certificate verifier for testing.
dchengfe3745e6242016-04-21 23:49:58160 std::unique_ptr<net::CertVerifier> mock_cert_verifier;
xunjieli013145f2015-10-20 23:20:11161
tbansale11aa362017-07-04 15:59:36162 // Enable Network Quality Estimator (NQE).
tbansal7018e2a2016-06-25 00:40:39163 const bool enable_network_quality_estimator;
164
kapishnikov385aa422016-07-01 20:53:02165 // Enable public key pinning bypass for local trust anchors.
166 const bool bypass_public_key_pinning_for_local_trust_anchors;
167
pauljensen9041eb3c2015-12-09 12:29:01168 // App-provided list of servers that support QUIC.
Donna Wu7ea51c22017-06-20 08:34:52169 std::vector<std::unique_ptr<QuicHint>> quic_hints;
pauljensen9041eb3c2015-12-09 12:29:01170
171 // The list of public key pins.
Donna Wu7ea51c22017-06-20 08:34:52172 std::vector<std::unique_ptr<Pkp>> pkp_list;
pauljensen9041eb3c2015-12-09 12:29:01173
mgershac5f75a2017-06-28 16:53:08174 // Enable DNS cache persistence.
175 bool enable_host_cache_persistence = false;
176
177 // Minimum time in milliseconds between writing the HostCache contents to
178 // prefs. Only relevant when |enable_host_cache_persistence| is true.
179 int host_cache_persistence_delay_ms = 60000;
180
xunjielid67295e2017-03-16 21:05:41181 // Experimental options that are recognized by the config parser.
mgershcc6ae892017-06-20 22:33:53182 std::unique_ptr<base::DictionaryValue> effective_experimental_options =
183 nullptr;
xunjielid67295e2017-03-16 21:05:41184
tbansale11aa362017-07-04 15:59:36185 // If set, forces NQE to return the set value as the effective connection
186 // type.
187 base::Optional<net::EffectiveConnectionType>
188 nqe_forced_effective_connection_type;
189
Douglas Creagera220947e2018-08-23 20:08:53190 // Preloaded Report-To headers, to preconfigure the Reporting API.
191 std::vector<PreloadedNelAndReportingHeader> preloaded_report_to_headers;
192
193 // Preloaded NEL headers, to preconfigure Network Error Logging.
194 std::vector<PreloadedNelAndReportingHeader> preloaded_nel_headers;
195
Paul Jensen6a1ea3a2018-08-24 14:46:41196 // Optional network thread priority.
197 // On Android, corresponds to android.os.Process.setThreadPriority() values.
198 // On iOS, corresponds to NSThread::setThreadPriority values.
199 const base::Optional<double> network_thread_priority;
200
mefc71361c2014-09-16 14:48:56201 private:
mgershcc6ae892017-06-20 22:33:53202 // Parses experimental options and makes appropriate changes to settings in
203 // the URLRequestContextConfig and URLRequestContextBuilder.
204 void ParseAndSetExperimentalOptions(
205 net::URLRequestContextBuilder* context_builder,
Matt Muellerde5dadf2019-11-27 20:11:58206 net::HttpNetworkSession::Params* session_params);
mgershcc6ae892017-06-20 22:33:53207
tbansale11aa362017-07-04 15:59:36208 // Experimental options encoded as a string in a JSON format containing
209 // experiments and their corresponding configuration options. The format
210 // is a JSON object with the name of the experiment as the key, and the
211 // configuration options as the value. An example:
mmenkecf3cb2a2017-07-07 20:48:44212 // {"experiment1": {"option1": "option_value1", "option2":
213 // "option_value2",
tbansale11aa362017-07-04 15:59:36214 // ...}, "experiment2: {"option3", "option_value3", ...}, ...}
215 const std::string experimental_options;
216
mefc71361c2014-09-16 14:48:56217 DISALLOW_COPY_AND_ASSIGN(URLRequestContextConfig);
[email protected]94de3e02014-06-17 00:09:51218};
219
lilyhoughton14e2a1f12017-01-11 14:50:27220// Stores intermediate state for URLRequestContextConfig. Initializes with
221// (mostly) sane defaults, then the appropriate member variables can be
222// modified, and it can be finalized with Build().
223struct URLRequestContextConfigBuilder {
224 URLRequestContextConfigBuilder();
225 ~URLRequestContextConfigBuilder();
226
227 // Finalize state into a URLRequestContextConfig. Must only be called once,
228 // as once |mock_cert_verifier| is moved into a URLRequestContextConfig, it
229 // cannot be used again.
230 std::unique_ptr<URLRequestContextConfig> Build();
231
232 // Enable QUIC.
233 bool enable_quic = false;
234 // QUIC User Agent ID.
235 std::string quic_user_agent_id = "";
236 // Enable SPDY.
237 bool enable_spdy = true;
xunjieli186d2bf2017-04-18 13:45:47238 // Enable Brotli.
239 bool enable_brotli = false;
lilyhoughton14e2a1f12017-01-11 14:50:27240 // Type of http cache.
241 URLRequestContextConfig::HttpCacheType http_cache =
242 URLRequestContextConfig::DISABLED;
243 // Max size of http cache in bytes.
244 int http_cache_max_size = 0;
245 // Disable caching for HTTP responses. Other information may be stored in
246 // the cache.
247 bool load_disable_cache = false;
248 // Storage path for http cache and cookie storage.
249 std::string storage_path = "";
Misha Efimovd4ab38302018-01-30 23:56:42250 // Accept-Language request header field.
251 std::string accept_language = "";
lilyhoughton14e2a1f12017-01-11 14:50:27252 // User-Agent request header field.
253 std::string user_agent = "";
254 // Experimental options encoded as a string in a JSON format containing
255 // experiments and their corresponding configuration options. The format
256 // is a JSON object with the name of the experiment as the key, and the
257 // configuration options as the value. An example:
258 // {"experiment1": {"option1": "option_value1", "option2": "option_value2",
259 // ...}, "experiment2: {"option3", "option_value3", ...}, ...}
260 std::string experimental_options = "{}";
lilyhoughton14e2a1f12017-01-11 14:50:27261
262 // Certificate verifier for testing.
263 std::unique_ptr<net::CertVerifier> mock_cert_verifier = nullptr;
264
265 // Enable network quality estimator.
266 bool enable_network_quality_estimator = false;
267
268 // Enable public key pinning bypass for local trust anchors.
269 bool bypass_public_key_pinning_for_local_trust_anchors = true;
270
Paul Jensen6a1ea3a2018-08-24 14:46:41271 // Optional network thread priority.
272 // On Android, corresponds to android.os.Process.setThreadPriority() values.
273 // On iOS, corresponds to NSThread::setThreadPriority values.
274 // Do not specify for other targets.
275 base::Optional<double> network_thread_priority;
276
lilyhoughton14e2a1f12017-01-11 14:50:27277 private:
278 DISALLOW_COPY_AND_ASSIGN(URLRequestContextConfigBuilder);
279};
280
[email protected]94de3e02014-06-17 00:09:51281} // namespace cronet
282
283#endif // COMPONENTS_CRONET_URL_REQUEST_CONTEXT_CONFIG_H_