blob: a7fc179f40d6f21d1c8a212c4d9dee4ea74ea078 [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"
tbansale11aa362017-07-04 15:59:3619#include "net/nqe/effective_connection_type.h"
[email protected]94de3e02014-06-17 00:09:5120
xunjielida7f77022016-03-28 16:36:3621namespace base {
22class SequencedTaskRunner;
23} // namespace base
24
[email protected]94de3e02014-06-17 00:09:5125namespace net {
xunjieli013145f2015-10-20 23:20:1126class CertVerifier;
pauljensene92c4092015-12-09 19:13:4827class NetLog;
[email protected]94de3e02014-06-17 00:09:5128class URLRequestContextBuilder;
29} // namespace net
30
31namespace cronet {
32
33// Common configuration parameters used by Cronet to configure
pauljensen9041eb3c2015-12-09 12:29:0134// URLRequestContext.
mgershcc6ae892017-06-20 22:33:5335// TODO(mgersh): This shouldn't be a struct, and experimental option parsing
36// should be kept more separate from applying the configuration.
[email protected]94de3e02014-06-17 00:09:5137struct URLRequestContextConfig {
pauljensen9041eb3c2015-12-09 12:29:0138 // Type of HTTP cache.
kapishnikovaa8f338c2016-10-28 16:17:3239 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.net.impl
pauljensen9041eb3c2015-12-09 12:29:0140 enum HttpCacheType {
41 // No HTTP cache.
42 DISABLED,
43 // HTTP cache persisted to disk.
44 DISK,
45 // HTTP cache kept in memory.
46 MEMORY,
47 };
48
mefc71361c2014-09-16 14:48:5649 // App-provided hint that server supports QUIC.
50 struct QuicHint {
pauljensen9041eb3c2015-12-09 12:29:0151 QuicHint(const std::string& host, int port, int alternate_port);
mefc71361c2014-09-16 14:48:5652 ~QuicHint();
53
mefc71361c2014-09-16 14:48:5654 // Host name of the server that supports QUIC.
pauljensen9041eb3c2015-12-09 12:29:0155 const std::string host;
mefc71361c2014-09-16 14:48:5656 // Port of the server that supports QUIC.
pauljensen9041eb3c2015-12-09 12:29:0157 const int port;
mefc71361c2014-09-16 14:48:5658 // Alternate protocol port.
pauljensen9041eb3c2015-12-09 12:29:0159 const int alternate_port;
mefc71361c2014-09-16 14:48:5660
61 private:
62 DISALLOW_COPY_AND_ASSIGN(QuicHint);
63 };
64
kapishnikovdf5ccab2015-12-03 18:38:5065 // Public-Key-Pinning configuration structure.
66 struct Pkp {
pauljensen9041eb3c2015-12-09 12:29:0167 Pkp(const std::string& host,
68 bool include_subdomains,
69 const base::Time& expiration_date);
kapishnikovdf5ccab2015-12-03 18:38:5070 ~Pkp();
71
kapishnikovdf5ccab2015-12-03 18:38:5072 // Host name.
pauljensen9041eb3c2015-12-09 12:29:0173 const std::string host;
kapishnikovdf5ccab2015-12-03 18:38:5074 // Pin hashes (currently SHA256 only).
pauljensen9041eb3c2015-12-09 12:29:0175 net::HashValueVector pin_hashes;
kapishnikovdf5ccab2015-12-03 18:38:5076 // Indicates whether the pinning should apply to the pinned host subdomains.
pauljensen9041eb3c2015-12-09 12:29:0177 const bool include_subdomains;
kapishnikovdf5ccab2015-12-03 18:38:5078 // Expiration date for the pins.
pauljensen9041eb3c2015-12-09 12:29:0179 const base::Time expiration_date;
kapishnikovdf5ccab2015-12-03 18:38:5080
81 private:
82 DISALLOW_COPY_AND_ASSIGN(Pkp);
83 };
84
pauljensen9041eb3c2015-12-09 12:29:0185 URLRequestContextConfig(
86 // Enable QUIC.
87 bool enable_quic,
mefc5da5712016-02-09 20:14:2388 // QUIC User Agent ID.
89 const std::string& quic_user_agent_id,
pauljensen9041eb3c2015-12-09 12:29:0190 // Enable SPDY.
91 bool enable_spdy,
92 // Enable SDCH.
93 bool enable_sdch,
xunjieli186d2bf2017-04-18 13:45:4794 // Enable Brotli.
95 bool enable_brotli,
pauljensen9041eb3c2015-12-09 12:29:0196 // Type of http cache.
97 HttpCacheType http_cache,
98 // Max size of http cache in bytes.
99 int http_cache_max_size,
100 // Disable caching for HTTP responses. Other information may be stored in
101 // the cache.
102 bool load_disable_cache,
103 // Storage path for http cache and cookie storage.
104 const std::string& storage_path,
105 // User-Agent request header field.
106 const std::string& user_agent,
107 // JSON encoded experimental options.
108 const std::string& experimental_options,
pauljensen9041eb3c2015-12-09 12:29:01109 // MockCertVerifier to use for testing purposes.
tbansal7018e2a2016-06-25 00:40:39110 std::unique_ptr<net::CertVerifier> mock_cert_verifier,
111 // Enable network quality estimator.
kapishnikov385aa422016-07-01 20:53:02112 bool enable_network_quality_estimator,
113 // Enable bypassing of public key pinning for local trust anchors
rtenneti121f9fa2016-07-07 23:49:28114 bool bypass_public_key_pinning_for_local_trust_anchors,
115 // Certificate verifier cache data.
116 const std::string& cert_verifier_data);
[email protected]94de3e02014-06-17 00:09:51117 ~URLRequestContextConfig();
118
xunjielid67295e2017-03-16 21:05:41119 // Configures |context_builder| based on |this|.
[email protected]94de3e02014-06-17 00:09:51120 void ConfigureURLRequestContextBuilder(
pauljensene92c4092015-12-09 19:13:48121 net::URLRequestContextBuilder* context_builder,
xunjielida7f77022016-03-28 16:36:36122 net::NetLog* net_log,
123 const scoped_refptr<base::SequencedTaskRunner>& file_task_runner);
[email protected]94de3e02014-06-17 00:09:51124
[email protected]94de3e02014-06-17 00:09:51125 // Enable QUIC.
pauljensen9041eb3c2015-12-09 12:29:01126 const bool enable_quic;
mefc5da5712016-02-09 20:14:23127 // QUIC User Agent ID.
128 const std::string quic_user_agent_id;
[email protected]94de3e02014-06-17 00:09:51129 // Enable SPDY.
pauljensen9041eb3c2015-12-09 12:29:01130 const bool enable_spdy;
xunjielib8a6d56f2015-04-29 17:36:14131 // Enable SDCH.
pauljensen9041eb3c2015-12-09 12:29:01132 const bool enable_sdch;
xunjieli186d2bf2017-04-18 13:45:47133 // Enable Brotli.
134 const bool enable_brotli;
pauljensen9041eb3c2015-12-09 12:29:01135 // Type of http cache.
136 const HttpCacheType http_cache;
[email protected]94de3e02014-06-17 00:09:51137 // Max size of http cache in bytes.
pauljensen9041eb3c2015-12-09 12:29:01138 const int http_cache_max_size;
mefbb4f45c2015-01-12 18:03:25139 // Disable caching for HTTP responses. Other information may be stored in
140 // the cache.
pauljensen9041eb3c2015-12-09 12:29:01141 const bool load_disable_cache;
[email protected]94de3e02014-06-17 00:09:51142 // Storage path for http cache and cookie storage.
pauljensen9041eb3c2015-12-09 12:29:01143 const std::string storage_path;
mefd1907102014-11-07 17:46:48144 // User-Agent request header field.
pauljensen9041eb3c2015-12-09 12:29:01145 const std::string user_agent;
mefc71361c2014-09-16 14:48:56146
xunjieli013145f2015-10-20 23:20:11147 // Certificate verifier for testing.
dchengfe3745e6242016-04-21 23:49:58148 std::unique_ptr<net::CertVerifier> mock_cert_verifier;
xunjieli013145f2015-10-20 23:20:11149
tbansale11aa362017-07-04 15:59:36150 // Enable Network Quality Estimator (NQE).
tbansal7018e2a2016-06-25 00:40:39151 const bool enable_network_quality_estimator;
152
kapishnikov385aa422016-07-01 20:53:02153 // Enable public key pinning bypass for local trust anchors.
154 const bool bypass_public_key_pinning_for_local_trust_anchors;
155
rtenneti121f9fa2016-07-07 23:49:28156 // Data to populte CertVerifierCache.
157 const std::string cert_verifier_data;
158
pauljensen9041eb3c2015-12-09 12:29:01159 // App-provided list of servers that support QUIC.
Donna Wu7ea51c22017-06-20 08:34:52160 std::vector<std::unique_ptr<QuicHint>> quic_hints;
pauljensen9041eb3c2015-12-09 12:29:01161
162 // The list of public key pins.
Donna Wu7ea51c22017-06-20 08:34:52163 std::vector<std::unique_ptr<Pkp>> pkp_list;
pauljensen9041eb3c2015-12-09 12:29:01164
mgershac5f75a2017-06-28 16:53:08165 // Enable DNS cache persistence.
166 bool enable_host_cache_persistence = false;
167
168 // Minimum time in milliseconds between writing the HostCache contents to
169 // prefs. Only relevant when |enable_host_cache_persistence| is true.
170 int host_cache_persistence_delay_ms = 60000;
171
xunjielid67295e2017-03-16 21:05:41172 // Experimental options that are recognized by the config parser.
mgershcc6ae892017-06-20 22:33:53173 std::unique_ptr<base::DictionaryValue> effective_experimental_options =
174 nullptr;
xunjielid67295e2017-03-16 21:05:41175
tbansale11aa362017-07-04 15:59:36176 // Enable reading of the network quality from the prefs.
177 bool nqe_persistent_caching_enabled;
178
179 // If set, forces NQE to return the set value as the effective connection
180 // type.
181 base::Optional<net::EffectiveConnectionType>
182 nqe_forced_effective_connection_type;
183
mefc71361c2014-09-16 14:48:56184 private:
mgershcc6ae892017-06-20 22:33:53185 // Parses experimental options and makes appropriate changes to settings in
186 // the URLRequestContextConfig and URLRequestContextBuilder.
187 void ParseAndSetExperimentalOptions(
188 net::URLRequestContextBuilder* context_builder,
189 net::NetLog* net_log,
190 const scoped_refptr<base::SequencedTaskRunner>& file_task_runner);
191
tbansale11aa362017-07-04 15:59:36192 // Experimental options encoded as a string in a JSON format containing
193 // experiments and their corresponding configuration options. The format
194 // is a JSON object with the name of the experiment as the key, and the
195 // configuration options as the value. An example:
196 // {"experiment1": {"option1": "option_value1", "option2": "option_value2",
197 // ...}, "experiment2: {"option3", "option_value3", ...}, ...}
198 const std::string experimental_options;
199
mefc71361c2014-09-16 14:48:56200 DISALLOW_COPY_AND_ASSIGN(URLRequestContextConfig);
[email protected]94de3e02014-06-17 00:09:51201};
202
lilyhoughton14e2a1f12017-01-11 14:50:27203// Stores intermediate state for URLRequestContextConfig. Initializes with
204// (mostly) sane defaults, then the appropriate member variables can be
205// modified, and it can be finalized with Build().
206struct URLRequestContextConfigBuilder {
207 URLRequestContextConfigBuilder();
208 ~URLRequestContextConfigBuilder();
209
210 // Finalize state into a URLRequestContextConfig. Must only be called once,
211 // as once |mock_cert_verifier| is moved into a URLRequestContextConfig, it
212 // cannot be used again.
213 std::unique_ptr<URLRequestContextConfig> Build();
214
215 // Enable QUIC.
216 bool enable_quic = false;
217 // QUIC User Agent ID.
218 std::string quic_user_agent_id = "";
219 // Enable SPDY.
220 bool enable_spdy = true;
221 // Enable SDCH.
222 bool enable_sdch = false;
xunjieli186d2bf2017-04-18 13:45:47223 // Enable Brotli.
224 bool enable_brotli = false;
lilyhoughton14e2a1f12017-01-11 14:50:27225 // Type of http cache.
226 URLRequestContextConfig::HttpCacheType http_cache =
227 URLRequestContextConfig::DISABLED;
228 // Max size of http cache in bytes.
229 int http_cache_max_size = 0;
230 // Disable caching for HTTP responses. Other information may be stored in
231 // the cache.
232 bool load_disable_cache = false;
233 // Storage path for http cache and cookie storage.
234 std::string storage_path = "";
235 // User-Agent request header field.
236 std::string user_agent = "";
237 // Experimental options encoded as a string in a JSON format containing
238 // experiments and their corresponding configuration options. The format
239 // is a JSON object with the name of the experiment as the key, and the
240 // configuration options as the value. An example:
241 // {"experiment1": {"option1": "option_value1", "option2": "option_value2",
242 // ...}, "experiment2: {"option3", "option_value3", ...}, ...}
243 std::string experimental_options = "{}";
lilyhoughton14e2a1f12017-01-11 14:50:27244
245 // Certificate verifier for testing.
246 std::unique_ptr<net::CertVerifier> mock_cert_verifier = nullptr;
247
248 // Enable network quality estimator.
249 bool enable_network_quality_estimator = false;
250
251 // Enable public key pinning bypass for local trust anchors.
252 bool bypass_public_key_pinning_for_local_trust_anchors = true;
253
254 // Data to populate CertVerifierCache.
255 std::string cert_verifier_data = "";
256
257 private:
258 DISALLOW_COPY_AND_ASSIGN(URLRequestContextConfigBuilder);
259};
260
[email protected]94de3e02014-06-17 00:09:51261} // namespace cronet
262
263#endif // COMPONENTS_CRONET_URL_REQUEST_CONTEXT_CONFIG_H_