Reland "Run file operations in DelayedCacheCleanup in a separate sequence"
This is a reland of commit 3db3ad33ccf711b71a74dbb15aac169ec5c8ed0b.
This removes NET_EXPORT_PRIVATE from CleanupDirectorySync, to avoid the
build failure.
Original change's description:
> Run file operations in DelayedCacheCleanup in a separate sequence
>
> - Rename DelayedCacheCleanup to CleanupDirectory.
> - CleanupDirectory runs file operations in a separate sequence. This
> is for CacheCreator which is used by both disk backends.
> - CleanupDirectorySync runs (some) file operations synchronously. This
> is for the blockfile backend.
>
> This change is a preparation for file operations brokering.
>
> This could regress cleaning up latency a bit, but that shouldn't matter
> because cleaning up cache rarely happens.
>
> Bug: 1289542
> Change-Id: I8b4c28a6e2408c3cf5ebd07b40575835d9314dda
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3610602
> Reviewed-by: Gabriel Charette <[email protected]>
> Reviewed-by: Maks Orlovich <[email protected]>
> Commit-Queue: Yutaka Hirano <[email protected]>
> Cr-Commit-Position: refs/heads/main@{#997553}
Bug: 1289542
Change-Id: I89ced6b2f27a6bb47885329ea77ae23c2aeb6123
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3615426
Reviewed-by: Gabriel Charette <[email protected]>
Reviewed-by: Maks Orlovich <[email protected]>
Commit-Queue: Yutaka Hirano <[email protected]>
Cr-Commit-Position: refs/heads/main@{#997694}
diff --git a/net/disk_cache/cache_util.h b/net/disk_cache/cache_util.h
index 623991f..429c1f1 100644
--- a/net/disk_cache/cache_util.h
+++ b/net/disk_cache/cache_util.h
@@ -7,6 +7,7 @@
#include <stdint.h>
+#include "base/callback_forward.h"
#include "base/feature_list.h"
#include "net/base/net_export.h"
#include "net/disk_cache/disk_cache.h"
@@ -35,9 +36,19 @@
NET_EXPORT_PRIVATE void DeleteCache(const base::FilePath& path,
bool remove_folder);
-// Renames cache directory synchronously and fires off a background cleanup
-// task. Used by cache creator itself or by backends for self-restart on error.
-bool DelayedCacheCleanup(const base::FilePath& full_path);
+// Deletes the given directory recursively, asynchronously. `callback` will
+// called with whether the operation succeeded.
+// This is done by:
+// 1. Renaming the directory to another directory,
+// 2. Calling `callback` with the result, and
+// 3. Deleting the directory.
+// This means the caller won't know the result of 3.
+NET_EXPORT_PRIVATE void CleanupDirectory(
+ const base::FilePath& path,
+ base::OnceCallback<void(bool)> callback);
+
+// This runs 1. (see the above comments) synchronously.
+bool CleanupDirectorySync(const base::FilePath& path);
// Returns the preferred max cache size given the available disk space and
// cache type.