Update V8 to version 4.5.32.
[chromium-blink-merge.git] / components / cronet / url_request_context_config.cc
blob201f9d30f291897c431fb3e55db57136c58c6a5a
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 context_builder->set_sdch_enabled(enable_sdch);
82 // TODO(mef): Use |config| to set cookies.
85 // static
86 void URLRequestContextConfig::RegisterJSONConverter(
87 base::JSONValueConverter<URLRequestContextConfig>* converter) {
88 converter->RegisterStringField(REQUEST_CONTEXT_CONFIG_USER_AGENT,
89 &URLRequestContextConfig::user_agent);
90 converter->RegisterStringField(REQUEST_CONTEXT_CONFIG_STORAGE_PATH,
91 &URLRequestContextConfig::storage_path);
92 converter->RegisterBoolField(REQUEST_CONTEXT_CONFIG_ENABLE_QUIC,
93 &URLRequestContextConfig::enable_quic);
94 converter->RegisterBoolField(REQUEST_CONTEXT_CONFIG_ENABLE_SPDY,
95 &URLRequestContextConfig::enable_spdy);
96 converter->RegisterBoolField(REQUEST_CONTEXT_CONFIG_ENABLE_SDCH,
97 &URLRequestContextConfig::enable_sdch);
98 converter->RegisterStringField(REQUEST_CONTEXT_CONFIG_HTTP_CACHE,
99 &URLRequestContextConfig::http_cache);
100 converter->RegisterBoolField(REQUEST_CONTEXT_CONFIG_LOAD_DISABLE_CACHE,
101 &URLRequestContextConfig::load_disable_cache);
102 converter->RegisterIntField(REQUEST_CONTEXT_CONFIG_HTTP_CACHE_MAX_SIZE,
103 &URLRequestContextConfig::http_cache_max_size);
104 converter->RegisterRepeatedMessage(REQUEST_CONTEXT_CONFIG_QUIC_HINTS,
105 &URLRequestContextConfig::quic_hints);
106 converter->RegisterStringField(
107 REQUEST_CONTEXT_CONFIG_QUIC_OPTIONS,
108 &URLRequestContextConfig::quic_connection_options);
109 converter->RegisterStringField(
110 REQUEST_CONTEXT_CONFIG_DATA_REDUCTION_PRIMARY_PROXY,
111 &URLRequestContextConfig::data_reduction_primary_proxy);
112 converter->RegisterStringField(
113 REQUEST_CONTEXT_CONFIG_DATA_REDUCTION_FALLBACK_PROXY,
114 &URLRequestContextConfig::data_reduction_fallback_proxy);
115 converter->RegisterStringField(
116 REQUEST_CONTEXT_CONFIG_DATA_REDUCTION_SECURE_PROXY_CHECK_URL,
117 &URLRequestContextConfig::data_reduction_secure_proxy_check_url);
118 converter->RegisterStringField(
119 REQUEST_CONTEXT_CONFIG_DATA_REDUCTION_PROXY_KEY,
120 &URLRequestContextConfig::data_reduction_proxy_key);
123 } // namespace cronet