Skip to content

Commit d65919d

Browse files
committed
Add --disable-http-cache switch, fixes electron#891
1 parent 895ccf6 commit d65919d

File tree

6 files changed

+32
-1
lines changed

6 files changed

+32
-1
lines changed

atom/browser/atom_browser_context.cc

+20
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#include "atom/browser/net/atom_url_request_job_factory.h"
99
#include "atom/browser/net/asar/asar_protocol_handler.h"
1010
#include "atom/browser/web_view/web_view_manager.h"
11+
#include "atom/common/options_switches.h"
12+
#include "base/command_line.h"
1113
#include "base/threading/sequenced_worker_pool.h"
1214
#include "base/threading/worker_pool.h"
1315
#include "chrome/browser/browser_process.h"
@@ -26,6 +28,14 @@ namespace {
2628

2729
const char* kAsarScheme = "asar";
2830

31+
class NoCacheBackend : public net::HttpCache::BackendFactory {
32+
int CreateBackend(net::NetLog* net_log,
33+
scoped_ptr<disk_cache::Backend>* backend,
34+
const net::CompletionCallback& callback) override {
35+
return net::ERR_FAILED;
36+
}
37+
};
38+
2939
} // namespace
3040

3141
AtomBrowserContext::AtomBrowserContext()
@@ -69,6 +79,16 @@ net::URLRequestJobFactory* AtomBrowserContext::CreateURLRequestJobFactory(
6979
return top_job_factory.release();
7080
}
7181

82+
net::HttpCache::BackendFactory*
83+
AtomBrowserContext::CreateHttpCacheBackendFactory(
84+
const base::FilePath& base_path) {
85+
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
86+
if (command_line->HasSwitch(switches::kDisableHttpCache))
87+
return new NoCacheBackend;
88+
else
89+
return brightray::BrowserContext::CreateHttpCacheBackendFactory(base_path);
90+
}
91+
7292
content::BrowserPluginGuestManager* AtomBrowserContext::GetGuestManager() {
7393
if (!guest_manager_)
7494
guest_manager_.reset(new WebViewManager(this));

atom/browser/atom_browser_context.h

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ class AtomBrowserContext : public brightray::BrowserContext {
2626
net::URLRequestJobFactory* CreateURLRequestJobFactory(
2727
content::ProtocolHandlerMap* handlers,
2828
content::URLRequestInterceptorScopedVector* interceptors) override;
29+
net::HttpCache::BackendFactory* CreateHttpCacheBackendFactory(
30+
const base::FilePath& base_path) override;
2931

3032
// content::BrowserContext:
3133
content::BrowserPluginGuestManager* GetGuestManager() override;

atom/common/options_switches.cc

+3
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ const char kOverlayScrollbars[] = "overlay-scrollbars";
7777
const char kOverlayFullscreenVideo[] = "overlay-fullscreen-video";
7878
const char kSharedWorker[] = "shared-worker";
7979

80+
// Disable HTTP cache.
81+
const char kDisableHttpCache[] = "disable-http-cache";
82+
8083
} // namespace switches
8184

8285
} // namespace atom

atom/common/options_switches.h

+2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ extern const char kOverlayScrollbars[];
4747
extern const char kOverlayFullscreenVideo[];
4848
extern const char kSharedWorker[];
4949

50+
extern const char kDisableHttpCache[];
51+
5052
} // namespace switches
5153

5254
} // namespace atom

docs/api/chrome-command-line-switches.md

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ app.on('ready', function() {
1414
});
1515
```
1616

17+
## --disable-http-cache
18+
19+
Disables the disk cache for HTTP requests.
20+
1721
## --remote-debugging-port=`port`
1822

1923
Enables remote debug over HTTP on the specified `port`.

vendor/brightray

0 commit comments

Comments
 (0)