| 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 "base/basictypes.h" | |
| 8 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
| 8 #include "base/logging.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| 11 #include "base/strings/string_piece.h" | 11 #include "base/strings/string_piece.h" |
| 12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "net/cert/cert_verifier.h" | 13 #include "net/cert/cert_verifier.h" |
| 14 #include "net/dns/host_resolver.h" |
| 14 #include "net/quic/quic_protocol.h" | 15 #include "net/quic/quic_protocol.h" |
| 15 #include "net/quic/quic_utils.h" | 16 #include "net/quic/quic_utils.h" |
| 16 #include "net/url_request/url_request_context_builder.h" | 17 #include "net/url_request/url_request_context_builder.h" |
| 17 | 18 |
| 18 namespace cronet { | 19 namespace cronet { |
| 19 | 20 |
| 20 namespace { | 21 namespace { |
| 21 | 22 |
| 22 // TODO(xunjieli): Refactor constants in io_thread.cc. | 23 // TODO(xunjieli): Refactor constants in io_thread.cc. |
| 23 const char kQuicFieldTrialName[] = "QUIC"; | 24 const char kQuicFieldTrialName[] = "QUIC"; |
| 24 const char kQuicConnectionOptions[] = "connection_options"; | 25 const char kQuicConnectionOptions[] = "connection_options"; |
| 25 const char kQuicStoreServerConfigsInProperties[] = | 26 const char kQuicStoreServerConfigsInProperties[] = |
| 26 "store_server_configs_in_properties"; | 27 "store_server_configs_in_properties"; |
| 27 const char kQuicDelayTcpRace[] = "delay_tcp_race"; | 28 const char kQuicDelayTcpRace[] = "delay_tcp_race"; |
| 28 const char kQuicMaxNumberOfLossyConnections[] = | 29 const char kQuicMaxNumberOfLossyConnections[] = |
| 29 "max_number_of_lossy_connections"; | 30 "max_number_of_lossy_connections"; |
| 30 const char kQuicPacketLossThreshold[] = "packet_loss_threshold"; | 31 const char kQuicPacketLossThreshold[] = "packet_loss_threshold"; |
| 31 | 32 |
| 33 // AsyncDNS experiment dictionary name. |
| 34 const char kAsyncDnsFieldTrialName[] = "AsyncDNS"; |
| 35 // Name of boolean to enable AsyncDNS experiment. |
| 36 const char kAsyncDnsEnable[] = "enable"; |
| 37 |
| 32 void ParseAndSetExperimentalOptions( | 38 void ParseAndSetExperimentalOptions( |
| 33 const std::string& experimental_options, | 39 const std::string& experimental_options, |
| 34 net::URLRequestContextBuilder* context_builder) { | 40 net::URLRequestContextBuilder* context_builder, |
| 41 net::NetLog* net_log) { |
| 35 if (experimental_options.empty()) | 42 if (experimental_options.empty()) |
| 36 return; | 43 return; |
| 37 | 44 |
| 38 DVLOG(1) << "Experimental Options:" << experimental_options; | 45 DVLOG(1) << "Experimental Options:" << experimental_options; |
| 39 scoped_ptr<base::Value> options = | 46 scoped_ptr<base::Value> options = |
| 40 base::JSONReader::Read(experimental_options); | 47 base::JSONReader::Read(experimental_options); |
| 41 | 48 |
| 42 if (!options) { | 49 if (!options) { |
| 43 DCHECK(false) << "Parsing experimental options failed: " | 50 DCHECK(false) << "Parsing experimental options failed: " |
| 44 << experimental_options; | 51 << experimental_options; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 quic_max_number_of_lossy_connections); | 89 quic_max_number_of_lossy_connections); |
| 83 } | 90 } |
| 84 | 91 |
| 85 double quic_packet_loss_threshold = 0.0; | 92 double quic_packet_loss_threshold = 0.0; |
| 86 if (quic_args->GetDouble(kQuicPacketLossThreshold, | 93 if (quic_args->GetDouble(kQuicPacketLossThreshold, |
| 87 &quic_packet_loss_threshold)) { | 94 &quic_packet_loss_threshold)) { |
| 88 context_builder->set_quic_packet_loss_threshold( | 95 context_builder->set_quic_packet_loss_threshold( |
| 89 quic_packet_loss_threshold); | 96 quic_packet_loss_threshold); |
| 90 } | 97 } |
| 91 } | 98 } |
| 99 |
| 100 const base::DictionaryValue* async_dns_args = nullptr; |
| 101 if (dict->GetDictionary(kAsyncDnsFieldTrialName, &async_dns_args)) { |
| 102 bool async_dns_enable = false; |
| 103 if (async_dns_args->GetBoolean(kAsyncDnsEnable, &async_dns_enable) && |
| 104 async_dns_enable) { |
| 105 if (net_log == nullptr) { |
| 106 DCHECK(false) << "AsyncDNS experiment requires NetLog."; |
| 107 } else { |
| 108 scoped_ptr<net::HostResolver> host_resolver( |
| 109 net::HostResolver::CreateDefaultResolver(net_log)); |
| 110 host_resolver->SetDnsClientEnabled(true); |
| 111 context_builder->set_host_resolver(std::move(host_resolver)); |
| 112 } |
| 113 } |
| 114 } |
| 92 } | 115 } |
| 93 | 116 |
| 94 } // namespace | 117 } // namespace |
| 95 | 118 |
| 96 URLRequestContextConfig::QuicHint::QuicHint(const std::string& host, | 119 URLRequestContextConfig::QuicHint::QuicHint(const std::string& host, |
| 97 int port, | 120 int port, |
| 98 int alternate_port) | 121 int alternate_port) |
| 99 : host(host), port(port), alternate_port(alternate_port) {} | 122 : host(host), port(port), alternate_port(alternate_port) {} |
| 100 | 123 |
| 101 URLRequestContextConfig::QuicHint::~QuicHint() {} | 124 URLRequestContextConfig::QuicHint::~QuicHint() {} |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 data_reduction_proxy_key(data_reduction_proxy_key), | 159 data_reduction_proxy_key(data_reduction_proxy_key), |
| 137 data_reduction_primary_proxy(data_reduction_primary_proxy), | 160 data_reduction_primary_proxy(data_reduction_primary_proxy), |
| 138 data_reduction_fallback_proxy(data_reduction_fallback_proxy), | 161 data_reduction_fallback_proxy(data_reduction_fallback_proxy), |
| 139 data_reduction_secure_proxy_check_url( | 162 data_reduction_secure_proxy_check_url( |
| 140 data_reduction_secure_proxy_check_url), | 163 data_reduction_secure_proxy_check_url), |
| 141 mock_cert_verifier(std::move(mock_cert_verifier)) {} | 164 mock_cert_verifier(std::move(mock_cert_verifier)) {} |
| 142 | 165 |
| 143 URLRequestContextConfig::~URLRequestContextConfig() {} | 166 URLRequestContextConfig::~URLRequestContextConfig() {} |
| 144 | 167 |
| 145 void URLRequestContextConfig::ConfigureURLRequestContextBuilder( | 168 void URLRequestContextConfig::ConfigureURLRequestContextBuilder( |
| 146 net::URLRequestContextBuilder* context_builder) { | 169 net::URLRequestContextBuilder* context_builder, |
| 170 net::NetLog* net_log) { |
| 147 std::string config_cache; | 171 std::string config_cache; |
| 148 if (http_cache != DISABLED) { | 172 if (http_cache != DISABLED) { |
| 149 net::URLRequestContextBuilder::HttpCacheParams cache_params; | 173 net::URLRequestContextBuilder::HttpCacheParams cache_params; |
| 150 if (http_cache == DISK && !storage_path.empty()) { | 174 if (http_cache == DISK && !storage_path.empty()) { |
| 151 cache_params.type = net::URLRequestContextBuilder::HttpCacheParams::DISK; | 175 cache_params.type = net::URLRequestContextBuilder::HttpCacheParams::DISK; |
| 152 cache_params.path = base::FilePath(storage_path); | 176 cache_params.path = base::FilePath(storage_path); |
| 153 } else { | 177 } else { |
| 154 cache_params.type = | 178 cache_params.type = |
| 155 net::URLRequestContextBuilder::HttpCacheParams::IN_MEMORY; | 179 net::URLRequestContextBuilder::HttpCacheParams::IN_MEMORY; |
| 156 } | 180 } |
| 157 cache_params.max_size = http_cache_max_size; | 181 cache_params.max_size = http_cache_max_size; |
| 158 context_builder->EnableHttpCache(cache_params); | 182 context_builder->EnableHttpCache(cache_params); |
| 159 } else { | 183 } else { |
| 160 context_builder->DisableHttpCache(); | 184 context_builder->DisableHttpCache(); |
| 161 } | 185 } |
| 162 context_builder->set_user_agent(user_agent); | 186 context_builder->set_user_agent(user_agent); |
| 163 context_builder->SetSpdyAndQuicEnabled(enable_spdy, enable_quic); | 187 context_builder->SetSpdyAndQuicEnabled(enable_spdy, enable_quic); |
| 164 context_builder->set_sdch_enabled(enable_sdch); | 188 context_builder->set_sdch_enabled(enable_sdch); |
| 165 | 189 |
| 166 ParseAndSetExperimentalOptions(experimental_options, context_builder); | 190 ParseAndSetExperimentalOptions(experimental_options, context_builder, |
| 191 net_log); |
| 167 | 192 |
| 168 if (mock_cert_verifier) | 193 if (mock_cert_verifier) |
| 169 context_builder->SetCertVerifier(mock_cert_verifier.Pass()); | 194 context_builder->SetCertVerifier(mock_cert_verifier.Pass()); |
| 170 // TODO(mef): Use |config| to set cookies. | 195 // TODO(mef): Use |config| to set cookies. |
| 171 } | 196 } |
| 172 | 197 |
| 173 } // namespace cronet | 198 } // namespace cronet |
| OLD | NEW |