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

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 Paul'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 bool GetMockCertVerifierFromString(
23 const base::StringPiece& mock_cert_verifier_string,
24 scoped_ptr<net::CertVerifier>* result) {
pauljensen 2015/10/20 13:53:58 passing pointers to scoped_ptr's is strictly forba
xunjieli 2015/10/20 15:23:11 Done.
25 int64 val;
26 bool success = base::StringToInt64(mock_cert_verifier_string, &val);
27 *result = make_scoped_ptr(reinterpret_cast<net::CertVerifier*>(val));
28 return success;
29 }
30
31 } // namespace
32
15 #define DEFINE_CONTEXT_CONFIG(x) const char REQUEST_CONTEXT_CONFIG_##x[] = #x; 33 #define DEFINE_CONTEXT_CONFIG(x) const char REQUEST_CONTEXT_CONFIG_##x[] = #x;
16 #include "components/cronet/url_request_context_config_list.h" 34 #include "components/cronet/url_request_context_config_list.h"
17 #undef DEFINE_CONTEXT_CONFIG 35 #undef DEFINE_CONTEXT_CONFIG
18 36
19 URLRequestContextConfig::QuicHint::QuicHint() { 37 URLRequestContextConfig::QuicHint::QuicHint() {
20 } 38 }
21 39
22 URLRequestContextConfig::QuicHint::~QuicHint() { 40 URLRequestContextConfig::QuicHint::~QuicHint() {
23 } 41 }
24 42
25 // static 43 // static
26 void URLRequestContextConfig::QuicHint::RegisterJSONConverter( 44 void URLRequestContextConfig::QuicHint::RegisterJSONConverter(
27 base::JSONValueConverter<URLRequestContextConfig::QuicHint>* converter) { 45 base::JSONValueConverter<URLRequestContextConfig::QuicHint>* converter) {
28 converter->RegisterStringField(REQUEST_CONTEXT_CONFIG_QUIC_HINT_HOST, 46 converter->RegisterStringField(REQUEST_CONTEXT_CONFIG_QUIC_HINT_HOST,
29 &URLRequestContextConfig::QuicHint::host); 47 &URLRequestContextConfig::QuicHint::host);
30 converter->RegisterIntField( 48 converter->RegisterIntField(
31 REQUEST_CONTEXT_CONFIG_QUIC_HINT_PORT, 49 REQUEST_CONTEXT_CONFIG_QUIC_HINT_PORT,
32 &URLRequestContextConfig::QuicHint::port); 50 &URLRequestContextConfig::QuicHint::port);
33 converter->RegisterIntField( 51 converter->RegisterIntField(
34 REQUEST_CONTEXT_CONFIG_QUIC_HINT_ALT_PORT, 52 REQUEST_CONTEXT_CONFIG_QUIC_HINT_ALT_PORT,
35 &URLRequestContextConfig::QuicHint::alternate_port); 53 &URLRequestContextConfig::QuicHint::alternate_port);
36 } 54 }
37 55
38 URLRequestContextConfig::URLRequestContextConfig() { 56 URLRequestContextConfig::URLRequestContextConfig()
39 } 57 : mock_cert_verifier(nullptr) {}
pauljensen 2015/10/20 13:53:58 unnecessary, remove
xunjieli 2015/10/20 15:23:11 Done.
40 58
41 URLRequestContextConfig::~URLRequestContextConfig() { 59 URLRequestContextConfig::~URLRequestContextConfig() {
42 } 60 }
43 61
44 bool URLRequestContextConfig::LoadFromJSON(const std::string& config_string) { 62 bool URLRequestContextConfig::LoadFromJSON(const std::string& config_string) {
45 scoped_ptr<base::Value> config_value = base::JSONReader::Read(config_string); 63 scoped_ptr<base::Value> config_value = base::JSONReader::Read(config_string);
46 if (!config_value || !config_value->IsType(base::Value::TYPE_DICTIONARY)) { 64 if (!config_value || !config_value->IsType(base::Value::TYPE_DICTIONARY)) {
47 DLOG(ERROR) << "Bad JSON: " << config_string; 65 DLOG(ERROR) << "Bad JSON: " << config_string;
48 return false; 66 return false;
49 } 67 }
(...skipping 22 matching lines...) Expand all
72 cache_params.max_size = http_cache_max_size; 90 cache_params.max_size = http_cache_max_size;
73 context_builder->EnableHttpCache(cache_params); 91 context_builder->EnableHttpCache(cache_params);
74 } else { 92 } else {
75 context_builder->DisableHttpCache(); 93 context_builder->DisableHttpCache();
76 } 94 }
77 context_builder->set_user_agent(user_agent); 95 context_builder->set_user_agent(user_agent);
78 context_builder->SetSpdyAndQuicEnabled(enable_spdy, enable_quic); 96 context_builder->SetSpdyAndQuicEnabled(enable_spdy, enable_quic);
79 context_builder->set_quic_connection_options( 97 context_builder->set_quic_connection_options(
80 net::QuicUtils::ParseQuicConnectionOptions(quic_connection_options)); 98 net::QuicUtils::ParseQuicConnectionOptions(quic_connection_options));
81 context_builder->set_sdch_enabled(enable_sdch); 99 context_builder->set_sdch_enabled(enable_sdch);
82 100 if (mock_cert_verifier)
101 context_builder->SetCertVerifier(mock_cert_verifier.Pass());
83 } 102 }
84 103
85 // static 104 // static
86 void URLRequestContextConfig::RegisterJSONConverter( 105 void URLRequestContextConfig::RegisterJSONConverter(
87 base::JSONValueConverter<URLRequestContextConfig>* converter) { 106 base::JSONValueConverter<URLRequestContextConfig>* converter) {
88 converter->RegisterStringField(REQUEST_CONTEXT_CONFIG_USER_AGENT, 107 converter->RegisterStringField(REQUEST_CONTEXT_CONFIG_USER_AGENT,
89 &URLRequestContextConfig::user_agent); 108 &URLRequestContextConfig::user_agent);
90 converter->RegisterStringField(REQUEST_CONTEXT_CONFIG_STORAGE_PATH, 109 converter->RegisterStringField(REQUEST_CONTEXT_CONFIG_STORAGE_PATH,
91 &URLRequestContextConfig::storage_path); 110 &URLRequestContextConfig::storage_path);
92 converter->RegisterBoolField(REQUEST_CONTEXT_CONFIG_ENABLE_QUIC, 111 converter->RegisterBoolField(REQUEST_CONTEXT_CONFIG_ENABLE_QUIC,
(...skipping 18 matching lines...) Expand all
111 &URLRequestContextConfig::data_reduction_primary_proxy); 130 &URLRequestContextConfig::data_reduction_primary_proxy);
112 converter->RegisterStringField( 131 converter->RegisterStringField(
113 REQUEST_CONTEXT_CONFIG_DATA_REDUCTION_FALLBACK_PROXY, 132 REQUEST_CONTEXT_CONFIG_DATA_REDUCTION_FALLBACK_PROXY,
114 &URLRequestContextConfig::data_reduction_fallback_proxy); 133 &URLRequestContextConfig::data_reduction_fallback_proxy);
115 converter->RegisterStringField( 134 converter->RegisterStringField(
116 REQUEST_CONTEXT_CONFIG_DATA_REDUCTION_SECURE_PROXY_CHECK_URL, 135 REQUEST_CONTEXT_CONFIG_DATA_REDUCTION_SECURE_PROXY_CHECK_URL,
117 &URLRequestContextConfig::data_reduction_secure_proxy_check_url); 136 &URLRequestContextConfig::data_reduction_secure_proxy_check_url);
118 converter->RegisterStringField( 137 converter->RegisterStringField(
119 REQUEST_CONTEXT_CONFIG_DATA_REDUCTION_PROXY_KEY, 138 REQUEST_CONTEXT_CONFIG_DATA_REDUCTION_PROXY_KEY,
120 &URLRequestContextConfig::data_reduction_proxy_key); 139 &URLRequestContextConfig::data_reduction_proxy_key);
140
141 // For Testing.
142 converter->RegisterCustomField<scoped_ptr<net::CertVerifier>>(
143 REQUEST_CONTEXT_CONFIG_MOCK_CERT_VERIFIER,
144 &URLRequestContextConfig::mock_cert_verifier,
145 &GetMockCertVerifierFromString);
121 } 146 }
122 147
123 } // namespace cronet 148 } // namespace cronet
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698