From 9ce08d08de7c2edb7b3ba798fc45d214a9285ca3 Mon Sep 17 00:00:00 2001 From: Dun Liang Date: Wed, 26 Apr 2017 17:16:25 +0800 Subject: [PATCH] support --disk-cache-size flag #290 --- brightray/browser/url_request_context_getter.cc | 9 ++++++++- brightray/common/switches.cc | 3 +++ brightray/common/switches.h | 1 + 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index 2e483d62ae5f..70c4624b3f04 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -15,6 +15,7 @@ #include "base/command_line.h" #include "base/memory/ptr_util.h" #include "base/strings/string_util.h" +#include "base/strings/string_number_conversions.h" #include "base/threading/sequenced_worker_pool.h" #include "base/threading/worker_pool.h" #include "content/public/browser/browser_thread.h" @@ -92,12 +93,18 @@ URLRequestContextGetter::Delegate::CreateURLRequestJobFactory( net::HttpCache::BackendFactory* URLRequestContextGetter::Delegate::CreateHttpCacheBackendFactory( const base::FilePath& base_path) { + auto& command_line = *base::CommandLine::ForCurrentProcess(); + int max_size = 0; + if (command_line.HasSwitch(switches::kDiskCacheSize)) { + base::StringToInt(command_line.GetSwitchValueASCII(switches::kDiskCacheSize), + &max_size); + } base::FilePath cache_path = base_path.Append(FILE_PATH_LITERAL("Cache")); return new net::HttpCache::DefaultBackend( net::DISK_CACHE, net::CACHE_BACKEND_DEFAULT, cache_path, - 0, + max_size, BrowserThread::GetTaskRunnerForThread(BrowserThread::CACHE)); } diff --git a/brightray/common/switches.cc b/brightray/common/switches.cc index 1f0da2adfddf..17ca05857739 100644 --- a/brightray/common/switches.cc +++ b/brightray/common/switches.cc @@ -53,6 +53,9 @@ const char kAuthNegotiateDelegateWhitelist[] = // Ignores certificate-related errors. const char kIgnoreCertificateErrors[] = "ignore-certificate-errors"; +// Forces the maximum disk space to be used by the disk cache, in bytes. +const char kDiskCacheSize[] = "disk-cache-size"; + } // namespace switches } // namespace brightray diff --git a/brightray/common/switches.h b/brightray/common/switches.h index 3aad50656b74..286c4d633b91 100644 --- a/brightray/common/switches.h +++ b/brightray/common/switches.h @@ -18,6 +18,7 @@ extern const char kDisableHttp2[]; extern const char kAuthServerWhitelist[]; extern const char kAuthNegotiateDelegateWhitelist[]; extern const char kIgnoreCertificateErrors[]; +extern const char kDiskCacheSize[]; } // namespace switches