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

Fix shader_disk_cache.cc not running the clearing callback when cache is empty

The ShaderClearHelper never runs the callback if there is no cache to clear.
Clearing shader cache is part of the BrowsingDataRemover's procedure when
DATA_TYPE_CACHE flag is set. So this results in BrowsingDataRemover never
reporting completion to its observers.

Bug: 1020168
Change-Id: I23ba6ed2a99b6c44acf0b349dd398f26133369a9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1890310Reviewed-by: default avatarKenneth Russell <kbr@chromium.org>
Reviewed-by: default avatarBo <boliu@chromium.org>
Commit-Queue: Pavel Shmakov <pshmakov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#711359}
parent 5e7f2837
......@@ -469,6 +469,10 @@ void ShaderCacheFactory::ClearByPath(const base::FilePath& path,
base::OnceClosure callback) {
DCHECK(CalledOnValidThread());
DCHECK(!callback.is_null());
if (path.empty()) {
std::move(callback).Run();
return;
}
auto helper = std::make_unique<ShaderClearHelper>(this, GetByPath(path), path,
delete_begin, delete_end,
......
......@@ -79,6 +79,23 @@ TEST_F(ShaderDiskCacheTest, ClearsCache) {
EXPECT_EQ(0, cache->Size());
}
TEST_F(ShaderDiskCacheTest, ClearByPathTriggersCallback) {
InitCache();
factory()->Get(kDefaultClientId)->Cache(kCacheKey, kCacheValue);
net::TestCompletionCallback test_callback;
factory()->ClearByPath(cache_path(), base::Time(), base::Time::Max(),
base::BindLambdaForTesting([&]() { test_callback.callback().Run(1); } ));
ASSERT_TRUE(test_callback.WaitForResult());
}
// Important for clearing in-memory profiles.
TEST_F(ShaderDiskCacheTest, ClearByPathWithEmptyPathTriggersCallback) {
net::TestCompletionCallback test_callback;
factory()->ClearByPath(base::FilePath(), base::Time(), base::Time::Max(),
base::BindLambdaForTesting([&]() { test_callback.callback().Run(1); } ));
ASSERT_TRUE(test_callback.WaitForResult());
}
// For https://crbug.com/663589.
TEST_F(ShaderDiskCacheTest, SafeToDeleteCacheMidEntryOpen) {
InitCache();
......
......@@ -48,10 +48,16 @@ public class DataClearingTest {
@Test
@SmallTest
public void clearCache_TriggersCallback() throws InterruptedException {
public void clearCacheWithPersistedProfile_TriggersCallback() throws InterruptedException {
checkTriggersCallbackOnClearData(new int[] {CACHE}, "Profile");
}
@Test
@SmallTest
public void clearCacheWithInMemoryProfile_TriggersCallback() throws InterruptedException {
checkTriggersCallbackOnClearData(new int[] {CACHE}, "");
}
@Test
@SmallTest
public void clearMultipleTypes_TriggersCallback() throws InterruptedException {
......
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