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

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: sync 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 } // namespace 94 } // namespace
107 95
108 #define DEFINE_CONTEXT_CONFIG(x) const char REQUEST_CONTEXT_CONFIG_##x[] = #x; 96 URLRequestContextConfig::QuicHint::QuicHint(const std::string& host,
109 #include "components/cronet/url_request_context_config_list.h" 97 int port,
110 #undef DEFINE_CONTEXT_CONFIG 98 int alternate_port)
111 99 : host(host), port(port), alternate_port(alternate_port) {}
112 URLRequestContextConfig::QuicHint::QuicHint() {
113 }
114 100
115 URLRequestContextConfig::QuicHint::~QuicHint() { 101 URLRequestContextConfig::QuicHint::~QuicHint() {
116 } 102 }
117 103
118 // static 104 URLRequestContextConfig::URLRequestContextConfig(
119 void URLRequestContextConfig::QuicHint::RegisterJSONConverter( 105 bool enable_quic,
120 base::JSONValueConverter<URLRequestContextConfig::QuicHint>* converter) { 106 bool enable_spdy,
121 converter->RegisterStringField(REQUEST_CONTEXT_CONFIG_QUIC_HINT_HOST, 107 bool enable_sdch,
122 &URLRequestContextConfig::QuicHint::host); 108 HttpCacheType http_cache,
123 converter->RegisterIntField( 109 int http_cache_max_size,
124 REQUEST_CONTEXT_CONFIG_QUIC_HINT_PORT, 110 bool load_disable_cache,
125 &URLRequestContextConfig::QuicHint::port); 111 const std::string& storage_path,
126 converter->RegisterIntField( 112 const std::string& user_agent,
127 REQUEST_CONTEXT_CONFIG_QUIC_HINT_ALT_PORT, 113 const std::string& experimental_options,
128 &URLRequestContextConfig::QuicHint::alternate_port); 114 const std::string& data_reduction_proxy_key,
129 } 115 const std::string& data_reduction_primary_proxy,
130 116 const std::string& data_reduction_fallback_proxy,
131 URLRequestContextConfig::URLRequestContextConfig() {} 117 const std::string& data_reduction_secure_proxy_check_url,
118 scoped_ptr<net::CertVerifier> mock_cert_verifier)
119 : enable_quic(enable_quic),
120 enable_spdy(enable_spdy),
121 enable_sdch(enable_sdch),
122 http_cache(http_cache),
123 http_cache_max_size(http_cache_max_size),
124 load_disable_cache(load_disable_cache),
125 storage_path(storage_path),
126 user_agent(user_agent),
127 experimental_options(experimental_options),
128 data_reduction_proxy_key(data_reduction_proxy_key),
129 data_reduction_primary_proxy(data_reduction_primary_proxy),
130 data_reduction_fallback_proxy(data_reduction_fallback_proxy),
131 data_reduction_secure_proxy_check_url(
132 data_reduction_secure_proxy_check_url),
133 mock_cert_verifier(mock_cert_verifier.Pass()) {}
xunjieli 2015/12/01 20:40:20 nit: std::move is now preferred over .Pass(). see:
pauljensen 2015/12/02 03:50:02 Done.
132 134
133 URLRequestContextConfig::~URLRequestContextConfig() {} 135 URLRequestContextConfig::~URLRequestContextConfig() {}
134 136
135 bool URLRequestContextConfig::LoadFromJSON(const std::string& config_string) {
136 scoped_ptr<base::Value> config_value = base::JSONReader::Read(config_string);
137 if (!config_value || !config_value->IsType(base::Value::TYPE_DICTIONARY)) {
138 DLOG(ERROR) << "Bad JSON: " << config_string;
139 return false;
140 }
141
142 base::JSONValueConverter<URLRequestContextConfig> converter;
143 if (!converter.Convert(*config_value, this)) {
144 DLOG(ERROR) << "Bad Config: " << config_value;
145 return false;
146 }
147 return true;
148 }
149
150 void URLRequestContextConfig::ConfigureURLRequestContextBuilder( 137 void URLRequestContextConfig::ConfigureURLRequestContextBuilder(
151 net::URLRequestContextBuilder* context_builder) { 138 net::URLRequestContextBuilder* context_builder) {
152 std::string config_cache; 139 std::string config_cache;
153 if (http_cache != REQUEST_CONTEXT_CONFIG_HTTP_CACHE_DISABLED) { 140 if (http_cache != DISABLED) {
154 net::URLRequestContextBuilder::HttpCacheParams cache_params; 141 net::URLRequestContextBuilder::HttpCacheParams cache_params;
155 if (http_cache == REQUEST_CONTEXT_CONFIG_HTTP_CACHE_DISK && 142 if (http_cache == DISK && !storage_path.empty()) {
156 !storage_path.empty()) {
157 cache_params.type = net::URLRequestContextBuilder::HttpCacheParams::DISK; 143 cache_params.type = net::URLRequestContextBuilder::HttpCacheParams::DISK;
158 cache_params.path = base::FilePath(storage_path); 144 cache_params.path = base::FilePath(storage_path);
159 } else { 145 } else {
160 cache_params.type = 146 cache_params.type =
161 net::URLRequestContextBuilder::HttpCacheParams::IN_MEMORY; 147 net::URLRequestContextBuilder::HttpCacheParams::IN_MEMORY;
162 } 148 }
163 cache_params.max_size = http_cache_max_size; 149 cache_params.max_size = http_cache_max_size;
164 context_builder->EnableHttpCache(cache_params); 150 context_builder->EnableHttpCache(cache_params);
165 } else { 151 } else {
166 context_builder->DisableHttpCache(); 152 context_builder->DisableHttpCache();
167 } 153 }
168 context_builder->set_user_agent(user_agent); 154 context_builder->set_user_agent(user_agent);
169 context_builder->SetSpdyAndQuicEnabled(enable_spdy, enable_quic); 155 context_builder->SetSpdyAndQuicEnabled(enable_spdy, enable_quic);
170 context_builder->set_sdch_enabled(enable_sdch); 156 context_builder->set_sdch_enabled(enable_sdch);
171 157
172 ParseAndSetExperimentalOptions(experimental_options, context_builder); 158 ParseAndSetExperimentalOptions(experimental_options, context_builder);
173 159
174 if (mock_cert_verifier) 160 if (mock_cert_verifier)
175 context_builder->SetCertVerifier(mock_cert_verifier.Pass()); 161 context_builder->SetCertVerifier(mock_cert_verifier.Pass());
176 // TODO(mef): Use |config| to set cookies. 162 // TODO(mef): Use |config| to set cookies.
177 } 163 }
178 164
179 // static
180 void URLRequestContextConfig::RegisterJSONConverter(
181 base::JSONValueConverter<URLRequestContextConfig>* converter) {
182 converter->RegisterStringField(REQUEST_CONTEXT_CONFIG_USER_AGENT,
183 &URLRequestContextConfig::user_agent);
184 converter->RegisterStringField(REQUEST_CONTEXT_CONFIG_STORAGE_PATH,
185 &URLRequestContextConfig::storage_path);
186 converter->RegisterBoolField(REQUEST_CONTEXT_CONFIG_ENABLE_QUIC,
187 &URLRequestContextConfig::enable_quic);
188 converter->RegisterBoolField(REQUEST_CONTEXT_CONFIG_ENABLE_SPDY,
189 &URLRequestContextConfig::enable_spdy);
190 converter->RegisterBoolField(REQUEST_CONTEXT_CONFIG_ENABLE_SDCH,
191 &URLRequestContextConfig::enable_sdch);
192 converter->RegisterStringField(REQUEST_CONTEXT_CONFIG_HTTP_CACHE,
193 &URLRequestContextConfig::http_cache);
194 converter->RegisterBoolField(REQUEST_CONTEXT_CONFIG_LOAD_DISABLE_CACHE,
195 &URLRequestContextConfig::load_disable_cache);
196 converter->RegisterIntField(REQUEST_CONTEXT_CONFIG_HTTP_CACHE_MAX_SIZE,
197 &URLRequestContextConfig::http_cache_max_size);
198 converter->RegisterRepeatedMessage(REQUEST_CONTEXT_CONFIG_QUIC_HINTS,
199 &URLRequestContextConfig::quic_hints);
200 converter->RegisterStringField(
201 REQUEST_CONTEXT_CONFIG_EXPERIMENTAL_OPTIONS,
202 &URLRequestContextConfig::experimental_options);
203 converter->RegisterStringField(
204 REQUEST_CONTEXT_CONFIG_DATA_REDUCTION_PRIMARY_PROXY,
205 &URLRequestContextConfig::data_reduction_primary_proxy);
206 converter->RegisterStringField(
207 REQUEST_CONTEXT_CONFIG_DATA_REDUCTION_FALLBACK_PROXY,
208 &URLRequestContextConfig::data_reduction_fallback_proxy);
209 converter->RegisterStringField(
210 REQUEST_CONTEXT_CONFIG_DATA_REDUCTION_SECURE_PROXY_CHECK_URL,
211 &URLRequestContextConfig::data_reduction_secure_proxy_check_url);
212 converter->RegisterStringField(
213 REQUEST_CONTEXT_CONFIG_DATA_REDUCTION_PROXY_KEY,
214 &URLRequestContextConfig::data_reduction_proxy_key);
215
216 // For Testing.
217 converter->RegisterCustomField<scoped_ptr<net::CertVerifier>>(
218 REQUEST_CONTEXT_CONFIG_MOCK_CERT_VERIFIER,
219 &URLRequestContextConfig::mock_cert_verifier,
220 &GetMockCertVerifierFromString);
221 }
222
223 } // namespace cronet 165 } // namespace cronet
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698