[email protected] | 94de3e0 | 2014-06-17 00:09:51 | [diff] [blame] | 1 | // 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 | |
dcheng | fe3745e624 | 2016-04-21 23:49:58 | [diff] [blame] | 8 | #include <memory> |
[email protected] | 94de3e0 | 2014-06-17 00:09:51 | [diff] [blame] | 9 | #include <string> |
Donna Wu | 7ea51c2 | 2017-06-20 08:34:52 | [diff] [blame] | 10 | #include <vector> |
[email protected] | 94de3e0 | 2014-06-17 00:09:51 | [diff] [blame] | 11 | |
mef | c71361c | 2014-09-16 14:48:56 | [diff] [blame] | 12 | #include "base/macros.h" |
xunjieli | da7f7702 | 2016-03-28 16:36:36 | [diff] [blame] | 13 | #include "base/memory/ref_counted.h" |
tbansal | e11aa36 | 2017-07-04 15:59:36 | [diff] [blame^] | 14 | #include "base/optional.h" |
kapishnikov | df5ccab | 2015-12-03 18:38:50 | [diff] [blame] | 15 | #include "base/time/time.h" |
mgersh | cc6ae89 | 2017-06-20 22:33:53 | [diff] [blame] | 16 | #include "base/values.h" |
pauljensen | 9041eb3c | 2015-12-09 12:29:01 | [diff] [blame] | 17 | #include "net/base/hash_value.h" |
lilyhoughton | 14e2a1f1 | 2017-01-11 14:50:27 | [diff] [blame] | 18 | #include "net/cert/cert_verifier.h" |
tbansal | e11aa36 | 2017-07-04 15:59:36 | [diff] [blame^] | 19 | #include "net/nqe/effective_connection_type.h" |
[email protected] | 94de3e0 | 2014-06-17 00:09:51 | [diff] [blame] | 20 | |
xunjieli | da7f7702 | 2016-03-28 16:36:36 | [diff] [blame] | 21 | namespace base { |
| 22 | class SequencedTaskRunner; |
| 23 | } // namespace base |
| 24 | |
[email protected] | 94de3e0 | 2014-06-17 00:09:51 | [diff] [blame] | 25 | namespace net { |
xunjieli | 013145f | 2015-10-20 23:20:11 | [diff] [blame] | 26 | class CertVerifier; |
pauljensen | e92c409 | 2015-12-09 19:13:48 | [diff] [blame] | 27 | class NetLog; |
[email protected] | 94de3e0 | 2014-06-17 00:09:51 | [diff] [blame] | 28 | class URLRequestContextBuilder; |
| 29 | } // namespace net |
| 30 | |
| 31 | namespace cronet { |
| 32 | |
| 33 | // Common configuration parameters used by Cronet to configure |
pauljensen | 9041eb3c | 2015-12-09 12:29:01 | [diff] [blame] | 34 | // URLRequestContext. |
mgersh | cc6ae89 | 2017-06-20 22:33:53 | [diff] [blame] | 35 | // TODO(mgersh): This shouldn't be a struct, and experimental option parsing |
| 36 | // should be kept more separate from applying the configuration. |
[email protected] | 94de3e0 | 2014-06-17 00:09:51 | [diff] [blame] | 37 | struct URLRequestContextConfig { |
pauljensen | 9041eb3c | 2015-12-09 12:29:01 | [diff] [blame] | 38 | // Type of HTTP cache. |
kapishnikov | aa8f338c | 2016-10-28 16:17:32 | [diff] [blame] | 39 | // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.net.impl |
pauljensen | 9041eb3c | 2015-12-09 12:29:01 | [diff] [blame] | 40 | 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 | |
mef | c71361c | 2014-09-16 14:48:56 | [diff] [blame] | 49 | // App-provided hint that server supports QUIC. |
| 50 | struct QuicHint { |
pauljensen | 9041eb3c | 2015-12-09 12:29:01 | [diff] [blame] | 51 | QuicHint(const std::string& host, int port, int alternate_port); |
mef | c71361c | 2014-09-16 14:48:56 | [diff] [blame] | 52 | ~QuicHint(); |
| 53 | |
mef | c71361c | 2014-09-16 14:48:56 | [diff] [blame] | 54 | // Host name of the server that supports QUIC. |
pauljensen | 9041eb3c | 2015-12-09 12:29:01 | [diff] [blame] | 55 | const std::string host; |
mef | c71361c | 2014-09-16 14:48:56 | [diff] [blame] | 56 | // Port of the server that supports QUIC. |
pauljensen | 9041eb3c | 2015-12-09 12:29:01 | [diff] [blame] | 57 | const int port; |
mef | c71361c | 2014-09-16 14:48:56 | [diff] [blame] | 58 | // Alternate protocol port. |
pauljensen | 9041eb3c | 2015-12-09 12:29:01 | [diff] [blame] | 59 | const int alternate_port; |
mef | c71361c | 2014-09-16 14:48:56 | [diff] [blame] | 60 | |
| 61 | private: |
| 62 | DISALLOW_COPY_AND_ASSIGN(QuicHint); |
| 63 | }; |
| 64 | |
kapishnikov | df5ccab | 2015-12-03 18:38:50 | [diff] [blame] | 65 | // Public-Key-Pinning configuration structure. |
| 66 | struct Pkp { |
pauljensen | 9041eb3c | 2015-12-09 12:29:01 | [diff] [blame] | 67 | Pkp(const std::string& host, |
| 68 | bool include_subdomains, |
| 69 | const base::Time& expiration_date); |
kapishnikov | df5ccab | 2015-12-03 18:38:50 | [diff] [blame] | 70 | ~Pkp(); |
| 71 | |
kapishnikov | df5ccab | 2015-12-03 18:38:50 | [diff] [blame] | 72 | // Host name. |
pauljensen | 9041eb3c | 2015-12-09 12:29:01 | [diff] [blame] | 73 | const std::string host; |
kapishnikov | df5ccab | 2015-12-03 18:38:50 | [diff] [blame] | 74 | // Pin hashes (currently SHA256 only). |
pauljensen | 9041eb3c | 2015-12-09 12:29:01 | [diff] [blame] | 75 | net::HashValueVector pin_hashes; |
kapishnikov | df5ccab | 2015-12-03 18:38:50 | [diff] [blame] | 76 | // Indicates whether the pinning should apply to the pinned host subdomains. |
pauljensen | 9041eb3c | 2015-12-09 12:29:01 | [diff] [blame] | 77 | const bool include_subdomains; |
kapishnikov | df5ccab | 2015-12-03 18:38:50 | [diff] [blame] | 78 | // Expiration date for the pins. |
pauljensen | 9041eb3c | 2015-12-09 12:29:01 | [diff] [blame] | 79 | const base::Time expiration_date; |
kapishnikov | df5ccab | 2015-12-03 18:38:50 | [diff] [blame] | 80 | |
| 81 | private: |
| 82 | DISALLOW_COPY_AND_ASSIGN(Pkp); |
| 83 | }; |
| 84 | |
pauljensen | 9041eb3c | 2015-12-09 12:29:01 | [diff] [blame] | 85 | URLRequestContextConfig( |
| 86 | // Enable QUIC. |
| 87 | bool enable_quic, |
mef | c5da571 | 2016-02-09 20:14:23 | [diff] [blame] | 88 | // QUIC User Agent ID. |
| 89 | const std::string& quic_user_agent_id, |
pauljensen | 9041eb3c | 2015-12-09 12:29:01 | [diff] [blame] | 90 | // Enable SPDY. |
| 91 | bool enable_spdy, |
| 92 | // Enable SDCH. |
| 93 | bool enable_sdch, |
xunjieli | 186d2bf | 2017-04-18 13:45:47 | [diff] [blame] | 94 | // Enable Brotli. |
| 95 | bool enable_brotli, |
pauljensen | 9041eb3c | 2015-12-09 12:29:01 | [diff] [blame] | 96 | // 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, |
pauljensen | 9041eb3c | 2015-12-09 12:29:01 | [diff] [blame] | 109 | // MockCertVerifier to use for testing purposes. |
tbansal | 7018e2a | 2016-06-25 00:40:39 | [diff] [blame] | 110 | std::unique_ptr<net::CertVerifier> mock_cert_verifier, |
| 111 | // Enable network quality estimator. |
kapishnikov | 385aa42 | 2016-07-01 20:53:02 | [diff] [blame] | 112 | bool enable_network_quality_estimator, |
| 113 | // Enable bypassing of public key pinning for local trust anchors |
rtenneti | 121f9fa | 2016-07-07 23:49:28 | [diff] [blame] | 114 | bool bypass_public_key_pinning_for_local_trust_anchors, |
| 115 | // Certificate verifier cache data. |
| 116 | const std::string& cert_verifier_data); |
[email protected] | 94de3e0 | 2014-06-17 00:09:51 | [diff] [blame] | 117 | ~URLRequestContextConfig(); |
| 118 | |
xunjieli | d67295e | 2017-03-16 21:05:41 | [diff] [blame] | 119 | // Configures |context_builder| based on |this|. |
[email protected] | 94de3e0 | 2014-06-17 00:09:51 | [diff] [blame] | 120 | void ConfigureURLRequestContextBuilder( |
pauljensen | e92c409 | 2015-12-09 19:13:48 | [diff] [blame] | 121 | net::URLRequestContextBuilder* context_builder, |
xunjieli | da7f7702 | 2016-03-28 16:36:36 | [diff] [blame] | 122 | net::NetLog* net_log, |
| 123 | const scoped_refptr<base::SequencedTaskRunner>& file_task_runner); |
[email protected] | 94de3e0 | 2014-06-17 00:09:51 | [diff] [blame] | 124 | |
[email protected] | 94de3e0 | 2014-06-17 00:09:51 | [diff] [blame] | 125 | // Enable QUIC. |
pauljensen | 9041eb3c | 2015-12-09 12:29:01 | [diff] [blame] | 126 | const bool enable_quic; |
mef | c5da571 | 2016-02-09 20:14:23 | [diff] [blame] | 127 | // QUIC User Agent ID. |
| 128 | const std::string quic_user_agent_id; |
[email protected] | 94de3e0 | 2014-06-17 00:09:51 | [diff] [blame] | 129 | // Enable SPDY. |
pauljensen | 9041eb3c | 2015-12-09 12:29:01 | [diff] [blame] | 130 | const bool enable_spdy; |
xunjieli | b8a6d56f | 2015-04-29 17:36:14 | [diff] [blame] | 131 | // Enable SDCH. |
pauljensen | 9041eb3c | 2015-12-09 12:29:01 | [diff] [blame] | 132 | const bool enable_sdch; |
xunjieli | 186d2bf | 2017-04-18 13:45:47 | [diff] [blame] | 133 | // Enable Brotli. |
| 134 | const bool enable_brotli; |
pauljensen | 9041eb3c | 2015-12-09 12:29:01 | [diff] [blame] | 135 | // Type of http cache. |
| 136 | const HttpCacheType http_cache; |
[email protected] | 94de3e0 | 2014-06-17 00:09:51 | [diff] [blame] | 137 | // Max size of http cache in bytes. |
pauljensen | 9041eb3c | 2015-12-09 12:29:01 | [diff] [blame] | 138 | const int http_cache_max_size; |
mef | bb4f45c | 2015-01-12 18:03:25 | [diff] [blame] | 139 | // Disable caching for HTTP responses. Other information may be stored in |
| 140 | // the cache. |
pauljensen | 9041eb3c | 2015-12-09 12:29:01 | [diff] [blame] | 141 | const bool load_disable_cache; |
[email protected] | 94de3e0 | 2014-06-17 00:09:51 | [diff] [blame] | 142 | // Storage path for http cache and cookie storage. |
pauljensen | 9041eb3c | 2015-12-09 12:29:01 | [diff] [blame] | 143 | const std::string storage_path; |
mef | d190710 | 2014-11-07 17:46:48 | [diff] [blame] | 144 | // User-Agent request header field. |
pauljensen | 9041eb3c | 2015-12-09 12:29:01 | [diff] [blame] | 145 | const std::string user_agent; |
mef | c71361c | 2014-09-16 14:48:56 | [diff] [blame] | 146 | |
xunjieli | 013145f | 2015-10-20 23:20:11 | [diff] [blame] | 147 | // Certificate verifier for testing. |
dcheng | fe3745e624 | 2016-04-21 23:49:58 | [diff] [blame] | 148 | std::unique_ptr<net::CertVerifier> mock_cert_verifier; |
xunjieli | 013145f | 2015-10-20 23:20:11 | [diff] [blame] | 149 | |
tbansal | e11aa36 | 2017-07-04 15:59:36 | [diff] [blame^] | 150 | // Enable Network Quality Estimator (NQE). |
tbansal | 7018e2a | 2016-06-25 00:40:39 | [diff] [blame] | 151 | const bool enable_network_quality_estimator; |
| 152 | |
kapishnikov | 385aa42 | 2016-07-01 20:53:02 | [diff] [blame] | 153 | // Enable public key pinning bypass for local trust anchors. |
| 154 | const bool bypass_public_key_pinning_for_local_trust_anchors; |
| 155 | |
rtenneti | 121f9fa | 2016-07-07 23:49:28 | [diff] [blame] | 156 | // Data to populte CertVerifierCache. |
| 157 | const std::string cert_verifier_data; |
| 158 | |
pauljensen | 9041eb3c | 2015-12-09 12:29:01 | [diff] [blame] | 159 | // App-provided list of servers that support QUIC. |
Donna Wu | 7ea51c2 | 2017-06-20 08:34:52 | [diff] [blame] | 160 | std::vector<std::unique_ptr<QuicHint>> quic_hints; |
pauljensen | 9041eb3c | 2015-12-09 12:29:01 | [diff] [blame] | 161 | |
| 162 | // The list of public key pins. |
Donna Wu | 7ea51c2 | 2017-06-20 08:34:52 | [diff] [blame] | 163 | std::vector<std::unique_ptr<Pkp>> pkp_list; |
pauljensen | 9041eb3c | 2015-12-09 12:29:01 | [diff] [blame] | 164 | |
mgersh | ac5f75a | 2017-06-28 16:53:08 | [diff] [blame] | 165 | // 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 | |
xunjieli | d67295e | 2017-03-16 21:05:41 | [diff] [blame] | 172 | // Experimental options that are recognized by the config parser. |
mgersh | cc6ae89 | 2017-06-20 22:33:53 | [diff] [blame] | 173 | std::unique_ptr<base::DictionaryValue> effective_experimental_options = |
| 174 | nullptr; |
xunjieli | d67295e | 2017-03-16 21:05:41 | [diff] [blame] | 175 | |
tbansal | e11aa36 | 2017-07-04 15:59:36 | [diff] [blame^] | 176 | // 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 | |
mef | c71361c | 2014-09-16 14:48:56 | [diff] [blame] | 184 | private: |
mgersh | cc6ae89 | 2017-06-20 22:33:53 | [diff] [blame] | 185 | // 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 | |
tbansal | e11aa36 | 2017-07-04 15:59:36 | [diff] [blame^] | 192 | // 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 | |
mef | c71361c | 2014-09-16 14:48:56 | [diff] [blame] | 200 | DISALLOW_COPY_AND_ASSIGN(URLRequestContextConfig); |
[email protected] | 94de3e0 | 2014-06-17 00:09:51 | [diff] [blame] | 201 | }; |
| 202 | |
lilyhoughton | 14e2a1f1 | 2017-01-11 14:50:27 | [diff] [blame] | 203 | // 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(). |
| 206 | struct 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; |
xunjieli | 186d2bf | 2017-04-18 13:45:47 | [diff] [blame] | 223 | // Enable Brotli. |
| 224 | bool enable_brotli = false; |
lilyhoughton | 14e2a1f1 | 2017-01-11 14:50:27 | [diff] [blame] | 225 | // 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 = "{}"; |
lilyhoughton | 14e2a1f1 | 2017-01-11 14:50:27 | [diff] [blame] | 244 | |
| 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] | 94de3e0 | 2014-06-17 00:09:51 | [diff] [blame] | 261 | } // namespace cronet |
| 262 | |
| 263 | #endif // COMPONENTS_CRONET_URL_REQUEST_CONTEXT_CONFIG_H_ |