blob: 69e1b809bb1e0d73d6bf34e5095ba0f0333708e1 [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 {
xunjielid67295e2017-03-16 21:05:4119class DictionaryValue;
xunjielida7f77022016-03-28 16:36:3620class 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.
[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
pauljensen9041eb3c2015-12-09 12:29:0181 URLRequestContextConfig(
82 // Enable QUIC.
83 bool enable_quic,
mefc5da5712016-02-09 20:14:2384 // QUIC User Agent ID.
85 const std::string& quic_user_agent_id,
pauljensen9041eb3c2015-12-09 12:29:0186 // Enable SPDY.
87 bool enable_spdy,
88 // Enable SDCH.
89 bool enable_sdch,
90 // Type of http cache.
91 HttpCacheType http_cache,
92 // Max size of http cache in bytes.
93 int http_cache_max_size,
94 // Disable caching for HTTP responses. Other information may be stored in
95 // the cache.
96 bool load_disable_cache,
97 // Storage path for http cache and cookie storage.
98 const std::string& storage_path,
99 // User-Agent request header field.
100 const std::string& user_agent,
101 // JSON encoded experimental options.
102 const std::string& experimental_options,
103 // Data reduction proxy key.
104 const std::string& data_reduction_proxy_key,
105 // Data reduction proxy.
106 const std::string& data_reduction_primary_proxy,
107 // Fallback data reduction proxy.
108 const std::string& data_reduction_fallback_proxy,
109 // Data reduction proxy secure proxy check URL.
110 const std::string& data_reduction_secure_proxy_check_url,
111 // MockCertVerifier to use for testing purposes.
tbansal7018e2a2016-06-25 00:40:39112 std::unique_ptr<net::CertVerifier> mock_cert_verifier,
113 // Enable network quality estimator.
kapishnikov385aa422016-07-01 20:53:02114 bool enable_network_quality_estimator,
115 // Enable bypassing of public key pinning for local trust anchors
rtenneti121f9fa2016-07-07 23:49:28116 bool bypass_public_key_pinning_for_local_trust_anchors,
117 // Certificate verifier cache data.
118 const std::string& cert_verifier_data);
[email protected]94de3e02014-06-17 00:09:51119 ~URLRequestContextConfig();
120
xunjielid67295e2017-03-16 21:05:41121 // Configures |context_builder| based on |this|.
[email protected]94de3e02014-06-17 00:09:51122 void ConfigureURLRequestContextBuilder(
pauljensene92c4092015-12-09 19:13:48123 net::URLRequestContextBuilder* context_builder,
xunjielida7f77022016-03-28 16:36:36124 net::NetLog* net_log,
125 const scoped_refptr<base::SequencedTaskRunner>& file_task_runner);
[email protected]94de3e02014-06-17 00:09:51126
[email protected]94de3e02014-06-17 00:09:51127 // Enable QUIC.
pauljensen9041eb3c2015-12-09 12:29:01128 const bool enable_quic;
mefc5da5712016-02-09 20:14:23129 // QUIC User Agent ID.
130 const std::string quic_user_agent_id;
[email protected]94de3e02014-06-17 00:09:51131 // Enable SPDY.
pauljensen9041eb3c2015-12-09 12:29:01132 const bool enable_spdy;
xunjielib8a6d56f2015-04-29 17:36:14133 // Enable SDCH.
pauljensen9041eb3c2015-12-09 12:29:01134 const bool enable_sdch;
135 // 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;
xunjieli61b1eaa2015-11-17 22:44:55146 // Experimental options encoded as a string in a JSON format containing
147 // experiments and their corresponding configuration options. The format
148 // is a JSON object with the name of the experiment as the key, and the
149 // configuration options as the value. An example:
150 // {"experiment1": {"option1": "option_value1", "option2": "option_value2",
151 // ...}, "experiment2: {"option3", "option_value3", ...}, ...}
pauljensen9041eb3c2015-12-09 12:29:01152 const std::string experimental_options;
bengr59cb6962015-05-13 17:55:58153 // Enable Data Reduction Proxy with authentication key.
pauljensen9041eb3c2015-12-09 12:29:01154 const std::string data_reduction_proxy_key;
155 const std::string data_reduction_primary_proxy;
156 const std::string data_reduction_fallback_proxy;
157 const std::string data_reduction_secure_proxy_check_url;
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
tbansal7018e2a2016-06-25 00:40:39162 // Enable network quality estimator.
163 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
rtenneti121f9fa2016-07-07 23:49:28168 // Data to populte CertVerifierCache.
169 const std::string cert_verifier_data;
170
pauljensen9041eb3c2015-12-09 12:29:01171 // App-provided list of servers that support QUIC.
172 ScopedVector<QuicHint> quic_hints;
173
174 // The list of public key pins.
175 ScopedVector<Pkp> pkp_list;
176
xunjielid67295e2017-03-16 21:05:41177 // Experimental options that are recognized by the config parser.
178 std::unique_ptr<base::DictionaryValue> effective_experimental_options;
179
mefc71361c2014-09-16 14:48:56180 private:
181 DISALLOW_COPY_AND_ASSIGN(URLRequestContextConfig);
[email protected]94de3e02014-06-17 00:09:51182};
183
lilyhoughton14e2a1f12017-01-11 14:50:27184// Stores intermediate state for URLRequestContextConfig. Initializes with
185// (mostly) sane defaults, then the appropriate member variables can be
186// modified, and it can be finalized with Build().
187struct URLRequestContextConfigBuilder {
188 URLRequestContextConfigBuilder();
189 ~URLRequestContextConfigBuilder();
190
191 // Finalize state into a URLRequestContextConfig. Must only be called once,
192 // as once |mock_cert_verifier| is moved into a URLRequestContextConfig, it
193 // cannot be used again.
194 std::unique_ptr<URLRequestContextConfig> Build();
195
196 // Enable QUIC.
197 bool enable_quic = false;
198 // QUIC User Agent ID.
199 std::string quic_user_agent_id = "";
200 // Enable SPDY.
201 bool enable_spdy = true;
202 // Enable SDCH.
203 bool enable_sdch = false;
204 // Type of http cache.
205 URLRequestContextConfig::HttpCacheType http_cache =
206 URLRequestContextConfig::DISABLED;
207 // Max size of http cache in bytes.
208 int http_cache_max_size = 0;
209 // Disable caching for HTTP responses. Other information may be stored in
210 // the cache.
211 bool load_disable_cache = false;
212 // Storage path for http cache and cookie storage.
213 std::string storage_path = "";
214 // User-Agent request header field.
215 std::string user_agent = "";
216 // Experimental options encoded as a string in a JSON format containing
217 // experiments and their corresponding configuration options. The format
218 // is a JSON object with the name of the experiment as the key, and the
219 // configuration options as the value. An example:
220 // {"experiment1": {"option1": "option_value1", "option2": "option_value2",
221 // ...}, "experiment2: {"option3", "option_value3", ...}, ...}
222 std::string experimental_options = "{}";
223 // Enable Data Reduction Proxy with authentication key.
224 std::string data_reduction_proxy_key = "";
225 std::string data_reduction_primary_proxy = "";
226 std::string data_reduction_fallback_proxy = "";
227 std::string data_reduction_secure_proxy_check_url = "";
228
229 // Certificate verifier for testing.
230 std::unique_ptr<net::CertVerifier> mock_cert_verifier = nullptr;
231
232 // Enable network quality estimator.
233 bool enable_network_quality_estimator = false;
234
235 // Enable public key pinning bypass for local trust anchors.
236 bool bypass_public_key_pinning_for_local_trust_anchors = true;
237
238 // Data to populate CertVerifierCache.
239 std::string cert_verifier_data = "";
240
241 private:
242 DISALLOW_COPY_AND_ASSIGN(URLRequestContextConfigBuilder);
243};
244
[email protected]94de3e02014-06-17 00:09:51245} // namespace cronet
246
247#endif // COMPONENTS_CRONET_URL_REQUEST_CONTEXT_CONFIG_H_