From 68a140dd4bbb9f2dd40fadb0d5110ba8f11db24e Mon Sep 17 00:00:00 2001
From: Szabolcs David <davidsz@inf.u-szeged.hu>
Date: Wed, 7 Feb 2018 15:17:52 +0100
Subject: [PATCH] Clear HTTP cache before disabling it

It is a workaround to satisfy this online cache test:
http://refreshyourcache.com/en/cache-test/
This way Chromium provides "cache-control: no-cache" headers and indicates
the disabled state of our cache backend.

Task-number: QTBUG-63606
Change-Id: I0fdaf0b8dcaa98891b3d0380f4deeaa28a8aba4b
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
---
 src/core/url_request_context_getter_qt.cpp | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/src/core/url_request_context_getter_qt.cpp b/src/core/url_request_context_getter_qt.cpp
index 2622cb09e..d3f461639 100644
--- a/src/core/url_request_context_getter_qt.cpp
+++ b/src/core/url_request_context_getter_qt.cpp
@@ -48,6 +48,7 @@
 #include "chrome/browser/net/chrome_mojo_proxy_resolver_factory.h"
 #include "content/network/proxy_service_mojo.h"
 #include "content/public/browser/browser_thread.h"
+#include "content/public/browser/browsing_data_remover.h"
 #include "content/public/browser/cookie_store_factory.h"
 #include "content/public/common/content_features.h"
 #include "content/public/common/content_switches.h"
@@ -406,6 +407,13 @@ void URLRequestContextGetterQt::updateHttpCache()
     m_httpCachePath = m_browserContext.data()->httpCachePath();
     m_httpCacheMaxSize = m_browserContext.data()->httpCacheMaxSize();
 
+    if (m_httpCacheType == BrowserContextAdapter::NoCache) {
+        content::BrowsingDataRemover *remover = content::BrowserContext::GetBrowsingDataRemover(m_browserContext.data()->browserContext());
+        remover->Remove(base::Time(), base::Time::Max(),
+            content::BrowsingDataRemover::DATA_TYPE_CACHE,
+            content::BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB | content::BrowsingDataRemover::ORIGIN_TYPE_PROTECTED_WEB);
+    }
+
     if (m_contextInitialized && !m_updateAllStorage && !m_updateHttpCache) {
         m_updateHttpCache = true;
         content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE,
-- 
GitLab