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

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

Issue 1898873006: Cronet: Use stale DNS cache entries experimentally. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@dns_stale2
Patch Set: Add integration test, rebase, format, &c. Created 4 years, 5 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 "net/cert/caching_cert_verifier.h" 18 #include "net/cert/caching_cert_verifier.h"
18 #include "net/cert/cert_verifier.h" 19 #include "net/cert/cert_verifier.h"
19 #include "net/cert/cert_verify_proc.h" 20 #include "net/cert/cert_verify_proc.h"
20 #include "net/cert/multi_threaded_cert_verifier.h" 21 #include "net/cert/multi_threaded_cert_verifier.h"
21 #include "net/dns/host_resolver.h" 22 #include "net/dns/host_resolver.h"
22 #include "net/http/http_server_properties.h" 23 #include "net/http/http_server_properties.h"
23 #include "net/quic/quic_protocol.h" 24 #include "net/quic/quic_protocol.h"
24 #include "net/quic/quic_utils.h" 25 #include "net/quic/quic_utils.h"
25 #include "net/socket/ssl_client_socket.h" 26 #include "net/socket/ssl_client_socket.h"
26 #include "net/url_request/url_request_context_builder.h" 27 #include "net/url_request/url_request_context_builder.h"
(...skipping 25 matching lines...) Expand all
52 const char kQuicUserAgentId[] = "user_agent_id"; 53 const char kQuicUserAgentId[] = "user_agent_id";
53 const char kQuicMigrateSessionsEarly[] = "migrate_sessions_early"; 54 const char kQuicMigrateSessionsEarly[] = "migrate_sessions_early";
54 const char kQuicDisableBidirectionalStreams[] = 55 const char kQuicDisableBidirectionalStreams[] =
55 "quic_disable_bidirectional_streams"; 56 "quic_disable_bidirectional_streams";
56 57
57 // AsyncDNS experiment dictionary name. 58 // AsyncDNS experiment dictionary name.
58 const char kAsyncDnsFieldTrialName[] = "AsyncDNS"; 59 const char kAsyncDnsFieldTrialName[] = "AsyncDNS";
59 // Name of boolean to enable AsyncDNS experiment. 60 // Name of boolean to enable AsyncDNS experiment.
60 const char kAsyncDnsEnable[] = "enable"; 61 const char kAsyncDnsEnable[] = "enable";
61 62
63 // Stale DNS (StaleHostResolver) experiment dictionary name.
64 const char kStaleDnsFieldTrialName[] = "StaleDNS";
65 // Name of boolean to enable stale DNS experiment.
66 const char kStaleDnsEnable[] = "enable";
67 // Name of integer delay in milliseconds before a stale DNS result will be
68 // used.
69 const char kStaleDnsDelayMs[] = "delay_ms";
70 // Name of integer maximum age (past expiration) in milliseconds of a stale DNS
71 // result that will be used.
72 const char kStaleDnsMaxExpiredTimeMs[] = "max_expired_time_ms";
73 // Name of integer maximum times each stale DNS result can be used.
74 const char kStaleDnsMaxStaleUses[] = "max_stale_uses";
75 // Name of boolean to allow stale DNS results from other networks to be used on
76 // the current network.
77 const char kStaleDnsAllowOtherNetwork[] = "allow_other_network";
78
62 const char kSSLKeyLogFile[] = "ssl_key_log_file"; 79 const char kSSLKeyLogFile[] = "ssl_key_log_file";
63 80
64 void ParseAndSetExperimentalOptions( 81 void ParseAndSetExperimentalOptions(
65 const std::string& experimental_options, 82 const std::string& experimental_options,
66 net::URLRequestContextBuilder* context_builder, 83 net::URLRequestContextBuilder* context_builder,
67 net::NetLog* net_log, 84 net::NetLog* net_log,
68 const scoped_refptr<base::SequencedTaskRunner>& file_task_runner) { 85 const scoped_refptr<base::SequencedTaskRunner>& file_task_runner) {
69 if (experimental_options.empty()) 86 if (experimental_options.empty())
70 return; 87 return;
71 88
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 } 199 }
183 200
184 bool quic_disable_bidirectional_streams = false; 201 bool quic_disable_bidirectional_streams = false;
185 if (quic_args->GetBoolean(kQuicDisableBidirectionalStreams, 202 if (quic_args->GetBoolean(kQuicDisableBidirectionalStreams,
186 &quic_disable_bidirectional_streams)) { 203 &quic_disable_bidirectional_streams)) {
187 context_builder->set_quic_disable_bidirectional_streams( 204 context_builder->set_quic_disable_bidirectional_streams(
188 quic_disable_bidirectional_streams); 205 quic_disable_bidirectional_streams);
189 } 206 }
190 } 207 }
191 208
209 bool async_dns_enable = false;
210 bool stale_dns_enable = false;
211 StaleHostResolver::StaleOptions stale_dns_options;
212
192 const base::DictionaryValue* async_dns_args = nullptr; 213 const base::DictionaryValue* async_dns_args = nullptr;
193 if (dict->GetDictionary(kAsyncDnsFieldTrialName, &async_dns_args)) { 214 if (dict->GetDictionary(kAsyncDnsFieldTrialName, &async_dns_args))
194 bool async_dns_enable = false; 215 async_dns_args->GetBoolean(kAsyncDnsEnable, &async_dns_enable);
195 if (async_dns_args->GetBoolean(kAsyncDnsEnable, &async_dns_enable) && 216
196 async_dns_enable) { 217 const base::DictionaryValue* stale_dns_args = nullptr;
197 if (net_log == nullptr) { 218 if (dict->GetDictionary(kStaleDnsFieldTrialName, &stale_dns_args)) {
198 DCHECK(false) << "AsyncDNS experiment requires NetLog."; 219 if (stale_dns_args->GetBoolean(kStaleDnsEnable, &stale_dns_enable) &&
199 } else { 220 stale_dns_enable) {
200 std::unique_ptr<net::HostResolver> host_resolver( 221 int delay;
201 net::HostResolver::CreateDefaultResolver(net_log)); 222 if (stale_dns_args->GetInteger(kStaleDnsDelayMs, &delay))
202 host_resolver->SetDnsClientEnabled(true); 223 stale_dns_options.delay = base::TimeDelta::FromMilliseconds(delay);
203 context_builder->set_host_resolver(std::move(host_resolver)); 224 int max_expired_time_ms;
225 if (stale_dns_args->GetInteger(kStaleDnsMaxExpiredTimeMs,
226 &max_expired_time_ms)) {
227 stale_dns_options.max_expired_time =
228 base::TimeDelta::FromMilliseconds(max_expired_time_ms);
229 }
230 int max_stale_uses;
231 if (stale_dns_args->GetInteger(kStaleDnsMaxStaleUses, &max_stale_uses))
232 stale_dns_options.max_stale_uses = max_stale_uses;
233 bool allow_other_network;
234 if (stale_dns_args->GetBoolean(kStaleDnsAllowOtherNetwork,
235 &allow_other_network)) {
236 stale_dns_options.allow_other_network = allow_other_network;
204 } 237 }
205 } 238 }
206 } 239 }
207 240
241 if (async_dns_enable || stale_dns_enable) {
242 if (net_log == nullptr)
243 CHECK(false) << "AsyncDNS and StaleDNS experiments require NetLog.";
244 std::unique_ptr<net::HostResolver> host_resolver;
245 if (stale_dns_enable) {
246 host_resolver.reset(new StaleHostResolver(
247 net::HostResolver::CreateDefaultResolverImpl(net_log),
248 stale_dns_options));
249 } else {
250 host_resolver = net::HostResolver::CreateDefaultResolver(net_log);
251 }
252 if (async_dns_enable)
253 host_resolver->SetDnsClientEnabled(true);
254 context_builder->set_host_resolver(std::move(host_resolver));
255 }
256
208 std::string ssl_key_log_file_string; 257 std::string ssl_key_log_file_string;
209 if (dict->GetString(kSSLKeyLogFile, &ssl_key_log_file_string)) { 258 if (dict->GetString(kSSLKeyLogFile, &ssl_key_log_file_string)) {
210 DCHECK(file_task_runner); 259 DCHECK(file_task_runner);
211 base::FilePath ssl_key_log_file(ssl_key_log_file_string); 260 base::FilePath ssl_key_log_file(ssl_key_log_file_string);
212 if (!ssl_key_log_file.empty() && file_task_runner) { 261 if (!ssl_key_log_file.empty() && file_task_runner) {
213 // SetSSLKeyLogFile is only safe to call before any SSLClientSockets are 262 // SetSSLKeyLogFile is only safe to call before any SSLClientSockets are
214 // created. This should not be used if there are multiple CronetEngine. 263 // created. This should not be used if there are multiple CronetEngine.
215 // TODO(xunjieli): Expose this as a stable API after crbug.com/458365 is 264 // TODO(xunjieli): Expose this as a stable API after crbug.com/458365 is
216 // resolved. 265 // resolved.
217 net::SSLClientSocket::SetSSLKeyLogFile(ssl_key_log_file, 266 net::SSLClientSocket::SetSSLKeyLogFile(ssl_key_log_file,
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 std::move(mock_cert_verifier)); 367 std::move(mock_cert_verifier));
319 } else { 368 } else {
320 // net::CertVerifier::CreateDefault() returns a CachingCertVerifier. 369 // net::CertVerifier::CreateDefault() returns a CachingCertVerifier.
321 cert_verifier = net::CertVerifier::CreateDefault(); 370 cert_verifier = net::CertVerifier::CreateDefault();
322 } 371 }
323 context_builder->SetCertVerifier(std::move(cert_verifier)); 372 context_builder->SetCertVerifier(std::move(cert_verifier));
324 // TODO(mef): Use |config| to set cookies. 373 // TODO(mef): Use |config| to set cookies.
325 } 374 }
326 375
327 } // namespace cronet 376 } // namespace cronet
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698