| 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" |
| 11 #include "base/sequenced_task_runner.h" | 11 #include "base/sequenced_task_runner.h" |
| 12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 13 #include "base/strings/string_piece.h" | 13 #include "base/strings/string_piece.h" |
| 14 #include "base/strings/string_split.h" | 14 #include "base/strings/string_split.h" |
| 15 #include "base/values.h" | 15 #include "base/values.h" |
| 16 #include "components/cronet/stale_host_resolver.h" |
| 16 #include "net/cert/cert_verifier.h" | 17 #include "net/cert/cert_verifier.h" |
| 17 #include "net/dns/host_resolver.h" | 18 #include "net/dns/host_resolver.h" |
| 18 #include "net/http/http_server_properties.h" | 19 #include "net/http/http_server_properties.h" |
| 19 #include "net/quic/quic_protocol.h" | 20 #include "net/quic/quic_protocol.h" |
| 20 #include "net/quic/quic_utils.h" | 21 #include "net/quic/quic_utils.h" |
| 21 #include "net/socket/ssl_client_socket.h" | 22 #include "net/socket/ssl_client_socket.h" |
| 22 #include "net/url_request/url_request_context_builder.h" | 23 #include "net/url_request/url_request_context_builder.h" |
| 23 | 24 |
| 24 namespace cronet { | 25 namespace cronet { |
| 25 | 26 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 48 const char kQuicUserAgentId[] = "user_agent_id"; | 49 const char kQuicUserAgentId[] = "user_agent_id"; |
| 49 const char kQuicMigrateSessionsEarly[] = "migrate_sessions_early"; | 50 const char kQuicMigrateSessionsEarly[] = "migrate_sessions_early"; |
| 50 const char kQuicDisableBidirectionalStreams[] = | 51 const char kQuicDisableBidirectionalStreams[] = |
| 51 "quic_disable_bidirectional_streams"; | 52 "quic_disable_bidirectional_streams"; |
| 52 | 53 |
| 53 // AsyncDNS experiment dictionary name. | 54 // AsyncDNS experiment dictionary name. |
| 54 const char kAsyncDnsFieldTrialName[] = "AsyncDNS"; | 55 const char kAsyncDnsFieldTrialName[] = "AsyncDNS"; |
| 55 // Name of boolean to enable AsyncDNS experiment. | 56 // Name of boolean to enable AsyncDNS experiment. |
| 56 const char kAsyncDnsEnable[] = "enable"; | 57 const char kAsyncDnsEnable[] = "enable"; |
| 57 | 58 |
| 59 // Stale DNS (StaleHostResolver) experiment dictionary name. |
| 60 const char kStaleDnsFieldTrialName[] = "StaleDNS"; |
| 61 // Name of boolean to enable stale DNS experiment. |
| 62 const char kStaleDnsEnable[] = "enable"; |
| 63 // Name of integer delay in milliseconds before a stale DNS result will be |
| 64 // used. |
| 65 const char kStaleDnsDelayMs[] = "delay_ms"; |
| 66 // Name of integer maximum age (past expiration) in milliseconds of a stale DNS |
| 67 // result that will be used. |
| 68 const char kStaleDnsMaxExpiredTimeMs[] = "max_expired_time_ms"; |
| 69 // Name of integer maximum times each stale DNS result can be used. |
| 70 const char kStaleDnsMaxStaleUses[] = "max_stale_uses"; |
| 71 // Name of boolean to allow stale DNS results from other networks to be used on |
| 72 // the current network. |
| 73 const char kStaleDnsAllowOtherNetwork[] = "allow_other_network"; |
| 74 |
| 58 const char kSSLKeyLogFile[] = "ssl_key_log_file"; | 75 const char kSSLKeyLogFile[] = "ssl_key_log_file"; |
| 59 | 76 |
| 60 void ParseAndSetExperimentalOptions( | 77 void ParseAndSetExperimentalOptions( |
| 61 const std::string& experimental_options, | 78 const std::string& experimental_options, |
| 62 net::URLRequestContextBuilder* context_builder, | 79 net::URLRequestContextBuilder* context_builder, |
| 63 net::NetLog* net_log, | 80 net::NetLog* net_log, |
| 64 const scoped_refptr<base::SequencedTaskRunner>& file_task_runner) { | 81 const scoped_refptr<base::SequencedTaskRunner>& file_task_runner) { |
| 65 if (experimental_options.empty()) | 82 if (experimental_options.empty()) |
| 66 return; | 83 return; |
| 67 | 84 |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 } | 195 } |
| 179 | 196 |
| 180 bool quic_disable_bidirectional_streams = false; | 197 bool quic_disable_bidirectional_streams = false; |
| 181 if (quic_args->GetBoolean(kQuicDisableBidirectionalStreams, | 198 if (quic_args->GetBoolean(kQuicDisableBidirectionalStreams, |
| 182 &quic_disable_bidirectional_streams)) { | 199 &quic_disable_bidirectional_streams)) { |
| 183 context_builder->set_quic_disable_bidirectional_streams( | 200 context_builder->set_quic_disable_bidirectional_streams( |
| 184 quic_disable_bidirectional_streams); | 201 quic_disable_bidirectional_streams); |
| 185 } | 202 } |
| 186 } | 203 } |
| 187 | 204 |
| 205 bool async_dns_enable = false; |
| 206 bool stale_dns_enable = false; |
| 207 StaleHostResolver::StaleOptions stale_dns_options; |
| 208 |
| 188 const base::DictionaryValue* async_dns_args = nullptr; | 209 const base::DictionaryValue* async_dns_args = nullptr; |
| 189 if (dict->GetDictionary(kAsyncDnsFieldTrialName, &async_dns_args)) { | 210 if (dict->GetDictionary(kAsyncDnsFieldTrialName, &async_dns_args)) |
| 190 bool async_dns_enable = false; | 211 async_dns_args->GetBoolean(kAsyncDnsEnable, &async_dns_enable); |
| 191 if (async_dns_args->GetBoolean(kAsyncDnsEnable, &async_dns_enable) && | 212 |
| 192 async_dns_enable) { | 213 const base::DictionaryValue* stale_dns_args = nullptr; |
| 193 if (net_log == nullptr) { | 214 if (dict->GetDictionary(kStaleDnsFieldTrialName, &stale_dns_args)) { |
| 194 DCHECK(false) << "AsyncDNS experiment requires NetLog."; | 215 if (stale_dns_args->GetBoolean(kStaleDnsEnable, &stale_dns_enable) && |
| 195 } else { | 216 stale_dns_enable) { |
| 196 std::unique_ptr<net::HostResolver> host_resolver( | 217 int delay; |
| 197 net::HostResolver::CreateDefaultResolver(net_log)); | 218 if (stale_dns_args->GetInteger(kStaleDnsDelayMs, &delay)) |
| 198 host_resolver->SetDnsClientEnabled(true); | 219 stale_dns_options.delay = base::TimeDelta::FromMilliseconds(delay); |
| 199 context_builder->set_host_resolver(std::move(host_resolver)); | 220 int max_expired_time_ms; |
| 221 if (stale_dns_args->GetInteger(kStaleDnsMaxExpiredTimeMs, |
| 222 &max_expired_time_ms)) { |
| 223 stale_dns_options.max_expired_time = |
| 224 base::TimeDelta::FromMilliseconds(max_expired_time_ms); |
| 225 } |
| 226 int max_stale_uses; |
| 227 if (stale_dns_args->GetInteger(kStaleDnsMaxStaleUses, &max_stale_uses)) |
| 228 stale_dns_options.max_stale_uses = max_stale_uses; |
| 229 bool allow_other_network; |
| 230 if (stale_dns_args->GetBoolean(kStaleDnsAllowOtherNetwork, |
| 231 &allow_other_network)) { |
| 232 stale_dns_options.allow_other_network = allow_other_network; |
| 200 } | 233 } |
| 201 } | 234 } |
| 202 } | 235 } |
| 203 | 236 |
| 237 if (async_dns_enable || stale_dns_enable) { |
| 238 if (net_log == nullptr) |
| 239 CHECK(false) << "AsyncDNS and StaleDNS experiments require NetLog."; |
| 240 std::unique_ptr<net::HostResolver> host_resolver; |
| 241 if (stale_dns_enable) { |
| 242 host_resolver.reset(new StaleHostResolver( |
| 243 net::HostResolver::CreateDefaultResolverImpl(net_log), |
| 244 stale_dns_options)); |
| 245 } else { |
| 246 host_resolver = net::HostResolver::CreateDefaultResolver(net_log); |
| 247 } |
| 248 if (async_dns_enable) |
| 249 host_resolver->SetDnsClientEnabled(true); |
| 250 context_builder->set_host_resolver(std::move(host_resolver)); |
| 251 } |
| 252 |
| 204 std::string ssl_key_log_file_string; | 253 std::string ssl_key_log_file_string; |
| 205 if (dict->GetString(kSSLKeyLogFile, &ssl_key_log_file_string)) { | 254 if (dict->GetString(kSSLKeyLogFile, &ssl_key_log_file_string)) { |
| 206 DCHECK(file_task_runner); | 255 DCHECK(file_task_runner); |
| 207 base::FilePath ssl_key_log_file(ssl_key_log_file_string); | 256 base::FilePath ssl_key_log_file(ssl_key_log_file_string); |
| 208 if (!ssl_key_log_file.empty() && file_task_runner) { | 257 if (!ssl_key_log_file.empty() && file_task_runner) { |
| 209 // SetSSLKeyLogFile is only safe to call before any SSLClientSockets are | 258 // SetSSLKeyLogFile is only safe to call before any SSLClientSockets are |
| 210 // created. This should not be used if there are multiple CronetEngine. | 259 // created. This should not be used if there are multiple CronetEngine. |
| 211 // TODO(xunjieli): Expose this as a stable API after crbug.com/458365 is | 260 // TODO(xunjieli): Expose this as a stable API after crbug.com/458365 is |
| 212 // resolved. | 261 // resolved. |
| 213 net::SSLClientSocket::SetSSLKeyLogFile(ssl_key_log_file, | 262 net::SSLClientSocket::SetSSLKeyLogFile(ssl_key_log_file, |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 | 347 |
| 299 ParseAndSetExperimentalOptions(experimental_options, context_builder, net_log, | 348 ParseAndSetExperimentalOptions(experimental_options, context_builder, net_log, |
| 300 file_task_runner); | 349 file_task_runner); |
| 301 | 350 |
| 302 if (mock_cert_verifier) | 351 if (mock_cert_verifier) |
| 303 context_builder->SetCertVerifier(std::move(mock_cert_verifier)); | 352 context_builder->SetCertVerifier(std::move(mock_cert_verifier)); |
| 304 // TODO(mef): Use |config| to set cookies. | 353 // TODO(mef): Use |config| to set cookies. |
| 305 } | 354 } |
| 306 | 355 |
| 307 } // namespace cronet | 356 } // namespace cronet |
| OLD | NEW |