Avi Drissman | 6459548 | 2022-09-14 20:52:29 | [diff] [blame] | 1 | // Copyright 2011 The Chromium Authors |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
[email protected] | 408d35f5 | 2008-08-13 18:30:22 | [diff] [blame] | 4 | |
| 5 | #ifndef NET_DISK_CACHE_CACHE_UTIL_H_ |
| 6 | #define NET_DISK_CACHE_CACHE_UTIL_H_ |
| 7 | |
avi | d0181f3 | 2015-12-10 19:41:47 | [diff] [blame] | 8 | #include <stdint.h> |
| 9 | |
Yutaka Hirano | bc3b4ddb | 2022-04-29 14:15:44 | [diff] [blame] | 10 | #include "base/callback_forward.h" |
Matt Menke | b0f4c7c | 2018-07-06 19:25:30 | [diff] [blame] | 11 | #include "base/feature_list.h" |
[email protected] | 172da1b | 2011-08-12 15:52:26 | [diff] [blame] | 12 | #include "net/base/net_export.h" |
[email protected] | 398ad13 | 2013-04-02 15:11:01 | [diff] [blame] | 13 | #include "net/disk_cache/disk_cache.h" |
[email protected] | 408d35f5 | 2008-08-13 18:30:22 | [diff] [blame] | 14 | |
[email protected] | a3ef483 | 2013-02-02 05:12:33 | [diff] [blame] | 15 | namespace base { |
[email protected] | cfaa1f2 | 2009-10-12 17:14:59 | [diff] [blame] | 16 | class FilePath; |
[email protected] | a3ef483 | 2013-02-02 05:12:33 | [diff] [blame] | 17 | } |
[email protected] | cfaa1f2 | 2009-10-12 17:14:59 | [diff] [blame] | 18 | |
[email protected] | 408d35f5 | 2008-08-13 18:30:22 | [diff] [blame] | 19 | namespace disk_cache { |
| 20 | |
shivanigithub | 19b2f34 | 2020-12-30 01:57:43 | [diff] [blame] | 21 | // Experiment to increase the cache size to see the impact on various |
| 22 | // performance metrics. |
Daniel Cheng | 3617b73 | 2022-10-01 03:36:35 | [diff] [blame] | 23 | NET_EXPORT_PRIVATE BASE_DECLARE_FEATURE(kChangeDiskCacheSizeExperiment); |
shivanigithub | 19b2f34 | 2020-12-30 01:57:43 | [diff] [blame] | 24 | |
[email protected] | 408d35f5 | 2008-08-13 18:30:22 | [diff] [blame] | 25 | // Moves the cache files from the given path to another location. |
[email protected] | 831a1a76 | 2010-10-12 05:57:08 | [diff] [blame] | 26 | // Fails if the destination exists already, or if it doesn't have |
| 27 | // permission for the operation. This is basically a rename operation |
| 28 | // for the cache directory. Returns true if successful. On ChromeOS, |
| 29 | // this moves the cache contents, and leaves the empty cache |
| 30 | // directory. |
[email protected] | a3ef483 | 2013-02-02 05:12:33 | [diff] [blame] | 31 | NET_EXPORT_PRIVATE bool MoveCache(const base::FilePath& from_path, |
| 32 | const base::FilePath& to_path); |
[email protected] | 408d35f5 | 2008-08-13 18:30:22 | [diff] [blame] | 33 | |
| 34 | // Deletes the cache files stored on |path|, and optionally also attempts to |
| 35 | // delete the folder itself. |
[email protected] | a3ef483 | 2013-02-02 05:12:33 | [diff] [blame] | 36 | NET_EXPORT_PRIVATE void DeleteCache(const base::FilePath& path, |
| 37 | bool remove_folder); |
[email protected] | 408d35f5 | 2008-08-13 18:30:22 | [diff] [blame] | 38 | |
Yutaka Hirano | bc3b4ddb | 2022-04-29 14:15:44 | [diff] [blame] | 39 | // Deletes the given directory recursively, asynchronously. `callback` will |
| 40 | // called with whether the operation succeeded. |
| 41 | // This is done by: |
| 42 | // 1. Renaming the directory to another directory, |
| 43 | // 2. Calling `callback` with the result, and |
| 44 | // 3. Deleting the directory. |
| 45 | // This means the caller won't know the result of 3. |
| 46 | NET_EXPORT_PRIVATE void CleanupDirectory( |
| 47 | const base::FilePath& path, |
| 48 | base::OnceCallback<void(bool)> callback); |
| 49 | |
| 50 | // This runs 1. (see the above comments) synchronously. |
| 51 | bool CleanupDirectorySync(const base::FilePath& path); |
[email protected] | 398ad13 | 2013-04-02 15:11:01 | [diff] [blame] | 52 | |
Bill Budge | 1bb18a94 | 2019-12-02 22:19:54 | [diff] [blame] | 53 | // Returns the preferred max cache size given the available disk space and |
| 54 | // cache type. |
| 55 | NET_EXPORT_PRIVATE int PreferredCacheSize( |
| 56 | int64_t available, |
| 57 | net::CacheType type = net::DISK_CACHE); |
[email protected] | 18b5b26 | 2013-11-19 18:41:37 | [diff] [blame] | 58 | |
| 59 | // The default cache size should not ideally be exposed, but the blockfile |
| 60 | // backend uses it for reasons that include testing. |
| 61 | NET_EXPORT_PRIVATE extern const int kDefaultCacheSize; |
| 62 | |
[email protected] | 408d35f5 | 2008-08-13 18:30:22 | [diff] [blame] | 63 | } // namespace disk_cache |
| 64 | |
| 65 | #endif // NET_DISK_CACHE_CACHE_UTIL_H_ |