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"; | |
|
mef
2015/11/06 18:52:39
I don't have strong opinion, but constants in io_t
xunjieli
2015/11/13 22:13:06
"connection_options" is the string hardcoded in ht
| |
| 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::DictionaryValue> dict = | |
| 45 base::DictionaryValue::From(base::JSONReader::Read(experimental_options)); | |
| 46 if (!dict) { | |
| 47 DCHECK(false) << "Parsing experimental options failed: " | |
| 48 << experimental_options; | |
| 49 return; | |
| 50 } | |
| 51 | |
| 52 const base::DictionaryValue* quic_args = nullptr; | |
| 53 if (dict->GetDictionary(kQuicFieldTrialName, &quic_args)) { | |
| 54 std::string quic_connection_options; | |
| 55 if (quic_args->GetString(kQuicConnectionOptions, | |
| 56 &quic_connection_options)) { | |
| 57 context_builder->set_quic_connection_options( | |
| 58 net::QuicUtils::ParseQuicConnectionOptions(quic_connection_options)); | |
| 59 } | |
| 60 } | |
| 61 } | |
| 62 | |
| 34 } // namespace | 63 } // namespace |
| 35 | 64 |
| 36 #define DEFINE_CONTEXT_CONFIG(x) const char REQUEST_CONTEXT_CONFIG_##x[] = #x; | 65 #define DEFINE_CONTEXT_CONFIG(x) const char REQUEST_CONTEXT_CONFIG_##x[] = #x; |
| 37 #include "components/cronet/url_request_context_config_list.h" | 66 #include "components/cronet/url_request_context_config_list.h" |
| 38 #undef DEFINE_CONTEXT_CONFIG | 67 #undef DEFINE_CONTEXT_CONFIG |
| 39 | 68 |
| 40 URLRequestContextConfig::QuicHint::QuicHint() { | 69 URLRequestContextConfig::QuicHint::QuicHint() { |
| 41 } | 70 } |
| 42 | 71 |
| 43 URLRequestContextConfig::QuicHint::~QuicHint() { | 72 URLRequestContextConfig::QuicHint::~QuicHint() { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 88 cache_params.type = | 117 cache_params.type = |
| 89 net::URLRequestContextBuilder::HttpCacheParams::IN_MEMORY; | 118 net::URLRequestContextBuilder::HttpCacheParams::IN_MEMORY; |
| 90 } | 119 } |
| 91 cache_params.max_size = http_cache_max_size; | 120 cache_params.max_size = http_cache_max_size; |
| 92 context_builder->EnableHttpCache(cache_params); | 121 context_builder->EnableHttpCache(cache_params); |
| 93 } else { | 122 } else { |
| 94 context_builder->DisableHttpCache(); | 123 context_builder->DisableHttpCache(); |
| 95 } | 124 } |
| 96 context_builder->set_user_agent(user_agent); | 125 context_builder->set_user_agent(user_agent); |
| 97 context_builder->SetSpdyAndQuicEnabled(enable_spdy, enable_quic); | 126 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); | 127 context_builder->set_sdch_enabled(enable_sdch); |
| 128 | |
| 129 ParseAndSetExperimentalOptions(experimental_options, context_builder); | |
| 130 | |
| 101 if (mock_cert_verifier) | 131 if (mock_cert_verifier) |
| 102 context_builder->SetCertVerifier(mock_cert_verifier.Pass()); | 132 context_builder->SetCertVerifier(mock_cert_verifier.Pass()); |
| 103 // TODO(mef): Use |config| to set cookies. | 133 // TODO(mef): Use |config| to set cookies. |
| 104 } | 134 } |
| 105 | 135 |
| 106 // static | 136 // static |
| 107 void URLRequestContextConfig::RegisterJSONConverter( | 137 void URLRequestContextConfig::RegisterJSONConverter( |
| 108 base::JSONValueConverter<URLRequestContextConfig>* converter) { | 138 base::JSONValueConverter<URLRequestContextConfig>* converter) { |
| 109 converter->RegisterStringField(REQUEST_CONTEXT_CONFIG_USER_AGENT, | 139 converter->RegisterStringField(REQUEST_CONTEXT_CONFIG_USER_AGENT, |
| 110 &URLRequestContextConfig::user_agent); | 140 &URLRequestContextConfig::user_agent); |
| 111 converter->RegisterStringField(REQUEST_CONTEXT_CONFIG_STORAGE_PATH, | 141 converter->RegisterStringField(REQUEST_CONTEXT_CONFIG_STORAGE_PATH, |
| 112 &URLRequestContextConfig::storage_path); | 142 &URLRequestContextConfig::storage_path); |
| 113 converter->RegisterBoolField(REQUEST_CONTEXT_CONFIG_ENABLE_QUIC, | 143 converter->RegisterBoolField(REQUEST_CONTEXT_CONFIG_ENABLE_QUIC, |
| 114 &URLRequestContextConfig::enable_quic); | 144 &URLRequestContextConfig::enable_quic); |
| 115 converter->RegisterBoolField(REQUEST_CONTEXT_CONFIG_ENABLE_SPDY, | 145 converter->RegisterBoolField(REQUEST_CONTEXT_CONFIG_ENABLE_SPDY, |
| 116 &URLRequestContextConfig::enable_spdy); | 146 &URLRequestContextConfig::enable_spdy); |
| 117 converter->RegisterBoolField(REQUEST_CONTEXT_CONFIG_ENABLE_SDCH, | 147 converter->RegisterBoolField(REQUEST_CONTEXT_CONFIG_ENABLE_SDCH, |
| 118 &URLRequestContextConfig::enable_sdch); | 148 &URLRequestContextConfig::enable_sdch); |
| 119 converter->RegisterStringField(REQUEST_CONTEXT_CONFIG_HTTP_CACHE, | 149 converter->RegisterStringField(REQUEST_CONTEXT_CONFIG_HTTP_CACHE, |
| 120 &URLRequestContextConfig::http_cache); | 150 &URLRequestContextConfig::http_cache); |
| 121 converter->RegisterBoolField(REQUEST_CONTEXT_CONFIG_LOAD_DISABLE_CACHE, | 151 converter->RegisterBoolField(REQUEST_CONTEXT_CONFIG_LOAD_DISABLE_CACHE, |
| 122 &URLRequestContextConfig::load_disable_cache); | 152 &URLRequestContextConfig::load_disable_cache); |
| 123 converter->RegisterIntField(REQUEST_CONTEXT_CONFIG_HTTP_CACHE_MAX_SIZE, | 153 converter->RegisterIntField(REQUEST_CONTEXT_CONFIG_HTTP_CACHE_MAX_SIZE, |
| 124 &URLRequestContextConfig::http_cache_max_size); | 154 &URLRequestContextConfig::http_cache_max_size); |
| 125 converter->RegisterRepeatedMessage(REQUEST_CONTEXT_CONFIG_QUIC_HINTS, | 155 converter->RegisterRepeatedMessage(REQUEST_CONTEXT_CONFIG_QUIC_HINTS, |
| 126 &URLRequestContextConfig::quic_hints); | 156 &URLRequestContextConfig::quic_hints); |
| 127 converter->RegisterStringField( | 157 converter->RegisterStringField( |
| 128 REQUEST_CONTEXT_CONFIG_QUIC_OPTIONS, | 158 REQUEST_CONTEXT_CONFIG_EXPERIMENTAL_OPTIONS, |
| 129 &URLRequestContextConfig::quic_connection_options); | 159 &URLRequestContextConfig::experimental_options); |
| 130 converter->RegisterStringField( | 160 converter->RegisterStringField( |
| 131 REQUEST_CONTEXT_CONFIG_DATA_REDUCTION_PRIMARY_PROXY, | 161 REQUEST_CONTEXT_CONFIG_DATA_REDUCTION_PRIMARY_PROXY, |
| 132 &URLRequestContextConfig::data_reduction_primary_proxy); | 162 &URLRequestContextConfig::data_reduction_primary_proxy); |
| 133 converter->RegisterStringField( | 163 converter->RegisterStringField( |
| 134 REQUEST_CONTEXT_CONFIG_DATA_REDUCTION_FALLBACK_PROXY, | 164 REQUEST_CONTEXT_CONFIG_DATA_REDUCTION_FALLBACK_PROXY, |
| 135 &URLRequestContextConfig::data_reduction_fallback_proxy); | 165 &URLRequestContextConfig::data_reduction_fallback_proxy); |
| 136 converter->RegisterStringField( | 166 converter->RegisterStringField( |
| 137 REQUEST_CONTEXT_CONFIG_DATA_REDUCTION_SECURE_PROXY_CHECK_URL, | 167 REQUEST_CONTEXT_CONFIG_DATA_REDUCTION_SECURE_PROXY_CHECK_URL, |
| 138 &URLRequestContextConfig::data_reduction_secure_proxy_check_url); | 168 &URLRequestContextConfig::data_reduction_secure_proxy_check_url); |
| 139 converter->RegisterStringField( | 169 converter->RegisterStringField( |
| 140 REQUEST_CONTEXT_CONFIG_DATA_REDUCTION_PROXY_KEY, | 170 REQUEST_CONTEXT_CONFIG_DATA_REDUCTION_PROXY_KEY, |
| 141 &URLRequestContextConfig::data_reduction_proxy_key); | 171 &URLRequestContextConfig::data_reduction_proxy_key); |
| 142 | 172 |
| 143 // For Testing. | 173 // For Testing. |
| 144 converter->RegisterCustomField<scoped_ptr<net::CertVerifier>>( | 174 converter->RegisterCustomField<scoped_ptr<net::CertVerifier>>( |
| 145 REQUEST_CONTEXT_CONFIG_MOCK_CERT_VERIFIER, | 175 REQUEST_CONTEXT_CONFIG_MOCK_CERT_VERIFIER, |
| 146 &URLRequestContextConfig::mock_cert_verifier, | 176 &URLRequestContextConfig::mock_cert_verifier, |
| 147 &GetMockCertVerifierFromString); | 177 &GetMockCertVerifierFromString); |
| 148 } | 178 } |
| 149 | 179 |
| 150 } // namespace cronet | 180 } // namespace cronet |
| OLD | NEW |