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

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

Powered by Google App Engine
This is Rietveld 408576698