Home | History | Annotate | Download | only in cronet
      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 
      9 namespace 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 
     15 URLRequestContextConfig::URLRequestContextConfig() {
     16 }
     17 
     18 URLRequestContextConfig::~URLRequestContextConfig() {
     19 }
     20 
     21 void URLRequestContextConfig::ConfigureURLRequestContextBuilder(
     22     net::URLRequestContextBuilder* context_builder) {
     23   std::string config_cache;
     24   if (http_cache != REQUEST_CONTEXT_CONFIG_HTTP_CACHE_DISABLED) {
     25     net::URLRequestContextBuilder::HttpCacheParams cache_params;
     26     if (http_cache == REQUEST_CONTEXT_CONFIG_HTTP_CACHE_DISK &&
     27         !storage_path.empty()) {
     28       cache_params.type = net::URLRequestContextBuilder::HttpCacheParams::DISK;
     29       cache_params.path = base::FilePath(storage_path);
     30     } else {
     31       cache_params.type =
     32           net::URLRequestContextBuilder::HttpCacheParams::IN_MEMORY;
     33     }
     34     cache_params.max_size = http_cache_max_size;
     35     context_builder->EnableHttpCache(cache_params);
     36   } else {
     37     context_builder->DisableHttpCache();
     38   }
     39 
     40   context_builder->SetSpdyAndQuicEnabled(enable_spdy, enable_quic);
     41   // TODO(mef): Use |config| to set cookies.
     42 }
     43 
     44 // static
     45 void URLRequestContextConfig::RegisterJSONConverter(
     46     base::JSONValueConverter<URLRequestContextConfig>* converter) {
     47   converter->RegisterBoolField(REQUEST_CONTEXT_CONFIG_ENABLE_QUIC,
     48                                &URLRequestContextConfig::enable_quic);
     49   converter->RegisterBoolField(REQUEST_CONTEXT_CONFIG_ENABLE_SPDY,
     50                                &URLRequestContextConfig::enable_spdy);
     51   converter->RegisterStringField(REQUEST_CONTEXT_CONFIG_HTTP_CACHE,
     52                                  &URLRequestContextConfig::http_cache);
     53   converter->RegisterIntField(REQUEST_CONTEXT_CONFIG_HTTP_CACHE_MAX_SIZE,
     54                               &URLRequestContextConfig::http_cache_max_size);
     55   converter->RegisterStringField(REQUEST_CONTEXT_CONFIG_STORAGE_PATH,
     56                                  &URLRequestContextConfig::storage_path);
     57 }
     58 
     59 }  // namespace cronet
     60