File: simple_version_upgrade.h

package info (click to toggle)
chromium 139.0.7258.127-2
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 6,122,156 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (86 lines) | stat: -rw-r--r-- 2,797 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef NET_DISK_CACHE_SIMPLE_SIMPLE_VERSION_UPGRADE_H_
#define NET_DISK_CACHE_SIMPLE_SIMPLE_VERSION_UPGRADE_H_

// Defines functionality to upgrade the file structure of the Simple Cache
// Backend on disk. Assumes no backend operations are running simultaneously.
// Hence must be run at cache initialization step.

#include <stdint.h>

#include <type_traits>

#include "net/base/cache_type.h"
#include "net/base/net_export.h"

namespace base {
class FilePath;
}

namespace disk_cache {

class BackendFileOperations;

// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
enum class SimpleCacheConsistencyResult {
  kOK = 0,
  kCreateDirectoryFailed = 1,
  kBadFakeIndexFile = 2,
  kBadInitialMagicNumber = 3,
  kVersionTooOld = 4,
  kVersionFromTheFuture = 5,
  kBadZeroCheck = 6,
  kUpgradeIndexV5V6Failed = 7,
  kWriteFakeIndexFileFailed = 8,
  kReplaceFileFailed = 9,
  kBadFakeIndexReadSize = 10,
  kMaxValue = kBadFakeIndexReadSize,
};

// Performs all necessary disk IO to upgrade the cache structure if it is
// needed.
//
// Returns true iff no errors were found during consistency checks and all
// necessary transitions succeeded. If this function fails, there is nothing
// left to do other than dropping the whole cache directory.
NET_EXPORT_PRIVATE SimpleCacheConsistencyResult
UpgradeSimpleCacheOnDisk(BackendFileOperations* file_operations,
                         const base::FilePath& path);

// Check if the cache structure at the given path is empty except for index
// files.  If so, then delete the index files.  Returns true if any files
// were deleted.
NET_EXPORT_PRIVATE bool DeleteIndexFilesIfCacheIsEmpty(
    const base::FilePath& path);

struct NET_EXPORT_PRIVATE FakeIndexData {
  FakeIndexData();

  // Must be equal to kSimpleInitialMagicNumber.
  uint64_t initial_magic_number = 0;

  // Must be equal kSimpleVersion when the cache backend is instantiated.
  uint32_t version = 0;

  // These must be zero. The first was used for experiment type (With a max
  // valid value of 2), and the second was used for an experiment parameter.
  uint32_t zero = 0;
  uint32_t zero2 = 0;

  // Avoid implicit padding so `std::has_unique_object_representations_v<>` will
  // hold.
  uint32_t unused_padding = 0;
};
static_assert(std::has_unique_object_representations_v<FakeIndexData>);

// Exposed for testing.
NET_EXPORT_PRIVATE bool UpgradeIndexV5V6(BackendFileOperations* file_operations,
                                         const base::FilePath& cache_directory);

}  // namespace disk_cache

#endif  // NET_DISK_CACHE_SIMPLE_SIMPLE_VERSION_UPGRADE_H_