From d65919d89639e04a9444b3f6314ffae515de5bcd Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 5 Jan 2015 13:40:38 -0800 Subject: [PATCH] Add --disable-http-cache switch, fixes #891 --- atom/browser/atom_browser_context.cc | 20 ++++++++++++++++++++ atom/browser/atom_browser_context.h | 2 ++ atom/common/options_switches.cc | 3 +++ atom/common/options_switches.h | 2 ++ docs/api/chrome-command-line-switches.md | 4 ++++ vendor/brightray | 2 +- 6 files changed, 32 insertions(+), 1 deletion(-) diff --git a/atom/browser/atom_browser_context.cc b/atom/browser/atom_browser_context.cc index 38f9bef470..f81894a5d3 100644 --- a/atom/browser/atom_browser_context.cc +++ b/atom/browser/atom_browser_context.cc @@ -8,6 +8,8 @@ #include "atom/browser/net/atom_url_request_job_factory.h" #include "atom/browser/net/asar/asar_protocol_handler.h" #include "atom/browser/web_view/web_view_manager.h" +#include "atom/common/options_switches.h" +#include "base/command_line.h" #include "base/threading/sequenced_worker_pool.h" #include "base/threading/worker_pool.h" #include "chrome/browser/browser_process.h" @@ -26,6 +28,14 @@ namespace { const char* kAsarScheme = "asar"; +class NoCacheBackend : public net::HttpCache::BackendFactory { + int CreateBackend(net::NetLog* net_log, + scoped_ptr* backend, + const net::CompletionCallback& callback) override { + return net::ERR_FAILED; + } +}; + } // namespace AtomBrowserContext::AtomBrowserContext() @@ -69,6 +79,16 @@ net::URLRequestJobFactory* AtomBrowserContext::CreateURLRequestJobFactory( return top_job_factory.release(); } +net::HttpCache::BackendFactory* +AtomBrowserContext::CreateHttpCacheBackendFactory( + const base::FilePath& base_path) { + base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); + if (command_line->HasSwitch(switches::kDisableHttpCache)) + return new NoCacheBackend; + else + return brightray::BrowserContext::CreateHttpCacheBackendFactory(base_path); +} + content::BrowserPluginGuestManager* AtomBrowserContext::GetGuestManager() { if (!guest_manager_) guest_manager_.reset(new WebViewManager(this)); diff --git a/atom/browser/atom_browser_context.h b/atom/browser/atom_browser_context.h index 8dd2dc7e0b..ab28c3e81a 100644 --- a/atom/browser/atom_browser_context.h +++ b/atom/browser/atom_browser_context.h @@ -26,6 +26,8 @@ class AtomBrowserContext : public brightray::BrowserContext { net::URLRequestJobFactory* CreateURLRequestJobFactory( content::ProtocolHandlerMap* handlers, content::URLRequestInterceptorScopedVector* interceptors) override; + net::HttpCache::BackendFactory* CreateHttpCacheBackendFactory( + const base::FilePath& base_path) override; // content::BrowserContext: content::BrowserPluginGuestManager* GetGuestManager() override; diff --git a/atom/common/options_switches.cc b/atom/common/options_switches.cc index 4bbc5e6075..ea8baa848d 100644 --- a/atom/common/options_switches.cc +++ b/atom/common/options_switches.cc @@ -77,6 +77,9 @@ const char kOverlayScrollbars[] = "overlay-scrollbars"; const char kOverlayFullscreenVideo[] = "overlay-fullscreen-video"; const char kSharedWorker[] = "shared-worker"; +// Disable HTTP cache. +const char kDisableHttpCache[] = "disable-http-cache"; + } // namespace switches } // namespace atom diff --git a/atom/common/options_switches.h b/atom/common/options_switches.h index a08983647c..f3b83f372e 100644 --- a/atom/common/options_switches.h +++ b/atom/common/options_switches.h @@ -47,6 +47,8 @@ extern const char kOverlayScrollbars[]; extern const char kOverlayFullscreenVideo[]; extern const char kSharedWorker[]; +extern const char kDisableHttpCache[]; + } // namespace switches } // namespace atom diff --git a/docs/api/chrome-command-line-switches.md b/docs/api/chrome-command-line-switches.md index 6ac57ac97d..d9f55056d5 100644 --- a/docs/api/chrome-command-line-switches.md +++ b/docs/api/chrome-command-line-switches.md @@ -14,6 +14,10 @@ app.on('ready', function() { }); ``` +## --disable-http-cache + +Disables the disk cache for HTTP requests. + ## --remote-debugging-port=`port` Enables remote debug over HTTP on the specified `port`. diff --git a/vendor/brightray b/vendor/brightray index ecda2421fb..bae4765d99 160000 --- a/vendor/brightray +++ b/vendor/brightray @@ -1 +1 @@ -Subproject commit ecda2421fbe41113d47a897f6656a740dc2d2dc3 +Subproject commit bae4765d993cda6507829961bef5edc59028edca