File: fake_transaction.cc

package info (click to toggle)
chromium 138.0.7204.183-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,080,960 kB
  • sloc: cpp: 34,937,079; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,954; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,811; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (191 lines) | stat: -rw-r--r-- 7,432 bytes parent folder | download | duplicates (2)
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "content/browser/indexed_db/instance/fake_transaction.h"

#include <utility>

#include "base/check.h"
#include "base/notreached.h"
#include "components/services/storage/indexed_db/locks/partitioned_lock_manager.h"
#include "content/browser/indexed_db/indexed_db_value.h"
#include "third_party/blink/public/common/indexeddb/indexeddb_key.h"
#include "third_party/blink/public/common/indexeddb/indexeddb_key_path.h"
#include "third_party/blink/public/common/indexeddb/indexeddb_key_range.h"
#include "third_party/blink/public/common/indexeddb/indexeddb_metadata.h"
#include "third_party/blink/public/mojom/indexeddb/indexeddb.mojom-forward.h"

namespace content::indexed_db {

FakeTransaction::FakeTransaction(
    Status phase_two_result,
    std::unique_ptr<BackingStore::Transaction> wrapped)
    : result_(phase_two_result), wrapped_transaction_(std::move(wrapped)) {}

FakeTransaction::~FakeTransaction() = default;

Status FakeTransaction::CommitPhaseOne(BlobWriteCallback callback) {
  return std::move(callback).Run(
      BlobWriteResult::kRunPhaseTwoAndReturnResult,
      storage::mojom::WriteBlobToFileResult::kSuccess);
}

Status FakeTransaction::CommitPhaseTwo() {
  return result_;
}

void FakeTransaction::Rollback() {}

void FakeTransaction::Begin(std::vector<PartitionedLock> locks) {
  wrapped_transaction_->Begin(std::move(locks));
}

void FakeTransaction::Reset() {
  wrapped_transaction_->Reset();
}

Status FakeTransaction::SetDatabaseVersion(int64_t version) {
  return wrapped_transaction_->SetDatabaseVersion(version);
}

Status FakeTransaction::CreateObjectStore(int64_t object_store_id,
                                          const std::u16string& name,
                                          blink::IndexedDBKeyPath key_path,
                                          bool auto_increment) {
  return wrapped_transaction_->CreateObjectStore(
      object_store_id, name, std::move(key_path), auto_increment);
}

Status FakeTransaction::DeleteObjectStore(int64_t object_store_id) {
  return wrapped_transaction_->DeleteObjectStore(object_store_id);
}

Status FakeTransaction::RenameObjectStore(int64_t object_store_id,
                                          const std::u16string& new_name) {
  return wrapped_transaction_->RenameObjectStore(object_store_id, new_name);
}

Status FakeTransaction::ClearObjectStore(int64_t object_store_id) {
  return wrapped_transaction_->ClearObjectStore(object_store_id);
}

Status FakeTransaction::CreateIndex(int64_t object_store_id,
                                    blink::IndexedDBIndexMetadata index) {
  return wrapped_transaction_->CreateIndex(object_store_id, std::move(index));
}

Status FakeTransaction::DeleteIndex(int64_t object_store_id, int64_t index_id) {
  return wrapped_transaction_->DeleteIndex(object_store_id, index_id);
}

Status FakeTransaction::RenameIndex(int64_t object_store_id,
                                    int64_t index_id,
                                    const std::u16string& new_name) {
  return wrapped_transaction_->RenameIndex(object_store_id, index_id, new_name);
}

Status FakeTransaction::GetRecord(int64_t object_store_id,
                                  const blink::IndexedDBKey& key,
                                  IndexedDBValue* record) {
  return wrapped_transaction_->GetRecord(object_store_id, key, record);
}

StatusOr<BackingStore::RecordIdentifier> FakeTransaction::PutRecord(
    int64_t object_store_id,
    const blink::IndexedDBKey& key,
    IndexedDBValue value) {
  return wrapped_transaction_->PutRecord(object_store_id, key,
                                         std::move(value));
}

Status FakeTransaction::DeleteRange(int64_t object_store_id,
                                    const blink::IndexedDBKeyRange& key_range) {
  return wrapped_transaction_->DeleteRange(object_store_id, key_range);
}

StatusOr<int64_t> FakeTransaction::GetKeyGeneratorCurrentNumber(
    int64_t object_store_id) {
  return wrapped_transaction_->GetKeyGeneratorCurrentNumber(object_store_id);
}

Status FakeTransaction::MaybeUpdateKeyGeneratorCurrentNumber(
    int64_t object_store_id,
    int64_t new_state,
    bool check_current) {
  return wrapped_transaction_->MaybeUpdateKeyGeneratorCurrentNumber(
      object_store_id, new_state, check_current);
}

StatusOr<std::optional<BackingStore::RecordIdentifier>>
FakeTransaction::KeyExistsInObjectStore(int64_t object_store_id,
                                        const blink::IndexedDBKey& key) {
  return wrapped_transaction_->KeyExistsInObjectStore(object_store_id, key);
}

Status FakeTransaction::PutIndexDataForRecord(
    int64_t object_store_id,
    int64_t index_id,
    const blink::IndexedDBKey& key,
    const BackingStore::RecordIdentifier& record) {
  return wrapped_transaction_->PutIndexDataForRecord(object_store_id, index_id,
                                                     key, record);
}

Status FakeTransaction::GetPrimaryKeyViaIndex(
    int64_t object_store_id,
    int64_t index_id,
    const blink::IndexedDBKey& key,
    std::unique_ptr<blink::IndexedDBKey>* primary_key) {
  return wrapped_transaction_->GetPrimaryKeyViaIndex(object_store_id, index_id,
                                                     key, primary_key);
}

Status FakeTransaction::KeyExistsInIndex(
    int64_t object_store_id,
    int64_t index_id,
    const blink::IndexedDBKey& key,
    std::unique_ptr<blink::IndexedDBKey>* found_primary_key,
    bool* exists) {
  return wrapped_transaction_->KeyExistsInIndex(object_store_id, index_id, key,
                                                found_primary_key, exists);
}

StatusOr<std::unique_ptr<indexed_db::BackingStore::Cursor>>
FakeTransaction::OpenObjectStoreKeyCursor(
    int64_t object_store_id,
    const blink::IndexedDBKeyRange& key_range,
    blink::mojom::IDBCursorDirection direction) {
  return wrapped_transaction_->OpenObjectStoreKeyCursor(object_store_id,
                                                        key_range, direction);
}

StatusOr<std::unique_ptr<indexed_db::BackingStore::Cursor>>
FakeTransaction::OpenObjectStoreCursor(
    int64_t object_store_id,
    const blink::IndexedDBKeyRange& key_range,
    blink::mojom::IDBCursorDirection direction) {
  return wrapped_transaction_->OpenObjectStoreCursor(object_store_id, key_range,
                                                     direction);
}

StatusOr<std::unique_ptr<indexed_db::BackingStore::Cursor>>
FakeTransaction::OpenIndexKeyCursor(
    int64_t object_store_id,
    int64_t index_id,
    const blink::IndexedDBKeyRange& key_range,
    blink::mojom::IDBCursorDirection direction) {
  return wrapped_transaction_->OpenIndexKeyCursor(object_store_id, index_id,
                                                  key_range, direction);
}

StatusOr<std::unique_ptr<indexed_db::BackingStore::Cursor>>
FakeTransaction::OpenIndexCursor(int64_t object_store_id,
                                 int64_t index_id,
                                 const blink::IndexedDBKeyRange& key_range,
                                 blink::mojom::IDBCursorDirection direction) {
  return wrapped_transaction_->OpenIndexCursor(object_store_id, index_id,
                                               key_range, direction);
}

}  // namespace content::indexed_db