diff options
author | Szabolcs David <davidsz@inf.u-szeged.hu> | 2015-12-10 07:05:29 -0800 |
---|---|---|
committer | Szabolcs David <davidsz@inf.u-szeged.hu> | 2016-01-06 08:06:33 +0000 |
commit | f5ed13b1e2d20ca49adb6fa378faee14bece16a0 (patch) | |
tree | 70dbd031d4a59a8b5031fc93795f5a08ac715c65 /src | |
parent | 1ae9e7cc00a366fddcb4909df375829e9727c7fa (diff) |
Add function to clear data from the cache
It marks the entries of the current cache backend for deletion
and starts to remove them.
Task-number: QTBUG-48177
Change-Id: I85ec25048ff5429976f1b2dcacd74666bdbe6624
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@theqtcompany.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/core/browser_context_adapter.cpp | 6 | ||||
-rw-r--r-- | src/core/browser_context_adapter.h | 2 | ||||
-rw-r--r-- | src/core/url_request_context_getter_qt.cpp | 18 | ||||
-rw-r--r-- | src/core/url_request_context_getter_qt.h | 2 | ||||
-rw-r--r-- | src/webengine/api/qquickwebengineprofile.cpp | 14 | ||||
-rw-r--r-- | src/webengine/api/qquickwebengineprofile_p.h | 1 | ||||
-rw-r--r-- | src/webenginewidgets/api/qwebengineprofile.cpp | 11 | ||||
-rw-r--r-- | src/webenginewidgets/api/qwebengineprofile.h | 2 |
8 files changed, 56 insertions, 0 deletions
diff --git a/src/core/browser_context_adapter.cpp b/src/core/browser_context_adapter.cpp index 7b40688a1..7d2d0478f 100644 --- a/src/core/browser_context_adapter.cpp +++ b/src/core/browser_context_adapter.cpp @@ -423,4 +423,10 @@ void BrowserContextAdapter::setHttpAcceptLanguage(const QString &httpAcceptLangu m_httpAcceptLanguage = httpAcceptLanguage; } +void BrowserContextAdapter::clearHttpCache() +{ + if (m_browserContext->url_request_getter_.get()) + m_browserContext->url_request_getter_->clearHttpCache(); +} + } // namespace QtWebEngineCore diff --git a/src/core/browser_context_adapter.h b/src/core/browser_context_adapter.h index 97a4dca4a..ee913b8cb 100644 --- a/src/core/browser_context_adapter.h +++ b/src/core/browser_context_adapter.h @@ -157,6 +157,8 @@ public: QString httpAcceptLanguage() const; void setHttpAcceptLanguage(const QString &httpAcceptLanguage); + void clearHttpCache(); + private: QString m_name; bool m_offTheRecord; diff --git a/src/core/url_request_context_getter_qt.cpp b/src/core/url_request_context_getter_qt.cpp index 121a103b0..4a2a63348 100644 --- a/src/core/url_request_context_getter_qt.cpp +++ b/src/core/url_request_context_getter_qt.cpp @@ -45,6 +45,7 @@ #include "content/public/common/content_switches.h" #include "net/base/cache_type.h" #include "net/cert/cert_verifier.h" +#include "net/disk_cache/disk_cache.h" #include "net/dns/host_resolver.h" #include "net/dns/mapped_host_resolver.h" #include "net/http/http_auth_handler_factory.h" @@ -330,6 +331,23 @@ void URLRequestContextGetterQt::generateHttpCache() m_storage->set_http_transaction_factory(scoped_ptr<net::HttpCache>(new net::HttpCache(network_session_params, main_backend))); } +void URLRequestContextGetterQt::clearHttpCache() +{ + if (m_urlRequestContext) + content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE, base::Bind(&URLRequestContextGetterQt::clearCurrentCacheBackend, this)); +} + +static void doomCallback(int error_code) { Q_UNUSED(error_code); } + +void URLRequestContextGetterQt::clearCurrentCacheBackend() +{ + if (m_urlRequestContext->http_transaction_factory() && m_urlRequestContext->http_transaction_factory()->GetCache()) { + disk_cache::Backend *backend = m_urlRequestContext->http_transaction_factory()->GetCache()->GetCurrentBackend(); + if (backend) + backend->DoomAllEntries(base::Bind(&doomCallback)); + } +} + void URLRequestContextGetterQt::generateJobFactory() { Q_ASSERT(m_urlRequestContext); diff --git a/src/core/url_request_context_getter_qt.h b/src/core/url_request_context_getter_qt.h index c7a4366ec..9c355082d 100644 --- a/src/core/url_request_context_getter_qt.h +++ b/src/core/url_request_context_getter_qt.h @@ -76,6 +76,7 @@ public: void updateUserAgent(); void updateCookieStore(); void updateHttpCache(); + void clearHttpCache(); private: virtual ~URLRequestContextGetterQt(); @@ -86,6 +87,7 @@ private: void generateHttpCache(); void generateUserAgent(); void generateJobFactory(); + void clearCurrentCacheBackend(); bool m_ignoreCertificateErrors; QAtomicInt m_updateCookieStore; diff --git a/src/webengine/api/qquickwebengineprofile.cpp b/src/webengine/api/qquickwebengineprofile.cpp index 0c3f7400b..6df16bf54 100644 --- a/src/webengine/api/qquickwebengineprofile.cpp +++ b/src/webengine/api/qquickwebengineprofile.cpp @@ -436,6 +436,20 @@ QWebEngineCookieStore *QQuickWebEngineProfile::cookieStore() const return d->browserContext()->cookieStore(); } +/*! + \qmlmethod void WebEngineProfile::clearHttpCache() + \since QtWebEngine 1.3 + + Removes the profile's cache entries. + + \sa WebEngineProfile::cachePath +*/ +void QQuickWebEngineProfile::clearHttpCache() +{ + Q_D(QQuickWebEngineProfile); + d->browserContext()->clearHttpCache(); +} + QQuickWebEngineSettings *QQuickWebEngineProfile::settings() const { const Q_D(QQuickWebEngineProfile); diff --git a/src/webengine/api/qquickwebengineprofile_p.h b/src/webengine/api/qquickwebengineprofile_p.h index 5839d51a5..2744ed0ec 100644 --- a/src/webengine/api/qquickwebengineprofile_p.h +++ b/src/webengine/api/qquickwebengineprofile_p.h @@ -123,6 +123,7 @@ public: static QQuickWebEngineProfile *defaultProfile(); Q_REVISION(1) Q_INVOKABLE QWebEngineCookieStore *cookieStore() const; + Q_REVISION(2) Q_INVOKABLE void clearHttpCache(); signals: void storageNameChanged(); diff --git a/src/webenginewidgets/api/qwebengineprofile.cpp b/src/webenginewidgets/api/qwebengineprofile.cpp index 9955f7728..286889c1f 100644 --- a/src/webenginewidgets/api/qwebengineprofile.cpp +++ b/src/webenginewidgets/api/qwebengineprofile.cpp @@ -629,4 +629,15 @@ void QWebEngineProfile::destroyedUrlSchemeHandler(QWebEngineUrlSchemeHandler *ob removeUrlSchemeHandler(obj); } +/*! + \since 5.7 + + Removes the profile's cache entries. +*/ +void QWebEngineProfile::clearHttpCache() +{ + Q_D(QWebEngineProfile); + d->browserContext()->clearHttpCache(); +} + QT_END_NAMESPACE diff --git a/src/webenginewidgets/api/qwebengineprofile.h b/src/webenginewidgets/api/qwebengineprofile.h index 416ef23db..4b37a7d73 100644 --- a/src/webenginewidgets/api/qwebengineprofile.h +++ b/src/webenginewidgets/api/qwebengineprofile.h @@ -115,6 +115,8 @@ public: void removeUrlSchemeHandler(QWebEngineUrlSchemeHandler *); void removeAllUrlSchemeHandlers(); + void clearHttpCache(); + static QWebEngineProfile *defaultProfile(); Q_SIGNALS: |