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 "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.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/quic/quic_protocol.h" | 14 #include "net/quic/quic_protocol.h" |
| 15 #include "net/quic/quic_utils.h" | 15 #include "net/quic/quic_utils.h" |
| 16 #include "net/url_request/url_request_context_builder.h" | 16 #include "net/url_request/url_request_context_builder.h" |
| 17 | 17 |
| 18 namespace cronet { | 18 namespace cronet { |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 // TODO(xunjieli): Refactor constants in io_thread.cc. | |
| 23 const char kQuicFieldTrialName[] = "QUIC"; | |
| 24 const char kQuicConnectionOptions[] = "connection_options"; | |
| 25 | |
| 22 // Using a reference to scoped_ptr is unavoidable because of the semantics of | 26 // Using a reference to scoped_ptr is unavoidable because of the semantics of |
| 23 // RegisterCustomField. | 27 // RegisterCustomField. |
| 24 // TODO(xunjieli): Remove this once crbug.com/544976 is fixed. | 28 // TODO(xunjieli): Remove this once crbug.com/544976 is fixed. |
| 25 bool GetMockCertVerifierFromString( | 29 bool GetMockCertVerifierFromString( |
| 26 const base::StringPiece& mock_cert_verifier_string, | 30 const base::StringPiece& mock_cert_verifier_string, |
| 27 scoped_ptr<net::CertVerifier>* result) { | 31 scoped_ptr<net::CertVerifier>* result) { |
| 28 int64 val; | 32 int64 val; |
| 29 bool success = base::StringToInt64(mock_cert_verifier_string, &val); | 33 bool success = base::StringToInt64(mock_cert_verifier_string, &val); |
| 30 *result = make_scoped_ptr(reinterpret_cast<net::CertVerifier*>(val)); | 34 *result = make_scoped_ptr(reinterpret_cast<net::CertVerifier*>(val)); |
| 31 return success; | 35 return success; |
| 32 } | 36 } |
| 33 | 37 |
| 38 void ParseAndSetExperimentalOptions( | |
| 39 const std::string& experimental_options, | |
| 40 net::URLRequestContextBuilder* context_builder) { | |
| 41 if (experimental_options.empty()) | |
| 42 return; | |
| 43 | |
| 44 scoped_ptr<base::Value> options = | |
| 45 base::JSONReader::Read(experimental_options); | |
| 46 | |
| 47 if (!options) { | |
| 48 DCHECK(false) << "Parsing experimental options failed: " | |
| 49 << experimental_options; | |
| 50 return; | |
| 51 } | |
| 52 scoped_ptr<base::DictionaryValue> dict = | |
| 53 base::DictionaryValue::From(options.Pass()); | |
| 54 | |
| 55 DCHECK(dict); | |
|
mef
2015/11/16 18:19:22
The dict will be null if experimental_options is v
xunjieli
2015/11/16 18:47:25
Done.
| |
| 56 | |
| 57 const base::DictionaryValue* quic_args = nullptr; | |
| 58 if (dict->GetDictionary(kQuicFieldTrialName, &quic_args)) { | |
| 59 std::string quic_connection_options; | |
| 60 if (quic_args->GetString(kQuicConnectionOptions, | |
| 61 &quic_connection_options)) { | |
| 62 context_builder->set_quic_connection_options( | |
| 63 net::QuicUtils::ParseQuicConnectionOptions(quic_connection_options)); | |
| 64 } | |
| 65 } | |
| 66 } | |
| 67 | |
| 34 } // namespace | 68 } // namespace |
| 35 | 69 |
| 36 #define DEFINE_CONTEXT_CONFIG(x) const char REQUEST_CONTEXT_CONFIG_##x[] = #x; | 70 #define DEFINE_CONTEXT_CONFIG(x) const char REQUEST_CONTEXT_CONFIG_##x[] = #x; |
| 37 #include "components/cronet/url_request_context_config_list.h" | 71 #include "components/cronet/url_request_context_config_list.h" |
| 38 #undef DEFINE_CONTEXT_CONFIG | 72 #undef DEFINE_CONTEXT_CONFIG |
| 39 | 73 |
| 40 URLRequestContextConfig::QuicHint::QuicHint() { | 74 URLRequestContextConfig::QuicHint::QuicHint() { |
| 41 } | 75 } |
| 42 | 76 |
| 43 URLRequestContextConfig::QuicHint::~QuicHint() { | 77 URLRequestContextConfig::QuicHint::~QuicHint() { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 88 cache_params.type = | 122 cache_params.type = |
| 89 net::URLRequestContextBuilder::HttpCacheParams::IN_MEMORY; | 123 net::URLRequestContextBuilder::HttpCacheParams::IN_MEMORY; |
| 90 } | 124 } |
| 91 cache_params.max_size = http_cache_max_size; | 125 cache_params.max_size = http_cache_max_size; |
| 92 context_builder->EnableHttpCache(cache_params); | 126 context_builder->EnableHttpCache(cache_params); |
| 93 } else { | 127 } else { |
| 94 context_builder->DisableHttpCache(); | 128 context_builder->DisableHttpCache(); |
| 95 } | 129 } |
| 96 context_builder->set_user_agent(user_agent); | 130 context_builder->set_user_agent(user_agent); |
| 97 context_builder->SetSpdyAndQuicEnabled(enable_spdy, enable_quic); | 131 context_builder->SetSpdyAndQuicEnabled(enable_spdy, enable_quic); |
| 98 context_builder->set_quic_connection_options( | |
| 99 net::QuicUtils::ParseQuicConnectionOptions(quic_connection_options)); | |
| 100 context_builder->set_sdch_enabled(enable_sdch); | 132 context_builder->set_sdch_enabled(enable_sdch); |
| 133 | |
| 134 ParseAndSetExperimentalOptions(experimental_options, context_builder); | |
| 135 | |
| 101 if (mock_cert_verifier) | 136 if (mock_cert_verifier) |
| 102 context_builder->SetCertVerifier(mock_cert_verifier.Pass()); | 137 context_builder->SetCertVerifier(mock_cert_verifier.Pass()); |
| 103 // TODO(mef): Use |config| to set cookies. | 138 // TODO(mef): Use |config| to set cookies. |
| 104 } | 139 } |
| 105 | 140 |
| 106 // static | 141 // static |
| 107 void URLRequestContextConfig::RegisterJSONConverter( | 142 void URLRequestContextConfig::RegisterJSONConverter( |
| 108 base::JSONValueConverter<URLRequestContextConfig>* converter) { | 143 base::JSONValueConverter<URLRequestContextConfig>* converter) { |
| 109 converter->RegisterStringField(REQUEST_CONTEXT_CONFIG_USER_AGENT, | 144 converter->RegisterStringField(REQUEST_CONTEXT_CONFIG_USER_AGENT, |
| 110 &URLRequestContextConfig::user_agent); | 145 &URLRequestContextConfig::user_agent); |
| 111 converter->RegisterStringField(REQUEST_CONTEXT_CONFIG_STORAGE_PATH, | 146 converter->RegisterStringField(REQUEST_CONTEXT_CONFIG_STORAGE_PATH, |
| 112 &URLRequestContextConfig::storage_path); | 147 &URLRequestContextConfig::storage_path); |
| 113 converter->RegisterBoolField(REQUEST_CONTEXT_CONFIG_ENABLE_QUIC, | 148 converter->RegisterBoolField(REQUEST_CONTEXT_CONFIG_ENABLE_QUIC, |
| 114 &URLRequestContextConfig::enable_quic); | 149 &URLRequestContextConfig::enable_quic); |
| 115 converter->RegisterBoolField(REQUEST_CONTEXT_CONFIG_ENABLE_SPDY, | 150 converter->RegisterBoolField(REQUEST_CONTEXT_CONFIG_ENABLE_SPDY, |
| 116 &URLRequestContextConfig::enable_spdy); | 151 &URLRequestContextConfig::enable_spdy); |
| 117 converter->RegisterBoolField(REQUEST_CONTEXT_CONFIG_ENABLE_SDCH, | 152 converter->RegisterBoolField(REQUEST_CONTEXT_CONFIG_ENABLE_SDCH, |
| 118 &URLRequestContextConfig::enable_sdch); | 153 &URLRequestContextConfig::enable_sdch); |
| 119 converter->RegisterStringField(REQUEST_CONTEXT_CONFIG_HTTP_CACHE, | 154 converter->RegisterStringField(REQUEST_CONTEXT_CONFIG_HTTP_CACHE, |
| 120 &URLRequestContextConfig::http_cache); | 155 &URLRequestContextConfig::http_cache); |
| 121 converter->RegisterBoolField(REQUEST_CONTEXT_CONFIG_LOAD_DISABLE_CACHE, | 156 converter->RegisterBoolField(REQUEST_CONTEXT_CONFIG_LOAD_DISABLE_CACHE, |
| 122 &URLRequestContextConfig::load_disable_cache); | 157 &URLRequestContextConfig::load_disable_cache); |
| 123 converter->RegisterIntField(REQUEST_CONTEXT_CONFIG_HTTP_CACHE_MAX_SIZE, | 158 converter->RegisterIntField(REQUEST_CONTEXT_CONFIG_HTTP_CACHE_MAX_SIZE, |
| 124 &URLRequestContextConfig::http_cache_max_size); | 159 &URLRequestContextConfig::http_cache_max_size); |
| 125 converter->RegisterRepeatedMessage(REQUEST_CONTEXT_CONFIG_QUIC_HINTS, | 160 converter->RegisterRepeatedMessage(REQUEST_CONTEXT_CONFIG_QUIC_HINTS, |
| 126 &URLRequestContextConfig::quic_hints); | 161 &URLRequestContextConfig::quic_hints); |
| 127 converter->RegisterStringField( | 162 converter->RegisterStringField( |
| 128 REQUEST_CONTEXT_CONFIG_QUIC_OPTIONS, | 163 REQUEST_CONTEXT_CONFIG_EXPERIMENTAL_OPTIONS, |
| 129 &URLRequestContextConfig::quic_connection_options); | 164 &URLRequestContextConfig::experimental_options); |
| 130 converter->RegisterStringField( | 165 converter->RegisterStringField( |
| 131 REQUEST_CONTEXT_CONFIG_DATA_REDUCTION_PRIMARY_PROXY, | 166 REQUEST_CONTEXT_CONFIG_DATA_REDUCTION_PRIMARY_PROXY, |
| 132 &URLRequestContextConfig::data_reduction_primary_proxy); | 167 &URLRequestContextConfig::data_reduction_primary_proxy); |
| 133 converter->RegisterStringField( | 168 converter->RegisterStringField( |
| 134 REQUEST_CONTEXT_CONFIG_DATA_REDUCTION_FALLBACK_PROXY, | 169 REQUEST_CONTEXT_CONFIG_DATA_REDUCTION_FALLBACK_PROXY, |
| 135 &URLRequestContextConfig::data_reduction_fallback_proxy); | 170 &URLRequestContextConfig::data_reduction_fallback_proxy); |
| 136 converter->RegisterStringField( | 171 converter->RegisterStringField( |
| 137 REQUEST_CONTEXT_CONFIG_DATA_REDUCTION_SECURE_PROXY_CHECK_URL, | 172 REQUEST_CONTEXT_CONFIG_DATA_REDUCTION_SECURE_PROXY_CHECK_URL, |
| 138 &URLRequestContextConfig::data_reduction_secure_proxy_check_url); | 173 &URLRequestContextConfig::data_reduction_secure_proxy_check_url); |
| 139 converter->RegisterStringField( | 174 converter->RegisterStringField( |
| 140 REQUEST_CONTEXT_CONFIG_DATA_REDUCTION_PROXY_KEY, | 175 REQUEST_CONTEXT_CONFIG_DATA_REDUCTION_PROXY_KEY, |
| 141 &URLRequestContextConfig::data_reduction_proxy_key); | 176 &URLRequestContextConfig::data_reduction_proxy_key); |
| 142 | 177 |
| 143 // For Testing. | 178 // For Testing. |
| 144 converter->RegisterCustomField<scoped_ptr<net::CertVerifier>>( | 179 converter->RegisterCustomField<scoped_ptr<net::CertVerifier>>( |
| 145 REQUEST_CONTEXT_CONFIG_MOCK_CERT_VERIFIER, | 180 REQUEST_CONTEXT_CONFIG_MOCK_CERT_VERIFIER, |
| 146 &URLRequestContextConfig::mock_cert_verifier, | 181 &URLRequestContextConfig::mock_cert_verifier, |
| 147 &GetMockCertVerifierFromString); | 182 &GetMockCertVerifierFromString); |
| 148 } | 183 } |
| 149 | 184 |
| 150 } // namespace cronet | 185 } // namespace cronet |
| OLD | NEW |