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

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

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