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

Side by Side Diff: components/cronet/url_request_context_config.cc

Issue 586143002: Initial implementation of Cronet Async API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Sync Created 6 years, 1 month 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/json/json_reader.h"
8 #include "base/values.h"
7 #include "net/url_request/url_request_context_builder.h" 9 #include "net/url_request/url_request_context_builder.h"
8 10
9 namespace cronet { 11 namespace cronet {
10 12
11 #define DEFINE_CONTEXT_CONFIG(x) const char REQUEST_CONTEXT_CONFIG_##x[] = #x; 13 #define DEFINE_CONTEXT_CONFIG(x) const char REQUEST_CONTEXT_CONFIG_##x[] = #x;
12 #include "components/cronet/url_request_context_config_list.h" 14 #include "components/cronet/url_request_context_config_list.h"
13 #undef DEFINE_CONTEXT_CONFIG 15 #undef DEFINE_CONTEXT_CONFIG
14 16
15 URLRequestContextConfig::QuicHint::QuicHint() { 17 URLRequestContextConfig::QuicHint::QuicHint() {
16 } 18 }
(...skipping 13 matching lines...) Expand all
30 REQUEST_CONTEXT_CONFIG_QUIC_HINT_ALT_PORT, 32 REQUEST_CONTEXT_CONFIG_QUIC_HINT_ALT_PORT,
31 &URLRequestContextConfig::QuicHint::alternate_port); 33 &URLRequestContextConfig::QuicHint::alternate_port);
32 } 34 }
33 35
34 URLRequestContextConfig::URLRequestContextConfig() { 36 URLRequestContextConfig::URLRequestContextConfig() {
35 } 37 }
36 38
37 URLRequestContextConfig::~URLRequestContextConfig() { 39 URLRequestContextConfig::~URLRequestContextConfig() {
38 } 40 }
39 41
42 bool URLRequestContextConfig::LoadFromJSON(const std::string& config_string) {
43 scoped_ptr<base::Value> config_value(base::JSONReader::Read(config_string));
44 if (!config_value || !config_value->IsType(base::Value::TYPE_DICTIONARY)) {
45 DLOG(ERROR) << "Bad JSON: " << config_string;
46 return false;
47 }
48
49 base::JSONValueConverter<URLRequestContextConfig> converter;
50 if (!converter.Convert(*config_value, this)) {
51 DLOG(ERROR) << "Bad Config: " << config_value;
52 return false;
53 }
54 return true;
55 }
56
40 void URLRequestContextConfig::ConfigureURLRequestContextBuilder( 57 void URLRequestContextConfig::ConfigureURLRequestContextBuilder(
41 net::URLRequestContextBuilder* context_builder) { 58 net::URLRequestContextBuilder* context_builder) {
42 std::string config_cache; 59 std::string config_cache;
43 if (http_cache != REQUEST_CONTEXT_CONFIG_HTTP_CACHE_DISABLED) { 60 if (http_cache != REQUEST_CONTEXT_CONFIG_HTTP_CACHE_DISABLED) {
44 net::URLRequestContextBuilder::HttpCacheParams cache_params; 61 net::URLRequestContextBuilder::HttpCacheParams cache_params;
45 if (http_cache == REQUEST_CONTEXT_CONFIG_HTTP_CACHE_DISK && 62 if (http_cache == REQUEST_CONTEXT_CONFIG_HTTP_CACHE_DISK &&
46 !storage_path.empty()) { 63 !storage_path.empty()) {
47 cache_params.type = net::URLRequestContextBuilder::HttpCacheParams::DISK; 64 cache_params.type = net::URLRequestContextBuilder::HttpCacheParams::DISK;
48 cache_params.path = base::FilePath(storage_path); 65 cache_params.path = base::FilePath(storage_path);
49 } else { 66 } else {
50 cache_params.type = 67 cache_params.type =
51 net::URLRequestContextBuilder::HttpCacheParams::IN_MEMORY; 68 net::URLRequestContextBuilder::HttpCacheParams::IN_MEMORY;
52 } 69 }
53 cache_params.max_size = http_cache_max_size; 70 cache_params.max_size = http_cache_max_size;
54 context_builder->EnableHttpCache(cache_params); 71 context_builder->EnableHttpCache(cache_params);
55 } else { 72 } else {
56 context_builder->DisableHttpCache(); 73 context_builder->DisableHttpCache();
57 } 74 }
58 75 context_builder->set_user_agent(user_agent);
59 context_builder->SetSpdyAndQuicEnabled(enable_spdy, enable_quic); 76 context_builder->SetSpdyAndQuicEnabled(enable_spdy, enable_quic);
60 // TODO(mef): Use |config| to set cookies. 77 // TODO(mef): Use |config| to set cookies.
61 } 78 }
62 79
63 // static 80 // static
64 void URLRequestContextConfig::RegisterJSONConverter( 81 void URLRequestContextConfig::RegisterJSONConverter(
65 base::JSONValueConverter<URLRequestContextConfig>* converter) { 82 base::JSONValueConverter<URLRequestContextConfig>* converter) {
83 converter->RegisterStringField(REQUEST_CONTEXT_CONFIG_USER_AGENT,
84 &URLRequestContextConfig::user_agent);
85 converter->RegisterStringField(REQUEST_CONTEXT_CONFIG_STORAGE_PATH,
86 &URLRequestContextConfig::storage_path);
66 converter->RegisterBoolField(REQUEST_CONTEXT_CONFIG_ENABLE_QUIC, 87 converter->RegisterBoolField(REQUEST_CONTEXT_CONFIG_ENABLE_QUIC,
67 &URLRequestContextConfig::enable_quic); 88 &URLRequestContextConfig::enable_quic);
68 converter->RegisterBoolField(REQUEST_CONTEXT_CONFIG_ENABLE_SPDY, 89 converter->RegisterBoolField(REQUEST_CONTEXT_CONFIG_ENABLE_SPDY,
69 &URLRequestContextConfig::enable_spdy); 90 &URLRequestContextConfig::enable_spdy);
70 converter->RegisterStringField(REQUEST_CONTEXT_CONFIG_HTTP_CACHE, 91 converter->RegisterStringField(REQUEST_CONTEXT_CONFIG_HTTP_CACHE,
71 &URLRequestContextConfig::http_cache); 92 &URLRequestContextConfig::http_cache);
72 converter->RegisterIntField(REQUEST_CONTEXT_CONFIG_HTTP_CACHE_MAX_SIZE, 93 converter->RegisterIntField(REQUEST_CONTEXT_CONFIG_HTTP_CACHE_MAX_SIZE,
73 &URLRequestContextConfig::http_cache_max_size); 94 &URLRequestContextConfig::http_cache_max_size);
74 converter->RegisterStringField(REQUEST_CONTEXT_CONFIG_STORAGE_PATH,
75 &URLRequestContextConfig::storage_path);
76 converter->RegisterRepeatedMessage(REQUEST_CONTEXT_CONFIG_QUIC_HINTS, 95 converter->RegisterRepeatedMessage(REQUEST_CONTEXT_CONFIG_QUIC_HINTS,
77 &URLRequestContextConfig::quic_hints); 96 &URLRequestContextConfig::quic_hints);
78 } 97 }
79 98
80 } // namespace cronet 99 } // namespace cronet
OLDNEW
« no previous file with comments | « components/cronet/url_request_context_config.h ('k') | components/cronet/url_request_context_config_list.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698