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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 | 96 |
97 double quic_packet_loss_threshold = 0.0; | 97 double quic_packet_loss_threshold = 0.0; |
98 if (quic_args->GetDouble(kQuicPacketLossThreshold, | 98 if (quic_args->GetDouble(kQuicPacketLossThreshold, |
99 &quic_packet_loss_threshold)) { | 99 &quic_packet_loss_threshold)) { |
100 context_builder->set_quic_packet_loss_threshold( | 100 context_builder->set_quic_packet_loss_threshold( |
101 quic_packet_loss_threshold); | 101 quic_packet_loss_threshold); |
102 } | 102 } |
103 } | 103 } |
104 } | 104 } |
105 | 105 |
| 106 bool GetTimeFromDouble(const base::Value* json_value, base::Time* time) { |
| 107 double time_double; |
| 108 bool success = json_value->GetAsDouble(&time_double); |
| 109 if (success) { |
| 110 *time = base::Time::FromDoubleT(time_double); |
| 111 } |
| 112 return success; |
| 113 } |
| 114 |
106 } // namespace | 115 } // namespace |
107 | 116 |
108 #define DEFINE_CONTEXT_CONFIG(x) const char REQUEST_CONTEXT_CONFIG_##x[] = #x; | 117 #define DEFINE_CONTEXT_CONFIG(x) const char REQUEST_CONTEXT_CONFIG_##x[] = #x; |
109 #include "components/cronet/url_request_context_config_list.h" | 118 #include "components/cronet/url_request_context_config_list.h" |
110 #undef DEFINE_CONTEXT_CONFIG | 119 #undef DEFINE_CONTEXT_CONFIG |
111 | 120 |
112 URLRequestContextConfig::QuicHint::QuicHint() { | 121 URLRequestContextConfig::QuicHint::QuicHint() {} |
113 } | |
114 | 122 |
115 URLRequestContextConfig::QuicHint::~QuicHint() { | 123 URLRequestContextConfig::QuicHint::~QuicHint() {} |
116 } | |
117 | 124 |
118 // static | 125 // static |
119 void URLRequestContextConfig::QuicHint::RegisterJSONConverter( | 126 void URLRequestContextConfig::QuicHint::RegisterJSONConverter( |
120 base::JSONValueConverter<URLRequestContextConfig::QuicHint>* converter) { | 127 base::JSONValueConverter<URLRequestContextConfig::QuicHint>* converter) { |
121 converter->RegisterStringField(REQUEST_CONTEXT_CONFIG_QUIC_HINT_HOST, | 128 converter->RegisterStringField(REQUEST_CONTEXT_CONFIG_QUIC_HINT_HOST, |
122 &URLRequestContextConfig::QuicHint::host); | 129 &URLRequestContextConfig::QuicHint::host); |
123 converter->RegisterIntField( | 130 converter->RegisterIntField( |
124 REQUEST_CONTEXT_CONFIG_QUIC_HINT_PORT, | 131 REQUEST_CONTEXT_CONFIG_QUIC_HINT_PORT, |
125 &URLRequestContextConfig::QuicHint::port); | 132 &URLRequestContextConfig::QuicHint::port); |
126 converter->RegisterIntField( | 133 converter->RegisterIntField( |
127 REQUEST_CONTEXT_CONFIG_QUIC_HINT_ALT_PORT, | 134 REQUEST_CONTEXT_CONFIG_QUIC_HINT_ALT_PORT, |
128 &URLRequestContextConfig::QuicHint::alternate_port); | 135 &URLRequestContextConfig::QuicHint::alternate_port); |
129 } | 136 } |
130 | 137 |
| 138 URLRequestContextConfig::Pkp::Pkp() {} |
| 139 |
| 140 URLRequestContextConfig::Pkp::~Pkp() {} |
| 141 |
| 142 // static |
| 143 void URLRequestContextConfig::Pkp::RegisterJSONConverter( |
| 144 base::JSONValueConverter<URLRequestContextConfig::Pkp>* converter) { |
| 145 converter->RegisterStringField(REQUEST_CONTEXT_CONFIG_PKP_HOST, |
| 146 &URLRequestContextConfig::Pkp::host); |
| 147 converter->RegisterRepeatedString(REQUEST_CONTEXT_CONFIG_PKP_PIN_HASHES, |
| 148 &URLRequestContextConfig::Pkp::pin_hashes); |
| 149 converter->RegisterBoolField( |
| 150 REQUEST_CONTEXT_CONFIG_PKP_INCLUDE_SUBDOMAINS, |
| 151 &URLRequestContextConfig::Pkp::include_subdomains); |
| 152 converter->RegisterCustomValueField<base::Time>( |
| 153 REQUEST_CONTEXT_CONFIG_PKP_EXPIRATION_DATE, |
| 154 &URLRequestContextConfig::Pkp::expiration_date, &GetTimeFromDouble); |
| 155 } |
| 156 |
131 URLRequestContextConfig::URLRequestContextConfig() {} | 157 URLRequestContextConfig::URLRequestContextConfig() {} |
132 | 158 |
133 URLRequestContextConfig::~URLRequestContextConfig() {} | 159 URLRequestContextConfig::~URLRequestContextConfig() {} |
134 | 160 |
135 bool URLRequestContextConfig::LoadFromJSON(const std::string& config_string) { | 161 bool URLRequestContextConfig::LoadFromJSON(const std::string& config_string) { |
136 scoped_ptr<base::Value> config_value = base::JSONReader::Read(config_string); | 162 scoped_ptr<base::Value> config_value = base::JSONReader::Read(config_string); |
137 if (!config_value || !config_value->IsType(base::Value::TYPE_DICTIONARY)) { | 163 if (!config_value || !config_value->IsType(base::Value::TYPE_DICTIONARY)) { |
138 DLOG(ERROR) << "Bad JSON: " << config_string; | 164 DLOG(ERROR) << "Bad JSON: " << config_string; |
139 return false; | 165 return false; |
140 } | 166 } |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 &URLRequestContextConfig::data_reduction_primary_proxy); | 231 &URLRequestContextConfig::data_reduction_primary_proxy); |
206 converter->RegisterStringField( | 232 converter->RegisterStringField( |
207 REQUEST_CONTEXT_CONFIG_DATA_REDUCTION_FALLBACK_PROXY, | 233 REQUEST_CONTEXT_CONFIG_DATA_REDUCTION_FALLBACK_PROXY, |
208 &URLRequestContextConfig::data_reduction_fallback_proxy); | 234 &URLRequestContextConfig::data_reduction_fallback_proxy); |
209 converter->RegisterStringField( | 235 converter->RegisterStringField( |
210 REQUEST_CONTEXT_CONFIG_DATA_REDUCTION_SECURE_PROXY_CHECK_URL, | 236 REQUEST_CONTEXT_CONFIG_DATA_REDUCTION_SECURE_PROXY_CHECK_URL, |
211 &URLRequestContextConfig::data_reduction_secure_proxy_check_url); | 237 &URLRequestContextConfig::data_reduction_secure_proxy_check_url); |
212 converter->RegisterStringField( | 238 converter->RegisterStringField( |
213 REQUEST_CONTEXT_CONFIG_DATA_REDUCTION_PROXY_KEY, | 239 REQUEST_CONTEXT_CONFIG_DATA_REDUCTION_PROXY_KEY, |
214 &URLRequestContextConfig::data_reduction_proxy_key); | 240 &URLRequestContextConfig::data_reduction_proxy_key); |
| 241 converter->RegisterRepeatedMessage(REQUEST_CONTEXT_CONFIG_PKP_LIST, |
| 242 &URLRequestContextConfig::pkp_list); |
215 | 243 |
216 // For Testing. | 244 // For Testing. |
217 converter->RegisterCustomField<scoped_ptr<net::CertVerifier>>( | 245 converter->RegisterCustomField<scoped_ptr<net::CertVerifier>>( |
218 REQUEST_CONTEXT_CONFIG_MOCK_CERT_VERIFIER, | 246 REQUEST_CONTEXT_CONFIG_MOCK_CERT_VERIFIER, |
219 &URLRequestContextConfig::mock_cert_verifier, | 247 &URLRequestContextConfig::mock_cert_verifier, |
220 &GetMockCertVerifierFromString); | 248 &GetMockCertVerifierFromString); |
221 } | 249 } |
222 | 250 |
223 } // namespace cronet | 251 } // namespace cronet |
OLD | NEW |