xref: /aosp_15_r20/external/cronet/net/disk_cache/cache_util.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1*6777b538SAndroid Build Coastguard Worker // Copyright 2011 The Chromium Authors
2*6777b538SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
3*6777b538SAndroid Build Coastguard Worker // found in the LICENSE file.
4*6777b538SAndroid Build Coastguard Worker 
5*6777b538SAndroid Build Coastguard Worker #ifndef NET_DISK_CACHE_CACHE_UTIL_H_
6*6777b538SAndroid Build Coastguard Worker #define NET_DISK_CACHE_CACHE_UTIL_H_
7*6777b538SAndroid Build Coastguard Worker 
8*6777b538SAndroid Build Coastguard Worker #include <stdint.h>
9*6777b538SAndroid Build Coastguard Worker 
10*6777b538SAndroid Build Coastguard Worker #include "base/feature_list.h"
11*6777b538SAndroid Build Coastguard Worker #include "base/functional/callback_forward.h"
12*6777b538SAndroid Build Coastguard Worker #include "net/base/net_export.h"
13*6777b538SAndroid Build Coastguard Worker #include "net/disk_cache/disk_cache.h"
14*6777b538SAndroid Build Coastguard Worker 
15*6777b538SAndroid Build Coastguard Worker namespace base {
16*6777b538SAndroid Build Coastguard Worker class FilePath;
17*6777b538SAndroid Build Coastguard Worker }
18*6777b538SAndroid Build Coastguard Worker 
19*6777b538SAndroid Build Coastguard Worker namespace disk_cache {
20*6777b538SAndroid Build Coastguard Worker 
21*6777b538SAndroid Build Coastguard Worker // Experiment to increase the cache size to see the impact on various
22*6777b538SAndroid Build Coastguard Worker // performance metrics.
23*6777b538SAndroid Build Coastguard Worker NET_EXPORT_PRIVATE BASE_DECLARE_FEATURE(kChangeDiskCacheSizeExperiment);
24*6777b538SAndroid Build Coastguard Worker 
25*6777b538SAndroid Build Coastguard Worker // Moves the cache files from the given path to another location.
26*6777b538SAndroid Build Coastguard Worker // Fails if the destination exists already, or if it doesn't have
27*6777b538SAndroid Build Coastguard Worker // permission for the operation.  This is basically a rename operation
28*6777b538SAndroid Build Coastguard Worker // for the cache directory.  Returns true if successful.  On ChromeOS,
29*6777b538SAndroid Build Coastguard Worker // this moves the cache contents, and leaves the empty cache
30*6777b538SAndroid Build Coastguard Worker // directory.
31*6777b538SAndroid Build Coastguard Worker NET_EXPORT_PRIVATE bool MoveCache(const base::FilePath& from_path,
32*6777b538SAndroid Build Coastguard Worker                                   const base::FilePath& to_path);
33*6777b538SAndroid Build Coastguard Worker 
34*6777b538SAndroid Build Coastguard Worker // Deletes the cache files stored on |path|, and optionally also attempts to
35*6777b538SAndroid Build Coastguard Worker // delete the folder itself.
36*6777b538SAndroid Build Coastguard Worker NET_EXPORT_PRIVATE void DeleteCache(const base::FilePath& path,
37*6777b538SAndroid Build Coastguard Worker                                     bool remove_folder);
38*6777b538SAndroid Build Coastguard Worker 
39*6777b538SAndroid Build Coastguard Worker // Deletes the given directory recursively, asynchronously. `callback` will
40*6777b538SAndroid Build Coastguard Worker // called with whether the operation succeeded.
41*6777b538SAndroid Build Coastguard Worker // This is done by:
42*6777b538SAndroid Build Coastguard Worker //  1. Renaming the directory to another directory,
43*6777b538SAndroid Build Coastguard Worker //  2. Calling `callback` with the result, and
44*6777b538SAndroid Build Coastguard Worker //  3. Deleting the directory.
45*6777b538SAndroid Build Coastguard Worker // This means the caller won't know the result of 3.
46*6777b538SAndroid Build Coastguard Worker NET_EXPORT_PRIVATE void CleanupDirectory(
47*6777b538SAndroid Build Coastguard Worker     const base::FilePath& path,
48*6777b538SAndroid Build Coastguard Worker     base::OnceCallback<void(bool)> callback);
49*6777b538SAndroid Build Coastguard Worker 
50*6777b538SAndroid Build Coastguard Worker // This runs 1. (see the above comments) synchronously.
51*6777b538SAndroid Build Coastguard Worker bool CleanupDirectorySync(const base::FilePath& path);
52*6777b538SAndroid Build Coastguard Worker 
53*6777b538SAndroid Build Coastguard Worker // Returns the preferred max cache size given the available disk space and
54*6777b538SAndroid Build Coastguard Worker // cache type.
55*6777b538SAndroid Build Coastguard Worker NET_EXPORT_PRIVATE int PreferredCacheSize(
56*6777b538SAndroid Build Coastguard Worker     int64_t available,
57*6777b538SAndroid Build Coastguard Worker     net::CacheType type = net::DISK_CACHE);
58*6777b538SAndroid Build Coastguard Worker 
59*6777b538SAndroid Build Coastguard Worker // The default cache size should not ideally be exposed, but the blockfile
60*6777b538SAndroid Build Coastguard Worker // backend uses it for reasons that include testing.
61*6777b538SAndroid Build Coastguard Worker NET_EXPORT_PRIVATE extern const int kDefaultCacheSize;
62*6777b538SAndroid Build Coastguard Worker 
63*6777b538SAndroid Build Coastguard Worker }  // namespace disk_cache
64*6777b538SAndroid Build Coastguard Worker 
65*6777b538SAndroid Build Coastguard Worker #endif  // NET_DISK_CACHE_CACHE_UTIL_H_
66