OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/cronet/url_request_context_config.h" | 5 #include "components/cronet/url_request_context_config.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 const char kHostResolverRulesFieldTrialName[] = "HostResolverRules"; | 79 const char kHostResolverRulesFieldTrialName[] = "HostResolverRules"; |
80 const char kHostResolverRules[] = "host_resolver_rules"; | 80 const char kHostResolverRules[] = "host_resolver_rules"; |
81 | 81 |
82 // Disable IPv6 when on WiFi. This is a workaround for a known issue on certain | 82 // Disable IPv6 when on WiFi. This is a workaround for a known issue on certain |
83 // Android phones, and should not be necessary when not on one of those devices. | 83 // Android phones, and should not be necessary when not on one of those devices. |
84 // See https://crbug.com/696569 for details. | 84 // See https://crbug.com/696569 for details. |
85 const char kDisableIPv6OnWifi[] = "disable_ipv6_on_wifi"; | 85 const char kDisableIPv6OnWifi[] = "disable_ipv6_on_wifi"; |
86 | 86 |
87 const char kSSLKeyLogFile[] = "ssl_key_log_file"; | 87 const char kSSLKeyLogFile[] = "ssl_key_log_file"; |
88 | 88 |
89 // Returns the effective experimental options. | 89 } // namespace |
90 std::unique_ptr<base::DictionaryValue> ParseAndSetExperimentalOptions( | 90 |
| 91 URLRequestContextConfig::QuicHint::QuicHint(const std::string& host, |
| 92 int port, |
| 93 int alternate_port) |
| 94 : host(host), port(port), alternate_port(alternate_port) {} |
| 95 |
| 96 URLRequestContextConfig::QuicHint::~QuicHint() {} |
| 97 |
| 98 URLRequestContextConfig::Pkp::Pkp(const std::string& host, |
| 99 bool include_subdomains, |
| 100 const base::Time& expiration_date) |
| 101 : host(host), |
| 102 include_subdomains(include_subdomains), |
| 103 expiration_date(expiration_date) {} |
| 104 |
| 105 URLRequestContextConfig::Pkp::~Pkp() {} |
| 106 |
| 107 URLRequestContextConfig::URLRequestContextConfig( |
| 108 bool enable_quic, |
| 109 const std::string& quic_user_agent_id, |
| 110 bool enable_spdy, |
| 111 bool enable_sdch, |
| 112 bool enable_brotli, |
| 113 HttpCacheType http_cache, |
| 114 int http_cache_max_size, |
| 115 bool load_disable_cache, |
| 116 const std::string& storage_path, |
| 117 const std::string& user_agent, |
91 const std::string& experimental_options, | 118 const std::string& experimental_options, |
| 119 std::unique_ptr<net::CertVerifier> mock_cert_verifier, |
| 120 bool enable_network_quality_estimator, |
| 121 bool bypass_public_key_pinning_for_local_trust_anchors, |
| 122 const std::string& cert_verifier_data) |
| 123 : enable_quic(enable_quic), |
| 124 quic_user_agent_id(quic_user_agent_id), |
| 125 enable_spdy(enable_spdy), |
| 126 enable_sdch(enable_sdch), |
| 127 enable_brotli(enable_brotli), |
| 128 http_cache(http_cache), |
| 129 http_cache_max_size(http_cache_max_size), |
| 130 load_disable_cache(load_disable_cache), |
| 131 storage_path(storage_path), |
| 132 user_agent(user_agent), |
| 133 experimental_options(experimental_options), |
| 134 mock_cert_verifier(std::move(mock_cert_verifier)), |
| 135 enable_network_quality_estimator(enable_network_quality_estimator), |
| 136 bypass_public_key_pinning_for_local_trust_anchors( |
| 137 bypass_public_key_pinning_for_local_trust_anchors), |
| 138 cert_verifier_data(cert_verifier_data) {} |
| 139 |
| 140 URLRequestContextConfig::~URLRequestContextConfig() {} |
| 141 |
| 142 void URLRequestContextConfig::ParseAndSetExperimentalOptions( |
92 net::URLRequestContextBuilder* context_builder, | 143 net::URLRequestContextBuilder* context_builder, |
93 net::NetLog* net_log, | 144 net::NetLog* net_log, |
94 const scoped_refptr<base::SequencedTaskRunner>& file_task_runner) { | 145 const scoped_refptr<base::SequencedTaskRunner>& file_task_runner) { |
95 if (experimental_options.empty()) | 146 if (experimental_options.empty()) |
96 return nullptr; | 147 return; |
97 | 148 |
98 DCHECK(net_log); | 149 DCHECK(net_log); |
99 | 150 |
100 DVLOG(1) << "Experimental Options:" << experimental_options; | 151 DVLOG(1) << "Experimental Options:" << experimental_options; |
101 std::unique_ptr<base::Value> options = | 152 std::unique_ptr<base::Value> options = |
102 base::JSONReader::Read(experimental_options); | 153 base::JSONReader::Read(experimental_options); |
103 | 154 |
104 if (!options) { | 155 if (!options) { |
105 DCHECK(false) << "Parsing experimental options failed: " | 156 DCHECK(false) << "Parsing experimental options failed: " |
106 << experimental_options; | 157 << experimental_options; |
107 return nullptr; | 158 return; |
108 } | 159 } |
109 | 160 |
110 std::unique_ptr<base::DictionaryValue> dict = | 161 std::unique_ptr<base::DictionaryValue> dict = |
111 base::DictionaryValue::From(std::move(options)); | 162 base::DictionaryValue::From(std::move(options)); |
112 | 163 |
113 if (!dict) { | 164 if (!dict) { |
114 DCHECK(false) << "Experimental options string is not a dictionary: " | 165 DCHECK(false) << "Experimental options string is not a dictionary: " |
115 << experimental_options; | 166 << experimental_options; |
116 return nullptr; | 167 return; |
117 } | 168 } |
118 | 169 |
119 bool async_dns_enable = false; | 170 bool async_dns_enable = false; |
120 bool stale_dns_enable = false; | 171 bool stale_dns_enable = false; |
121 bool host_resolver_rules_enable = false; | 172 bool host_resolver_rules_enable = false; |
122 bool disable_ipv6_on_wifi = false; | 173 bool disable_ipv6_on_wifi = false; |
123 | 174 |
124 std::unique_ptr<base::DictionaryValue> effective_experimental_options = | 175 effective_experimental_options = dict->CreateDeepCopy(); |
125 dict->CreateDeepCopy(); | |
126 StaleHostResolver::StaleOptions stale_dns_options; | 176 StaleHostResolver::StaleOptions stale_dns_options; |
127 std::string host_resolver_rules_string; | 177 std::string host_resolver_rules_string; |
128 for (base::DictionaryValue::Iterator it(*dict.get()); !it.IsAtEnd(); | 178 for (base::DictionaryValue::Iterator it(*dict.get()); !it.IsAtEnd(); |
129 it.Advance()) { | 179 it.Advance()) { |
130 if (it.key() == kQuicFieldTrialName) { | 180 if (it.key() == kQuicFieldTrialName) { |
131 const base::DictionaryValue* quic_args = nullptr; | 181 const base::DictionaryValue* quic_args = nullptr; |
132 if (!it.value().GetAsDictionary(&quic_args)) { | 182 if (!it.value().GetAsDictionary(&quic_args)) { |
133 LOG(ERROR) << "Quic config params \"" << it.value() | 183 LOG(ERROR) << "Quic config params \"" << it.value() |
134 << "\" is not a dictionary value"; | 184 << "\" is not a dictionary value"; |
135 effective_experimental_options->Remove(it.key(), nullptr); | 185 effective_experimental_options->Remove(it.key(), nullptr); |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 if (async_dns_enable) | 349 if (async_dns_enable) |
300 host_resolver->SetDnsClientEnabled(true); | 350 host_resolver->SetDnsClientEnabled(true); |
301 if (host_resolver_rules_enable) { | 351 if (host_resolver_rules_enable) { |
302 std::unique_ptr<net::MappedHostResolver> remapped_resolver( | 352 std::unique_ptr<net::MappedHostResolver> remapped_resolver( |
303 new net::MappedHostResolver(std::move(host_resolver))); | 353 new net::MappedHostResolver(std::move(host_resolver))); |
304 remapped_resolver->SetRulesFromString(host_resolver_rules_string); | 354 remapped_resolver->SetRulesFromString(host_resolver_rules_string); |
305 host_resolver = std::move(remapped_resolver); | 355 host_resolver = std::move(remapped_resolver); |
306 } | 356 } |
307 context_builder->set_host_resolver(std::move(host_resolver)); | 357 context_builder->set_host_resolver(std::move(host_resolver)); |
308 } | 358 } |
309 return effective_experimental_options; | |
310 } | 359 } |
311 | 360 |
312 } // namespace | |
313 | |
314 URLRequestContextConfig::QuicHint::QuicHint(const std::string& host, | |
315 int port, | |
316 int alternate_port) | |
317 : host(host), port(port), alternate_port(alternate_port) {} | |
318 | |
319 URLRequestContextConfig::QuicHint::~QuicHint() {} | |
320 | |
321 URLRequestContextConfig::Pkp::Pkp(const std::string& host, | |
322 bool include_subdomains, | |
323 const base::Time& expiration_date) | |
324 : host(host), | |
325 include_subdomains(include_subdomains), | |
326 expiration_date(expiration_date) {} | |
327 | |
328 URLRequestContextConfig::Pkp::~Pkp() {} | |
329 | |
330 URLRequestContextConfig::URLRequestContextConfig( | |
331 bool enable_quic, | |
332 const std::string& quic_user_agent_id, | |
333 bool enable_spdy, | |
334 bool enable_sdch, | |
335 bool enable_brotli, | |
336 HttpCacheType http_cache, | |
337 int http_cache_max_size, | |
338 bool load_disable_cache, | |
339 const std::string& storage_path, | |
340 const std::string& user_agent, | |
341 const std::string& experimental_options, | |
342 std::unique_ptr<net::CertVerifier> mock_cert_verifier, | |
343 bool enable_network_quality_estimator, | |
344 bool bypass_public_key_pinning_for_local_trust_anchors, | |
345 const std::string& cert_verifier_data) | |
346 : enable_quic(enable_quic), | |
347 quic_user_agent_id(quic_user_agent_id), | |
348 enable_spdy(enable_spdy), | |
349 enable_sdch(enable_sdch), | |
350 enable_brotli(enable_brotli), | |
351 http_cache(http_cache), | |
352 http_cache_max_size(http_cache_max_size), | |
353 load_disable_cache(load_disable_cache), | |
354 storage_path(storage_path), | |
355 user_agent(user_agent), | |
356 experimental_options(experimental_options), | |
357 mock_cert_verifier(std::move(mock_cert_verifier)), | |
358 enable_network_quality_estimator(enable_network_quality_estimator), | |
359 bypass_public_key_pinning_for_local_trust_anchors( | |
360 bypass_public_key_pinning_for_local_trust_anchors), | |
361 cert_verifier_data(cert_verifier_data) {} | |
362 | |
363 URLRequestContextConfig::~URLRequestContextConfig() {} | |
364 | |
365 void URLRequestContextConfig::ConfigureURLRequestContextBuilder( | 361 void URLRequestContextConfig::ConfigureURLRequestContextBuilder( |
366 net::URLRequestContextBuilder* context_builder, | 362 net::URLRequestContextBuilder* context_builder, |
367 net::NetLog* net_log, | 363 net::NetLog* net_log, |
368 const scoped_refptr<base::SequencedTaskRunner>& file_task_runner) { | 364 const scoped_refptr<base::SequencedTaskRunner>& file_task_runner) { |
369 DCHECK(net_log); | 365 DCHECK(net_log); |
370 | 366 |
371 std::string config_cache; | 367 std::string config_cache; |
372 if (http_cache != DISABLED) { | 368 if (http_cache != DISABLED) { |
373 net::URLRequestContextBuilder::HttpCacheParams cache_params; | 369 net::URLRequestContextBuilder::HttpCacheParams cache_params; |
374 if (http_cache == DISK && !storage_path.empty()) { | 370 if (http_cache == DISK && !storage_path.empty()) { |
375 cache_params.type = net::URLRequestContextBuilder::HttpCacheParams::DISK; | 371 cache_params.type = net::URLRequestContextBuilder::HttpCacheParams::DISK; |
376 cache_params.path = | 372 cache_params.path = |
377 base::FilePath(storage_path) | 373 base::FilePath(storage_path) |
378 .Append(FILE_PATH_LITERAL(kDiskCacheDirectoryName)); | 374 .Append(FILE_PATH_LITERAL(kDiskCacheDirectoryName)); |
379 } else { | 375 } else { |
380 cache_params.type = | 376 cache_params.type = |
381 net::URLRequestContextBuilder::HttpCacheParams::IN_MEMORY; | 377 net::URLRequestContextBuilder::HttpCacheParams::IN_MEMORY; |
382 } | 378 } |
383 cache_params.max_size = http_cache_max_size; | 379 cache_params.max_size = http_cache_max_size; |
384 context_builder->EnableHttpCache(cache_params); | 380 context_builder->EnableHttpCache(cache_params); |
385 } else { | 381 } else { |
386 context_builder->DisableHttpCache(); | 382 context_builder->DisableHttpCache(); |
387 } | 383 } |
388 context_builder->set_user_agent(user_agent); | 384 context_builder->set_user_agent(user_agent); |
389 context_builder->SetSpdyAndQuicEnabled(enable_spdy, enable_quic); | 385 context_builder->SetSpdyAndQuicEnabled(enable_spdy, enable_quic); |
390 context_builder->set_sdch_enabled(enable_sdch); | 386 context_builder->set_sdch_enabled(enable_sdch); |
391 if (enable_quic) | 387 if (enable_quic) |
392 context_builder->set_quic_user_agent_id(quic_user_agent_id); | 388 context_builder->set_quic_user_agent_id(quic_user_agent_id); |
393 | 389 |
394 effective_experimental_options = ParseAndSetExperimentalOptions( | 390 ParseAndSetExperimentalOptions(context_builder, net_log, file_task_runner); |
395 experimental_options, context_builder, net_log, file_task_runner); | |
396 | 391 |
397 std::unique_ptr<net::CertVerifier> cert_verifier; | 392 std::unique_ptr<net::CertVerifier> cert_verifier; |
398 if (mock_cert_verifier) { | 393 if (mock_cert_verifier) { |
399 // Because |context_builder| expects CachingCertVerifier, wrap | 394 // Because |context_builder| expects CachingCertVerifier, wrap |
400 // |mock_cert_verifier| into a CachingCertVerifier. | 395 // |mock_cert_verifier| into a CachingCertVerifier. |
401 cert_verifier = base::MakeUnique<net::CachingCertVerifier>( | 396 cert_verifier = base::MakeUnique<net::CachingCertVerifier>( |
402 std::move(mock_cert_verifier)); | 397 std::move(mock_cert_verifier)); |
403 } else { | 398 } else { |
404 // net::CertVerifier::CreateDefault() returns a CachingCertVerifier. | 399 // net::CertVerifier::CreateDefault() returns a CachingCertVerifier. |
405 cert_verifier = net::CertVerifier::CreateDefault(); | 400 cert_verifier = net::CertVerifier::CreateDefault(); |
406 } | 401 } |
407 context_builder->SetCertVerifier(std::move(cert_verifier)); | 402 context_builder->SetCertVerifier(std::move(cert_verifier)); |
408 // TODO(mef): Use |config| to set cookies. | 403 // TODO(mef): Use |config| to set cookies. |
409 } | 404 } |
410 | 405 |
411 URLRequestContextConfigBuilder::URLRequestContextConfigBuilder() {} | 406 URLRequestContextConfigBuilder::URLRequestContextConfigBuilder() {} |
412 URLRequestContextConfigBuilder::~URLRequestContextConfigBuilder() {} | 407 URLRequestContextConfigBuilder::~URLRequestContextConfigBuilder() {} |
413 | 408 |
414 std::unique_ptr<URLRequestContextConfig> | 409 std::unique_ptr<URLRequestContextConfig> |
415 URLRequestContextConfigBuilder::Build() { | 410 URLRequestContextConfigBuilder::Build() { |
416 return base::MakeUnique<URLRequestContextConfig>( | 411 return base::MakeUnique<URLRequestContextConfig>( |
417 enable_quic, quic_user_agent_id, enable_spdy, enable_sdch, enable_brotli, | 412 enable_quic, quic_user_agent_id, enable_spdy, enable_sdch, enable_brotli, |
418 http_cache, http_cache_max_size, load_disable_cache, storage_path, | 413 http_cache, http_cache_max_size, load_disable_cache, storage_path, |
419 user_agent, experimental_options, std::move(mock_cert_verifier), | 414 user_agent, experimental_options, std::move(mock_cert_verifier), |
420 enable_network_quality_estimator, | 415 enable_network_quality_estimator, |
421 bypass_public_key_pinning_for_local_trust_anchors, cert_verifier_data); | 416 bypass_public_key_pinning_for_local_trust_anchors, cert_verifier_data); |
422 } | 417 } |
423 | 418 |
424 } // namespace cronet | 419 } // namespace cronet |
OLD | NEW |