Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(114)

Side by Side Diff: components/cronet/url_request_context_config.cc

Issue 1429863008: [Cronet] Remove JSON serialization of CronetEngine.Builder (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix component_unittests Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 11 matching lines...) Expand all
22 // TODO(xunjieli): Refactor constants in io_thread.cc. 22 // TODO(xunjieli): Refactor constants in io_thread.cc.
23 const char kQuicFieldTrialName[] = "QUIC"; 23 const char kQuicFieldTrialName[] = "QUIC";
24 const char kQuicConnectionOptions[] = "connection_options"; 24 const char kQuicConnectionOptions[] = "connection_options";
25 const char kQuicStoreServerConfigsInProperties[] = 25 const char kQuicStoreServerConfigsInProperties[] =
26 "store_server_configs_in_properties"; 26 "store_server_configs_in_properties";
27 const char kQuicDelayTcpRace[] = "delay_tcp_race"; 27 const char kQuicDelayTcpRace[] = "delay_tcp_race";
28 const char kQuicMaxNumberOfLossyConnections[] = 28 const char kQuicMaxNumberOfLossyConnections[] =
29 "max_number_of_lossy_connections"; 29 "max_number_of_lossy_connections";
30 const char kQuicPacketLossThreshold[] = "packet_loss_threshold"; 30 const char kQuicPacketLossThreshold[] = "packet_loss_threshold";
31 31
32 // Using a reference to scoped_ptr is unavoidable because of the semantics of
33 // RegisterCustomField.
34 // TODO(xunjieli): Remove this once crbug.com/544976 is fixed.
35 bool GetMockCertVerifierFromString(
36 const base::StringPiece& mock_cert_verifier_string,
37 scoped_ptr<net::CertVerifier>* result) {
38 int64 val;
39 bool success = base::StringToInt64(mock_cert_verifier_string, &val);
40 *result = make_scoped_ptr(reinterpret_cast<net::CertVerifier*>(val));
41 return success;
42 }
43
44 void ParseAndSetExperimentalOptions( 32 void ParseAndSetExperimentalOptions(
45 const std::string& experimental_options, 33 const std::string& experimental_options,
46 net::URLRequestContextBuilder* context_builder) { 34 net::URLRequestContextBuilder* context_builder) {
47 if (experimental_options.empty()) 35 if (experimental_options.empty())
48 return; 36 return;
49 37
50 DVLOG(1) << "Experimental Options:" << experimental_options; 38 DVLOG(1) << "Experimental Options:" << experimental_options;
51 scoped_ptr<base::Value> options = 39 scoped_ptr<base::Value> options =
52 base::JSONReader::Read(experimental_options); 40 base::JSONReader::Read(experimental_options);
53 41
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 84
97 double quic_packet_loss_threshold = 0.0; 85 double quic_packet_loss_threshold = 0.0;
98 if (quic_args->GetDouble(kQuicPacketLossThreshold, 86 if (quic_args->GetDouble(kQuicPacketLossThreshold,
99 &quic_packet_loss_threshold)) { 87 &quic_packet_loss_threshold)) {
100 context_builder->set_quic_packet_loss_threshold( 88 context_builder->set_quic_packet_loss_threshold(
101 quic_packet_loss_threshold); 89 quic_packet_loss_threshold);
102 } 90 }
103 } 91 }
104 } 92 }
105 93
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
115 } // namespace 94 } // namespace
116 95
117 #define DEFINE_CONTEXT_CONFIG(x) const char REQUEST_CONTEXT_CONFIG_##x[] = #x; 96 URLRequestContextConfig::QuicHint::QuicHint(const std::string& host,
118 #include "components/cronet/url_request_context_config_list.h" 97 int port,
119 #undef DEFINE_CONTEXT_CONFIG 98 int alternate_port)
120 99 : host(host), port(port), alternate_port(alternate_port) {}
121 URLRequestContextConfig::QuicHint::QuicHint() {}
122 100
123 URLRequestContextConfig::QuicHint::~QuicHint() {} 101 URLRequestContextConfig::QuicHint::~QuicHint() {}
124 102
125 // static 103 URLRequestContextConfig::Pkp::Pkp(const std::string& host,
126 void URLRequestContextConfig::QuicHint::RegisterJSONConverter( 104 bool include_subdomains,
127 base::JSONValueConverter<URLRequestContextConfig::QuicHint>* converter) { 105 const base::Time& expiration_date)
128 converter->RegisterStringField(REQUEST_CONTEXT_CONFIG_QUIC_HINT_HOST, 106 : host(host),
129 &URLRequestContextConfig::QuicHint::host); 107 include_subdomains(include_subdomains),
130 converter->RegisterIntField( 108 expiration_date(expiration_date) {}
131 REQUEST_CONTEXT_CONFIG_QUIC_HINT_PORT,
132 &URLRequestContextConfig::QuicHint::port);
133 converter->RegisterIntField(
134 REQUEST_CONTEXT_CONFIG_QUIC_HINT_ALT_PORT,
135 &URLRequestContextConfig::QuicHint::alternate_port);
136 }
137
138 URLRequestContextConfig::Pkp::Pkp() {}
139 109
140 URLRequestContextConfig::Pkp::~Pkp() {} 110 URLRequestContextConfig::Pkp::~Pkp() {}
141 111
142 // static 112 URLRequestContextConfig::URLRequestContextConfig(
143 void URLRequestContextConfig::Pkp::RegisterJSONConverter( 113 bool enable_quic,
144 base::JSONValueConverter<URLRequestContextConfig::Pkp>* converter) { 114 bool enable_spdy,
145 converter->RegisterStringField(REQUEST_CONTEXT_CONFIG_PKP_HOST, 115 bool enable_sdch,
146 &URLRequestContextConfig::Pkp::host); 116 HttpCacheType http_cache,
147 converter->RegisterRepeatedString(REQUEST_CONTEXT_CONFIG_PKP_PIN_HASHES, 117 int http_cache_max_size,
148 &URLRequestContextConfig::Pkp::pin_hashes); 118 bool load_disable_cache,
149 converter->RegisterBoolField( 119 const std::string& storage_path,
150 REQUEST_CONTEXT_CONFIG_PKP_INCLUDE_SUBDOMAINS, 120 const std::string& user_agent,
151 &URLRequestContextConfig::Pkp::include_subdomains); 121 const std::string& experimental_options,
152 converter->RegisterCustomValueField<base::Time>( 122 const std::string& data_reduction_proxy_key,
153 REQUEST_CONTEXT_CONFIG_PKP_EXPIRATION_DATE, 123 const std::string& data_reduction_primary_proxy,
154 &URLRequestContextConfig::Pkp::expiration_date, &GetTimeFromDouble); 124 const std::string& data_reduction_fallback_proxy,
155 } 125 const std::string& data_reduction_secure_proxy_check_url,
156 126 scoped_ptr<net::CertVerifier> mock_cert_verifier)
157 URLRequestContextConfig::URLRequestContextConfig() {} 127 : enable_quic(enable_quic),
128 enable_spdy(enable_spdy),
129 enable_sdch(enable_sdch),
130 http_cache(http_cache),
131 http_cache_max_size(http_cache_max_size),
132 load_disable_cache(load_disable_cache),
133 storage_path(storage_path),
134 user_agent(user_agent),
135 experimental_options(experimental_options),
136 data_reduction_proxy_key(data_reduction_proxy_key),
137 data_reduction_primary_proxy(data_reduction_primary_proxy),
138 data_reduction_fallback_proxy(data_reduction_fallback_proxy),
139 data_reduction_secure_proxy_check_url(
140 data_reduction_secure_proxy_check_url),
141 mock_cert_verifier(std::move(mock_cert_verifier)) {}
158 142
159 URLRequestContextConfig::~URLRequestContextConfig() {} 143 URLRequestContextConfig::~URLRequestContextConfig() {}
160 144
161 bool URLRequestContextConfig::LoadFromJSON(const std::string& config_string) {
162 scoped_ptr<base::Value> config_value = base::JSONReader::Read(config_string);
163 if (!config_value || !config_value->IsType(base::Value::TYPE_DICTIONARY)) {
164 DLOG(ERROR) << "Bad JSON: " << config_string;
165 return false;
166 }
167
168 base::JSONValueConverter<URLRequestContextConfig> converter;
169 if (!converter.Convert(*config_value, this)) {
170 DLOG(ERROR) << "Bad Config: " << config_value;
171 return false;
172 }
173 return true;
174 }
175
176 void URLRequestContextConfig::ConfigureURLRequestContextBuilder( 145 void URLRequestContextConfig::ConfigureURLRequestContextBuilder(
177 net::URLRequestContextBuilder* context_builder) { 146 net::URLRequestContextBuilder* context_builder) {
178 std::string config_cache; 147 std::string config_cache;
179 if (http_cache != REQUEST_CONTEXT_CONFIG_HTTP_CACHE_DISABLED) { 148 if (http_cache != DISABLED) {
180 net::URLRequestContextBuilder::HttpCacheParams cache_params; 149 net::URLRequestContextBuilder::HttpCacheParams cache_params;
181 if (http_cache == REQUEST_CONTEXT_CONFIG_HTTP_CACHE_DISK && 150 if (http_cache == DISK && !storage_path.empty()) {
182 !storage_path.empty()) {
183 cache_params.type = net::URLRequestContextBuilder::HttpCacheParams::DISK; 151 cache_params.type = net::URLRequestContextBuilder::HttpCacheParams::DISK;
184 cache_params.path = base::FilePath(storage_path); 152 cache_params.path = base::FilePath(storage_path);
185 } else { 153 } else {
186 cache_params.type = 154 cache_params.type =
187 net::URLRequestContextBuilder::HttpCacheParams::IN_MEMORY; 155 net::URLRequestContextBuilder::HttpCacheParams::IN_MEMORY;
188 } 156 }
189 cache_params.max_size = http_cache_max_size; 157 cache_params.max_size = http_cache_max_size;
190 context_builder->EnableHttpCache(cache_params); 158 context_builder->EnableHttpCache(cache_params);
191 } else { 159 } else {
192 context_builder->DisableHttpCache(); 160 context_builder->DisableHttpCache();
193 } 161 }
194 context_builder->set_user_agent(user_agent); 162 context_builder->set_user_agent(user_agent);
195 context_builder->SetSpdyAndQuicEnabled(enable_spdy, enable_quic); 163 context_builder->SetSpdyAndQuicEnabled(enable_spdy, enable_quic);
196 context_builder->set_sdch_enabled(enable_sdch); 164 context_builder->set_sdch_enabled(enable_sdch);
197 165
198 ParseAndSetExperimentalOptions(experimental_options, context_builder); 166 ParseAndSetExperimentalOptions(experimental_options, context_builder);
199 167
200 if (mock_cert_verifier) 168 if (mock_cert_verifier)
201 context_builder->SetCertVerifier(mock_cert_verifier.Pass()); 169 context_builder->SetCertVerifier(mock_cert_verifier.Pass());
202 // TODO(mef): Use |config| to set cookies. 170 // TODO(mef): Use |config| to set cookies.
203 } 171 }
204 172
205 // static
206 void URLRequestContextConfig::RegisterJSONConverter(
207 base::JSONValueConverter<URLRequestContextConfig>* converter) {
208 converter->RegisterStringField(REQUEST_CONTEXT_CONFIG_USER_AGENT,
209 &URLRequestContextConfig::user_agent);
210 converter->RegisterStringField(REQUEST_CONTEXT_CONFIG_STORAGE_PATH,
211 &URLRequestContextConfig::storage_path);
212 converter->RegisterBoolField(REQUEST_CONTEXT_CONFIG_ENABLE_QUIC,
213 &URLRequestContextConfig::enable_quic);
214 converter->RegisterBoolField(REQUEST_CONTEXT_CONFIG_ENABLE_SPDY,
215 &URLRequestContextConfig::enable_spdy);
216 converter->RegisterBoolField(REQUEST_CONTEXT_CONFIG_ENABLE_SDCH,
217 &URLRequestContextConfig::enable_sdch);
218 converter->RegisterStringField(REQUEST_CONTEXT_CONFIG_HTTP_CACHE,
219 &URLRequestContextConfig::http_cache);
220 converter->RegisterBoolField(REQUEST_CONTEXT_CONFIG_LOAD_DISABLE_CACHE,
221 &URLRequestContextConfig::load_disable_cache);
222 converter->RegisterIntField(REQUEST_CONTEXT_CONFIG_HTTP_CACHE_MAX_SIZE,
223 &URLRequestContextConfig::http_cache_max_size);
224 converter->RegisterRepeatedMessage(REQUEST_CONTEXT_CONFIG_QUIC_HINTS,
225 &URLRequestContextConfig::quic_hints);
226 converter->RegisterStringField(
227 REQUEST_CONTEXT_CONFIG_EXPERIMENTAL_OPTIONS,
228 &URLRequestContextConfig::experimental_options);
229 converter->RegisterStringField(
230 REQUEST_CONTEXT_CONFIG_DATA_REDUCTION_PRIMARY_PROXY,
231 &URLRequestContextConfig::data_reduction_primary_proxy);
232 converter->RegisterStringField(
233 REQUEST_CONTEXT_CONFIG_DATA_REDUCTION_FALLBACK_PROXY,
234 &URLRequestContextConfig::data_reduction_fallback_proxy);
235 converter->RegisterStringField(
236 REQUEST_CONTEXT_CONFIG_DATA_REDUCTION_SECURE_PROXY_CHECK_URL,
237 &URLRequestContextConfig::data_reduction_secure_proxy_check_url);
238 converter->RegisterStringField(
239 REQUEST_CONTEXT_CONFIG_DATA_REDUCTION_PROXY_KEY,
240 &URLRequestContextConfig::data_reduction_proxy_key);
241 converter->RegisterRepeatedMessage(REQUEST_CONTEXT_CONFIG_PKP_LIST,
242 &URLRequestContextConfig::pkp_list);
243
244 // For Testing.
245 converter->RegisterCustomField<scoped_ptr<net::CertVerifier>>(
246 REQUEST_CONTEXT_CONFIG_MOCK_CERT_VERIFIER,
247 &URLRequestContextConfig::mock_cert_verifier,
248 &GetMockCertVerifierFromString);
249 }
250
251 } // namespace cronet 173 } // namespace cronet
OLDNEW
« no previous file with comments | « components/cronet/url_request_context_config.h ('k') | components/cronet/url_request_context_config_list.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698