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.
4
5#include "components/cronet/url_request_context_config.h"
6
7#include "net/url_request/url_request_context_builder.h"
8
9namespace cronet {
10
11#define DEFINE_CONTEXT_CONFIG(x) const char REQUEST_CONTEXT_CONFIG_##x[] = #x;
12#include "components/cronet/url_request_context_config_list.h"
13#undef DEFINE_CONTEXT_CONFIG
14
15URLRequestContextConfig::QuicHint::QuicHint() {
16}
17
18URLRequestContextConfig::QuicHint::~QuicHint() {
19}
20
21// static
22void URLRequestContextConfig::QuicHint::RegisterJSONConverter(
23    base::JSONValueConverter<URLRequestContextConfig::QuicHint>* converter) {
24  converter->RegisterStringField(REQUEST_CONTEXT_CONFIG_QUIC_HINT_HOST,
25                                 &URLRequestContextConfig::QuicHint::host);
26  converter->RegisterIntField(
27      REQUEST_CONTEXT_CONFIG_QUIC_HINT_PORT,
28      &URLRequestContextConfig::QuicHint::port);
29  converter->RegisterIntField(
30      REQUEST_CONTEXT_CONFIG_QUIC_HINT_ALT_PORT,
31      &URLRequestContextConfig::QuicHint::alternate_port);
32}
33
34URLRequestContextConfig::URLRequestContextConfig() {
35}
36
37URLRequestContextConfig::~URLRequestContextConfig() {
38}
39
40void URLRequestContextConfig::ConfigureURLRequestContextBuilder(
41    net::URLRequestContextBuilder* context_builder) {
42  std::string config_cache;
43  if (http_cache != REQUEST_CONTEXT_CONFIG_HTTP_CACHE_DISABLED) {
44    net::URLRequestContextBuilder::HttpCacheParams cache_params;
45    if (http_cache == REQUEST_CONTEXT_CONFIG_HTTP_CACHE_DISK &&
46        !storage_path.empty()) {
47      cache_params.type = net::URLRequestContextBuilder::HttpCacheParams::DISK;
48      cache_params.path = base::FilePath(storage_path);
49    } else {
50      cache_params.type =
51          net::URLRequestContextBuilder::HttpCacheParams::IN_MEMORY;
52    }
53    cache_params.max_size = http_cache_max_size;
54    context_builder->EnableHttpCache(cache_params);
55  } else {
56    context_builder->DisableHttpCache();
57  }
58
59  context_builder->SetSpdyAndQuicEnabled(enable_spdy, enable_quic);
60  // TODO(mef): Use |config| to set cookies.
61}
62
63// static
64void URLRequestContextConfig::RegisterJSONConverter(
65    base::JSONValueConverter<URLRequestContextConfig>* converter) {
66  converter->RegisterBoolField(REQUEST_CONTEXT_CONFIG_ENABLE_QUIC,
67                               &URLRequestContextConfig::enable_quic);
68  converter->RegisterBoolField(REQUEST_CONTEXT_CONFIG_ENABLE_SPDY,
69                               &URLRequestContextConfig::enable_spdy);
70  converter->RegisterStringField(REQUEST_CONTEXT_CONFIG_HTTP_CACHE,
71                                 &URLRequestContextConfig::http_cache);
72  converter->RegisterIntField(REQUEST_CONTEXT_CONFIG_HTTP_CACHE_MAX_SIZE,
73                              &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,
77                                     &URLRequestContextConfig::quic_hints);
78}
79
80}  // namespace cronet
81