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/json/json_reader.h" | |
pauljensen
2015/11/04 15:03:26
duplicate line
xunjieli
2015/11/06 14:48:51
Done.
| |
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" | |
pauljensen
2015/11/04 15:03:26
ditto
xunjieli
2015/11/06 14:48:51
Done.
| |
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 const char kQuicConnectionOptions[] = "connection_options"; | |
27 | |
22 // Using a reference to scoped_ptr is unavoidable because of the semantics of | 28 // Using a reference to scoped_ptr is unavoidable because of the semantics of |
23 // RegisterCustomField. | 29 // RegisterCustomField. |
24 // TODO(xunjieli): Remove this once crbug.com/544976 is fixed. | 30 // TODO(xunjieli): Remove this once crbug.com/544976 is fixed. |
25 bool GetMockCertVerifierFromString( | 31 bool GetMockCertVerifierFromString( |
26 const base::StringPiece& mock_cert_verifier_string, | 32 const base::StringPiece& mock_cert_verifier_string, |
27 scoped_ptr<net::CertVerifier>* result) { | 33 scoped_ptr<net::CertVerifier>* result) { |
28 int64 val; | 34 int64 val; |
29 bool success = base::StringToInt64(mock_cert_verifier_string, &val); | 35 bool success = base::StringToInt64(mock_cert_verifier_string, &val); |
30 *result = make_scoped_ptr(reinterpret_cast<net::CertVerifier*>(val)); | 36 *result = make_scoped_ptr(reinterpret_cast<net::CertVerifier*>(val)); |
31 return success; | 37 return success; |
32 } | 38 } |
33 | 39 |
40 void ParseAndSetExperimentalOptions( | |
41 const std::string& experimental_options, | |
42 net::URLRequestContextBuilder* context_builder) { | |
43 if (experimental_options.empty()) | |
44 return; | |
45 | |
46 scoped_ptr<base::DictionaryValue> dict = | |
47 base::DictionaryValue::From(base::JSONReader::Read(experimental_options)); | |
48 if (!dict) { | |
49 DCHECK(false) << "Parsing experimental options failed: " | |
50 << experimental_options; | |
51 return; | |
52 } | |
53 | |
54 const base::DictionaryValue* quic_args = nullptr; | |
pauljensen
2015/11/04 15:03:26
I don't think we need this initializer
xunjieli
2015/11/06 14:48:51
But I looked through code search. All the usage of
| |
55 if (dict->GetDictionary(kQuicFieldTrialName, &quic_args)) { | |
56 std::string quic_connection_options; | |
57 if (quic_args->GetString(kQuicConnectionOptions, | |
58 &quic_connection_options)) { | |
59 context_builder->set_quic_connection_options( | |
60 net::QuicUtils::ParseQuicConnectionOptions(quic_connection_options)); | |
61 } | |
62 } | |
63 } | |
64 | |
34 } // namespace | 65 } // namespace |
35 | 66 |
36 #define DEFINE_CONTEXT_CONFIG(x) const char REQUEST_CONTEXT_CONFIG_##x[] = #x; | 67 #define DEFINE_CONTEXT_CONFIG(x) const char REQUEST_CONTEXT_CONFIG_##x[] = #x; |
37 #include "components/cronet/url_request_context_config_list.h" | 68 #include "components/cronet/url_request_context_config_list.h" |
38 #undef DEFINE_CONTEXT_CONFIG | 69 #undef DEFINE_CONTEXT_CONFIG |
39 | 70 |
40 URLRequestContextConfig::QuicHint::QuicHint() { | 71 URLRequestContextConfig::QuicHint::QuicHint() { |
41 } | 72 } |
42 | 73 |
43 URLRequestContextConfig::QuicHint::~QuicHint() { | 74 URLRequestContextConfig::QuicHint::~QuicHint() { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
89 cache_params.type = | 120 cache_params.type = |
90 net::URLRequestContextBuilder::HttpCacheParams::IN_MEMORY; | 121 net::URLRequestContextBuilder::HttpCacheParams::IN_MEMORY; |
91 } | 122 } |
92 cache_params.max_size = http_cache_max_size; | 123 cache_params.max_size = http_cache_max_size; |
93 context_builder->EnableHttpCache(cache_params); | 124 context_builder->EnableHttpCache(cache_params); |
94 } else { | 125 } else { |
95 context_builder->DisableHttpCache(); | 126 context_builder->DisableHttpCache(); |
96 } | 127 } |
97 context_builder->set_user_agent(user_agent); | 128 context_builder->set_user_agent(user_agent); |
98 context_builder->SetSpdyAndQuicEnabled(enable_spdy, enable_quic); | 129 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); | 130 context_builder->set_sdch_enabled(enable_sdch); |
131 | |
132 ParseAndSetExperimentalOptions(experimental_options, context_builder); | |
133 | |
102 if (mock_cert_verifier) | 134 if (mock_cert_verifier) |
103 context_builder->SetCertVerifier(mock_cert_verifier.Pass()); | 135 context_builder->SetCertVerifier(mock_cert_verifier.Pass()); |
104 // TODO(mef): Use |config| to set cookies. | 136 // TODO(mef): Use |config| to set cookies. |
105 } | 137 } |
106 | 138 |
107 // static | 139 // static |
108 void URLRequestContextConfig::RegisterJSONConverter( | 140 void URLRequestContextConfig::RegisterJSONConverter( |
109 base::JSONValueConverter<URLRequestContextConfig>* converter) { | 141 base::JSONValueConverter<URLRequestContextConfig>* converter) { |
110 converter->RegisterStringField(REQUEST_CONTEXT_CONFIG_USER_AGENT, | 142 converter->RegisterStringField(REQUEST_CONTEXT_CONFIG_USER_AGENT, |
111 &URLRequestContextConfig::user_agent); | 143 &URLRequestContextConfig::user_agent); |
112 converter->RegisterStringField(REQUEST_CONTEXT_CONFIG_STORAGE_PATH, | 144 converter->RegisterStringField(REQUEST_CONTEXT_CONFIG_STORAGE_PATH, |
113 &URLRequestContextConfig::storage_path); | 145 &URLRequestContextConfig::storage_path); |
114 converter->RegisterBoolField(REQUEST_CONTEXT_CONFIG_ENABLE_QUIC, | 146 converter->RegisterBoolField(REQUEST_CONTEXT_CONFIG_ENABLE_QUIC, |
115 &URLRequestContextConfig::enable_quic); | 147 &URLRequestContextConfig::enable_quic); |
116 converter->RegisterBoolField(REQUEST_CONTEXT_CONFIG_ENABLE_SPDY, | 148 converter->RegisterBoolField(REQUEST_CONTEXT_CONFIG_ENABLE_SPDY, |
117 &URLRequestContextConfig::enable_spdy); | 149 &URLRequestContextConfig::enable_spdy); |
118 converter->RegisterBoolField(REQUEST_CONTEXT_CONFIG_ENABLE_SDCH, | 150 converter->RegisterBoolField(REQUEST_CONTEXT_CONFIG_ENABLE_SDCH, |
119 &URLRequestContextConfig::enable_sdch); | 151 &URLRequestContextConfig::enable_sdch); |
120 converter->RegisterStringField(REQUEST_CONTEXT_CONFIG_HTTP_CACHE, | 152 converter->RegisterStringField(REQUEST_CONTEXT_CONFIG_HTTP_CACHE, |
121 &URLRequestContextConfig::http_cache); | 153 &URLRequestContextConfig::http_cache); |
122 converter->RegisterBoolField(REQUEST_CONTEXT_CONFIG_LOAD_DISABLE_CACHE, | 154 converter->RegisterBoolField(REQUEST_CONTEXT_CONFIG_LOAD_DISABLE_CACHE, |
123 &URLRequestContextConfig::load_disable_cache); | 155 &URLRequestContextConfig::load_disable_cache); |
124 converter->RegisterIntField(REQUEST_CONTEXT_CONFIG_HTTP_CACHE_MAX_SIZE, | 156 converter->RegisterIntField(REQUEST_CONTEXT_CONFIG_HTTP_CACHE_MAX_SIZE, |
125 &URLRequestContextConfig::http_cache_max_size); | 157 &URLRequestContextConfig::http_cache_max_size); |
126 converter->RegisterRepeatedMessage(REQUEST_CONTEXT_CONFIG_QUIC_HINTS, | 158 converter->RegisterRepeatedMessage(REQUEST_CONTEXT_CONFIG_QUIC_HINTS, |
127 &URLRequestContextConfig::quic_hints); | 159 &URLRequestContextConfig::quic_hints); |
128 converter->RegisterStringField( | 160 converter->RegisterStringField( |
129 REQUEST_CONTEXT_CONFIG_QUIC_OPTIONS, | 161 REQUEST_CONTEXT_CONFIG_EXPERIMENTAL_OPTIONS, |
130 &URLRequestContextConfig::quic_connection_options); | 162 &URLRequestContextConfig::experimental_options); |
163 | |
pauljensen
2015/11/04 15:03:26
remove blank line to match style here?
xunjieli
2015/11/06 14:48:51
Done.
| |
131 converter->RegisterStringField( | 164 converter->RegisterStringField( |
132 REQUEST_CONTEXT_CONFIG_DATA_REDUCTION_PRIMARY_PROXY, | 165 REQUEST_CONTEXT_CONFIG_DATA_REDUCTION_PRIMARY_PROXY, |
133 &URLRequestContextConfig::data_reduction_primary_proxy); | 166 &URLRequestContextConfig::data_reduction_primary_proxy); |
134 converter->RegisterStringField( | 167 converter->RegisterStringField( |
135 REQUEST_CONTEXT_CONFIG_DATA_REDUCTION_FALLBACK_PROXY, | 168 REQUEST_CONTEXT_CONFIG_DATA_REDUCTION_FALLBACK_PROXY, |
136 &URLRequestContextConfig::data_reduction_fallback_proxy); | 169 &URLRequestContextConfig::data_reduction_fallback_proxy); |
137 converter->RegisterStringField( | 170 converter->RegisterStringField( |
138 REQUEST_CONTEXT_CONFIG_DATA_REDUCTION_SECURE_PROXY_CHECK_URL, | 171 REQUEST_CONTEXT_CONFIG_DATA_REDUCTION_SECURE_PROXY_CHECK_URL, |
139 &URLRequestContextConfig::data_reduction_secure_proxy_check_url); | 172 &URLRequestContextConfig::data_reduction_secure_proxy_check_url); |
140 converter->RegisterStringField( | 173 converter->RegisterStringField( |
141 REQUEST_CONTEXT_CONFIG_DATA_REDUCTION_PROXY_KEY, | 174 REQUEST_CONTEXT_CONFIG_DATA_REDUCTION_PROXY_KEY, |
142 &URLRequestContextConfig::data_reduction_proxy_key); | 175 &URLRequestContextConfig::data_reduction_proxy_key); |
143 | 176 |
144 // For Testing. | 177 // For Testing. |
145 converter->RegisterCustomField<scoped_ptr<net::CertVerifier>>( | 178 converter->RegisterCustomField<scoped_ptr<net::CertVerifier>>( |
146 REQUEST_CONTEXT_CONFIG_MOCK_CERT_VERIFIER, | 179 REQUEST_CONTEXT_CONFIG_MOCK_CERT_VERIFIER, |
147 &URLRequestContextConfig::mock_cert_verifier, | 180 &URLRequestContextConfig::mock_cert_verifier, |
148 &GetMockCertVerifierFromString); | 181 &GetMockCertVerifierFromString); |
149 } | 182 } |
150 | 183 |
151 } // namespace cronet | 184 } // namespace cronet |
OLD | NEW |