Chromium Code Reviews| 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 <map> | |
| 7 #include <utility> | 8 #include <utility> |
| 8 | 9 |
| 10 #include "base/compiler_specific.h" | |
| 9 #include "base/json/json_reader.h" | 11 #include "base/json/json_reader.h" |
| 10 #include "base/logging.h" | 12 #include "base/logging.h" |
| 11 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
| 12 #include "base/sequenced_task_runner.h" | 14 #include "base/sequenced_task_runner.h" |
| 13 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/strings/string_piece.h" | 16 #include "base/strings/string_piece.h" |
| 15 #include "base/strings/string_split.h" | 17 #include "base/strings/string_split.h" |
| 16 #include "base/values.h" | 18 #include "base/values.h" |
| 17 #include "components/cronet/stale_host_resolver.h" | 19 #include "components/cronet/stale_host_resolver.h" |
| 18 #include "net/base/address_family.h" | 20 #include "net/base/address_family.h" |
| 19 #include "net/cert/caching_cert_verifier.h" | 21 #include "net/cert/caching_cert_verifier.h" |
| 20 #include "net/cert/cert_verifier.h" | 22 #include "net/cert/cert_verifier.h" |
| 21 #include "net/cert/cert_verify_proc.h" | 23 #include "net/cert/cert_verify_proc.h" |
| 22 #include "net/cert/multi_threaded_cert_verifier.h" | 24 #include "net/cert/multi_threaded_cert_verifier.h" |
| 23 #include "net/dns/host_resolver.h" | 25 #include "net/dns/host_resolver.h" |
| 24 #include "net/dns/mapped_host_resolver.h" | 26 #include "net/dns/mapped_host_resolver.h" |
| 25 #include "net/http/http_server_properties.h" | 27 #include "net/http/http_server_properties.h" |
| 28 #include "net/nqe/network_quality_estimator_params.h" | |
| 26 #include "net/quic/chromium/quic_utils_chromium.h" | 29 #include "net/quic/chromium/quic_utils_chromium.h" |
| 27 #include "net/quic/core/quic_packets.h" | 30 #include "net/quic/core/quic_packets.h" |
| 28 #include "net/socket/ssl_client_socket.h" | 31 #include "net/socket/ssl_client_socket.h" |
| 29 #include "net/url_request/url_request_context_builder.h" | 32 #include "net/url_request/url_request_context_builder.h" |
| 30 | 33 |
| 31 namespace cronet { | 34 namespace cronet { |
| 32 | 35 |
| 33 namespace { | 36 namespace { |
| 34 | 37 |
| 35 // Name of disk cache directory. | 38 // Name of disk cache directory. |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 72 const char kStaleDnsMaxStaleUses[] = "max_stale_uses"; | 75 const char kStaleDnsMaxStaleUses[] = "max_stale_uses"; |
| 73 // 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 |
| 74 // the current network. | 77 // the current network. |
| 75 const char kStaleDnsAllowOtherNetwork[] = "allow_other_network"; | 78 const char kStaleDnsAllowOtherNetwork[] = "allow_other_network"; |
| 76 | 79 |
| 77 // Rules to override DNS resolution. Intended for testing. | 80 // Rules to override DNS resolution. Intended for testing. |
| 78 // See explanation of format in net/dns/mapped_host_resolver.h. | 81 // See explanation of format in net/dns/mapped_host_resolver.h. |
| 79 const char kHostResolverRulesFieldTrialName[] = "HostResolverRules"; | 82 const char kHostResolverRulesFieldTrialName[] = "HostResolverRules"; |
| 80 const char kHostResolverRules[] = "host_resolver_rules"; | 83 const char kHostResolverRules[] = "host_resolver_rules"; |
| 81 | 84 |
| 85 // NetworkQualityEstimator experiment dictionary name. | |
| 86 const char kNetworkQualityEstimatorFieldTrialName[] = "NetworkQualityEstimator"; | |
| 87 | |
| 82 // Disable IPv6 when on WiFi. This is a workaround for a known issue on certain | 88 // 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. | 89 // Android phones, and should not be necessary when not on one of those devices. |
| 84 // See https://crbug.com/696569 for details. | 90 // See https://crbug.com/696569 for details. |
| 85 const char kDisableIPv6OnWifi[] = "disable_ipv6_on_wifi"; | 91 const char kDisableIPv6OnWifi[] = "disable_ipv6_on_wifi"; |
| 86 | 92 |
| 87 const char kSSLKeyLogFile[] = "ssl_key_log_file"; | 93 const char kSSLKeyLogFile[] = "ssl_key_log_file"; |
| 88 | 94 |
| 89 } // namespace | 95 } // namespace |
| 90 | 96 |
| 91 URLRequestContextConfig::QuicHint::QuicHint(const std::string& host, | 97 URLRequestContextConfig::QuicHint::QuicHint(const std::string& host, |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 123 : enable_quic(enable_quic), | 129 : enable_quic(enable_quic), |
| 124 quic_user_agent_id(quic_user_agent_id), | 130 quic_user_agent_id(quic_user_agent_id), |
| 125 enable_spdy(enable_spdy), | 131 enable_spdy(enable_spdy), |
| 126 enable_sdch(enable_sdch), | 132 enable_sdch(enable_sdch), |
| 127 enable_brotli(enable_brotli), | 133 enable_brotli(enable_brotli), |
| 128 http_cache(http_cache), | 134 http_cache(http_cache), |
| 129 http_cache_max_size(http_cache_max_size), | 135 http_cache_max_size(http_cache_max_size), |
| 130 load_disable_cache(load_disable_cache), | 136 load_disable_cache(load_disable_cache), |
| 131 storage_path(storage_path), | 137 storage_path(storage_path), |
| 132 user_agent(user_agent), | 138 user_agent(user_agent), |
| 133 experimental_options(experimental_options), | |
| 134 mock_cert_verifier(std::move(mock_cert_verifier)), | 139 mock_cert_verifier(std::move(mock_cert_verifier)), |
| 135 enable_network_quality_estimator(enable_network_quality_estimator), | 140 enable_network_quality_estimator(enable_network_quality_estimator), |
| 136 bypass_public_key_pinning_for_local_trust_anchors( | 141 bypass_public_key_pinning_for_local_trust_anchors( |
| 137 bypass_public_key_pinning_for_local_trust_anchors), | 142 bypass_public_key_pinning_for_local_trust_anchors), |
| 138 cert_verifier_data(cert_verifier_data) {} | 143 cert_verifier_data(cert_verifier_data), |
| 144 experimental_options(experimental_options) {} | |
| 139 | 145 |
| 140 URLRequestContextConfig::~URLRequestContextConfig() {} | 146 URLRequestContextConfig::~URLRequestContextConfig() {} |
| 141 | 147 |
| 142 void URLRequestContextConfig::ParseAndSetExperimentalOptions( | 148 void URLRequestContextConfig::ParseAndSetExperimentalOptions( |
| 143 net::URLRequestContextBuilder* context_builder, | 149 net::URLRequestContextBuilder* context_builder, |
| 144 net::NetLog* net_log, | 150 net::NetLog* net_log, |
| 145 const scoped_refptr<base::SequencedTaskRunner>& file_task_runner) { | 151 const scoped_refptr<base::SequencedTaskRunner>& file_task_runner) { |
| 152 nqe_params.reset(new net::NetworkQualityEstimatorParams( | |
|
mgersh
2017/06/28 18:26:50
base::MakeUnique is preferred over raw new.
tbansal1
2017/06/29 01:17:58
Done.
| |
| 153 std::map<std::string, std::string>())); | |
| 146 if (experimental_options.empty()) | 154 if (experimental_options.empty()) |
| 147 return; | 155 return; |
| 148 | 156 |
| 149 DCHECK(net_log); | 157 DCHECK(net_log); |
| 150 | 158 |
| 151 DVLOG(1) << "Experimental Options:" << experimental_options; | 159 DVLOG(1) << "Experimental Options:" << experimental_options; |
| 152 std::unique_ptr<base::Value> options = | 160 std::unique_ptr<base::Value> options = |
| 153 base::JSONReader::Read(experimental_options); | 161 base::JSONReader::Read(experimental_options); |
| 154 | 162 |
| 155 if (!options) { | 163 if (!options) { |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 318 if (!ssl_key_log_file.empty() && file_task_runner) { | 326 if (!ssl_key_log_file.empty() && file_task_runner) { |
| 319 // SetSSLKeyLogFile is only safe to call before any SSLClientSockets | 327 // SetSSLKeyLogFile is only safe to call before any SSLClientSockets |
| 320 // are created. This should not be used if there are multiple | 328 // are created. This should not be used if there are multiple |
| 321 // CronetEngine. | 329 // CronetEngine. |
| 322 // TODO(xunjieli): Expose this as a stable API after crbug.com/458365 | 330 // TODO(xunjieli): Expose this as a stable API after crbug.com/458365 |
| 323 // is resolved. | 331 // is resolved. |
| 324 net::SSLClientSocket::SetSSLKeyLogFile(ssl_key_log_file, | 332 net::SSLClientSocket::SetSSLKeyLogFile(ssl_key_log_file, |
| 325 file_task_runner); | 333 file_task_runner); |
| 326 } | 334 } |
| 327 } | 335 } |
| 336 } else if (it.key() == kNetworkQualityEstimatorFieldTrialName) { | |
| 337 const base::DictionaryValue* nqe_args = nullptr; | |
| 338 if (!it.value().GetAsDictionary(&nqe_args)) { | |
| 339 LOG(ERROR) << "\"" << it.key() << "\" config params \"" << it.value() | |
| 340 << "\" is not a dictionary value"; | |
| 341 effective_experimental_options->Remove(it.key(), nullptr); | |
| 342 continue; | |
| 343 } | |
| 344 | |
| 345 std::string nqe_option; | |
| 346 if (nqe_args->GetString("persistent_cache_reading_enabled", | |
|
mgersh
2017/06/28 18:26:50
This string can be moved to the top with the other
tbansal1
2017/06/29 01:17:58
Done.
| |
| 347 &nqe_option)) { | |
| 348 nqe_params->set_persistent_cache_reading_enabled( | |
| 349 nqe_option == "true" ? true : false); | |
|
mgersh
2017/06/28 18:26:50
This option could be a boolean instead of a string
tbansal1
2017/06/29 01:17:58
Thanks, that's much better.
| |
| 350 } | |
| 351 | |
| 352 if (nqe_args->GetString("effective_connection_type_algorithm", | |
|
mgersh
2017/06/28 18:26:50
This string too.
tbansal1
2017/06/29 01:17:58
Done.
| |
| 353 &nqe_option)) { | |
| 354 nqe_params->SetEffectiveConnectionTypeAlgorithm( | |
| 355 net::NetworkQualityEstimatorParams:: | |
| 356 GetEffectiveConnectionTypeAlgorithmFromString(nqe_option)); | |
| 357 } | |
| 358 | |
| 359 if (nqe_args->GetString(net::kForceEffectiveConnectionType, | |
| 360 &nqe_option)) { | |
| 361 net::EffectiveConnectionType forced_effective_connection_type = | |
| 362 net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN; | |
| 363 bool effective_connection_type_available = | |
| 364 net::GetEffectiveConnectionTypeForName( | |
| 365 nqe_option, &forced_effective_connection_type); | |
| 366 DCHECK(effective_connection_type_available); | |
|
mgersh
2017/06/28 18:26:50
This depends on a user-provided value being correc
tbansal1
2017/06/29 01:17:58
Done.
| |
| 367 ALLOW_UNUSED_LOCAL(effective_connection_type_available); | |
| 368 nqe_params->SetForcedEffectiveConnectionType( | |
| 369 forced_effective_connection_type); | |
| 370 } | |
| 371 | |
| 328 } else { | 372 } else { |
| 329 LOG(WARNING) << "Unrecognized Cronet experimental option \"" << it.key() | 373 LOG(WARNING) << "Unrecognized Cronet experimental option \"" << it.key() |
| 330 << "\" with params \"" << it.value(); | 374 << "\" with params \"" << it.value(); |
| 331 effective_experimental_options->Remove(it.key(), nullptr); | 375 effective_experimental_options->Remove(it.key(), nullptr); |
| 332 } | 376 } |
| 333 } | 377 } |
| 334 | 378 |
| 335 if (async_dns_enable || stale_dns_enable || host_resolver_rules_enable || | 379 if (async_dns_enable || stale_dns_enable || host_resolver_rules_enable || |
| 336 disable_ipv6_on_wifi) { | 380 disable_ipv6_on_wifi) { |
| 337 CHECK(net_log) << "All DNS-related experiments require NetLog."; | 381 CHECK(net_log) << "All DNS-related experiments require NetLog."; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 410 URLRequestContextConfigBuilder::Build() { | 454 URLRequestContextConfigBuilder::Build() { |
| 411 return base::MakeUnique<URLRequestContextConfig>( | 455 return base::MakeUnique<URLRequestContextConfig>( |
| 412 enable_quic, quic_user_agent_id, enable_spdy, enable_sdch, enable_brotli, | 456 enable_quic, quic_user_agent_id, enable_spdy, enable_sdch, enable_brotli, |
| 413 http_cache, http_cache_max_size, load_disable_cache, storage_path, | 457 http_cache, http_cache_max_size, load_disable_cache, storage_path, |
| 414 user_agent, experimental_options, std::move(mock_cert_verifier), | 458 user_agent, experimental_options, std::move(mock_cert_verifier), |
| 415 enable_network_quality_estimator, | 459 enable_network_quality_estimator, |
| 416 bypass_public_key_pinning_for_local_trust_anchors, cert_verifier_data); | 460 bypass_public_key_pinning_for_local_trust_anchors, cert_verifier_data); |
| 417 } | 461 } |
| 418 | 462 |
| 419 } // namespace cronet | 463 } // namespace cronet |
| OLD | NEW |