Make castv2 performance test work.
[chromium-blink-merge.git] / components / cronet / url_request_context_config.cc
blob0aa208977dd12a6d5289c99fd788f968b6b0b54b
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
3 // found in the LICENSE file.
5 #include "components/cronet/url_request_context_config.h"
7 #include "base/json/json_reader.h"
8 #include "base/values.h"
9 #include "net/quic/quic_protocol.h"
10 #include "net/quic/quic_utils.h"
11 #include "net/url_request/url_request_context_builder.h"
13 namespace cronet {
15 #define DEFINE_CONTEXT_CONFIG(x) const char REQUEST_CONTEXT_CONFIG_##x[] = #x;
16 #include "components/cronet/url_request_context_config_list.h"
17 #undef DEFINE_CONTEXT_CONFIG
19 URLRequestContextConfig::QuicHint::QuicHint() {
22 URLRequestContextConfig::QuicHint::~QuicHint() {
25 // static
26 void URLRequestContextConfig::QuicHint::RegisterJSONConverter(
27 base::JSONValueConverter<URLRequestContextConfig::QuicHint>* converter) {
28 converter->RegisterStringField(REQUEST_CONTEXT_CONFIG_QUIC_HINT_HOST,
29 &URLRequestContextConfig::QuicHint::host);
30 converter->RegisterIntField(
31 REQUEST_CONTEXT_CONFIG_QUIC_HINT_PORT,
32 &URLRequestContextConfig::QuicHint::port);
33 converter->RegisterIntField(
34 REQUEST_CONTEXT_CONFIG_QUIC_HINT_ALT_PORT,
35 &URLRequestContextConfig::QuicHint::alternate_port);
38 URLRequestContextConfig::URLRequestContextConfig() {
41 URLRequestContextConfig::~URLRequestContextConfig() {
44 bool URLRequestContextConfig::LoadFromJSON(const std::string& config_string) {
45 scoped_ptr<base::Value> config_value(base::JSONReader::Read(config_string));
46 if (!config_value || !config_value->IsType(base::Value::TYPE_DICTIONARY)) {
47 DLOG(ERROR) << "Bad JSON: " << config_string;
48 return false;
51 base::JSONValueConverter<URLRequestContextConfig> converter;
52 if (!converter.Convert(*config_value, this)) {
53 DLOG(ERROR) << "Bad Config: " << config_value;
54 return false;
56 return true;
59 void URLRequestContextConfig::ConfigureURLRequestContextBuilder(
60 net::URLRequestContextBuilder* context_builder) {
61 std::string config_cache;
62 if (http_cache != REQUEST_CONTEXT_CONFIG_HTTP_CACHE_DISABLED) {
63 net::URLRequestContextBuilder::HttpCacheParams cache_params;
64 if (http_cache == REQUEST_CONTEXT_CONFIG_HTTP_CACHE_DISK &&
65 !storage_path.empty()) {
66 cache_params.type = net::URLRequestContextBuilder::HttpCacheParams::DISK;
67 cache_params.path = base::FilePath(storage_path);
68 } else {
69 cache_params.type =
70 net::URLRequestContextBuilder::HttpCacheParams::IN_MEMORY;
72 cache_params.max_size = http_cache_max_size;
73 context_builder->EnableHttpCache(cache_params);
74 } else {
75 context_builder->DisableHttpCache();
77 context_builder->set_user_agent(user_agent);
78 context_builder->SetSpdyAndQuicEnabled(enable_spdy, enable_quic);
79 context_builder->set_quic_connection_options(
80 net::QuicUtils::ParseQuicConnectionOptions(quic_connection_options));
81 // TODO(mef): Use |config| to set cookies.
84 // static
85 void URLRequestContextConfig::RegisterJSONConverter(
86 base::JSONValueConverter<URLRequestContextConfig>* converter) {
87 converter->RegisterStringField(REQUEST_CONTEXT_CONFIG_USER_AGENT,
88 &URLRequestContextConfig::user_agent);
89 converter->RegisterStringField(REQUEST_CONTEXT_CONFIG_STORAGE_PATH,
90 &URLRequestContextConfig::storage_path);
91 converter->RegisterBoolField(REQUEST_CONTEXT_CONFIG_ENABLE_QUIC,
92 &URLRequestContextConfig::enable_quic);
93 converter->RegisterBoolField(REQUEST_CONTEXT_CONFIG_ENABLE_SPDY,
94 &URLRequestContextConfig::enable_spdy);
95 converter->RegisterStringField(REQUEST_CONTEXT_CONFIG_HTTP_CACHE,
96 &URLRequestContextConfig::http_cache);
97 converter->RegisterBoolField(REQUEST_CONTEXT_CONFIG_LOAD_DISABLE_CACHE,
98 &URLRequestContextConfig::load_disable_cache);
99 converter->RegisterIntField(REQUEST_CONTEXT_CONFIG_HTTP_CACHE_MAX_SIZE,
100 &URLRequestContextConfig::http_cache_max_size);
101 converter->RegisterRepeatedMessage(REQUEST_CONTEXT_CONFIG_QUIC_HINTS,
102 &URLRequestContextConfig::quic_hints);
103 converter->RegisterStringField(
104 REQUEST_CONTEXT_CONFIG_QUIC_OPTIONS,
105 &URLRequestContextConfig::quic_connection_options);
108 } // namespace cronet