Commit 14e2a1f1 authored by lilyhoughton's avatar lilyhoughton Committed by Commit bot

[cronet] Add a Builder class for UrlRequestContextConfig

This adds a Builder class for UrlRequestContextConfig, so that the rather
large constructor can be avoided when many of the arguments should remain
as their defaults.
CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.android:android_cronet_tester

Review-Url: https://codereview.chromium.org/2567093002
Cr-Commit-Position: refs/heads/master@{#442902}
parent 7b9e6bc4
......@@ -272,28 +272,18 @@ void CronetEnvironment::InitializeOnNetworkThread() {
return;
cache_path = cache_path.Append(FILE_PATH_LITERAL("cronet"));
std::unique_ptr<URLRequestContextConfig> config(new URLRequestContextConfig(
quic_enabled_, // Enable QUIC.
quic_enabled_ && quic_user_agent_id_.empty()
? getDefaultQuicUserAgentId()
: quic_user_agent_id_, // QUIC User Agent ID.
http2_enabled_, // Enable SPDY.
false, // Enable SDCH
URLRequestContextConfig::DISK, // Type of http cache.
0, // Max size of http cache in bytes.
false, // Disable caching for HTTP responses.
cache_path.value(), // Storage path for http cache and cookie storage.
user_agent_, // User-Agent request header field.
"{}", // JSON encoded experimental options.
"", // Data reduction proxy key.
"", // Data reduction proxy.
"", // Fallback data reduction proxy.
"", // Data reduction proxy secure proxy check URL.
std::move(mock_cert_verifier_), // MockCertVerifier to use for testing
// purposes.
false, // Enable network quality estimator.
true, // Enable bypassing of public key pinning for local trust anchors
"")); // Certificate verifier cache data.
URLRequestContextConfigBuilder context_config_builder;
context_config_builder.enable_quic = quic_enabled_; // Enable QUIC.
context_config_builder.enable_spdy = http2_enabled_; // Enable HTTP/2.
context_config_builder.http_cache = URLRequestContextConfig::DISK;
context_config_builder.storage_path =
cache_path.value(); // Storage path for http cache and cookie storage.
context_config_builder.user_agent =
user_agent_; // User-Agent request header field.
context_config_builder.mock_cert_verifier = std::move(
mock_cert_verifier_); // MockCertVerifier to use for testing purposes.
std::unique_ptr<URLRequestContextConfig> config =
context_config_builder.Build();
net::URLRequestContextBuilder context_builder;
......
......@@ -392,4 +392,19 @@ void URLRequestContextConfig::ConfigureURLRequestContextBuilder(
// TODO(mef): Use |config| to set cookies.
}
URLRequestContextConfigBuilder::URLRequestContextConfigBuilder() {}
URLRequestContextConfigBuilder::~URLRequestContextConfigBuilder() {}
std::unique_ptr<URLRequestContextConfig>
URLRequestContextConfigBuilder::Build() {
return base::MakeUnique<URLRequestContextConfig>(
enable_quic, quic_user_agent_id, enable_spdy, enable_sdch, http_cache,
http_cache_max_size, load_disable_cache, storage_path, user_agent,
experimental_options, data_reduction_proxy_key,
data_reduction_primary_proxy, data_reduction_fallback_proxy,
data_reduction_secure_proxy_check_url, std::move(mock_cert_verifier),
enable_network_quality_estimator,
bypass_public_key_pinning_for_local_trust_anchors, cert_verifier_data);
}
} // namespace cronet
......@@ -13,6 +13,7 @@
#include "base/memory/scoped_vector.h"
#include "base/time/time.h"
#include "net/base/hash_value.h"
#include "net/cert/cert_verifier.h"
namespace base {
class SequencedTaskRunner;
......@@ -176,6 +177,67 @@ struct URLRequestContextConfig {
DISALLOW_COPY_AND_ASSIGN(URLRequestContextConfig);
};
// Stores intermediate state for URLRequestContextConfig. Initializes with
// (mostly) sane defaults, then the appropriate member variables can be
// modified, and it can be finalized with Build().
struct URLRequestContextConfigBuilder {
URLRequestContextConfigBuilder();
~URLRequestContextConfigBuilder();
// Finalize state into a URLRequestContextConfig. Must only be called once,
// as once |mock_cert_verifier| is moved into a URLRequestContextConfig, it
// cannot be used again.
std::unique_ptr<URLRequestContextConfig> Build();
// Enable QUIC.
bool enable_quic = false;
// QUIC User Agent ID.
std::string quic_user_agent_id = "";
// Enable SPDY.
bool enable_spdy = true;
// Enable SDCH.
bool enable_sdch = false;
// Type of http cache.
URLRequestContextConfig::HttpCacheType http_cache =
URLRequestContextConfig::DISABLED;
// Max size of http cache in bytes.
int http_cache_max_size = 0;
// Disable caching for HTTP responses. Other information may be stored in
// the cache.
bool load_disable_cache = false;
// Storage path for http cache and cookie storage.
std::string storage_path = "";
// User-Agent request header field.
std::string user_agent = "";
// Experimental options encoded as a string in a JSON format containing
// experiments and their corresponding configuration options. The format
// is a JSON object with the name of the experiment as the key, and the
// configuration options as the value. An example:
// {"experiment1": {"option1": "option_value1", "option2": "option_value2",
// ...}, "experiment2: {"option3", "option_value3", ...}, ...}
std::string experimental_options = "{}";
// Enable Data Reduction Proxy with authentication key.
std::string data_reduction_proxy_key = "";
std::string data_reduction_primary_proxy = "";
std::string data_reduction_fallback_proxy = "";
std::string data_reduction_secure_proxy_check_url = "";
// Certificate verifier for testing.
std::unique_ptr<net::CertVerifier> mock_cert_verifier = nullptr;
// Enable network quality estimator.
bool enable_network_quality_estimator = false;
// Enable public key pinning bypass for local trust anchors.
bool bypass_public_key_pinning_for_local_trust_anchors = true;
// Data to populate CertVerifierCache.
std::string cert_verifier_data = "";
private:
DISALLOW_COPY_AND_ASSIGN(URLRequestContextConfigBuilder);
};
} // namespace cronet
#endif // COMPONENTS_CRONET_URL_REQUEST_CONTEXT_CONFIG_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment