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

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

Issue 1414053008: [Cronet] Replace setExperimentalQuicConnectionOptions with a more general API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address Misha's comments Created 5 years, 1 month 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/json/json_reader.h"
9 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
10 #include "base/strings/string_number_conversions.h" 11 #include "base/strings/string_number_conversions.h"
11 #include "base/strings/string_piece.h" 12 #include "base/strings/string_piece.h"
12 #include "base/values.h" 13 #include "base/values.h"
14 #include "base/values.h"
13 #include "net/cert/cert_verifier.h" 15 #include "net/cert/cert_verifier.h"
14 #include "net/quic/quic_protocol.h" 16 #include "net/quic/quic_protocol.h"
15 #include "net/quic/quic_utils.h" 17 #include "net/quic/quic_utils.h"
16 #include "net/url_request/url_request_context_builder.h" 18 #include "net/url_request/url_request_context_builder.h"
17 19
18 namespace cronet { 20 namespace cronet {
19 21
20 namespace { 22 namespace {
21 23
24 // TODO(xunjieli): Refactor constants in io_thread.cc.
25 const char kQuicFieldTrialName[] = "QUIC";
26
22 // Using a reference to scoped_ptr is unavoidable because of the semantics of 27 // Using a reference to scoped_ptr is unavoidable because of the semantics of
23 // RegisterCustomField. 28 // RegisterCustomField.
24 // TODO(xunjieli): Remove this once crbug.com/544976 is fixed. 29 // TODO(xunjieli): Remove this once crbug.com/544976 is fixed.
25 bool GetMockCertVerifierFromString( 30 bool GetMockCertVerifierFromString(
26 const base::StringPiece& mock_cert_verifier_string, 31 const base::StringPiece& mock_cert_verifier_string,
27 scoped_ptr<net::CertVerifier>* result) { 32 scoped_ptr<net::CertVerifier>* result) {
28 int64 val; 33 int64 val;
29 bool success = base::StringToInt64(mock_cert_verifier_string, &val); 34 bool success = base::StringToInt64(mock_cert_verifier_string, &val);
30 *result = make_scoped_ptr(reinterpret_cast<net::CertVerifier*>(val)); 35 *result = make_scoped_ptr(reinterpret_cast<net::CertVerifier*>(val));
31 return success; 36 return success;
32 } 37 }
33 38
39 void ParseAndSetExperimentalOptions(
40 const std::string& experimental_options,
41 net::URLRequestContextBuilder* context_builder) {
42 if (experimental_options.empty())
43 return;
44
45 scoped_ptr<base::DictionaryValue> dict =
46 base::DictionaryValue::From(base::JSONReader::Read(experimental_options));
47 if (!dict) {
48 DCHECK(false) << "Parsing experimental options failed: "
49 << experimental_options;
50 return;
51 }
52
53 const base::DictionaryValue* quic_args = nullptr;
54 if (dict->GetDictionary(kQuicFieldTrialName, &quic_args)) {
55 std::string quic_connection_options;
56 if (quic_args->GetString("connection_options", &quic_connection_options)) {
pauljensen 2015/10/30 18:05:23 if we're going to pull "QUIC" into a file-scoped c
xunjieli 2015/10/30 18:30:57 Done.
57 context_builder->set_quic_connection_options(
58 net::QuicUtils::ParseQuicConnectionOptions(quic_connection_options));
59 }
60 }
61 }
62
34 } // namespace 63 } // namespace
35 64
36 #define DEFINE_CONTEXT_CONFIG(x) const char REQUEST_CONTEXT_CONFIG_##x[] = #x; 65 #define DEFINE_CONTEXT_CONFIG(x) const char REQUEST_CONTEXT_CONFIG_##x[] = #x;
37 #include "components/cronet/url_request_context_config_list.h" 66 #include "components/cronet/url_request_context_config_list.h"
38 #undef DEFINE_CONTEXT_CONFIG 67 #undef DEFINE_CONTEXT_CONFIG
39 68
40 URLRequestContextConfig::QuicHint::QuicHint() { 69 URLRequestContextConfig::QuicHint::QuicHint() {
41 } 70 }
42 71
43 URLRequestContextConfig::QuicHint::~QuicHint() { 72 URLRequestContextConfig::QuicHint::~QuicHint() {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 cache_params.type = 118 cache_params.type =
90 net::URLRequestContextBuilder::HttpCacheParams::IN_MEMORY; 119 net::URLRequestContextBuilder::HttpCacheParams::IN_MEMORY;
91 } 120 }
92 cache_params.max_size = http_cache_max_size; 121 cache_params.max_size = http_cache_max_size;
93 context_builder->EnableHttpCache(cache_params); 122 context_builder->EnableHttpCache(cache_params);
94 } else { 123 } else {
95 context_builder->DisableHttpCache(); 124 context_builder->DisableHttpCache();
96 } 125 }
97 context_builder->set_user_agent(user_agent); 126 context_builder->set_user_agent(user_agent);
98 context_builder->SetSpdyAndQuicEnabled(enable_spdy, enable_quic); 127 context_builder->SetSpdyAndQuicEnabled(enable_spdy, enable_quic);
99 context_builder->set_quic_connection_options(
100 net::QuicUtils::ParseQuicConnectionOptions(quic_connection_options));
101 context_builder->set_sdch_enabled(enable_sdch); 128 context_builder->set_sdch_enabled(enable_sdch);
129
130 ParseAndSetExperimentalOptions(experimental_options, context_builder);
131
102 if (mock_cert_verifier) 132 if (mock_cert_verifier)
103 context_builder->SetCertVerifier(mock_cert_verifier.Pass()); 133 context_builder->SetCertVerifier(mock_cert_verifier.Pass());
104 // TODO(mef): Use |config| to set cookies. 134 // TODO(mef): Use |config| to set cookies.
105 } 135 }
106 136
107 // static 137 // static
108 void URLRequestContextConfig::RegisterJSONConverter( 138 void URLRequestContextConfig::RegisterJSONConverter(
109 base::JSONValueConverter<URLRequestContextConfig>* converter) { 139 base::JSONValueConverter<URLRequestContextConfig>* converter) {
110 converter->RegisterStringField(REQUEST_CONTEXT_CONFIG_USER_AGENT, 140 converter->RegisterStringField(REQUEST_CONTEXT_CONFIG_USER_AGENT,
111 &URLRequestContextConfig::user_agent); 141 &URLRequestContextConfig::user_agent);
112 converter->RegisterStringField(REQUEST_CONTEXT_CONFIG_STORAGE_PATH, 142 converter->RegisterStringField(REQUEST_CONTEXT_CONFIG_STORAGE_PATH,
113 &URLRequestContextConfig::storage_path); 143 &URLRequestContextConfig::storage_path);
114 converter->RegisterBoolField(REQUEST_CONTEXT_CONFIG_ENABLE_QUIC, 144 converter->RegisterBoolField(REQUEST_CONTEXT_CONFIG_ENABLE_QUIC,
115 &URLRequestContextConfig::enable_quic); 145 &URLRequestContextConfig::enable_quic);
116 converter->RegisterBoolField(REQUEST_CONTEXT_CONFIG_ENABLE_SPDY, 146 converter->RegisterBoolField(REQUEST_CONTEXT_CONFIG_ENABLE_SPDY,
117 &URLRequestContextConfig::enable_spdy); 147 &URLRequestContextConfig::enable_spdy);
118 converter->RegisterBoolField(REQUEST_CONTEXT_CONFIG_ENABLE_SDCH, 148 converter->RegisterBoolField(REQUEST_CONTEXT_CONFIG_ENABLE_SDCH,
119 &URLRequestContextConfig::enable_sdch); 149 &URLRequestContextConfig::enable_sdch);
120 converter->RegisterStringField(REQUEST_CONTEXT_CONFIG_HTTP_CACHE, 150 converter->RegisterStringField(REQUEST_CONTEXT_CONFIG_HTTP_CACHE,
121 &URLRequestContextConfig::http_cache); 151 &URLRequestContextConfig::http_cache);
122 converter->RegisterBoolField(REQUEST_CONTEXT_CONFIG_LOAD_DISABLE_CACHE, 152 converter->RegisterBoolField(REQUEST_CONTEXT_CONFIG_LOAD_DISABLE_CACHE,
123 &URLRequestContextConfig::load_disable_cache); 153 &URLRequestContextConfig::load_disable_cache);
124 converter->RegisterIntField(REQUEST_CONTEXT_CONFIG_HTTP_CACHE_MAX_SIZE, 154 converter->RegisterIntField(REQUEST_CONTEXT_CONFIG_HTTP_CACHE_MAX_SIZE,
125 &URLRequestContextConfig::http_cache_max_size); 155 &URLRequestContextConfig::http_cache_max_size);
126 converter->RegisterRepeatedMessage(REQUEST_CONTEXT_CONFIG_QUIC_HINTS, 156 converter->RegisterRepeatedMessage(REQUEST_CONTEXT_CONFIG_QUIC_HINTS,
127 &URLRequestContextConfig::quic_hints); 157 &URLRequestContextConfig::quic_hints);
128 converter->RegisterStringField( 158 converter->RegisterStringField(
129 REQUEST_CONTEXT_CONFIG_QUIC_OPTIONS, 159 REQUEST_CONTEXT_CONFIG_EXPERIMENTAL_OPTIONS,
130 &URLRequestContextConfig::quic_connection_options); 160 &URLRequestContextConfig::experimental_options);
161
131 converter->RegisterStringField( 162 converter->RegisterStringField(
132 REQUEST_CONTEXT_CONFIG_DATA_REDUCTION_PRIMARY_PROXY, 163 REQUEST_CONTEXT_CONFIG_DATA_REDUCTION_PRIMARY_PROXY,
133 &URLRequestContextConfig::data_reduction_primary_proxy); 164 &URLRequestContextConfig::data_reduction_primary_proxy);
134 converter->RegisterStringField( 165 converter->RegisterStringField(
135 REQUEST_CONTEXT_CONFIG_DATA_REDUCTION_FALLBACK_PROXY, 166 REQUEST_CONTEXT_CONFIG_DATA_REDUCTION_FALLBACK_PROXY,
136 &URLRequestContextConfig::data_reduction_fallback_proxy); 167 &URLRequestContextConfig::data_reduction_fallback_proxy);
137 converter->RegisterStringField( 168 converter->RegisterStringField(
138 REQUEST_CONTEXT_CONFIG_DATA_REDUCTION_SECURE_PROXY_CHECK_URL, 169 REQUEST_CONTEXT_CONFIG_DATA_REDUCTION_SECURE_PROXY_CHECK_URL,
139 &URLRequestContextConfig::data_reduction_secure_proxy_check_url); 170 &URLRequestContextConfig::data_reduction_secure_proxy_check_url);
140 converter->RegisterStringField( 171 converter->RegisterStringField(
141 REQUEST_CONTEXT_CONFIG_DATA_REDUCTION_PROXY_KEY, 172 REQUEST_CONTEXT_CONFIG_DATA_REDUCTION_PROXY_KEY,
142 &URLRequestContextConfig::data_reduction_proxy_key); 173 &URLRequestContextConfig::data_reduction_proxy_key);
143 174
144 // For Testing. 175 // For Testing.
145 converter->RegisterCustomField<scoped_ptr<net::CertVerifier>>( 176 converter->RegisterCustomField<scoped_ptr<net::CertVerifier>>(
146 REQUEST_CONTEXT_CONFIG_MOCK_CERT_VERIFIER, 177 REQUEST_CONTEXT_CONFIG_MOCK_CERT_VERIFIER,
147 &URLRequestContextConfig::mock_cert_verifier, 178 &URLRequestContextConfig::mock_cert_verifier,
148 &GetMockCertVerifierFromString); 179 &GetMockCertVerifierFromString);
149 } 180 }
150 181
151 } // namespace cronet 182 } // namespace cronet
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698