| 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 const char kStaleDnsMaxStaleUses[] = "max_stale_uses"; | 75 const char kStaleDnsMaxStaleUses[] = "max_stale_uses"; |
| 76 // Name of boolean to allow stale DNS results from other networks to be used on | 76 // Name of boolean to allow stale DNS results from other networks to be used on |
| 77 // the current network. | 77 // the current network. |
| 78 const char kStaleDnsAllowOtherNetwork[] = "allow_other_network"; | 78 const char kStaleDnsAllowOtherNetwork[] = "allow_other_network"; |
| 79 | 79 |
| 80 // Rules to override DNS resolution. Intended for testing. | 80 // Rules to override DNS resolution. Intended for testing. |
| 81 // See explanation of format in net/dns/mapped_host_resolver.h. | 81 // See explanation of format in net/dns/mapped_host_resolver.h. |
| 82 const char kHostResolverRulesFieldTrialName[] = "HostResolverRules"; | 82 const char kHostResolverRulesFieldTrialName[] = "HostResolverRules"; |
| 83 const char kHostResolverRules[] = "host_resolver_rules"; | 83 const char kHostResolverRules[] = "host_resolver_rules"; |
| 84 | 84 |
| 85 // Disable IPv6. This should almost never be necessary because the network stack | 85 // Disable IPv6 when on WiFi. This is a workaround for a known issue on certain |
| 86 // has IPv6 detection logic. Please do not turn on this option without first | 86 // Android phones, and should not be necessary when not on one of those devices. |
| 87 // reporting a bug. See http://crbug.com/696569 for the currently known issue. | 87 // See https://crbug.com/696569 for details. |
| 88 const char kDisableIPv6[] = "disable_ipv6"; | 88 const char kDisableIPv6OnWifi[] = "disable_ipv6_on_wifi"; |
| 89 | 89 |
| 90 const char kSSLKeyLogFile[] = "ssl_key_log_file"; | 90 const char kSSLKeyLogFile[] = "ssl_key_log_file"; |
| 91 | 91 |
| 92 // Returns the effective experimental options. | 92 // Returns the effective experimental options. |
| 93 std::unique_ptr<base::DictionaryValue> ParseAndSetExperimentalOptions( | 93 std::unique_ptr<base::DictionaryValue> ParseAndSetExperimentalOptions( |
| 94 const std::string& experimental_options, | 94 const std::string& experimental_options, |
| 95 net::URLRequestContextBuilder* context_builder, | 95 net::URLRequestContextBuilder* context_builder, |
| 96 net::NetLog* net_log, | 96 net::NetLog* net_log, |
| 97 const scoped_refptr<base::SequencedTaskRunner>& file_task_runner) { | 97 const scoped_refptr<base::SequencedTaskRunner>& file_task_runner) { |
| 98 if (experimental_options.empty()) | 98 if (experimental_options.empty()) |
| (...skipping 16 matching lines...) Expand all Loading... |
| 115 | 115 |
| 116 if (!dict) { | 116 if (!dict) { |
| 117 DCHECK(false) << "Experimental options string is not a dictionary: " | 117 DCHECK(false) << "Experimental options string is not a dictionary: " |
| 118 << experimental_options; | 118 << experimental_options; |
| 119 return nullptr; | 119 return nullptr; |
| 120 } | 120 } |
| 121 | 121 |
| 122 bool async_dns_enable = false; | 122 bool async_dns_enable = false; |
| 123 bool stale_dns_enable = false; | 123 bool stale_dns_enable = false; |
| 124 bool host_resolver_rules_enable = false; | 124 bool host_resolver_rules_enable = false; |
| 125 bool disable_ipv6 = false; | 125 bool disable_ipv6_on_wifi = false; |
| 126 | 126 |
| 127 std::unique_ptr<base::DictionaryValue> effective_experimental_options = | 127 std::unique_ptr<base::DictionaryValue> effective_experimental_options = |
| 128 dict->CreateDeepCopy(); | 128 dict->CreateDeepCopy(); |
| 129 StaleHostResolver::StaleOptions stale_dns_options; | 129 StaleHostResolver::StaleOptions stale_dns_options; |
| 130 std::string host_resolver_rules_string; | 130 std::string host_resolver_rules_string; |
| 131 for (base::DictionaryValue::Iterator it(*dict.get()); !it.IsAtEnd(); | 131 for (base::DictionaryValue::Iterator it(*dict.get()); !it.IsAtEnd(); |
| 132 it.Advance()) { | 132 it.Advance()) { |
| 133 if (it.key() == kQuicFieldTrialName) { | 133 if (it.key() == kQuicFieldTrialName) { |
| 134 const base::DictionaryValue* quic_args = nullptr; | 134 const base::DictionaryValue* quic_args = nullptr; |
| 135 if (!it.value().GetAsDictionary(&quic_args)) { | 135 if (!it.value().GetAsDictionary(&quic_args)) { |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 } else if (it.key() == kHostResolverRulesFieldTrialName) { | 270 } else if (it.key() == kHostResolverRulesFieldTrialName) { |
| 271 const base::DictionaryValue* host_resolver_rules_args = nullptr; | 271 const base::DictionaryValue* host_resolver_rules_args = nullptr; |
| 272 if (!it.value().GetAsDictionary(&host_resolver_rules_args)) { | 272 if (!it.value().GetAsDictionary(&host_resolver_rules_args)) { |
| 273 LOG(ERROR) << "\"" << it.key() << "\" config params \"" << it.value() | 273 LOG(ERROR) << "\"" << it.key() << "\" config params \"" << it.value() |
| 274 << "\" is not a dictionary value"; | 274 << "\" is not a dictionary value"; |
| 275 effective_experimental_options->Remove(it.key(), nullptr); | 275 effective_experimental_options->Remove(it.key(), nullptr); |
| 276 continue; | 276 continue; |
| 277 } | 277 } |
| 278 host_resolver_rules_enable = host_resolver_rules_args->GetString( | 278 host_resolver_rules_enable = host_resolver_rules_args->GetString( |
| 279 kHostResolverRules, &host_resolver_rules_string); | 279 kHostResolverRules, &host_resolver_rules_string); |
| 280 } else if (it.key() == kDisableIPv6) { | 280 } else if (it.key() == kDisableIPv6OnWifi) { |
| 281 if (!it.value().GetAsBoolean(&disable_ipv6)) { | 281 if (!it.value().GetAsBoolean(&disable_ipv6_on_wifi)) { |
| 282 LOG(ERROR) << "\"" << it.key() << "\" config params \"" << it.value() | 282 LOG(ERROR) << "\"" << it.key() << "\" config params \"" << it.value() |
| 283 << "\" is not a bool"; | 283 << "\" is not a bool"; |
| 284 effective_experimental_options->Remove(it.key(), nullptr); | 284 effective_experimental_options->Remove(it.key(), nullptr); |
| 285 continue; | 285 continue; |
| 286 } | 286 } |
| 287 } else if (it.key() == kSSLKeyLogFile) { | 287 } else if (it.key() == kSSLKeyLogFile) { |
| 288 std::string ssl_key_log_file_string; | 288 std::string ssl_key_log_file_string; |
| 289 if (it.value().GetAsString(&ssl_key_log_file_string)) { | 289 if (it.value().GetAsString(&ssl_key_log_file_string)) { |
| 290 DCHECK(file_task_runner); | 290 DCHECK(file_task_runner); |
| 291 base::FilePath ssl_key_log_file(ssl_key_log_file_string); | 291 base::FilePath ssl_key_log_file(ssl_key_log_file_string); |
| 292 if (!ssl_key_log_file.empty() && file_task_runner) { | 292 if (!ssl_key_log_file.empty() && file_task_runner) { |
| 293 // SetSSLKeyLogFile is only safe to call before any SSLClientSockets | 293 // SetSSLKeyLogFile is only safe to call before any SSLClientSockets |
| 294 // are created. This should not be used if there are multiple | 294 // are created. This should not be used if there are multiple |
| 295 // CronetEngine. | 295 // CronetEngine. |
| 296 // TODO(xunjieli): Expose this as a stable API after crbug.com/458365 | 296 // TODO(xunjieli): Expose this as a stable API after crbug.com/458365 |
| 297 // is resolved. | 297 // is resolved. |
| 298 net::SSLClientSocket::SetSSLKeyLogFile(ssl_key_log_file, | 298 net::SSLClientSocket::SetSSLKeyLogFile(ssl_key_log_file, |
| 299 file_task_runner); | 299 file_task_runner); |
| 300 } | 300 } |
| 301 } | 301 } |
| 302 } else { | 302 } else { |
| 303 LOG(WARNING) << "Unrecognized Cronet experimental option \"" << it.key() | 303 LOG(WARNING) << "Unrecognized Cronet experimental option \"" << it.key() |
| 304 << "\" with params \"" << it.value(); | 304 << "\" with params \"" << it.value(); |
| 305 effective_experimental_options->Remove(it.key(), nullptr); | 305 effective_experimental_options->Remove(it.key(), nullptr); |
| 306 } | 306 } |
| 307 } | 307 } |
| 308 | 308 |
| 309 if (async_dns_enable || stale_dns_enable || host_resolver_rules_enable || | 309 if (async_dns_enable || stale_dns_enable || host_resolver_rules_enable || |
| 310 disable_ipv6) { | 310 disable_ipv6_on_wifi) { |
| 311 CHECK(net_log) << "All DNS-related experiments require NetLog."; | 311 CHECK(net_log) << "All DNS-related experiments require NetLog."; |
| 312 std::unique_ptr<net::HostResolver> host_resolver; | 312 std::unique_ptr<net::HostResolver> host_resolver; |
| 313 if (stale_dns_enable) { | 313 if (stale_dns_enable) { |
| 314 DCHECK(!disable_ipv6); | 314 DCHECK(!disable_ipv6_on_wifi); |
| 315 host_resolver.reset(new StaleHostResolver( | 315 host_resolver.reset(new StaleHostResolver( |
| 316 net::HostResolver::CreateDefaultResolverImpl(net_log), | 316 net::HostResolver::CreateDefaultResolverImpl(net_log), |
| 317 stale_dns_options)); | 317 stale_dns_options)); |
| 318 } else { | 318 } else { |
| 319 host_resolver = net::HostResolver::CreateDefaultResolver(net_log); | 319 host_resolver = net::HostResolver::CreateDefaultResolver(net_log); |
| 320 } | 320 } |
| 321 if (disable_ipv6) | 321 if (disable_ipv6_on_wifi) |
| 322 host_resolver->SetDefaultAddressFamily(net::ADDRESS_FAMILY_IPV4); | 322 host_resolver->SetNoIPv6OnWifi(true); |
| 323 if (async_dns_enable) | 323 if (async_dns_enable) |
| 324 host_resolver->SetDnsClientEnabled(true); | 324 host_resolver->SetDnsClientEnabled(true); |
| 325 if (host_resolver_rules_enable) { | 325 if (host_resolver_rules_enable) { |
| 326 std::unique_ptr<net::MappedHostResolver> remapped_resolver( | 326 std::unique_ptr<net::MappedHostResolver> remapped_resolver( |
| 327 new net::MappedHostResolver(std::move(host_resolver))); | 327 new net::MappedHostResolver(std::move(host_resolver))); |
| 328 remapped_resolver->SetRulesFromString(host_resolver_rules_string); | 328 remapped_resolver->SetRulesFromString(host_resolver_rules_string); |
| 329 host_resolver = std::move(remapped_resolver); | 329 host_resolver = std::move(remapped_resolver); |
| 330 } | 330 } |
| 331 context_builder->set_host_resolver(std::move(host_resolver)); | 331 context_builder->set_host_resolver(std::move(host_resolver)); |
| 332 } | 332 } |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 enable_quic, quic_user_agent_id, enable_spdy, enable_sdch, http_cache, | 448 enable_quic, quic_user_agent_id, enable_spdy, enable_sdch, http_cache, |
| 449 http_cache_max_size, load_disable_cache, storage_path, user_agent, | 449 http_cache_max_size, load_disable_cache, storage_path, user_agent, |
| 450 experimental_options, data_reduction_proxy_key, | 450 experimental_options, data_reduction_proxy_key, |
| 451 data_reduction_primary_proxy, data_reduction_fallback_proxy, | 451 data_reduction_primary_proxy, data_reduction_fallback_proxy, |
| 452 data_reduction_secure_proxy_check_url, std::move(mock_cert_verifier), | 452 data_reduction_secure_proxy_check_url, std::move(mock_cert_verifier), |
| 453 enable_network_quality_estimator, | 453 enable_network_quality_estimator, |
| 454 bypass_public_key_pinning_for_local_trust_anchors, cert_verifier_data); | 454 bypass_public_key_pinning_for_local_trust_anchors, cert_verifier_data); |
| 455 } | 455 } |
| 456 | 456 |
| 457 } // namespace cronet | 457 } // namespace cronet |
| OLD | NEW |