Commit b4aa4174 authored by Pavel Shmakov's avatar Pavel Shmakov Committed by Commit Bot

Implement cache clearing API 2/2

Both WebView's and Chrome's cache clearing APIs do the following:
1) Clear the GL shader cache, which corresponds to DATA_TYPE_CACHE in
the language of browser_data_remover.h.
2) Clear the Blink cache of the renderers.

This CL implements the second part.

Change-Id: I2c85de5ca6d286c22954c56a838e4b02cd57b5ee
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1893251Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarBo <boliu@chromium.org>
Commit-Queue: Pavel Shmakov <pshmakov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#712648}
parent 9a1fdb3b
...@@ -122,6 +122,7 @@ jumbo_static_library("weblayer_lib") { ...@@ -122,6 +122,7 @@ jumbo_static_library("weblayer_lib") {
"//components/security_interstitials/content:security_interstitial_page", "//components/security_interstitials/content:security_interstitial_page",
"//components/security_interstitials/content/renderer:security_interstitial_page_controller", "//components/security_interstitials/content/renderer:security_interstitial_page_controller",
"//components/security_interstitials/core", "//components/security_interstitials/core",
"//components/web_cache/browser",
"//content:resources", "//content:resources",
"//content/app/resources", "//content/app/resources",
"//content/public/app:both", "//content/public/app:both",
......
...@@ -4,6 +4,7 @@ include_rules = [ ...@@ -4,6 +4,7 @@ include_rules = [
"+components/embedder_support", "+components/embedder_support",
"+components/safe_browsing", "+components/safe_browsing",
"+components/security_interstitials", "+components/security_interstitials",
"+components/web_cache/browser",
"+content/public", "+content/public",
"+mojo/public", "+mojo/public",
"+net", "+net",
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/callback_forward.h" #include "base/callback_forward.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "components/web_cache/browser/web_cache_manager.h"
#include "content/public/browser/browser_context.h" #include "content/public/browser/browser_context.h"
#include "content/public/browser/browsing_data_remover.h" #include "content/public/browser/browsing_data_remover.h"
#include "content/public/browser/download_manager_delegate.h" #include "content/public/browser/download_manager_delegate.h"
...@@ -192,6 +193,10 @@ class ProfileImpl::DataClearer : public content::BrowsingDataRemover::Observer { ...@@ -192,6 +193,10 @@ class ProfileImpl::DataClearer : public content::BrowsingDataRemover::Observer {
}; };
ProfileImpl::ProfileImpl(const base::FilePath& path) : path_(path) { ProfileImpl::ProfileImpl(const base::FilePath& path) : path_(path) {
// Ensure WebCacheManager is created so that it starts observing
// OnRenderProcessHostCreated events.
web_cache::WebCacheManager::GetInstance();
browser_context_ = std::make_unique<BrowserContextImpl>(path_); browser_context_ = std::make_unique<BrowserContextImpl>(path_);
} }
...@@ -225,6 +230,7 @@ void ProfileImpl::ClearBrowsingData( ...@@ -225,6 +230,7 @@ void ProfileImpl::ClearBrowsingData(
break; break;
case BrowsingDataType::CACHE: case BrowsingDataType::CACHE:
remove_mask |= content::BrowsingDataRemover::DATA_TYPE_CACHE; remove_mask |= content::BrowsingDataRemover::DATA_TYPE_CACHE;
ClearRendererCache();
break; break;
default: default:
NOTREACHED(); NOTREACHED();
...@@ -233,6 +239,19 @@ void ProfileImpl::ClearBrowsingData( ...@@ -233,6 +239,19 @@ void ProfileImpl::ClearBrowsingData(
clearer->ClearData(remove_mask, from_time, to_time); clearer->ClearData(remove_mask, from_time, to_time);
} }
void ProfileImpl::ClearRendererCache() {
for (content::RenderProcessHost::iterator iter =
content::RenderProcessHost::AllHostsIterator();
!iter.IsAtEnd(); iter.Advance()) {
content::RenderProcessHost* render_process_host = iter.GetCurrentValue();
if (render_process_host->GetBrowserContext() == browser_context_.get() &&
render_process_host->IsInitializedAndNotDead()) {
web_cache::WebCacheManager::GetInstance()->ClearCacheForProcess(
render_process_host->GetID());
}
}
}
std::unique_ptr<Profile> Profile::Create(const base::FilePath& path) { std::unique_ptr<Profile> Profile::Create(const base::FilePath& path) {
return std::make_unique<ProfileImpl>(path); return std::make_unique<ProfileImpl>(path);
} }
......
...@@ -49,6 +49,8 @@ class ProfileImpl : public Profile { ...@@ -49,6 +49,8 @@ class ProfileImpl : public Profile {
class BrowserContextImpl; class BrowserContextImpl;
class DataClearer; class DataClearer;
void ClearRendererCache();
base::FilePath path_; base::FilePath path_;
std::unique_ptr<BrowserContextImpl> browser_context_; std::unique_ptr<BrowserContextImpl> browser_context_;
......
Markdown is supported
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