Commit e6edc78d authored by Mythri Alle's avatar Mythri Alle Committed by Commit Bot

Fix ClearCodeCache to also consider cases when code caching is disabled

Embedders can disable code caching and we need to handle those cases
when clearing the caches.

Bug: chromium:812168
Change-Id: Ib9f2b60faa07c3e023298f46c5fdc2ef049ee797
Reviewed-on: https://chromium-review.googlesource.com/1219227
Commit-Queue: Kinuko Yasuda <kinuko@chromium.org>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Reviewed-by: default avatarVictor Costan <pwnall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#591256}
parent 3e1adea2
......@@ -172,8 +172,8 @@ void StoragePartitionHttpCacheDataRemover::DoClearCache(int rv) {
}
case CacheState::DELETE_CODE: {
next_cache_state_ = CacheState::DONE;
if (base::FeatureList::IsEnabled(features::kIsolatedCodeCache)) {
DCHECK(generated_code_cache_context_);
// Embedders can disable code caches.
if (generated_code_cache_context_) {
GeneratedCodeCache* code_cache =
generated_code_cache_context_->generated_code_cache();
if (code_cache) {
......
......@@ -10,6 +10,7 @@
#include "base/macros.h"
#include "base/run_loop.h"
#include "base/single_thread_task_runner.h"
#include "base/test/scoped_feature_list.h"
#include "base/threading/thread.h"
#include "base/threading/thread_task_runner_handle.h"
#include "components/services/leveldb/public/cpp/util.h"
......@@ -1338,6 +1339,45 @@ TEST_F(StoragePartitionImplTest, ClearCodeCache) {
EXPECT_FALSE(tester.ContainsEntry(kResourceURL, origin));
}
TEST_F(StoragePartitionImplTest, ClearCodeCacheNoIsolatedCodeCache) {
base::test::ScopedFeatureList feature_list;
feature_list.InitAndDisableFeature(features::kIsolatedCodeCache);
ASSERT_FALSE(base::FeatureList::IsEnabled(features::kIsolatedCodeCache));
StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>(
BrowserContext::GetDefaultStoragePartition(browser_context()));
base::RunLoop().RunUntilIdle();
// We should not create GeneratedCodeCacheContext when IsolatedCodeCache
// is disabled.
EXPECT_EQ(nullptr, partition->GetGeneratedCodeCacheContext());
base::RunLoop run_loop;
// This shouldn't crash.
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::BindOnce(&ClearCodeCache, partition, &run_loop));
run_loop.Run();
}
TEST_F(StoragePartitionImplTest, ClearCodeCacheIncognito) {
base::test::ScopedFeatureList feature_list;
feature_list.InitAndEnableFeature(features::kIsolatedCodeCache);
ASSERT_TRUE(base::FeatureList::IsEnabled(features::kIsolatedCodeCache));
browser_context()->set_is_off_the_record(true);
StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>(
BrowserContext::GetDefaultStoragePartition(browser_context()));
base::RunLoop().RunUntilIdle();
// We should not create GeneratedCodeCacheContext for off the record mode.
EXPECT_EQ(nullptr, partition->GetGeneratedCodeCacheContext());
base::RunLoop run_loop;
// This shouldn't crash.
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::BindOnce(&ClearCodeCache, partition, &run_loop));
run_loop.Run();
}
#if BUILDFLAG(ENABLE_PLUGINS)
TEST_F(StoragePartitionImplTest, RemovePluginPrivateDataForever) {
StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>(
......
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