| 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 "net/cert/cert_verifier.h" | 16 #include "net/cert/cert_verifier.h" |
| 17 #include "net/dns/host_resolver.h" | 17 #include "net/dns/host_resolver.h" |
| 18 #include "net/dns/mapped_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 |
| 26 namespace { | 27 namespace { |
| 27 | 28 |
| (...skipping 20 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 // Rules to override DNS resolution. Intended for testing. |
| 60 // See explanation of format in net/dns/mapped_host_resolver.h. |
| 61 const char kHostResolverRulesFieldTrialName[] = "HostResolverRules"; |
| 62 const char kHostResolverRules[] = "host_resolver_rules"; |
| 63 |
| 58 const char kSSLKeyLogFile[] = "ssl_key_log_file"; | 64 const char kSSLKeyLogFile[] = "ssl_key_log_file"; |
| 59 | 65 |
| 60 void ParseAndSetExperimentalOptions( | 66 void ParseAndSetExperimentalOptions( |
| 61 const std::string& experimental_options, | 67 const std::string& experimental_options, |
| 62 net::URLRequestContextBuilder* context_builder, | 68 net::URLRequestContextBuilder* context_builder, |
| 63 net::NetLog* net_log, | 69 net::NetLog* net_log, |
| 64 const scoped_refptr<base::SequencedTaskRunner>& file_task_runner) { | 70 const scoped_refptr<base::SequencedTaskRunner>& file_task_runner) { |
| 65 if (experimental_options.empty()) | 71 if (experimental_options.empty()) |
| 66 return; | 72 return; |
| 67 | 73 |
| 74 DCHECK(net_log); |
| 75 |
| 68 DVLOG(1) << "Experimental Options:" << experimental_options; | 76 DVLOG(1) << "Experimental Options:" << experimental_options; |
| 69 std::unique_ptr<base::Value> options = | 77 std::unique_ptr<base::Value> options = |
| 70 base::JSONReader::Read(experimental_options); | 78 base::JSONReader::Read(experimental_options); |
| 71 | 79 |
| 72 if (!options) { | 80 if (!options) { |
| 73 DCHECK(false) << "Parsing experimental options failed: " | 81 DCHECK(false) << "Parsing experimental options failed: " |
| 74 << experimental_options; | 82 << experimental_options; |
| 75 return; | 83 return; |
| 76 } | 84 } |
| 77 | 85 |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 } | 186 } |
| 179 | 187 |
| 180 bool quic_disable_bidirectional_streams = false; | 188 bool quic_disable_bidirectional_streams = false; |
| 181 if (quic_args->GetBoolean(kQuicDisableBidirectionalStreams, | 189 if (quic_args->GetBoolean(kQuicDisableBidirectionalStreams, |
| 182 &quic_disable_bidirectional_streams)) { | 190 &quic_disable_bidirectional_streams)) { |
| 183 context_builder->set_quic_disable_bidirectional_streams( | 191 context_builder->set_quic_disable_bidirectional_streams( |
| 184 quic_disable_bidirectional_streams); | 192 quic_disable_bidirectional_streams); |
| 185 } | 193 } |
| 186 } | 194 } |
| 187 | 195 |
| 196 std::unique_ptr<net::HostResolver> host_resolver = |
| 197 net::HostResolver::CreateDefaultResolver(net_log); |
| 198 |
| 188 const base::DictionaryValue* async_dns_args = nullptr; | 199 const base::DictionaryValue* async_dns_args = nullptr; |
| 189 if (dict->GetDictionary(kAsyncDnsFieldTrialName, &async_dns_args)) { | 200 if (dict->GetDictionary(kAsyncDnsFieldTrialName, &async_dns_args)) { |
| 190 bool async_dns_enable = false; | 201 bool async_dns_enable = false; |
| 191 if (async_dns_args->GetBoolean(kAsyncDnsEnable, &async_dns_enable) && | 202 if (async_dns_args->GetBoolean(kAsyncDnsEnable, &async_dns_enable) && |
| 192 async_dns_enable) { | 203 async_dns_enable) { |
| 193 if (net_log == nullptr) { | 204 host_resolver->SetDnsClientEnabled(true); |
| 194 DCHECK(false) << "AsyncDNS experiment requires NetLog."; | |
| 195 } else { | |
| 196 std::unique_ptr<net::HostResolver> host_resolver( | |
| 197 net::HostResolver::CreateDefaultResolver(net_log)); | |
| 198 host_resolver->SetDnsClientEnabled(true); | |
| 199 context_builder->set_host_resolver(std::move(host_resolver)); | |
| 200 } | |
| 201 } | 205 } |
| 202 } | 206 } |
| 203 | 207 |
| 208 const base::DictionaryValue* host_resolver_args = nullptr; |
| 209 if (dict->GetDictionary(kHostResolverRulesFieldTrialName, |
| 210 &host_resolver_args)) { |
| 211 std::string host_resolver_rules; |
| 212 if (host_resolver_args->GetString(kHostResolverRules, |
| 213 &host_resolver_rules)) { |
| 214 std::unique_ptr<net::MappedHostResolver> remapped_resolver( |
| 215 new net::MappedHostResolver(std::move(host_resolver))); |
| 216 remapped_resolver->SetRulesFromString(host_resolver_rules); |
| 217 host_resolver = std::move(remapped_resolver); |
| 218 } |
| 219 } |
| 220 |
| 221 context_builder->set_host_resolver(std::move(host_resolver)); |
| 222 |
| 204 std::string ssl_key_log_file_string; | 223 std::string ssl_key_log_file_string; |
| 205 if (dict->GetString(kSSLKeyLogFile, &ssl_key_log_file_string)) { | 224 if (dict->GetString(kSSLKeyLogFile, &ssl_key_log_file_string)) { |
| 206 DCHECK(file_task_runner); | 225 DCHECK(file_task_runner); |
| 207 base::FilePath ssl_key_log_file(ssl_key_log_file_string); | 226 base::FilePath ssl_key_log_file(ssl_key_log_file_string); |
| 208 if (!ssl_key_log_file.empty() && file_task_runner) { | 227 if (!ssl_key_log_file.empty() && file_task_runner) { |
| 209 // SetSSLKeyLogFile is only safe to call before any SSLClientSockets are | 228 // SetSSLKeyLogFile is only safe to call before any SSLClientSockets are |
| 210 // created. This should not be used if there are multiple CronetEngine. | 229 // 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 | 230 // TODO(xunjieli): Expose this as a stable API after crbug.com/458365 is |
| 212 // resolved. | 231 // resolved. |
| 213 net::SSLClientSocket::SetSSLKeyLogFile(ssl_key_log_file, | 232 net::SSLClientSocket::SetSSLKeyLogFile(ssl_key_log_file, |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 data_reduction_secure_proxy_check_url( | 285 data_reduction_secure_proxy_check_url( |
| 267 data_reduction_secure_proxy_check_url), | 286 data_reduction_secure_proxy_check_url), |
| 268 mock_cert_verifier(std::move(mock_cert_verifier)) {} | 287 mock_cert_verifier(std::move(mock_cert_verifier)) {} |
| 269 | 288 |
| 270 URLRequestContextConfig::~URLRequestContextConfig() {} | 289 URLRequestContextConfig::~URLRequestContextConfig() {} |
| 271 | 290 |
| 272 void URLRequestContextConfig::ConfigureURLRequestContextBuilder( | 291 void URLRequestContextConfig::ConfigureURLRequestContextBuilder( |
| 273 net::URLRequestContextBuilder* context_builder, | 292 net::URLRequestContextBuilder* context_builder, |
| 274 net::NetLog* net_log, | 293 net::NetLog* net_log, |
| 275 const scoped_refptr<base::SequencedTaskRunner>& file_task_runner) { | 294 const scoped_refptr<base::SequencedTaskRunner>& file_task_runner) { |
| 295 DCHECK(net_log); |
| 296 |
| 276 std::string config_cache; | 297 std::string config_cache; |
| 277 if (http_cache != DISABLED) { | 298 if (http_cache != DISABLED) { |
| 278 net::URLRequestContextBuilder::HttpCacheParams cache_params; | 299 net::URLRequestContextBuilder::HttpCacheParams cache_params; |
| 279 if (http_cache == DISK && !storage_path.empty()) { | 300 if (http_cache == DISK && !storage_path.empty()) { |
| 280 cache_params.type = net::URLRequestContextBuilder::HttpCacheParams::DISK; | 301 cache_params.type = net::URLRequestContextBuilder::HttpCacheParams::DISK; |
| 281 cache_params.path = | 302 cache_params.path = |
| 282 base::FilePath(storage_path) | 303 base::FilePath(storage_path) |
| 283 .Append(FILE_PATH_LITERAL(kDiskCacheDirectoryName)); | 304 .Append(FILE_PATH_LITERAL(kDiskCacheDirectoryName)); |
| 284 } else { | 305 } else { |
| 285 cache_params.type = | 306 cache_params.type = |
| (...skipping 12 matching lines...) Expand all Loading... |
| 298 | 319 |
| 299 ParseAndSetExperimentalOptions(experimental_options, context_builder, net_log, | 320 ParseAndSetExperimentalOptions(experimental_options, context_builder, net_log, |
| 300 file_task_runner); | 321 file_task_runner); |
| 301 | 322 |
| 302 if (mock_cert_verifier) | 323 if (mock_cert_verifier) |
| 303 context_builder->SetCertVerifier(std::move(mock_cert_verifier)); | 324 context_builder->SetCertVerifier(std::move(mock_cert_verifier)); |
| 304 // TODO(mef): Use |config| to set cookies. | 325 // TODO(mef): Use |config| to set cookies. |
| 305 } | 326 } |
| 306 | 327 |
| 307 } // namespace cronet | 328 } // namespace cronet |
| OLD | NEW |