diff options
author | Allan Sandfeld Jensen <allan.jensen@digia.com> | 2014-11-25 17:16:23 +0100 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@theqtcompany.com> | 2014-12-03 14:04:54 +0100 |
commit | 065a197007038ea02f0c72bdb592cd26edd4d20a (patch) | |
tree | 81cab628bd953c68385e0c93571991f9cd9c187d /src/core/url_request_context_getter_qt.cpp | |
parent | 9fb7bb8a3a2316fb447a612f1194947f9d65186c (diff) |
Use in-memory caches for off-the-record browsing
Off the record should leave no record, which means we should not use
disk storage for cookies and cache but instead trigger memory caching.
Change-Id: I3e14ed0f91f925bc65675d2e7d9f07eb379a30b0
Reviewed-by: Andras Becsi <andras.becsi@theqtcompany.com>
Reviewed-by: Jocelyn Turcotte <jocelyn.turcotte@digia.com>
Diffstat (limited to 'src/core/url_request_context_getter_qt.cpp')
-rw-r--r-- | src/core/url_request_context_getter_qt.cpp | 48 |
1 files changed, 32 insertions, 16 deletions
diff --git a/src/core/url_request_context_getter_qt.cpp b/src/core/url_request_context_getter_qt.cpp index 8ec600a85..282e5e94f 100644 --- a/src/core/url_request_context_getter_qt.cpp +++ b/src/core/url_request_context_getter_qt.cpp @@ -61,18 +61,18 @@ #include "net/url_request/ftp_protocol_handler.h" #include "net/ftp/ftp_network_layer.h" -#include "network_delegate_qt.h" +#include "browser_context_qt.h" #include "content_client_qt.h" +#include "network_delegate_qt.h" #include "qrc_protocol_handler_qt.h" static const char kQrcSchemeQt[] = "qrc"; using content::BrowserThread; -URLRequestContextGetterQt::URLRequestContextGetterQt(const base::FilePath &dataPath, const base::FilePath &cachePath, content::ProtocolHandlerMap *protocolHandlers) +URLRequestContextGetterQt::URLRequestContextGetterQt(BrowserContextQt *browserContext, content::ProtocolHandlerMap *protocolHandlers) : m_ignoreCertificateErrors(false) - , m_dataPath(dataPath) - , m_cachePath(cachePath) + , m_browserContext(browserContext) { std::swap(m_protocolHandlers, *protocolHandlers); @@ -94,9 +94,13 @@ net::URLRequestContext *URLRequestContextGetterQt::GetURLRequestContext() m_urlRequestContext->set_network_delegate(m_networkDelegate.get()); - base::FilePath cookiesPath = m_dataPath.Append(FILE_PATH_LITERAL("Cookies")); - content::CookieStoreConfig cookieStoreConfig(cookiesPath, content::CookieStoreConfig::PERSISTANT_SESSION_COOKIES, NULL, NULL); - scoped_refptr<net::CookieStore> cookieStore = content::CreateCookieStore(cookieStoreConfig); + scoped_refptr<net::CookieStore> cookieStore; + if (m_browserContext->IsOffTheRecord()) { + cookieStore = content::CreateCookieStore(content::CookieStoreConfig(base::FilePath(), content::CookieStoreConfig::EPHEMERAL_SESSION_COOKIES, NULL, NULL)); + } else { + base::FilePath cookiesPath = m_browserContext->GetPath().Append(FILE_PATH_LITERAL("Cookies")); + cookieStore = content::CreateCookieStore(content::CookieStoreConfig(cookiesPath, content::CookieStoreConfig::PERSISTANT_SESSION_COOKIES, NULL, NULL)); + } m_storage.reset(new net::URLRequestContextStorage(m_urlRequestContext.get())); m_storage->set_cookie_store(cookieStore.get()); @@ -120,15 +124,27 @@ net::URLRequestContext *URLRequestContextGetterQt::GetURLRequestContext() net::HttpAuthHandlerFactory::CreateDefault(host_resolver.get())); m_storage->set_http_server_properties(scoped_ptr<net::HttpServerProperties>(new net::HttpServerPropertiesImpl)); - base::FilePath cache_path = m_cachePath.Append(FILE_PATH_LITERAL("Cache")); - net::HttpCache::DefaultBackend* main_backend = - new net::HttpCache::DefaultBackend( - net::DISK_CACHE, - net::CACHE_BACKEND_DEFAULT, - cache_path, - 0, - BrowserThread::GetMessageLoopProxyForThread( - BrowserThread::CACHE)); + net::HttpCache::DefaultBackend* main_backend; + if (m_browserContext->IsOffTheRecord()) { + main_backend = + new net::HttpCache::DefaultBackend( + net::MEMORY_CACHE, + net::CACHE_BACKEND_DEFAULT, + base::FilePath(), + 0, + BrowserThread::GetMessageLoopProxyForThread( + BrowserThread::CACHE)); + } else { + base::FilePath cache_path = m_browserContext->GetCachePath().Append(FILE_PATH_LITERAL("Cache")); + main_backend = + new net::HttpCache::DefaultBackend( + net::DISK_CACHE, + net::CACHE_BACKEND_DEFAULT, + cache_path, + 0, + BrowserThread::GetMessageLoopProxyForThread( + BrowserThread::CACHE)); + } net::HttpNetworkSession::Params network_session_params; network_session_params.transport_security_state = |