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 // static |
| 108 void URLRequestContextConfig::Pkp::RegisterJSONConverter( |
| 109 base::JSONValueConverter<URLRequestContextConfig::Pkp>* converter) { |
| 110 converter->RegisterStringField(REQUEST_CONTEXT_CONFIG_PKP_HOST, |
| 111 &URLRequestContextConfig::Pkp::host); |
| 112 converter->RegisterRepeatedString(REQUEST_CONTEXT_CONFIG_PKP_PIN_HASHES, |
| 113 &URLRequestContextConfig::Pkp::pin_hashes); |
| 114 converter->RegisterBoolField( |
| 115 REQUEST_CONTEXT_CONFIG_PKP_INCLUDE_SUBDOMAINS, |
| 116 &URLRequestContextConfig::Pkp::include_subdomains); |
| 117 converter->RegisterCustomValueField<base::Time>( |
| 118 REQUEST_CONTEXT_CONFIG_PKP_EXPIRATION_DATE, |
| 119 &URLRequestContextConfig::Pkp::expiration_date, &GetTimeFromDouble); |
| 120 } |
| 121 |
98 URLRequestContextConfig::URLRequestContextConfig() {} | 122 URLRequestContextConfig::URLRequestContextConfig() {} |
99 | 123 |
100 URLRequestContextConfig::~URLRequestContextConfig() {} | 124 URLRequestContextConfig::~URLRequestContextConfig() {} |
101 | 125 |
102 bool URLRequestContextConfig::LoadFromJSON(const std::string& config_string) { | 126 bool URLRequestContextConfig::LoadFromJSON(const std::string& config_string) { |
103 scoped_ptr<base::Value> config_value = base::JSONReader::Read(config_string); | 127 scoped_ptr<base::Value> config_value = base::JSONReader::Read(config_string); |
104 if (!config_value || !config_value->IsType(base::Value::TYPE_DICTIONARY)) { | 128 if (!config_value || !config_value->IsType(base::Value::TYPE_DICTIONARY)) { |
105 DLOG(ERROR) << "Bad JSON: " << config_string; | 129 DLOG(ERROR) << "Bad JSON: " << config_string; |
106 return false; | 130 return false; |
107 } | 131 } |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 &URLRequestContextConfig::data_reduction_primary_proxy); | 196 &URLRequestContextConfig::data_reduction_primary_proxy); |
173 converter->RegisterStringField( | 197 converter->RegisterStringField( |
174 REQUEST_CONTEXT_CONFIG_DATA_REDUCTION_FALLBACK_PROXY, | 198 REQUEST_CONTEXT_CONFIG_DATA_REDUCTION_FALLBACK_PROXY, |
175 &URLRequestContextConfig::data_reduction_fallback_proxy); | 199 &URLRequestContextConfig::data_reduction_fallback_proxy); |
176 converter->RegisterStringField( | 200 converter->RegisterStringField( |
177 REQUEST_CONTEXT_CONFIG_DATA_REDUCTION_SECURE_PROXY_CHECK_URL, | 201 REQUEST_CONTEXT_CONFIG_DATA_REDUCTION_SECURE_PROXY_CHECK_URL, |
178 &URLRequestContextConfig::data_reduction_secure_proxy_check_url); | 202 &URLRequestContextConfig::data_reduction_secure_proxy_check_url); |
179 converter->RegisterStringField( | 203 converter->RegisterStringField( |
180 REQUEST_CONTEXT_CONFIG_DATA_REDUCTION_PROXY_KEY, | 204 REQUEST_CONTEXT_CONFIG_DATA_REDUCTION_PROXY_KEY, |
181 &URLRequestContextConfig::data_reduction_proxy_key); | 205 &URLRequestContextConfig::data_reduction_proxy_key); |
| 206 converter->RegisterRepeatedMessage(REQUEST_CONTEXT_CONFIG_PKP_LIST, |
| 207 &URLRequestContextConfig::pkp_list); |
182 | 208 |
183 // For Testing. | 209 // For Testing. |
184 converter->RegisterCustomField<scoped_ptr<net::CertVerifier>>( | 210 converter->RegisterCustomField<scoped_ptr<net::CertVerifier>>( |
185 REQUEST_CONTEXT_CONFIG_MOCK_CERT_VERIFIER, | 211 REQUEST_CONTEXT_CONFIG_MOCK_CERT_VERIFIER, |
186 &URLRequestContextConfig::mock_cert_verifier, | 212 &URLRequestContextConfig::mock_cert_verifier, |
187 &GetMockCertVerifierFromString); | 213 &GetMockCertVerifierFromString); |
188 } | 214 } |
189 | 215 |
190 } // namespace cronet | 216 } // namespace cronet |
OLD | NEW |