Commit f343e9d6 authored by Allan Sandfeld Jensen's avatar Allan Sandfeld Jensen Committed by Allan Sandfeld Jensen
Browse files

Cache to QStandardPaths::CacheLocation


We should save our cache in the configured CacheLocation, and ensure
we are prepared for multiple BrowserContext by caching to a Default
subdir. This matches how chromium caches on linux.

Change-Id: Ibe914fca35435ea1658565be87747cfabc71e97b
Reviewed-by: default avatarJocelyn Turcotte <jocelyn.turcotte@digia.com>
Showing with 22 additions and 7 deletions
......@@ -72,9 +72,21 @@ base::FilePath BrowserContextQt::GetPath() const
dataLocation = QDir::homePath() % QDir::separator() % QChar::fromLatin1('.') % QCoreApplication::applicationName();
dataLocation.append(QDir::separator() % QLatin1String("QtWebEngine"));
dataLocation.append(QDir::separator() % QLatin1String("Default"));
return base::FilePath(toFilePathString(dataLocation));
}
base::FilePath BrowserContextQt::GetCachePath() const
{
QString cacheLocation = QStandardPaths::writableLocation(QStandardPaths::CacheLocation);
if (cacheLocation.isEmpty())
cacheLocation = QDir::homePath() % QDir::separator() % QChar::fromLatin1('.') % QCoreApplication::applicationName();
cacheLocation.append(QDir::separator() % QLatin1String("QtWebEngine"));
cacheLocation.append(QDir::separator() % QLatin1String("Default"));
return base::FilePath(toFilePathString(cacheLocation));
}
bool BrowserContextQt::IsOffTheRecord() const
{
return false;
......@@ -133,7 +145,7 @@ content::PushMessagingService *BrowserContextQt::GetPushMessagingService()
net::URLRequestContextGetter *BrowserContextQt::CreateRequestContext(content::ProtocolHandlerMap *protocol_handlers)
{
url_request_getter_ = new URLRequestContextGetterQt(GetPath(), protocol_handlers);
url_request_getter_ = new URLRequestContextGetterQt(GetPath(), GetCachePath(), protocol_handlers);
static_cast<ResourceContextQt*>(resourceContext.get())->set_url_request_context_getter(url_request_getter_.get());
return url_request_getter_.get();
}
......@@ -51,6 +51,7 @@ public:
virtual ~BrowserContextQt();
virtual base::FilePath GetPath() const Q_DECL_OVERRIDE;
base::FilePath GetCachePath() const;
virtual bool IsOffTheRecord() const Q_DECL_OVERRIDE;
virtual net::URLRequestContextGetter *GetRequestContext() Q_DECL_OVERRIDE;
......
......@@ -69,9 +69,10 @@ static const char kQrcSchemeQt[] = "qrc";
using content::BrowserThread;
URLRequestContextGetterQt::URLRequestContextGetterQt(const base::FilePath &basePath, content::ProtocolHandlerMap *protocolHandlers)
URLRequestContextGetterQt::URLRequestContextGetterQt(const base::FilePath &dataPath, const base::FilePath &cachePath, content::ProtocolHandlerMap *protocolHandlers)
: m_ignoreCertificateErrors(false)
, m_basePath(basePath)
, m_dataPath(dataPath)
, m_cachePath(cachePath)
{
std::swap(m_protocolHandlers, *protocolHandlers);
......@@ -93,7 +94,7 @@ net::URLRequestContext *URLRequestContextGetterQt::GetURLRequestContext()
m_urlRequestContext->set_network_delegate(m_networkDelegate.get());
base::FilePath cookiesPath = m_basePath.Append(FILE_PATH_LITERAL("Cookies"));
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);
......@@ -119,7 +120,7 @@ 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_basePath.Append(FILE_PATH_LITERAL("Cache"));
base::FilePath cache_path = m_cachePath.Append(FILE_PATH_LITERAL("Cache"));
net::HttpCache::DefaultBackend* main_backend =
new net::HttpCache::DefaultBackend(
net::DISK_CACHE,
......
......@@ -58,7 +58,7 @@ class ProxyConfigService;
class URLRequestContextGetterQt : public net::URLRequestContextGetter {
public:
explicit URLRequestContextGetterQt(const base::FilePath &, content::ProtocolHandlerMap *protocolHandlers);
explicit URLRequestContextGetterQt(const base::FilePath &, const base::FilePath &, content::ProtocolHandlerMap *protocolHandlers);
virtual net::URLRequestContext *GetURLRequestContext() Q_DECL_OVERRIDE;
virtual scoped_refptr<base::SingleThreadTaskRunner> GetNetworkTaskRunner() const Q_DECL_OVERRIDE;
......@@ -67,7 +67,8 @@ private:
virtual ~URLRequestContextGetterQt() {}
bool m_ignoreCertificateErrors;
base::FilePath m_basePath;
base::FilePath m_dataPath;
base::FilePath m_cachePath;
content::ProtocolHandlerMap m_protocolHandlers;
scoped_ptr<net::ProxyConfigService> m_proxyConfigService;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment