blob: 51eb80b635821c9b17b81ea6856f7905c9c090c0 [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"
kapishnikovdf5ccab2015-12-03 18:38:5014#include "base/time/time.h"
mgershcc6ae892017-06-20 22:33:5315#include "base/values.h"
pauljensen9041eb3c2015-12-09 12:29:0116#include "net/base/hash_value.h"
lilyhoughton14e2a1f12017-01-11 14:50:2717#include "net/cert/cert_verifier.h"
[email protected]94de3e02014-06-17 00:09:5118
xunjielida7f77022016-03-28 16:36:3619namespace base {
20class SequencedTaskRunner;
21} // namespace base
22
[email protected]94de3e02014-06-17 00:09:5123namespace net {
xunjieli013145f2015-10-20 23:20:1124class CertVerifier;
pauljensene92c4092015-12-09 19:13:4825class NetLog;
[email protected]94de3e02014-06-17 00:09:5126class URLRequestContextBuilder;
27} // namespace net
28
29namespace cronet {
30
31// Common configuration parameters used by Cronet to configure
pauljensen9041eb3c2015-12-09 12:29:0132// URLRequestContext.
mgershcc6ae892017-06-20 22:33:5333// TODO(mgersh): This shouldn't be a struct, and experimental option parsing
34// should be kept more separate from applying the configuration.
[email protected]94de3e02014-06-17 00:09:5135struct URLRequestContextConfig {
pauljensen9041eb3c2015-12-09 12:29:0136 // Type of HTTP cache.
kapishnikovaa8f338c2016-10-28 16:17:3237 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.net.impl
pauljensen9041eb3c2015-12-09 12:29:0138 enum HttpCacheType {
39 // No HTTP cache.
40 DISABLED,
41 // HTTP cache persisted to disk.
42 DISK,
43 // HTTP cache kept in memory.
44 MEMORY,
45 };
46
mefc71361c2014-09-16 14:48:5647 // App-provided hint that server supports QUIC.
48 struct QuicHint {
pauljensen9041eb3c2015-12-09 12:29:0149 QuicHint(const std::string& host, int port, int alternate_port);
mefc71361c2014-09-16 14:48:5650 ~QuicHint();
51
mefc71361c2014-09-16 14:48:5652 // Host name of the server that supports QUIC.
pauljensen9041eb3c2015-12-09 12:29:0153 const std::string host;
mefc71361c2014-09-16 14:48:5654 // Port of the server that supports QUIC.
pauljensen9041eb3c2015-12-09 12:29:0155 const int port;
mefc71361c2014-09-16 14:48:5656 // Alternate protocol port.
pauljensen9041eb3c2015-12-09 12:29:0157 const int alternate_port;
mefc71361c2014-09-16 14:48:5658
59 private:
60 DISALLOW_COPY_AND_ASSIGN(QuicHint);
61 };
62
kapishnikovdf5ccab2015-12-03 18:38:5063 // Public-Key-Pinning configuration structure.
64 struct Pkp {
pauljensen9041eb3c2015-12-09 12:29:0165 Pkp(const std::string& host,
66 bool include_subdomains,
67 const base::Time& expiration_date);
kapishnikovdf5ccab2015-12-03 18:38:5068 ~Pkp();
69
kapishnikovdf5ccab2015-12-03 18:38:5070 // Host name.
pauljensen9041eb3c2015-12-09 12:29:0171 const std::string host;
kapishnikovdf5ccab2015-12-03 18:38:5072 // Pin hashes (currently SHA256 only).
pauljensen9041eb3c2015-12-09 12:29:0173 net::HashValueVector pin_hashes;
kapishnikovdf5ccab2015-12-03 18:38:5074 // Indicates whether the pinning should apply to the pinned host subdomains.
pauljensen9041eb3c2015-12-09 12:29:0175 const bool include_subdomains;
kapishnikovdf5ccab2015-12-03 18:38:5076 // Expiration date for the pins.
pauljensen9041eb3c2015-12-09 12:29:0177 const base::Time expiration_date;
kapishnikovdf5ccab2015-12-03 18:38:5078
79 private:
80 DISALLOW_COPY_AND_ASSIGN(Pkp);
81 };
82
pauljensen9041eb3c2015-12-09 12:29:0183 URLRequestContextConfig(
84 // Enable QUIC.
85 bool enable_quic,
mefc5da5712016-02-09 20:14:2386 // QUIC User Agent ID.
87 const std::string& quic_user_agent_id,
pauljensen9041eb3c2015-12-09 12:29:0188 // Enable SPDY.
89 bool enable_spdy,
90 // Enable SDCH.
91 bool enable_sdch,
xunjieli186d2bf2017-04-18 13:45:4792 // Enable Brotli.
93 bool enable_brotli,
pauljensen9041eb3c2015-12-09 12:29:0194 // Type of http cache.
95 HttpCacheType http_cache,
96 // Max size of http cache in bytes.
97 int http_cache_max_size,
98 // Disable caching for HTTP responses. Other information may be stored in
99 // the cache.
100 bool load_disable_cache,
101 // Storage path for http cache and cookie storage.
102 const std::string& storage_path,
103 // User-Agent request header field.
104 const std::string& user_agent,
105 // JSON encoded experimental options.
106 const std::string& experimental_options,
pauljensen9041eb3c2015-12-09 12:29:01107 // MockCertVerifier to use for testing purposes.
tbansal7018e2a2016-06-25 00:40:39108 std::unique_ptr<net::CertVerifier> mock_cert_verifier,
109 // Enable network quality estimator.
kapishnikov385aa422016-07-01 20:53:02110 bool enable_network_quality_estimator,
111 // Enable bypassing of public key pinning for local trust anchors
rtenneti121f9fa2016-07-07 23:49:28112 bool bypass_public_key_pinning_for_local_trust_anchors,
113 // Certificate verifier cache data.
114 const std::string& cert_verifier_data);
[email protected]94de3e02014-06-17 00:09:51115 ~URLRequestContextConfig();
116
xunjielid67295e2017-03-16 21:05:41117 // Configures |context_builder| based on |this|.
[email protected]94de3e02014-06-17 00:09:51118 void ConfigureURLRequestContextBuilder(
pauljensene92c4092015-12-09 19:13:48119 net::URLRequestContextBuilder* context_builder,
xunjielida7f77022016-03-28 16:36:36120 net::NetLog* net_log,
121 const scoped_refptr<base::SequencedTaskRunner>& file_task_runner);
[email protected]94de3e02014-06-17 00:09:51122
[email protected]94de3e02014-06-17 00:09:51123 // Enable QUIC.
pauljensen9041eb3c2015-12-09 12:29:01124 const bool enable_quic;
mefc5da5712016-02-09 20:14:23125 // QUIC User Agent ID.
126 const std::string quic_user_agent_id;
[email protected]94de3e02014-06-17 00:09:51127 // Enable SPDY.
pauljensen9041eb3c2015-12-09 12:29:01128 const bool enable_spdy;
xunjielib8a6d56f2015-04-29 17:36:14129 // Enable SDCH.
pauljensen9041eb3c2015-12-09 12:29:01130 const bool enable_sdch;
xunjieli186d2bf2017-04-18 13:45:47131 // Enable Brotli.
132 const bool enable_brotli;
pauljensen9041eb3c2015-12-09 12:29:01133 // Type of http cache.
134 const HttpCacheType http_cache;
[email protected]94de3e02014-06-17 00:09:51135 // Max size of http cache in bytes.
pauljensen9041eb3c2015-12-09 12:29:01136 const int http_cache_max_size;
mefbb4f45c2015-01-12 18:03:25137 // Disable caching for HTTP responses. Other information may be stored in
138 // the cache.
pauljensen9041eb3c2015-12-09 12:29:01139 const bool load_disable_cache;
[email protected]94de3e02014-06-17 00:09:51140 // Storage path for http cache and cookie storage.
pauljensen9041eb3c2015-12-09 12:29:01141 const std::string storage_path;
mefd1907102014-11-07 17:46:48142 // User-Agent request header field.
pauljensen9041eb3c2015-12-09 12:29:01143 const std::string user_agent;
xunjieli61b1eaa2015-11-17 22:44:55144 // Experimental options encoded as a string in a JSON format containing
145 // experiments and their corresponding configuration options. The format
146 // is a JSON object with the name of the experiment as the key, and the
147 // configuration options as the value. An example:
148 // {"experiment1": {"option1": "option_value1", "option2": "option_value2",
149 // ...}, "experiment2: {"option3", "option_value3", ...}, ...}
pauljensen9041eb3c2015-12-09 12:29:01150 const std::string experimental_options;
mefc71361c2014-09-16 14:48:56151
xunjieli013145f2015-10-20 23:20:11152 // Certificate verifier for testing.
dchengfe3745e6242016-04-21 23:49:58153 std::unique_ptr<net::CertVerifier> mock_cert_verifier;
xunjieli013145f2015-10-20 23:20:11154
tbansal7018e2a2016-06-25 00:40:39155 // Enable network quality estimator.
156 const bool enable_network_quality_estimator;
157
kapishnikov385aa422016-07-01 20:53:02158 // Enable public key pinning bypass for local trust anchors.
159 const bool bypass_public_key_pinning_for_local_trust_anchors;
160
rtenneti121f9fa2016-07-07 23:49:28161 // Data to populte CertVerifierCache.
162 const std::string cert_verifier_data;
163
pauljensen9041eb3c2015-12-09 12:29:01164 // App-provided list of servers that support QUIC.
Donna Wu7ea51c22017-06-20 08:34:52165 std::vector<std::unique_ptr<QuicHint>> quic_hints;
pauljensen9041eb3c2015-12-09 12:29:01166
167 // The list of public key pins.
Donna Wu7ea51c22017-06-20 08:34:52168 std::vector<std::unique_ptr<Pkp>> pkp_list;
pauljensen9041eb3c2015-12-09 12:29:01169
mgershac5f75a2017-06-28 16:53:08170 // Enable DNS cache persistence.
171 bool enable_host_cache_persistence = false;
172
173 // Minimum time in milliseconds between writing the HostCache contents to
174 // prefs. Only relevant when |enable_host_cache_persistence| is true.
175 int host_cache_persistence_delay_ms = 60000;
176
xunjielid67295e2017-03-16 21:05:41177 // Experimental options that are recognized by the config parser.
mgershcc6ae892017-06-20 22:33:53178 std::unique_ptr<base::DictionaryValue> effective_experimental_options =
179 nullptr;
xunjielid67295e2017-03-16 21:05:41180
mefc71361c2014-09-16 14:48:56181 private:
mgershcc6ae892017-06-20 22:33:53182 // Parses experimental options and makes appropriate changes to settings in
183 // the URLRequestContextConfig and URLRequestContextBuilder.
184 void ParseAndSetExperimentalOptions(
185 net::URLRequestContextBuilder* context_builder,
186 net::NetLog* net_log,
187 const scoped_refptr<base::SequencedTaskRunner>& file_task_runner);
188
mefc71361c2014-09-16 14:48:56189 DISALLOW_COPY_AND_ASSIGN(URLRequestContextConfig);
[email protected]94de3e02014-06-17 00:09:51190};
191
lilyhoughton14e2a1f12017-01-11 14:50:27192// Stores intermediate state for URLRequestContextConfig. Initializes with
193// (mostly) sane defaults, then the appropriate member variables can be
194// modified, and it can be finalized with Build().
195struct URLRequestContextConfigBuilder {
196 URLRequestContextConfigBuilder();
197 ~URLRequestContextConfigBuilder();
198
199 // Finalize state into a URLRequestContextConfig. Must only be called once,
200 // as once |mock_cert_verifier| is moved into a URLRequestContextConfig, it
201 // cannot be used again.
202 std::unique_ptr<URLRequestContextConfig> Build();
203
204 // Enable QUIC.
205 bool enable_quic = false;
206 // QUIC User Agent ID.
207 std::string quic_user_agent_id = "";
208 // Enable SPDY.
209 bool enable_spdy = true;
210 // Enable SDCH.
211 bool enable_sdch = false;
xunjieli186d2bf2017-04-18 13:45:47212 // Enable Brotli.
213 bool enable_brotli = false;
lilyhoughton14e2a1f12017-01-11 14:50:27214 // Type of http cache.
215 URLRequestContextConfig::HttpCacheType http_cache =
216 URLRequestContextConfig::DISABLED;
217 // Max size of http cache in bytes.
218 int http_cache_max_size = 0;
219 // Disable caching for HTTP responses. Other information may be stored in
220 // the cache.
221 bool load_disable_cache = false;
222 // Storage path for http cache and cookie storage.
223 std::string storage_path = "";
224 // User-Agent request header field.
225 std::string user_agent = "";
226 // Experimental options encoded as a string in a JSON format containing
227 // experiments and their corresponding configuration options. The format
228 // is a JSON object with the name of the experiment as the key, and the
229 // configuration options as the value. An example:
230 // {"experiment1": {"option1": "option_value1", "option2": "option_value2",
231 // ...}, "experiment2: {"option3", "option_value3", ...}, ...}
232 std::string experimental_options = "{}";
lilyhoughton14e2a1f12017-01-11 14:50:27233
234 // Certificate verifier for testing.
235 std::unique_ptr<net::CertVerifier> mock_cert_verifier = nullptr;
236
237 // Enable network quality estimator.
238 bool enable_network_quality_estimator = false;
239
240 // Enable public key pinning bypass for local trust anchors.
241 bool bypass_public_key_pinning_for_local_trust_anchors = true;
242
243 // Data to populate CertVerifierCache.
244 std::string cert_verifier_data = "";
245
246 private:
247 DISALLOW_COPY_AND_ASSIGN(URLRequestContextConfigBuilder);
248};
249
[email protected]94de3e02014-06-17 00:09:51250} // namespace cronet
251
252#endif // COMPONENTS_CRONET_URL_REQUEST_CONTEXT_CONFIG_H_