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

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

Issue 1389213003: [Cronet] Use Https for Quic Test Server (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ryancl
Patch Set: Address Misha's comments Created 5 years, 2 months 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/json/json_reader.h" 8 #include "base/json/json_reader.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/strings/string_number_conversions.h"
11 #include "base/strings/string_piece.h"
8 #include "base/values.h" 12 #include "base/values.h"
13 #include "net/cert/cert_verifier.h"
9 #include "net/quic/quic_protocol.h" 14 #include "net/quic/quic_protocol.h"
10 #include "net/quic/quic_utils.h" 15 #include "net/quic/quic_utils.h"
11 #include "net/url_request/url_request_context_builder.h" 16 #include "net/url_request/url_request_context_builder.h"
12 17
13 namespace cronet { 18 namespace cronet {
14 19
20 namespace {
21
22 // Using a reference to scoped_ptr is unavoidable because of the semantics of
23 // RegisterCustomField.
24 // TODO(xunjieli): Remove this once crbug.com/544976 is fixed.
25 bool GetMockCertVerifierFromString(
26 const base::StringPiece& mock_cert_verifier_string,
27 scoped_ptr<net::CertVerifier>* result) {
28 int64 val;
29 bool success = base::StringToInt64(mock_cert_verifier_string, &val);
30 *result = make_scoped_ptr(reinterpret_cast<net::CertVerifier*>(val));
31 return success;
32 }
33
34 } // namespace
35
15 #define DEFINE_CONTEXT_CONFIG(x) const char REQUEST_CONTEXT_CONFIG_##x[] = #x; 36 #define DEFINE_CONTEXT_CONFIG(x) const char REQUEST_CONTEXT_CONFIG_##x[] = #x;
16 #include "components/cronet/url_request_context_config_list.h" 37 #include "components/cronet/url_request_context_config_list.h"
17 #undef DEFINE_CONTEXT_CONFIG 38 #undef DEFINE_CONTEXT_CONFIG
18 39
19 URLRequestContextConfig::QuicHint::QuicHint() { 40 URLRequestContextConfig::QuicHint::QuicHint() {
20 } 41 }
21 42
22 URLRequestContextConfig::QuicHint::~QuicHint() { 43 URLRequestContextConfig::QuicHint::~QuicHint() {
23 } 44 }
24 45
25 // static 46 // static
26 void URLRequestContextConfig::QuicHint::RegisterJSONConverter( 47 void URLRequestContextConfig::QuicHint::RegisterJSONConverter(
27 base::JSONValueConverter<URLRequestContextConfig::QuicHint>* converter) { 48 base::JSONValueConverter<URLRequestContextConfig::QuicHint>* converter) {
28 converter->RegisterStringField(REQUEST_CONTEXT_CONFIG_QUIC_HINT_HOST, 49 converter->RegisterStringField(REQUEST_CONTEXT_CONFIG_QUIC_HINT_HOST,
29 &URLRequestContextConfig::QuicHint::host); 50 &URLRequestContextConfig::QuicHint::host);
30 converter->RegisterIntField( 51 converter->RegisterIntField(
31 REQUEST_CONTEXT_CONFIG_QUIC_HINT_PORT, 52 REQUEST_CONTEXT_CONFIG_QUIC_HINT_PORT,
32 &URLRequestContextConfig::QuicHint::port); 53 &URLRequestContextConfig::QuicHint::port);
33 converter->RegisterIntField( 54 converter->RegisterIntField(
34 REQUEST_CONTEXT_CONFIG_QUIC_HINT_ALT_PORT, 55 REQUEST_CONTEXT_CONFIG_QUIC_HINT_ALT_PORT,
35 &URLRequestContextConfig::QuicHint::alternate_port); 56 &URLRequestContextConfig::QuicHint::alternate_port);
36 } 57 }
37 58
38 URLRequestContextConfig::URLRequestContextConfig() { 59 URLRequestContextConfig::URLRequestContextConfig() {}
39 }
40 60
41 URLRequestContextConfig::~URLRequestContextConfig() { 61 URLRequestContextConfig::~URLRequestContextConfig() {
42 } 62 }
43 63
44 bool URLRequestContextConfig::LoadFromJSON(const std::string& config_string) { 64 bool URLRequestContextConfig::LoadFromJSON(const std::string& config_string) {
45 scoped_ptr<base::Value> config_value = base::JSONReader::Read(config_string); 65 scoped_ptr<base::Value> config_value = base::JSONReader::Read(config_string);
46 if (!config_value || !config_value->IsType(base::Value::TYPE_DICTIONARY)) { 66 if (!config_value || !config_value->IsType(base::Value::TYPE_DICTIONARY)) {
47 DLOG(ERROR) << "Bad JSON: " << config_string; 67 DLOG(ERROR) << "Bad JSON: " << config_string;
48 return false; 68 return false;
49 } 69 }
(...skipping 22 matching lines...) Expand all
72 cache_params.max_size = http_cache_max_size; 92 cache_params.max_size = http_cache_max_size;
73 context_builder->EnableHttpCache(cache_params); 93 context_builder->EnableHttpCache(cache_params);
74 } else { 94 } else {
75 context_builder->DisableHttpCache(); 95 context_builder->DisableHttpCache();
76 } 96 }
77 context_builder->set_user_agent(user_agent); 97 context_builder->set_user_agent(user_agent);
78 context_builder->SetSpdyAndQuicEnabled(enable_spdy, enable_quic); 98 context_builder->SetSpdyAndQuicEnabled(enable_spdy, enable_quic);
79 context_builder->set_quic_connection_options( 99 context_builder->set_quic_connection_options(
80 net::QuicUtils::ParseQuicConnectionOptions(quic_connection_options)); 100 net::QuicUtils::ParseQuicConnectionOptions(quic_connection_options));
81 context_builder->set_sdch_enabled(enable_sdch); 101 context_builder->set_sdch_enabled(enable_sdch);
82 #if defined(CRONET_TEST) 102 if (mock_cert_verifier)
83 // Enable insecure quic only if Cronet is built for testing. 103 context_builder->SetCertVerifier(mock_cert_verifier.Pass());
84 // TODO(xunjieli): Remove once crbug.com/514629 is fixed.
85 context_builder->set_enable_insecure_quic(true);
86 #endif
87 // TODO(mef): Use |config| to set cookies. 104 // TODO(mef): Use |config| to set cookies.
88 } 105 }
89 106
90 // static 107 // static
91 void URLRequestContextConfig::RegisterJSONConverter( 108 void URLRequestContextConfig::RegisterJSONConverter(
92 base::JSONValueConverter<URLRequestContextConfig>* converter) { 109 base::JSONValueConverter<URLRequestContextConfig>* converter) {
93 converter->RegisterStringField(REQUEST_CONTEXT_CONFIG_USER_AGENT, 110 converter->RegisterStringField(REQUEST_CONTEXT_CONFIG_USER_AGENT,
94 &URLRequestContextConfig::user_agent); 111 &URLRequestContextConfig::user_agent);
95 converter->RegisterStringField(REQUEST_CONTEXT_CONFIG_STORAGE_PATH, 112 converter->RegisterStringField(REQUEST_CONTEXT_CONFIG_STORAGE_PATH,
96 &URLRequestContextConfig::storage_path); 113 &URLRequestContextConfig::storage_path);
(...skipping 19 matching lines...) Expand all
116 &URLRequestContextConfig::data_reduction_primary_proxy); 133 &URLRequestContextConfig::data_reduction_primary_proxy);
117 converter->RegisterStringField( 134 converter->RegisterStringField(
118 REQUEST_CONTEXT_CONFIG_DATA_REDUCTION_FALLBACK_PROXY, 135 REQUEST_CONTEXT_CONFIG_DATA_REDUCTION_FALLBACK_PROXY,
119 &URLRequestContextConfig::data_reduction_fallback_proxy); 136 &URLRequestContextConfig::data_reduction_fallback_proxy);
120 converter->RegisterStringField( 137 converter->RegisterStringField(
121 REQUEST_CONTEXT_CONFIG_DATA_REDUCTION_SECURE_PROXY_CHECK_URL, 138 REQUEST_CONTEXT_CONFIG_DATA_REDUCTION_SECURE_PROXY_CHECK_URL,
122 &URLRequestContextConfig::data_reduction_secure_proxy_check_url); 139 &URLRequestContextConfig::data_reduction_secure_proxy_check_url);
123 converter->RegisterStringField( 140 converter->RegisterStringField(
124 REQUEST_CONTEXT_CONFIG_DATA_REDUCTION_PROXY_KEY, 141 REQUEST_CONTEXT_CONFIG_DATA_REDUCTION_PROXY_KEY,
125 &URLRequestContextConfig::data_reduction_proxy_key); 142 &URLRequestContextConfig::data_reduction_proxy_key);
143
144 // For Testing.
145 converter->RegisterCustomField<scoped_ptr<net::CertVerifier>>(
146 REQUEST_CONTEXT_CONFIG_MOCK_CERT_VERIFIER,
147 &URLRequestContextConfig::mock_cert_verifier,
148 &GetMockCertVerifierFromString);
126 } 149 }
127 150
128 } // namespace cronet 151 } // 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