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"; | |
31 | 25 |
32 // 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 |
33 // RegisterCustomField. | 27 // RegisterCustomField. |
34 // TODO(xunjieli): Remove this once crbug.com/544976 is fixed. | 28 // TODO(xunjieli): Remove this once crbug.com/544976 is fixed. |
35 bool GetMockCertVerifierFromString( | 29 bool GetMockCertVerifierFromString( |
36 const base::StringPiece& mock_cert_verifier_string, | 30 const base::StringPiece& mock_cert_verifier_string, |
37 scoped_ptr<net::CertVerifier>* result) { | 31 scoped_ptr<net::CertVerifier>* result) { |
38 int64 val; | 32 int64 val; |
39 bool success = base::StringToInt64(mock_cert_verifier_string, &val); | 33 bool success = base::StringToInt64(mock_cert_verifier_string, &val); |
40 *result = make_scoped_ptr(reinterpret_cast<net::CertVerifier*>(val)); | 34 *result = make_scoped_ptr(reinterpret_cast<net::CertVerifier*>(val)); |
41 return success; | 35 return success; |
42 } | 36 } |
43 | 37 |
44 void ParseAndSetExperimentalOptions( | 38 void ParseAndSetExperimentalOptions( |
45 const std::string& experimental_options, | 39 const std::string& experimental_options, |
46 net::URLRequestContextBuilder* context_builder) { | 40 net::URLRequestContextBuilder* context_builder) { |
47 if (experimental_options.empty()) | 41 if (experimental_options.empty()) |
48 return; | 42 return; |
49 | 43 |
50 DVLOG(1) << "Experimental Options:" << experimental_options; | |
51 scoped_ptr<base::Value> options = | 44 scoped_ptr<base::Value> options = |
52 base::JSONReader::Read(experimental_options); | 45 base::JSONReader::Read(experimental_options); |
53 | 46 |
54 if (!options) { | 47 if (!options) { |
55 DCHECK(false) << "Parsing experimental options failed: " | 48 DCHECK(false) << "Parsing experimental options failed: " |
56 << experimental_options; | 49 << experimental_options; |
57 return; | 50 return; |
58 } | 51 } |
59 | 52 |
60 scoped_ptr<base::DictionaryValue> dict = | 53 scoped_ptr<base::DictionaryValue> dict = |
61 base::DictionaryValue::From(options.Pass()); | 54 base::DictionaryValue::From(options.Pass()); |
62 | 55 |
63 if (!dict) { | 56 if (!dict) { |
64 DCHECK(false) << "Experimental options string is not a dictionary: " | 57 DCHECK(false) << "Experimental options string is not a dictionary: " |
65 << experimental_options; | 58 << experimental_options; |
66 return; | 59 return; |
67 } | 60 } |
68 | 61 |
69 const base::DictionaryValue* quic_args = nullptr; | 62 const base::DictionaryValue* quic_args = nullptr; |
70 if (dict->GetDictionary(kQuicFieldTrialName, &quic_args)) { | 63 if (dict->GetDictionary(kQuicFieldTrialName, &quic_args)) { |
71 std::string quic_connection_options; | 64 std::string quic_connection_options; |
72 if (quic_args->GetString(kQuicConnectionOptions, | 65 if (quic_args->GetString(kQuicConnectionOptions, |
73 &quic_connection_options)) { | 66 &quic_connection_options)) { |
74 context_builder->set_quic_connection_options( | 67 context_builder->set_quic_connection_options( |
75 net::QuicUtils::ParseQuicConnectionOptions(quic_connection_options)); | 68 net::QuicUtils::ParseQuicConnectionOptions(quic_connection_options)); |
76 } | 69 } |
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 } | |
103 } | 70 } |
104 } | 71 } |
105 | 72 |
106 } // namespace | 73 } // namespace |
107 | 74 |
108 #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; |
109 #include "components/cronet/url_request_context_config_list.h" | 76 #include "components/cronet/url_request_context_config_list.h" |
110 #undef DEFINE_CONTEXT_CONFIG | 77 #undef DEFINE_CONTEXT_CONFIG |
111 | 78 |
112 URLRequestContextConfig::QuicHint::QuicHint() { | 79 URLRequestContextConfig::QuicHint::QuicHint() { |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 &URLRequestContextConfig::data_reduction_proxy_key); | 181 &URLRequestContextConfig::data_reduction_proxy_key); |
215 | 182 |
216 // For Testing. | 183 // For Testing. |
217 converter->RegisterCustomField<scoped_ptr<net::CertVerifier>>( | 184 converter->RegisterCustomField<scoped_ptr<net::CertVerifier>>( |
218 REQUEST_CONTEXT_CONFIG_MOCK_CERT_VERIFIER, | 185 REQUEST_CONTEXT_CONFIG_MOCK_CERT_VERIFIER, |
219 &URLRequestContextConfig::mock_cert_verifier, | 186 &URLRequestContextConfig::mock_cert_verifier, |
220 &GetMockCertVerifierFromString); | 187 &GetMockCertVerifierFromString); |
221 } | 188 } |
222 | 189 |
223 } // namespace cronet | 190 } // namespace cronet |
OLD | NEW |