cache_util.h 2.3 KB

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