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/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. | 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[] = |
| 26 "store_server_configs_in_properties"; |
| 27 const char kQuicDelayTcpRace[] = "delay_tcp_race"; |
| 28 const char kQuicMaxNumberOfLossyConnections[] = |
| 29 "max_number_of_lossy_connections"; |
| 30 const char kQuicPacketLossThreshold[] = "packet_loss_threshold"; |
25 | 31 |
26 // Using a reference to scoped_ptr is unavoidable because of the semantics of | 32 // Using a reference to scoped_ptr is unavoidable because of the semantics of |
27 // RegisterCustomField. | 33 // RegisterCustomField. |
28 // TODO(xunjieli): Remove this once crbug.com/544976 is fixed. | 34 // TODO(xunjieli): Remove this once crbug.com/544976 is fixed. |
29 bool GetMockCertVerifierFromString( | 35 bool GetMockCertVerifierFromString( |
30 const base::StringPiece& mock_cert_verifier_string, | 36 const base::StringPiece& mock_cert_verifier_string, |
31 scoped_ptr<net::CertVerifier>* result) { | 37 scoped_ptr<net::CertVerifier>* result) { |
32 int64 val; | 38 int64 val; |
33 bool success = base::StringToInt64(mock_cert_verifier_string, &val); | 39 bool success = base::StringToInt64(mock_cert_verifier_string, &val); |
34 *result = make_scoped_ptr(reinterpret_cast<net::CertVerifier*>(val)); | 40 *result = make_scoped_ptr(reinterpret_cast<net::CertVerifier*>(val)); |
35 return success; | 41 return success; |
36 } | 42 } |
37 | 43 |
38 void ParseAndSetExperimentalOptions( | 44 void ParseAndSetExperimentalOptions( |
39 const std::string& experimental_options, | 45 const std::string& experimental_options, |
40 net::URLRequestContextBuilder* context_builder) { | 46 net::URLRequestContextBuilder* context_builder) { |
41 if (experimental_options.empty()) | 47 if (experimental_options.empty()) |
42 return; | 48 return; |
43 | 49 |
| 50 DVLOG(1) << "Experimental Options:" << experimental_options; |
44 scoped_ptr<base::Value> options = | 51 scoped_ptr<base::Value> options = |
45 base::JSONReader::Read(experimental_options); | 52 base::JSONReader::Read(experimental_options); |
46 | 53 |
47 if (!options) { | 54 if (!options) { |
48 DCHECK(false) << "Parsing experimental options failed: " | 55 DCHECK(false) << "Parsing experimental options failed: " |
49 << experimental_options; | 56 << experimental_options; |
50 return; | 57 return; |
51 } | 58 } |
52 | 59 |
53 scoped_ptr<base::DictionaryValue> dict = | 60 scoped_ptr<base::DictionaryValue> dict = |
54 base::DictionaryValue::From(options.Pass()); | 61 base::DictionaryValue::From(options.Pass()); |
55 | 62 |
56 if (!dict) { | 63 if (!dict) { |
57 DCHECK(false) << "Experimental options string is not a dictionary: " | 64 DCHECK(false) << "Experimental options string is not a dictionary: " |
58 << experimental_options; | 65 << experimental_options; |
59 return; | 66 return; |
60 } | 67 } |
61 | 68 |
62 const base::DictionaryValue* quic_args = nullptr; | 69 const base::DictionaryValue* quic_args = nullptr; |
63 if (dict->GetDictionary(kQuicFieldTrialName, &quic_args)) { | 70 if (dict->GetDictionary(kQuicFieldTrialName, &quic_args)) { |
64 std::string quic_connection_options; | 71 std::string quic_connection_options; |
65 if (quic_args->GetString(kQuicConnectionOptions, | 72 if (quic_args->GetString(kQuicConnectionOptions, |
66 &quic_connection_options)) { | 73 &quic_connection_options)) { |
67 context_builder->set_quic_connection_options( | 74 context_builder->set_quic_connection_options( |
68 net::QuicUtils::ParseQuicConnectionOptions(quic_connection_options)); | 75 net::QuicUtils::ParseQuicConnectionOptions(quic_connection_options)); |
69 } | 76 } |
| 77 |
| 78 bool quic_store_server_configs_in_properties = false; |
| 79 if (quic_args->GetBoolean(kQuicStoreServerConfigsInProperties, |
| 80 &quic_store_server_configs_in_properties)) { |
| 81 context_builder->set_quic_store_server_configs_in_properties( |
| 82 quic_store_server_configs_in_properties); |
| 83 } |
| 84 |
| 85 bool quic_delay_tcp_race = false; |
| 86 if (quic_args->GetBoolean(kQuicDelayTcpRace, &quic_delay_tcp_race)) { |
| 87 context_builder->set_quic_delay_tcp_race(quic_delay_tcp_race); |
| 88 } |
| 89 |
| 90 int quic_max_number_of_lossy_connections = 0; |
| 91 if (quic_args->GetInteger(kQuicMaxNumberOfLossyConnections, |
| 92 &quic_max_number_of_lossy_connections)) { |
| 93 context_builder->set_quic_max_number_of_lossy_connections( |
| 94 quic_max_number_of_lossy_connections); |
| 95 } |
| 96 |
| 97 double quic_packet_loss_threshold = 0.0; |
| 98 if (quic_args->GetDouble(kQuicPacketLossThreshold, |
| 99 &quic_packet_loss_threshold)) { |
| 100 context_builder->set_quic_packet_loss_threshold( |
| 101 quic_packet_loss_threshold); |
| 102 } |
70 } | 103 } |
71 } | 104 } |
72 | 105 |
73 } // namespace | 106 } // namespace |
74 | 107 |
75 #define DEFINE_CONTEXT_CONFIG(x) const char REQUEST_CONTEXT_CONFIG_##x[] = #x; | 108 #define DEFINE_CONTEXT_CONFIG(x) const char REQUEST_CONTEXT_CONFIG_##x[] = #x; |
76 #include "components/cronet/url_request_context_config_list.h" | 109 #include "components/cronet/url_request_context_config_list.h" |
77 #undef DEFINE_CONTEXT_CONFIG | 110 #undef DEFINE_CONTEXT_CONFIG |
78 | 111 |
79 URLRequestContextConfig::QuicHint::QuicHint() { | 112 URLRequestContextConfig::QuicHint::QuicHint() { |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 &URLRequestContextConfig::data_reduction_proxy_key); | 214 &URLRequestContextConfig::data_reduction_proxy_key); |
182 | 215 |
183 // For Testing. | 216 // For Testing. |
184 converter->RegisterCustomField<scoped_ptr<net::CertVerifier>>( | 217 converter->RegisterCustomField<scoped_ptr<net::CertVerifier>>( |
185 REQUEST_CONTEXT_CONFIG_MOCK_CERT_VERIFIER, | 218 REQUEST_CONTEXT_CONFIG_MOCK_CERT_VERIFIER, |
186 &URLRequestContextConfig::mock_cert_verifier, | 219 &URLRequestContextConfig::mock_cert_verifier, |
187 &GetMockCertVerifierFromString); | 220 &GetMockCertVerifierFromString); |
188 } | 221 } |
189 | 222 |
190 } // namespace cronet | 223 } // namespace cronet |
OLD | NEW |