Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(149)

Side by Side Diff: components/cronet/url_request_context_config.cc

Issue 2711153007: Add Cronet experimental option to disable ipv6 (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
12 #include "base/sequenced_task_runner.h" 12 #include "base/sequenced_task_runner.h"
13 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
14 #include "base/strings/string_piece.h" 14 #include "base/strings/string_piece.h"
15 #include "base/strings/string_split.h" 15 #include "base/strings/string_split.h"
16 #include "base/values.h" 16 #include "base/values.h"
17 #include "components/cronet/stale_host_resolver.h" 17 #include "components/cronet/stale_host_resolver.h"
18 #include "net/base/address_family.h"
18 #include "net/cert/caching_cert_verifier.h" 19 #include "net/cert/caching_cert_verifier.h"
19 #include "net/cert/cert_verifier.h" 20 #include "net/cert/cert_verifier.h"
20 #include "net/cert/cert_verify_proc.h" 21 #include "net/cert/cert_verify_proc.h"
21 #include "net/cert/multi_threaded_cert_verifier.h" 22 #include "net/cert/multi_threaded_cert_verifier.h"
22 #include "net/dns/host_resolver.h" 23 #include "net/dns/host_resolver.h"
23 #include "net/dns/mapped_host_resolver.h" 24 #include "net/dns/mapped_host_resolver.h"
24 #include "net/http/http_server_properties.h" 25 #include "net/http/http_server_properties.h"
25 #include "net/quic/chromium/quic_utils_chromium.h" 26 #include "net/quic/chromium/quic_utils_chromium.h"
26 #include "net/quic/core/quic_packets.h" 27 #include "net/quic/core/quic_packets.h"
27 #include "net/socket/ssl_client_socket.h" 28 #include "net/socket/ssl_client_socket.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 const char kStaleDnsMaxStaleUses[] = "max_stale_uses"; 75 const char kStaleDnsMaxStaleUses[] = "max_stale_uses";
75 // 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
76 // the current network. 77 // the current network.
77 const char kStaleDnsAllowOtherNetwork[] = "allow_other_network"; 78 const char kStaleDnsAllowOtherNetwork[] = "allow_other_network";
78 79
79 // Rules to override DNS resolution. Intended for testing. 80 // Rules to override DNS resolution. Intended for testing.
80 // See explanation of format in net/dns/mapped_host_resolver.h. 81 // See explanation of format in net/dns/mapped_host_resolver.h.
81 const char kHostResolverRulesFieldTrialName[] = "HostResolverRules"; 82 const char kHostResolverRulesFieldTrialName[] = "HostResolverRules";
82 const char kHostResolverRules[] = "host_resolver_rules"; 83 const char kHostResolverRules[] = "host_resolver_rules";
83 84
85 // Disable IPv6. This should almost never be necessary because the network stack
86 // has IPv6 detection logic. Please do not turn on this option without first
87 // reporting a bug.
xunjieli 2017/02/27 15:37:39 nit: Open a bug and link it here.
mgersh 2017/02/28 18:29:57 Done.
88 const char kDisableIPv6[] = "disable_ipv6";
89
84 const char kSSLKeyLogFile[] = "ssl_key_log_file"; 90 const char kSSLKeyLogFile[] = "ssl_key_log_file";
85 91
86 void ParseAndSetExperimentalOptions( 92 void ParseAndSetExperimentalOptions(
87 const std::string& experimental_options, 93 const std::string& experimental_options,
88 net::URLRequestContextBuilder* context_builder, 94 net::URLRequestContextBuilder* context_builder,
89 net::NetLog* net_log, 95 net::NetLog* net_log,
90 const scoped_refptr<base::SequencedTaskRunner>& file_task_runner) { 96 const scoped_refptr<base::SequencedTaskRunner>& file_task_runner) {
91 if (experimental_options.empty()) 97 if (experimental_options.empty())
92 return; 98 return;
93 99
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 if (quic_args->GetBoolean(kQuicRaceCertVerification, 208 if (quic_args->GetBoolean(kQuicRaceCertVerification,
203 &quic_race_cert_verification)) { 209 &quic_race_cert_verification)) {
204 context_builder->set_quic_race_cert_verification( 210 context_builder->set_quic_race_cert_verification(
205 quic_race_cert_verification); 211 quic_race_cert_verification);
206 } 212 }
207 } 213 }
208 214
209 bool async_dns_enable = false; 215 bool async_dns_enable = false;
210 bool stale_dns_enable = false; 216 bool stale_dns_enable = false;
211 bool host_resolver_rules_enable = false; 217 bool host_resolver_rules_enable = false;
218 bool disable_ipv6 = false;
212 StaleHostResolver::StaleOptions stale_dns_options; 219 StaleHostResolver::StaleOptions stale_dns_options;
213 std::string host_resolver_rules_string; 220 std::string host_resolver_rules_string;
214 221
215 const base::DictionaryValue* async_dns_args = nullptr; 222 const base::DictionaryValue* async_dns_args = nullptr;
216 if (dict->GetDictionary(kAsyncDnsFieldTrialName, &async_dns_args)) 223 if (dict->GetDictionary(kAsyncDnsFieldTrialName, &async_dns_args))
217 async_dns_args->GetBoolean(kAsyncDnsEnable, &async_dns_enable); 224 async_dns_args->GetBoolean(kAsyncDnsEnable, &async_dns_enable);
218 225
219 const base::DictionaryValue* stale_dns_args = nullptr; 226 const base::DictionaryValue* stale_dns_args = nullptr;
220 if (dict->GetDictionary(kStaleDnsFieldTrialName, &stale_dns_args)) { 227 if (dict->GetDictionary(kStaleDnsFieldTrialName, &stale_dns_args)) {
221 if (stale_dns_args->GetBoolean(kStaleDnsEnable, &stale_dns_enable) && 228 if (stale_dns_args->GetBoolean(kStaleDnsEnable, &stale_dns_enable) &&
(...skipping 18 matching lines...) Expand all
240 } 247 }
241 } 248 }
242 249
243 const base::DictionaryValue* host_resolver_rules_args = nullptr; 250 const base::DictionaryValue* host_resolver_rules_args = nullptr;
244 if (dict->GetDictionary(kHostResolverRulesFieldTrialName, 251 if (dict->GetDictionary(kHostResolverRulesFieldTrialName,
245 &host_resolver_rules_args)) { 252 &host_resolver_rules_args)) {
246 host_resolver_rules_enable = host_resolver_rules_args->GetString( 253 host_resolver_rules_enable = host_resolver_rules_args->GetString(
247 kHostResolverRules, &host_resolver_rules_string); 254 kHostResolverRules, &host_resolver_rules_string);
248 } 255 }
249 256
250 if (async_dns_enable || stale_dns_enable || host_resolver_rules_enable) { 257 dict->GetBoolean(kDisableIPv6, &disable_ipv6);
258
259 if (async_dns_enable || stale_dns_enable || host_resolver_rules_enable ||
260 disable_ipv6) {
251 if (net_log == nullptr) { 261 if (net_log == nullptr) {
252 CHECK(false) << "AsyncDNS, StaleDNS, and HostResolverRules experiments " 262 CHECK(false) << "All DNS-related experiments require NetLog.";
253 << "require NetLog.";
254 } 263 }
255 std::unique_ptr<net::HostResolver> host_resolver; 264 std::unique_ptr<net::HostResolver> host_resolver;
256 if (stale_dns_enable) { 265 if (stale_dns_enable) {
257 host_resolver.reset(new StaleHostResolver( 266 host_resolver.reset(new StaleHostResolver(
258 net::HostResolver::CreateDefaultResolverImpl(net_log), 267 net::HostResolver::CreateDefaultResolverImpl(net_log),
259 stale_dns_options)); 268 stale_dns_options));
xunjieli 2017/02/27 15:37:39 nit: suggest add a DCHECK(disable_ipv6) here (see
mgersh 2017/02/28 18:29:57 Done.
260 } else { 269 } else {
261 host_resolver = net::HostResolver::CreateDefaultResolver(net_log); 270 host_resolver = net::HostResolver::CreateDefaultResolver(net_log);
262 } 271 }
272 if (disable_ipv6)
273 host_resolver->SetDefaultAddressFamily(net::ADDRESS_FAMILY_IPV4);
263 if (async_dns_enable) 274 if (async_dns_enable)
264 host_resolver->SetDnsClientEnabled(true); 275 host_resolver->SetDnsClientEnabled(true);
265 if (host_resolver_rules_enable) { 276 if (host_resolver_rules_enable) {
266 std::unique_ptr<net::MappedHostResolver> remapped_resolver( 277 std::unique_ptr<net::MappedHostResolver> remapped_resolver(
267 new net::MappedHostResolver(std::move(host_resolver))); 278 new net::MappedHostResolver(std::move(host_resolver)));
268 remapped_resolver->SetRulesFromString(host_resolver_rules_string); 279 remapped_resolver->SetRulesFromString(host_resolver_rules_string);
269 host_resolver = std::move(remapped_resolver); 280 host_resolver = std::move(remapped_resolver);
270 } 281 }
271 context_builder->set_host_resolver(std::move(host_resolver)); 282 context_builder->set_host_resolver(std::move(host_resolver));
272 } 283 }
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 enable_quic, quic_user_agent_id, enable_spdy, enable_sdch, http_cache, 412 enable_quic, quic_user_agent_id, enable_spdy, enable_sdch, http_cache,
402 http_cache_max_size, load_disable_cache, storage_path, user_agent, 413 http_cache_max_size, load_disable_cache, storage_path, user_agent,
403 experimental_options, data_reduction_proxy_key, 414 experimental_options, data_reduction_proxy_key,
404 data_reduction_primary_proxy, data_reduction_fallback_proxy, 415 data_reduction_primary_proxy, data_reduction_fallback_proxy,
405 data_reduction_secure_proxy_check_url, std::move(mock_cert_verifier), 416 data_reduction_secure_proxy_check_url, std::move(mock_cert_verifier),
406 enable_network_quality_estimator, 417 enable_network_quality_estimator,
407 bypass_public_key_pinning_for_local_trust_anchors, cert_verifier_data); 418 bypass_public_key_pinning_for_local_trust_anchors, cert_verifier_data);
408 } 419 }
409 420
410 } // namespace cronet 421 } // namespace cronet
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698