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 <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/scoped_ptr.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/http/http_server_properties.h" | 18 #include "net/http/http_server_properties.h" |
| 19 #include "net/quic/quic_protocol.h" | 19 #include "net/quic/quic_protocol.h" |
| 20 #include "net/quic/quic_utils.h" | 20 #include "net/quic/quic_utils.h" |
| 21 #include "net/socket/ssl_client_socket.h" | |
| 21 #include "net/url_request/url_request_context_builder.h" | 22 #include "net/url_request/url_request_context_builder.h" |
| 22 | 23 |
| 23 namespace cronet { | 24 namespace cronet { |
| 24 | 25 |
| 25 namespace { | 26 namespace { |
| 26 | 27 |
| 27 // TODO(xunjieli): Refactor constants in io_thread.cc. | 28 // TODO(xunjieli): Refactor constants in io_thread.cc. |
| 28 const char kQuicFieldTrialName[] = "QUIC"; | 29 const char kQuicFieldTrialName[] = "QUIC"; |
| 29 const char kQuicConnectionOptions[] = "connection_options"; | 30 const char kQuicConnectionOptions[] = "connection_options"; |
| 30 const char kQuicStoreServerConfigsInProperties[] = | 31 const char kQuicStoreServerConfigsInProperties[] = |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 45 const char kQuicUserAgentId[] = "user_agent_id"; | 46 const char kQuicUserAgentId[] = "user_agent_id"; |
| 46 const char kQuicMigrateSessionsEarly[] = "migrate_sessions_early"; | 47 const char kQuicMigrateSessionsEarly[] = "migrate_sessions_early"; |
| 47 const char kQuicDisableBidirectionalStreams[] = | 48 const char kQuicDisableBidirectionalStreams[] = |
| 48 "quic_disable_bidirectional_streams"; | 49 "quic_disable_bidirectional_streams"; |
| 49 | 50 |
| 50 // AsyncDNS experiment dictionary name. | 51 // AsyncDNS experiment dictionary name. |
| 51 const char kAsyncDnsFieldTrialName[] = "AsyncDNS"; | 52 const char kAsyncDnsFieldTrialName[] = "AsyncDNS"; |
| 52 // Name of boolean to enable AsyncDNS experiment. | 53 // Name of boolean to enable AsyncDNS experiment. |
| 53 const char kAsyncDnsEnable[] = "enable"; | 54 const char kAsyncDnsEnable[] = "enable"; |
| 54 | 55 |
| 56 const char kSSLKeyLogFile[] = "ssl_key_log_file"; | |
| 57 | |
| 55 void ParseAndSetExperimentalOptions( | 58 void ParseAndSetExperimentalOptions( |
| 56 const std::string& experimental_options, | 59 const std::string& experimental_options, |
| 57 net::URLRequestContextBuilder* context_builder, | 60 net::URLRequestContextBuilder* context_builder, |
| 58 net::NetLog* net_log) { | 61 net::NetLog* net_log, |
| 62 const scoped_refptr<base::SequencedTaskRunner>& file_task_runner) { | |
| 59 if (experimental_options.empty()) | 63 if (experimental_options.empty()) |
| 60 return; | 64 return; |
| 61 | 65 |
| 62 DVLOG(1) << "Experimental Options:" << experimental_options; | 66 DVLOG(1) << "Experimental Options:" << experimental_options; |
| 63 scoped_ptr<base::Value> options = | 67 scoped_ptr<base::Value> options = |
| 64 base::JSONReader::Read(experimental_options); | 68 base::JSONReader::Read(experimental_options); |
| 65 | 69 |
| 66 if (!options) { | 70 if (!options) { |
| 67 DCHECK(false) << "Parsing experimental options failed: " | 71 DCHECK(false) << "Parsing experimental options failed: " |
| 68 << experimental_options; | 72 << experimental_options; |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 187 if (net_log == nullptr) { | 191 if (net_log == nullptr) { |
| 188 DCHECK(false) << "AsyncDNS experiment requires NetLog."; | 192 DCHECK(false) << "AsyncDNS experiment requires NetLog."; |
| 189 } else { | 193 } else { |
| 190 scoped_ptr<net::HostResolver> host_resolver( | 194 scoped_ptr<net::HostResolver> host_resolver( |
| 191 net::HostResolver::CreateDefaultResolver(net_log)); | 195 net::HostResolver::CreateDefaultResolver(net_log)); |
| 192 host_resolver->SetDnsClientEnabled(true); | 196 host_resolver->SetDnsClientEnabled(true); |
| 193 context_builder->set_host_resolver(std::move(host_resolver)); | 197 context_builder->set_host_resolver(std::move(host_resolver)); |
| 194 } | 198 } |
| 195 } | 199 } |
| 196 } | 200 } |
| 201 | |
| 202 std::string ssl_key_log_file_string; | |
| 203 if (dict->GetString(kSSLKeyLogFile, &ssl_key_log_file_string)) { | |
| 204 DCHECK(file_task_runner); | |
| 205 base::FilePath ssl_key_log_file(ssl_key_log_file_string); | |
| 206 if (!ssl_key_log_file.empty()) { | |
| 207 net::SSLClientSocket::SetSSLKeyLogFile(ssl_key_log_file, | |
| 208 file_task_runner); | |
|
davidben
2016/03/25 20:30:45
Hrm. When can this method get called? It's not saf
xunjieli
2016/03/25 20:45:35
Acknowledged. Talked to David offline. Assuming cl
| |
| 209 } | |
| 210 } | |
| 197 } | 211 } |
| 198 | 212 |
| 199 } // namespace | 213 } // namespace |
| 200 | 214 |
| 201 URLRequestContextConfig::QuicHint::QuicHint(const std::string& host, | 215 URLRequestContextConfig::QuicHint::QuicHint(const std::string& host, |
| 202 int port, | 216 int port, |
| 203 int alternate_port) | 217 int alternate_port) |
| 204 : host(host), port(port), alternate_port(alternate_port) {} | 218 : host(host), port(port), alternate_port(alternate_port) {} |
| 205 | 219 |
| 206 URLRequestContextConfig::QuicHint::~QuicHint() {} | 220 URLRequestContextConfig::QuicHint::~QuicHint() {} |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 244 data_reduction_primary_proxy(data_reduction_primary_proxy), | 258 data_reduction_primary_proxy(data_reduction_primary_proxy), |
| 245 data_reduction_fallback_proxy(data_reduction_fallback_proxy), | 259 data_reduction_fallback_proxy(data_reduction_fallback_proxy), |
| 246 data_reduction_secure_proxy_check_url( | 260 data_reduction_secure_proxy_check_url( |
| 247 data_reduction_secure_proxy_check_url), | 261 data_reduction_secure_proxy_check_url), |
| 248 mock_cert_verifier(std::move(mock_cert_verifier)) {} | 262 mock_cert_verifier(std::move(mock_cert_verifier)) {} |
| 249 | 263 |
| 250 URLRequestContextConfig::~URLRequestContextConfig() {} | 264 URLRequestContextConfig::~URLRequestContextConfig() {} |
| 251 | 265 |
| 252 void URLRequestContextConfig::ConfigureURLRequestContextBuilder( | 266 void URLRequestContextConfig::ConfigureURLRequestContextBuilder( |
| 253 net::URLRequestContextBuilder* context_builder, | 267 net::URLRequestContextBuilder* context_builder, |
| 254 net::NetLog* net_log) { | 268 net::NetLog* net_log, |
| 269 const scoped_refptr<base::SequencedTaskRunner>& file_task_runner) { | |
| 255 std::string config_cache; | 270 std::string config_cache; |
| 256 if (http_cache != DISABLED) { | 271 if (http_cache != DISABLED) { |
| 257 net::URLRequestContextBuilder::HttpCacheParams cache_params; | 272 net::URLRequestContextBuilder::HttpCacheParams cache_params; |
| 258 if (http_cache == DISK && !storage_path.empty()) { | 273 if (http_cache == DISK && !storage_path.empty()) { |
| 259 cache_params.type = net::URLRequestContextBuilder::HttpCacheParams::DISK; | 274 cache_params.type = net::URLRequestContextBuilder::HttpCacheParams::DISK; |
| 260 cache_params.path = base::FilePath(storage_path); | 275 cache_params.path = base::FilePath(storage_path); |
| 261 } else { | 276 } else { |
| 262 cache_params.type = | 277 cache_params.type = |
| 263 net::URLRequestContextBuilder::HttpCacheParams::IN_MEMORY; | 278 net::URLRequestContextBuilder::HttpCacheParams::IN_MEMORY; |
| 264 } | 279 } |
| 265 cache_params.max_size = http_cache_max_size; | 280 cache_params.max_size = http_cache_max_size; |
| 266 context_builder->EnableHttpCache(cache_params); | 281 context_builder->EnableHttpCache(cache_params); |
| 267 } else { | 282 } else { |
| 268 context_builder->DisableHttpCache(); | 283 context_builder->DisableHttpCache(); |
| 269 } | 284 } |
| 270 context_builder->set_user_agent(user_agent); | 285 context_builder->set_user_agent(user_agent); |
| 271 context_builder->SetSpdyAndQuicEnabled(enable_spdy, enable_quic); | 286 context_builder->SetSpdyAndQuicEnabled(enable_spdy, enable_quic); |
| 272 context_builder->set_sdch_enabled(enable_sdch); | 287 context_builder->set_sdch_enabled(enable_sdch); |
| 273 if (enable_quic) | 288 if (enable_quic) |
| 274 context_builder->set_quic_user_agent_id(quic_user_agent_id); | 289 context_builder->set_quic_user_agent_id(quic_user_agent_id); |
| 275 | 290 |
| 276 ParseAndSetExperimentalOptions(experimental_options, context_builder, | 291 ParseAndSetExperimentalOptions(experimental_options, context_builder, net_log, |
| 277 net_log); | 292 file_task_runner); |
| 278 | 293 |
| 279 if (mock_cert_verifier) | 294 if (mock_cert_verifier) |
| 280 context_builder->SetCertVerifier(std::move(mock_cert_verifier)); | 295 context_builder->SetCertVerifier(std::move(mock_cert_verifier)); |
| 281 // TODO(mef): Use |config| to set cookies. | 296 // TODO(mef): Use |config| to set cookies. |
| 282 } | 297 } |
| 283 | 298 |
| 284 } // namespace cronet | 299 } // namespace cronet |
| OLD | NEW |