simple_version_upgrade.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // Copyright 2013 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_SIMPLE_SIMPLE_VERSION_UPGRADE_H_
  5. #define NET_DISK_CACHE_SIMPLE_SIMPLE_VERSION_UPGRADE_H_
  6. // Defines functionality to upgrade the file structure of the Simple Cache
  7. // Backend on disk. Assumes no backend operations are running simultaneously.
  8. // Hence must be run at cache initialization step.
  9. #include <stdint.h>
  10. #include "net/base/cache_type.h"
  11. #include "net/base/net_export.h"
  12. namespace base {
  13. class FilePath;
  14. }
  15. namespace disk_cache {
  16. class BackendFileOperations;
  17. // These values are persisted to logs. Entries should not be renumbered and
  18. // numeric values should never be reused.
  19. enum class SimpleCacheConsistencyResult {
  20. kOK = 0,
  21. kCreateDirectoryFailed = 1,
  22. kBadFakeIndexFile = 2,
  23. kBadInitialMagicNumber = 3,
  24. kVersionTooOld = 4,
  25. kVersionFromTheFuture = 5,
  26. kBadZeroCheck = 6,
  27. kUpgradeIndexV5V6Failed = 7,
  28. kWriteFakeIndexFileFailed = 8,
  29. kReplaceFileFailed = 9,
  30. kBadFakeIndexReadSize = 10,
  31. kMaxValue = kBadFakeIndexReadSize,
  32. };
  33. // Performs all necessary disk IO to upgrade the cache structure if it is
  34. // needed.
  35. //
  36. // Returns true iff no errors were found during consistency checks and all
  37. // necessary transitions succeeded. If this function fails, there is nothing
  38. // left to do other than dropping the whole cache directory.
  39. NET_EXPORT_PRIVATE SimpleCacheConsistencyResult
  40. UpgradeSimpleCacheOnDisk(BackendFileOperations* file_operations,
  41. const base::FilePath& path);
  42. // Check if the cache structure at the given path is empty except for index
  43. // files. If so, then delete the index files. Returns true if any files
  44. // were deleted.
  45. NET_EXPORT_PRIVATE bool DeleteIndexFilesIfCacheIsEmpty(
  46. const base::FilePath& path);
  47. struct NET_EXPORT_PRIVATE FakeIndexData {
  48. FakeIndexData();
  49. // Must be equal to simplecache_v4::kSimpleInitialMagicNumber.
  50. uint64_t initial_magic_number;
  51. // Must be equal kSimpleVersion when the cache backend is instantiated.
  52. uint32_t version;
  53. // These must be zero. The first was used for experiment type (With a max
  54. // valid value of 2), and the second was used for an experiment parameter.
  55. uint32_t zero;
  56. uint32_t zero2;
  57. };
  58. // Exposed for testing.
  59. NET_EXPORT_PRIVATE bool UpgradeIndexV5V6(BackendFileOperations* file_operations,
  60. const base::FilePath& cache_directory);
  61. } // namespace disk_cache
  62. #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_VERSION_UPGRADE_H_