| 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" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 // TODO(xunjieli): Remove this once crbug.com/544976 is fixed. | 24 // TODO(xunjieli): Remove this once crbug.com/544976 is fixed. |
| 25 bool GetMockCertVerifierFromString( | 25 bool GetMockCertVerifierFromString( |
| 26 const base::StringPiece& mock_cert_verifier_string, | 26 const base::StringPiece& mock_cert_verifier_string, |
| 27 scoped_ptr<net::CertVerifier>* result) { | 27 scoped_ptr<net::CertVerifier>* result) { |
| 28 int64 val; | 28 int64 val; |
| 29 bool success = base::StringToInt64(mock_cert_verifier_string, &val); | 29 bool success = base::StringToInt64(mock_cert_verifier_string, &val); |
| 30 *result = make_scoped_ptr(reinterpret_cast<net::CertVerifier*>(val)); | 30 *result = make_scoped_ptr(reinterpret_cast<net::CertVerifier*>(val)); |
| 31 return success; | 31 return success; |
| 32 } | 32 } |
| 33 | 33 |
| 34 bool GetDateFromDouble(const base::Value* json_value, base::Time* time) { |
| 35 double time_double; |
| 36 bool success = json_value->GetAsDouble(&time_double); |
| 37 if (success) { |
| 38 *time = base::Time::FromDoubleT(time_double); |
| 39 } |
| 40 return success; |
| 41 } |
| 42 |
| 34 } // namespace | 43 } // namespace |
| 35 | 44 |
| 36 #define DEFINE_CONTEXT_CONFIG(x) const char REQUEST_CONTEXT_CONFIG_##x[] = #x; | 45 #define DEFINE_CONTEXT_CONFIG(x) const char REQUEST_CONTEXT_CONFIG_##x[] = #x; |
| 37 #include "components/cronet/url_request_context_config_list.h" | 46 #include "components/cronet/url_request_context_config_list.h" |
| 38 #undef DEFINE_CONTEXT_CONFIG | 47 #undef DEFINE_CONTEXT_CONFIG |
| 39 | 48 |
| 40 URLRequestContextConfig::QuicHint::QuicHint() { | 49 URLRequestContextConfig::QuicHint::QuicHint() { |
| 41 } | 50 } |
| 42 | 51 |
| 43 URLRequestContextConfig::QuicHint::~QuicHint() { | 52 URLRequestContextConfig::QuicHint::~QuicHint() { |
| 44 } | 53 } |
| 45 | 54 |
| 46 // static | 55 // static |
| 47 void URLRequestContextConfig::QuicHint::RegisterJSONConverter( | 56 void URLRequestContextConfig::QuicHint::RegisterJSONConverter( |
| 48 base::JSONValueConverter<URLRequestContextConfig::QuicHint>* converter) { | 57 base::JSONValueConverter<URLRequestContextConfig::QuicHint>* converter) { |
| 49 converter->RegisterStringField(REQUEST_CONTEXT_CONFIG_QUIC_HINT_HOST, | 58 converter->RegisterStringField(REQUEST_CONTEXT_CONFIG_QUIC_HINT_HOST, |
| 50 &URLRequestContextConfig::QuicHint::host); | 59 &URLRequestContextConfig::QuicHint::host); |
| 51 converter->RegisterIntField( | 60 converter->RegisterIntField( |
| 52 REQUEST_CONTEXT_CONFIG_QUIC_HINT_PORT, | 61 REQUEST_CONTEXT_CONFIG_QUIC_HINT_PORT, |
| 53 &URLRequestContextConfig::QuicHint::port); | 62 &URLRequestContextConfig::QuicHint::port); |
| 54 converter->RegisterIntField( | 63 converter->RegisterIntField( |
| 55 REQUEST_CONTEXT_CONFIG_QUIC_HINT_ALT_PORT, | 64 REQUEST_CONTEXT_CONFIG_QUIC_HINT_ALT_PORT, |
| 56 &URLRequestContextConfig::QuicHint::alternate_port); | 65 &URLRequestContextConfig::QuicHint::alternate_port); |
| 57 } | 66 } |
| 58 | 67 |
| 68 // static |
| 69 void URLRequestContextConfig::Hpkp::RegisterJSONConverter( |
| 70 base::JSONValueConverter<URLRequestContextConfig::Hpkp>* converter) { |
| 71 converter->RegisterStringField(REQUEST_CONTEXT_CONFIG_HPKP_HOST, |
| 72 &URLRequestContextConfig::Hpkp::host); |
| 73 converter->RegisterRepeatedString(REQUEST_CONTEXT_CONFIG_HPKP_PIN_HASHES, |
| 74 &URLRequestContextConfig::Hpkp::pin_hashes); |
| 75 converter->RegisterBoolField( |
| 76 REQUEST_CONTEXT_CONFIG_HPKP_INCLUDE_SUBDOMAINS, |
| 77 &URLRequestContextConfig::Hpkp::include_subdomains); |
| 78 converter->RegisterCustomValueField<base::Time>( |
| 79 REQUEST_CONTEXT_CONFIG_HPKP_EXPIRATION_DATE, |
| 80 &URLRequestContextConfig::Hpkp::expiration_date, &GetDateFromDouble); |
| 81 } |
| 82 |
| 59 URLRequestContextConfig::URLRequestContextConfig() {} | 83 URLRequestContextConfig::URLRequestContextConfig() {} |
| 60 | 84 |
| 61 URLRequestContextConfig::~URLRequestContextConfig() {} | 85 URLRequestContextConfig::~URLRequestContextConfig() {} |
| 62 | 86 |
| 63 bool URLRequestContextConfig::LoadFromJSON(const std::string& config_string) { | 87 bool URLRequestContextConfig::LoadFromJSON(const std::string& config_string) { |
| 64 scoped_ptr<base::Value> config_value = base::JSONReader::Read(config_string); | 88 scoped_ptr<base::Value> config_value = base::JSONReader::Read(config_string); |
| 65 if (!config_value || !config_value->IsType(base::Value::TYPE_DICTIONARY)) { | 89 if (!config_value || !config_value->IsType(base::Value::TYPE_DICTIONARY)) { |
| 66 DLOG(ERROR) << "Bad JSON: " << config_string; | 90 DLOG(ERROR) << "Bad JSON: " << config_string; |
| 67 return false; | 91 return false; |
| 68 } | 92 } |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 &URLRequestContextConfig::data_reduction_primary_proxy); | 156 &URLRequestContextConfig::data_reduction_primary_proxy); |
| 133 converter->RegisterStringField( | 157 converter->RegisterStringField( |
| 134 REQUEST_CONTEXT_CONFIG_DATA_REDUCTION_FALLBACK_PROXY, | 158 REQUEST_CONTEXT_CONFIG_DATA_REDUCTION_FALLBACK_PROXY, |
| 135 &URLRequestContextConfig::data_reduction_fallback_proxy); | 159 &URLRequestContextConfig::data_reduction_fallback_proxy); |
| 136 converter->RegisterStringField( | 160 converter->RegisterStringField( |
| 137 REQUEST_CONTEXT_CONFIG_DATA_REDUCTION_SECURE_PROXY_CHECK_URL, | 161 REQUEST_CONTEXT_CONFIG_DATA_REDUCTION_SECURE_PROXY_CHECK_URL, |
| 138 &URLRequestContextConfig::data_reduction_secure_proxy_check_url); | 162 &URLRequestContextConfig::data_reduction_secure_proxy_check_url); |
| 139 converter->RegisterStringField( | 163 converter->RegisterStringField( |
| 140 REQUEST_CONTEXT_CONFIG_DATA_REDUCTION_PROXY_KEY, | 164 REQUEST_CONTEXT_CONFIG_DATA_REDUCTION_PROXY_KEY, |
| 141 &URLRequestContextConfig::data_reduction_proxy_key); | 165 &URLRequestContextConfig::data_reduction_proxy_key); |
| 166 converter->RegisterRepeatedMessage(REQUEST_CONTEXT_CONFIG_HPKP_LIST, |
| 167 &URLRequestContextConfig::hpkp_list); |
| 142 | 168 |
| 143 // For Testing. | 169 // For Testing. |
| 144 converter->RegisterCustomField<scoped_ptr<net::CertVerifier>>( | 170 converter->RegisterCustomField<scoped_ptr<net::CertVerifier>>( |
| 145 REQUEST_CONTEXT_CONFIG_MOCK_CERT_VERIFIER, | 171 REQUEST_CONTEXT_CONFIG_MOCK_CERT_VERIFIER, |
| 146 &URLRequestContextConfig::mock_cert_verifier, | 172 &URLRequestContextConfig::mock_cert_verifier, |
| 147 &GetMockCertVerifierFromString); | 173 &GetMockCertVerifierFromString); |
| 148 } | 174 } |
| 149 | 175 |
| 150 } // namespace cronet | 176 } // namespace cronet |
| OLD | NEW |