| 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 if (dict->GetDictionary(kQuicFieldTrialName, &quic_args)) { | 63 if (dict->GetDictionary(kQuicFieldTrialName, &quic_args)) { |
| 64 std::string quic_connection_options; | 64 std::string quic_connection_options; |
| 65 if (quic_args->GetString(kQuicConnectionOptions, | 65 if (quic_args->GetString(kQuicConnectionOptions, |
| 66 &quic_connection_options)) { | 66 &quic_connection_options)) { |
| 67 context_builder->set_quic_connection_options( | 67 context_builder->set_quic_connection_options( |
| 68 net::QuicUtils::ParseQuicConnectionOptions(quic_connection_options)); | 68 net::QuicUtils::ParseQuicConnectionOptions(quic_connection_options)); |
| 69 } | 69 } |
| 70 } | 70 } |
| 71 } | 71 } |
| 72 | 72 |
| 73 bool GetTimeFromDouble(const base::Value* json_value, base::Time* time) { |
| 74 double time_double; |
| 75 bool success = json_value->GetAsDouble(&time_double); |
| 76 if (success) { |
| 77 *time = base::Time::FromDoubleT(time_double); |
| 78 } |
| 79 return success; |
| 80 } |
| 81 |
| 73 } // namespace | 82 } // namespace |
| 74 | 83 |
| 75 #define DEFINE_CONTEXT_CONFIG(x) const char REQUEST_CONTEXT_CONFIG_##x[] = #x; | 84 #define DEFINE_CONTEXT_CONFIG(x) const char REQUEST_CONTEXT_CONFIG_##x[] = #x; |
| 76 #include "components/cronet/url_request_context_config_list.h" | 85 #include "components/cronet/url_request_context_config_list.h" |
| 77 #undef DEFINE_CONTEXT_CONFIG | 86 #undef DEFINE_CONTEXT_CONFIG |
| 78 | 87 |
| 79 URLRequestContextConfig::QuicHint::QuicHint() { | 88 URLRequestContextConfig::QuicHint::QuicHint() { |
| 80 } | 89 } |
| 81 | 90 |
| 82 URLRequestContextConfig::QuicHint::~QuicHint() { | 91 URLRequestContextConfig::QuicHint::~QuicHint() { |
| 83 } | 92 } |
| 84 | 93 |
| 85 // static | 94 // static |
| 86 void URLRequestContextConfig::QuicHint::RegisterJSONConverter( | 95 void URLRequestContextConfig::QuicHint::RegisterJSONConverter( |
| 87 base::JSONValueConverter<URLRequestContextConfig::QuicHint>* converter) { | 96 base::JSONValueConverter<URLRequestContextConfig::QuicHint>* converter) { |
| 88 converter->RegisterStringField(REQUEST_CONTEXT_CONFIG_QUIC_HINT_HOST, | 97 converter->RegisterStringField(REQUEST_CONTEXT_CONFIG_QUIC_HINT_HOST, |
| 89 &URLRequestContextConfig::QuicHint::host); | 98 &URLRequestContextConfig::QuicHint::host); |
| 90 converter->RegisterIntField( | 99 converter->RegisterIntField( |
| 91 REQUEST_CONTEXT_CONFIG_QUIC_HINT_PORT, | 100 REQUEST_CONTEXT_CONFIG_QUIC_HINT_PORT, |
| 92 &URLRequestContextConfig::QuicHint::port); | 101 &URLRequestContextConfig::QuicHint::port); |
| 93 converter->RegisterIntField( | 102 converter->RegisterIntField( |
| 94 REQUEST_CONTEXT_CONFIG_QUIC_HINT_ALT_PORT, | 103 REQUEST_CONTEXT_CONFIG_QUIC_HINT_ALT_PORT, |
| 95 &URLRequestContextConfig::QuicHint::alternate_port); | 104 &URLRequestContextConfig::QuicHint::alternate_port); |
| 96 } | 105 } |
| 97 | 106 |
| 107 URLRequestContextConfig::Pkp::Pkp() {} |
| 108 |
| 109 URLRequestContextConfig::Pkp::~Pkp() {} |
| 110 |
| 111 // static |
| 112 void URLRequestContextConfig::Pkp::RegisterJSONConverter( |
| 113 base::JSONValueConverter<URLRequestContextConfig::Pkp>* converter) { |
| 114 converter->RegisterStringField(REQUEST_CONTEXT_CONFIG_PKP_HOST, |
| 115 &URLRequestContextConfig::Pkp::host); |
| 116 converter->RegisterRepeatedString(REQUEST_CONTEXT_CONFIG_PKP_PIN_HASHES, |
| 117 &URLRequestContextConfig::Pkp::pin_hashes); |
| 118 converter->RegisterBoolField( |
| 119 REQUEST_CONTEXT_CONFIG_PKP_INCLUDE_SUBDOMAINS, |
| 120 &URLRequestContextConfig::Pkp::include_subdomains); |
| 121 converter->RegisterCustomValueField<base::Time>( |
| 122 REQUEST_CONTEXT_CONFIG_PKP_EXPIRATION_DATE, |
| 123 &URLRequestContextConfig::Pkp::expiration_date, &GetTimeFromDouble); |
| 124 } |
| 125 |
| 98 URLRequestContextConfig::URLRequestContextConfig() {} | 126 URLRequestContextConfig::URLRequestContextConfig() {} |
| 99 | 127 |
| 100 URLRequestContextConfig::~URLRequestContextConfig() {} | 128 URLRequestContextConfig::~URLRequestContextConfig() {} |
| 101 | 129 |
| 102 bool URLRequestContextConfig::LoadFromJSON(const std::string& config_string) { | 130 bool URLRequestContextConfig::LoadFromJSON(const std::string& config_string) { |
| 103 scoped_ptr<base::Value> config_value = base::JSONReader::Read(config_string); | 131 scoped_ptr<base::Value> config_value = base::JSONReader::Read(config_string); |
| 104 if (!config_value || !config_value->IsType(base::Value::TYPE_DICTIONARY)) { | 132 if (!config_value || !config_value->IsType(base::Value::TYPE_DICTIONARY)) { |
| 105 DLOG(ERROR) << "Bad JSON: " << config_string; | 133 DLOG(ERROR) << "Bad JSON: " << config_string; |
| 106 return false; | 134 return false; |
| 107 } | 135 } |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 &URLRequestContextConfig::data_reduction_primary_proxy); | 200 &URLRequestContextConfig::data_reduction_primary_proxy); |
| 173 converter->RegisterStringField( | 201 converter->RegisterStringField( |
| 174 REQUEST_CONTEXT_CONFIG_DATA_REDUCTION_FALLBACK_PROXY, | 202 REQUEST_CONTEXT_CONFIG_DATA_REDUCTION_FALLBACK_PROXY, |
| 175 &URLRequestContextConfig::data_reduction_fallback_proxy); | 203 &URLRequestContextConfig::data_reduction_fallback_proxy); |
| 176 converter->RegisterStringField( | 204 converter->RegisterStringField( |
| 177 REQUEST_CONTEXT_CONFIG_DATA_REDUCTION_SECURE_PROXY_CHECK_URL, | 205 REQUEST_CONTEXT_CONFIG_DATA_REDUCTION_SECURE_PROXY_CHECK_URL, |
| 178 &URLRequestContextConfig::data_reduction_secure_proxy_check_url); | 206 &URLRequestContextConfig::data_reduction_secure_proxy_check_url); |
| 179 converter->RegisterStringField( | 207 converter->RegisterStringField( |
| 180 REQUEST_CONTEXT_CONFIG_DATA_REDUCTION_PROXY_KEY, | 208 REQUEST_CONTEXT_CONFIG_DATA_REDUCTION_PROXY_KEY, |
| 181 &URLRequestContextConfig::data_reduction_proxy_key); | 209 &URLRequestContextConfig::data_reduction_proxy_key); |
| 210 converter->RegisterRepeatedMessage(REQUEST_CONTEXT_CONFIG_PKP_LIST, |
| 211 &URLRequestContextConfig::pkp_list); |
| 182 | 212 |
| 183 // For Testing. | 213 // For Testing. |
| 184 converter->RegisterCustomField<scoped_ptr<net::CertVerifier>>( | 214 converter->RegisterCustomField<scoped_ptr<net::CertVerifier>>( |
| 185 REQUEST_CONTEXT_CONFIG_MOCK_CERT_VERIFIER, | 215 REQUEST_CONTEXT_CONFIG_MOCK_CERT_VERIFIER, |
| 186 &URLRequestContextConfig::mock_cert_verifier, | 216 &URLRequestContextConfig::mock_cert_verifier, |
| 187 &GetMockCertVerifierFromString); | 217 &GetMockCertVerifierFromString); |
| 188 } | 218 } |
| 189 | 219 |
| 190 } // namespace cronet | 220 } // namespace cronet |
| OLD | NEW |