From 1166a56ceb1491633d602a9e036deda297fb4703 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 5 Jan 2015 13:29:16 -0800 Subject: [PATCH] Add a way to custom http cache backend --- .../browser/url_request_context_getter.cc | 21 +++++++++++-------- .../browser/url_request_context_getter.h | 3 +++ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index 44a0f6cbcd..7f2f6d878e 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -20,7 +20,6 @@ #include "net/cookies/cookie_monster.h" #include "net/dns/mapped_host_resolver.h" #include "net/http/http_auth_handler_factory.h" -#include "net/http/http_cache.h" #include "net/http/http_server_properties_impl.h" #include "net/proxy/dhcp_proxy_script_fetcher_factory.h" #include "net/proxy/proxy_config_service.h" @@ -99,6 +98,17 @@ net::URLRequestJobFactory* URLRequestContextGetter::Delegate::CreateURLRequestJo return top_job_factory.release(); } +net::HttpCache::BackendFactory* +URLRequestContextGetter::Delegate::CreateHttpCacheBackendFactory(const base::FilePath& base_path) { + 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, + BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE)); +} + URLRequestContextGetter::URLRequestContextGetter( Delegate* delegate, const base::FilePath& base_path, @@ -213,14 +223,7 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { storage_->set_host_resolver(host_resolver.Pass()); network_session_params.host_resolver = url_request_context_->host_resolver(); - base::FilePath cache_path = base_path_.Append(FILE_PATH_LITERAL("Cache")); - net::HttpCache::DefaultBackend* backend = - new net::HttpCache::DefaultBackend( - net::DISK_CACHE, - net::CACHE_BACKEND_DEFAULT, - cache_path, - 0, - BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE)); + net::HttpCache::BackendFactory* backend = delegate_->CreateHttpCacheBackendFactory(base_path_); storage_->set_http_transaction_factory(new net::HttpCache(network_session_params, backend)); storage_->set_job_factory(delegate_->CreateURLRequestJobFactory( diff --git a/brightray/browser/url_request_context_getter.h b/brightray/browser/url_request_context_getter.h index 05588c20ee..85ed014422 100644 --- a/brightray/browser/url_request_context_getter.h +++ b/brightray/browser/url_request_context_getter.h @@ -8,6 +8,7 @@ #include "base/files/file_path.h" #include "base/memory/scoped_ptr.h" #include "content/public/browser/content_browser_client.h" +#include "net/http/http_cache.h" #include "net/url_request/url_request_context_getter.h" namespace base { @@ -36,6 +37,8 @@ class URLRequestContextGetter : public net::URLRequestContextGetter { virtual net::URLRequestJobFactory* CreateURLRequestJobFactory( content::ProtocolHandlerMap* protocol_handlers, content::URLRequestInterceptorScopedVector* protocol_interceptors); + virtual net::HttpCache::BackendFactory* CreateHttpCacheBackendFactory( + const base::FilePath& base_path); }; URLRequestContextGetter(