File: backend_storage_delegate.cc

package info (click to toggle)
chromium 146.0.7680.153-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,057,156 kB
  • sloc: cpp: 36,426,539; ansic: 7,626,206; javascript: 3,599,825; python: 1,658,592; xml: 842,302; asm: 722,011; pascal: 186,153; sh: 88,976; perl: 88,684; objc: 79,984; sql: 60,492; cs: 42,470; fortran: 24,101; makefile: 21,141; tcl: 15,277; php: 14,022; yacc: 9,154; ruby: 7,553; awk: 3,720; lisp: 3,233; lex: 1,328; ada: 727; jsp: 228; sed: 36
file content (87 lines) | stat: -rw-r--r-- 3,197 bytes parent folder | download | duplicates (4)
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
87
// Copyright 2025 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/persistent_cache/sqlite/backend_storage_delegate.h"

#include <memory>
#include <utility>

#include "base/files/file_path.h"
#include "base/numerics/clamped_math.h"
#include "base/types/expected_macros.h"
#include "components/persistent_cache/pending_backend.h"
#include "components/persistent_cache/sqlite/sqlite_backend_impl.h"
#include "components/persistent_cache/sqlite/vfs_util.h"
#include "components/sqlite_vfs/client.h"
#include "components/sqlite_vfs/pending_file_set.h"
#include "components/sqlite_vfs/sqlite_database_vfs_file_set.h"
#include "components/sqlite_vfs/vfs_utils.h"

namespace persistent_cache::sqlite {

std::optional<PendingBackend> BackendStorageDelegate::MakePendingBackend(
    Client client,
    const base::FilePath& directory,
    const base::FilePath& base_name,
    bool single_connection,
    bool journal_mode_wal) {
  ASSIGN_OR_RETURN(auto pending_file_set,
                   sqlite_vfs::MakePendingFileSet(
                       VfsClientFromClient(client), directory, base_name,
                       single_connection, journal_mode_wal));
  return PendingBackend(std::move(pending_file_set));
}

std::unique_ptr<Backend> BackendStorageDelegate::MakeBackend(
    Client client,
    const base::FilePath& directory,
    const base::FilePath& base_name,
    bool single_connection,
    bool journal_mode_wal) {
  if (auto pending_backend = MakePendingBackend(
          client, directory, base_name, single_connection, journal_mode_wal);
      pending_backend.has_value()) {
    return SqliteBackendImpl::Bind(*std::move(pending_backend), client);
  }
  return nullptr;
}

std::optional<PendingBackend> BackendStorageDelegate::ShareReadOnlyConnection(
    const base::FilePath& directory,
    const base::FilePath& base_name,
    const Backend& backend) {
  ASSIGN_OR_RETURN(
      auto pending_file_set,
      sqlite_vfs::ShareConnection(
          directory, base_name,
          static_cast<const SqliteBackendImpl&>(backend).file_set(),
          /*read_write=*/false));
  return PendingBackend(std::move(pending_file_set));
}

std::optional<PendingBackend> BackendStorageDelegate::ShareReadWriteConnection(
    const base::FilePath& directory,
    const base::FilePath& base_name,
    const Backend& backend) {
  ASSIGN_OR_RETURN(
      auto pending_file_set,
      sqlite_vfs::ShareConnection(
          directory, base_name,
          static_cast<const SqliteBackendImpl&>(backend).file_set(),
          /*read_write=*/true));
  return PendingBackend(std::move(pending_file_set));
}

base::FilePath BackendStorageDelegate::GetBaseName(const base::FilePath& file) {
  return sqlite_vfs::GetBaseName(file);
}

int64_t BackendStorageDelegate::DeleteFiles(Client client,
                                            const base::FilePath& directory,
                                            const base::FilePath& base_name) {
  return sqlite_vfs::DeleteFiles(VfsClientFromClient(client), directory,
                                 base_name);
}

}  // namespace persistent_cache::sqlite