Commit d701f479 authored by Adrienne Walker's avatar Adrienne Walker Committed by Commit Bot

appcache: delete appcache directory from profile when disabled

Once AppCache has been removed from Chrome, sites will have no way of
cleaning up user data in local profiles.  To fix this, when a storage
partition is accessed when AppCache has been disabled, we will delete
the AppCache directory from that profile directory.

This is a relanding of:
https://chromium-review.googlesource.com/c/chromium/src/+/2343588

Bug: 1081897
Change-Id: I14498094d0262c2806eb66ca3cfde85956d59d17
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2357071Reviewed-by: default avatarMarijn Kruisselbrink <mek@chromium.org>
Reviewed-by: default avatarJeremy Roman <jbroman@chromium.org>
Auto-Submit: enne <enne@chromium.org>
Commit-Queue: Jeremy Roman <jbroman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#799952}
parent ec6a26d8
......@@ -175,7 +175,8 @@ const char kAppCacheName[] = "AppCache web API and browser backend";
const char kAppCacheDescription[] =
"When disabled, turns off all AppCache code so that developers "
"can test that their code works properly in the future when AppCache "
"has been removed.";
"has been removed. If disabled, this will also delete any AppCache data "
"from profile directories.";
const char kDnsHttpssvcName[] = "Support for HTTPSSVC records in DNS.";
const char kDnsHttpssvcDescription[] =
......
......@@ -451,6 +451,14 @@ void StoragePartitionImplMap::PostCreateInitialization(
in_memory ? base::FilePath()
: partition->GetPath().Append(kAppCacheDirname),
browser_context_, browser_context_->GetSpecialStoragePolicy());
} else if (!in_memory) {
// If AppCache is not enabled, clean up any on disk storage. This is the
// path that will execute once AppCache has been fully removed from Chrome.
base::ThreadPool::PostTask(
FROM_HERE, {base::MayBlock(), base::TaskPriority::BEST_EFFORT},
base::BindOnce(
[](const base::FilePath& dir) { base::DeletePathRecursively(dir); },
partition->GetPath().Append(kAppCacheDirname)));
}
// Check first to avoid memory leak in unittests.
......
......@@ -9,11 +9,14 @@
#include "base/files/file_util.h"
#include "base/run_loop.h"
#include "base/test/scoped_feature_list.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/common/content_constants.h"
#include "content/public/test/browser_task_environment.h"
#include "content/public/test/test_browser_context.h"
#include "content/public/test/test_utils.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/features.h"
namespace content {
......@@ -46,4 +49,44 @@ TEST(StoragePartitionImplMapTest, GarbageCollect) {
EXPECT_FALSE(base::PathExists(inactive_path));
}
TEST(StoragePartitionImplMapTest, AppCacheCleanup) {
const auto kOnDiskConfig = content::StoragePartitionConfig::Create(
"foo", /*partition_name=*/"", /*in_memory=*/false);
base::test::ScopedFeatureList f;
f.InitAndDisableFeature(blink::features::kAppCache);
BrowserTaskEnvironment task_environment;
TestBrowserContext browser_context;
base::FilePath appcache_path;
{
// Creating the partition in the map also does the deletion, so
// create it once, so we can find out what path the partition
// with this name is.
StoragePartitionImplMap map(&browser_context);
auto* partition = map.Get(kOnDiskConfig, true);
appcache_path = partition->GetPath().Append(kAppCacheDirname);
task_environment.RunUntilIdle();
}
// Create an AppCache directory that would have existed.
EXPECT_FALSE(base::PathExists(appcache_path));
EXPECT_TRUE(base::CreateDirectory(appcache_path));
{
StoragePartitionImplMap map(&browser_context);
auto* partition = map.Get(kOnDiskConfig, true);
ASSERT_EQ(appcache_path, partition->GetPath().Append(kAppCacheDirname));
task_environment.RunUntilIdle();
// Verify that creating this partition deletes any AppCache directory it may
// have had.
EXPECT_FALSE(base::PathExists(appcache_path));
}
}
} // namespace content
......@@ -580,7 +580,8 @@ const base::FeatureParam<DelayAsyncScriptDelayType>
// The AppCache feature is a kill-switch for the entire AppCache feature,
// both backend and API. If disabled, then it will turn off the backend and
// api, regardless of the presence of valid origin trial tokens.
// api, regardless of the presence of valid origin trial tokens. Disabling
// AppCache will also delete any AppCache data from the profile directory.
const base::Feature kAppCache{"AppCache", base::FEATURE_ENABLED_BY_DEFAULT};
// If AppCacheRequireOriginTrial is enabled, then the AppCache backend in the
// browser will require origin trial tokens in order to load or store manifests
......
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