From 716d179927c001934b177a36fab5dc209ac6d5c9 Mon Sep 17 00:00:00 2001 From: Szabolcs David Date: Wed, 29 Nov 2017 12:23:44 +0100 Subject: Use BrowsingDataRemover to clear HTTP cache This is a more convenient solution to remove cache instead of going down to the current cache backend and dooming its entries manually. It also fixes WebCacheManager and behavior of clearHttpCache() API on http://refreshyourcache.com/en/cache-test/ example. Task-number: QTBUG-63606 Change-Id: I43e5d6eb53aff66ed1b23caa2868ccfc0f4ebce1 Reviewed-by: Allan Sandfeld Jensen --- src/core/browser_context_adapter.cpp | 7 ++- src/core/browser_context_qt.cpp | 3 +- src/core/browsing_data_remover_delegate_qt.cpp | 85 ++++++++++++++++++++++++++ src/core/browsing_data_remover_delegate_qt.h | 66 ++++++++++++++++++++ src/core/core_chromium.pri | 2 + src/core/url_request_context_getter_qt.cpp | 18 ------ src/core/url_request_context_getter_qt.h | 2 - src/core/web_engine_context.cpp | 4 ++ 8 files changed, 164 insertions(+), 23 deletions(-) create mode 100644 src/core/browsing_data_remover_delegate_qt.cpp create mode 100644 src/core/browsing_data_remover_delegate_qt.h (limited to 'src/core') diff --git a/src/core/browser_context_adapter.cpp b/src/core/browser_context_adapter.cpp index f76969c74..0f392f9f8 100644 --- a/src/core/browser_context_adapter.cpp +++ b/src/core/browser_context_adapter.cpp @@ -41,6 +41,7 @@ #include "content/browser/web_contents/web_contents_impl.h" #include "content/public/browser/browser_thread.h" +#include "content/public/browser/browsing_data_remover.h" #include "browser_context_qt.h" #include "content_client_qt.h" @@ -500,8 +501,10 @@ void BrowserContextAdapter::setHttpAcceptLanguage(const QString &httpAcceptLangu void BrowserContextAdapter::clearHttpCache() { - if (m_browserContext->url_request_getter_.get()) - m_browserContext->url_request_getter_->clearHttpCache(); + content::BrowsingDataRemover *remover = content::BrowserContext::GetBrowsingDataRemover(m_browserContext.data()); + remover->Remove(base::Time(), base::Time::Max(), + content::BrowsingDataRemover::DATA_TYPE_CACHE, + content::BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB | content::BrowsingDataRemover::ORIGIN_TYPE_PROTECTED_WEB); } void BrowserContextAdapter::setSpellCheckLanguages(const QStringList &languages) diff --git a/src/core/browser_context_qt.cpp b/src/core/browser_context_qt.cpp index 415318fe8..dd0884edb 100644 --- a/src/core/browser_context_qt.cpp +++ b/src/core/browser_context_qt.cpp @@ -40,6 +40,7 @@ #include "browser_context_qt.h" #include "browser_context_adapter.h" +#include "browsing_data_remover_delegate_qt.h" #include "download_manager_delegate_qt.h" #include "permission_manager_qt.h" #include "qtwebenginecoreglobal_p.h" @@ -184,7 +185,7 @@ content::BackgroundSyncController* BrowserContextQt::GetBackgroundSyncController content::BrowsingDataRemoverDelegate *BrowserContextQt::GetBrowsingDataRemoverDelegate() { - return nullptr; + return new BrowsingDataRemoverDelegateQt; } content::PermissionManager *BrowserContextQt::GetPermissionManager() diff --git a/src/core/browsing_data_remover_delegate_qt.cpp b/src/core/browsing_data_remover_delegate_qt.cpp new file mode 100644 index 000000000..aeb7a4884 --- /dev/null +++ b/src/core/browsing_data_remover_delegate_qt.cpp @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtWebEngine module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "browsing_data_remover_delegate_qt.h" + +#include "base/bind.h" +#include "components/web_cache/browser/web_cache_manager.h" +#include "content/public/browser/browsing_data_remover.h" + +#include + +namespace QtWebEngineCore { + +bool DoesOriginMatchEmbedderMask(int origin_type_mask, + const GURL &origin, + storage::SpecialStoragePolicy *policy) { + Q_UNUSED(origin_type_mask); + Q_UNUSED(origin); + Q_UNUSED(policy); + return true; +} + +content::BrowsingDataRemoverDelegate::EmbedderOriginTypeMatcher BrowsingDataRemoverDelegateQt::GetOriginTypeMatcher() const { + return base::Bind(&DoesOriginMatchEmbedderMask); +} + +bool BrowsingDataRemoverDelegateQt::MayRemoveDownloadHistory() const { + return true; +} + +void BrowsingDataRemoverDelegateQt::RemoveEmbedderData( + const base::Time &delete_begin, + const base::Time &delete_end, + int remove_mask, + const content::BrowsingDataFilterBuilder& filter_builder, + int origin_type_mask, + const base::Closure &callback) { + Q_UNUSED(delete_begin); + Q_UNUSED(delete_end); + Q_UNUSED(filter_builder); + Q_UNUSED(origin_type_mask); + + if (remove_mask & content::BrowsingDataRemover::DATA_TYPE_CACHE) + web_cache::WebCacheManager::GetInstance()->ClearCache(); + + callback.Run(); +} + +} // namespace QtWebEngineCore diff --git a/src/core/browsing_data_remover_delegate_qt.h b/src/core/browsing_data_remover_delegate_qt.h new file mode 100644 index 000000000..204f4e625 --- /dev/null +++ b/src/core/browsing_data_remover_delegate_qt.h @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtWebEngine module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef BROWSING_DATA_REMOVER_DELEGATE_QT_H +#define BROWSING_DATA_REMOVER_DELEGATE_QT_H + +#include "content/public/browser/browsing_data_remover_delegate.h" + +namespace QtWebEngineCore { + +class BrowsingDataRemoverDelegateQt : public content::BrowsingDataRemoverDelegate { + +public: + BrowsingDataRemoverDelegateQt() {} + ~BrowsingDataRemoverDelegateQt() override {} + + content::BrowsingDataRemoverDelegate::EmbedderOriginTypeMatcher GetOriginTypeMatcher() const override; + bool MayRemoveDownloadHistory() const override; + void RemoveEmbedderData( + const base::Time &delete_begin, + const base::Time &delete_end, + int remove_mask, + const content::BrowsingDataFilterBuilder& filter_builder, + int origin_type_mask, + const base::Closure &callback) override; +}; + +} // namespace QtWebEngineCore + +#endif // BROWSING_DATA_REMOVER_DELEGATE_QT_H diff --git a/src/core/core_chromium.pri b/src/core/core_chromium.pri index 0ec6979c8..e63199e89 100644 --- a/src/core/core_chromium.pri +++ b/src/core/core_chromium.pri @@ -44,6 +44,7 @@ SOURCES = \ browser_context_adapter.cpp \ browser_context_adapter_client.cpp \ browser_context_qt.cpp \ + browsing_data_remover_delegate_qt.cpp \ browser_message_filter_qt.cpp \ certificate_error_controller.cpp \ chromium_gpu_helper.cpp \ @@ -117,6 +118,7 @@ HEADERS = \ browser_context_adapter.h \ browser_context_adapter_client.h \ browser_context_qt.h \ + browsing_data_remover_delegate_qt.h \ browser_message_filter_qt.h \ certificate_error_controller_p.h \ certificate_error_controller.h \ diff --git a/src/core/url_request_context_getter_qt.cpp b/src/core/url_request_context_getter_qt.cpp index 86f0c2b60..10a6cfe7a 100644 --- a/src/core/url_request_context_getter_qt.cpp +++ b/src/core/url_request_context_getter_qt.cpp @@ -54,7 +54,6 @@ #include "net/cert/ct_log_verifier.h" #include "net/cert/ct_policy_enforcer.h" #include "net/cert/multi_log_ct_verifier.h" -#include "net/disk_cache/disk_cache.h" #include "net/dns/host_resolver.h" #include "net/dns/mapped_host_resolver.h" #include "net/extras/sqlite/sqlite_channel_id_store.h" @@ -545,23 +544,6 @@ void URLRequestContextGetterQt::generateHttpCache() m_storage->set_http_transaction_factory(std::unique_ptr(cache)); } -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(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); diff --git a/src/core/url_request_context_getter_qt.h b/src/core/url_request_context_getter_qt.h index 495c9eb28..4a97a1398 100644 --- a/src/core/url_request_context_getter_qt.h +++ b/src/core/url_request_context_getter_qt.h @@ -82,7 +82,6 @@ public: void updateUserAgent(); void updateCookieStore(); void updateHttpCache(); - void clearHttpCache(); void updateJobFactory(); void updateRequestInterceptor(); @@ -97,7 +96,6 @@ private: void generateUserAgent(); void generateJobFactory(); void regenerateJobFactory(); - void clearCurrentCacheBackend(); void cancelAllUrlRequests(); net::HttpNetworkSession::Params generateNetworkSessionParams(); net::HttpNetworkSession::Context generateNetworkSessionContext(); diff --git a/src/core/web_engine_context.cpp b/src/core/web_engine_context.cpp index f3818b194..bc8d1d3eb 100644 --- a/src/core/web_engine_context.cpp +++ b/src/core/web_engine_context.cpp @@ -51,6 +51,7 @@ #if BUILDFLAG(ENABLE_BASIC_PRINTING) #include "chrome/browser/printing/print_job_manager.h" #endif // defined(ENABLE_BASIC_PRINTING) +#include "components/web_cache/browser/web_cache_manager.h" #include "content/browser/devtools/devtools_http_handler.h" #include "content/browser/gpu/gpu_main_thread_factory.h" #include "content/browser/renderer_host/render_process_host_impl.h" @@ -492,6 +493,9 @@ WebEngineContext::WebEngineContext() // first gets referenced on the IO thread. MediaCaptureDevicesDispatcher::GetInstance(); + // Initialize WebCacheManager here to ensure its subscription to render process creation events. + web_cache::WebCacheManager::GetInstance(); + base::ThreadRestrictions::SetIOAllowed(true); if (parsedCommandLine->HasSwitch(switches::kExplicitlyAllowedPorts)) { -- cgit v1.2.3