File: backing_store_transaction_impl.cc

package info (click to toggle)
chromium 139.0.7258.154-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 6,129,716 kB
  • sloc: cpp: 35,100,894; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,921; 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,152; 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 (215 lines) | stat: -rw-r--r-- 7,682 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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
// 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 "content/browser/indexed_db/instance/sqlite/backing_store_transaction_impl.h"

#include "base/check.h"
#include "base/notimplemented.h"
#include "base/types/expected_macros.h"
#include "content/browser/indexed_db/indexed_db_value.h"
#include "content/browser/indexed_db/instance/sqlite/database_connection.h"
#include "content/browser/indexed_db/status.h"

namespace content::indexed_db::sqlite {

BackingStoreTransactionImpl::BackingStoreTransactionImpl(
    base::WeakPtr<DatabaseConnection> db,
    blink::mojom::IDBTransactionDurability durability,
    blink::mojom::IDBTransactionMode mode)
    : db_(std::move(db)), durability_(durability), mode_(mode) {}

BackingStoreTransactionImpl::~BackingStoreTransactionImpl() = default;

void BackingStoreTransactionImpl::Begin(std::vector<PartitionedLock> locks) {
  locks_ = std::move(locks);
  db_->BeginTransaction(PassKey(), *this);
}

Status BackingStoreTransactionImpl::CommitPhaseOne(BlobWriteCallback callback) {
  return db_->CommitTransactionPhaseOne(PassKey(), *this, std::move(callback));
}

Status BackingStoreTransactionImpl::CommitPhaseTwo() {
  return db_->CommitTransactionPhaseTwo(PassKey(), *this);
}

void BackingStoreTransactionImpl::Rollback() {
  return db_->RollBackTransaction(PassKey(), *this);
}

Status BackingStoreTransactionImpl::SetDatabaseVersion(int64_t version) {
  return db_->SetDatabaseVersion(PassKey(), version);
}

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

Status BackingStoreTransactionImpl::DeleteObjectStore(int64_t object_store_id) {
  return db_->DeleteObjectStore(PassKey(), object_store_id);
}

Status BackingStoreTransactionImpl::RenameObjectStore(
    int64_t object_store_id,
    const std::u16string& new_name) {
  NOTIMPLEMENTED();
  return Status::InvalidArgument("Not implemented");
}

Status BackingStoreTransactionImpl::ClearObjectStore(int64_t object_store_id) {
  NOTIMPLEMENTED();
  return Status::InvalidArgument("Not implemented");
}

Status BackingStoreTransactionImpl::CreateIndex(
    int64_t object_store_id,
    blink::IndexedDBIndexMetadata index) {
  return db_->CreateIndex(PassKey(), object_store_id, std::move(index));
}

Status BackingStoreTransactionImpl::DeleteIndex(int64_t object_store_id,
                                                int64_t index_id) {
  NOTIMPLEMENTED();
  return Status::InvalidArgument("Not implemented");
}

Status BackingStoreTransactionImpl::RenameIndex(
    int64_t object_store_id,
    int64_t index_id,
    const std::u16string& new_name) {
  NOTIMPLEMENTED();
  return Status::InvalidArgument("Not implemented");
}

StatusOr<IndexedDBValue> BackingStoreTransactionImpl::GetRecord(
    int64_t object_store_id,
    const blink::IndexedDBKey& key) {
  return db_->GetValue(PassKey(), object_store_id, key);
}

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

Status BackingStoreTransactionImpl::DeleteRange(
    int64_t object_store_id,
    const blink::IndexedDBKeyRange& range) {
  return db_->DeleteRange(object_store_id, range);
}

StatusOr<int64_t> BackingStoreTransactionImpl::GetKeyGeneratorCurrentNumber(
    int64_t object_store_id) {
  return db_->GetKeyGeneratorCurrentNumber(PassKey(), object_store_id);
}

Status BackingStoreTransactionImpl::MaybeUpdateKeyGeneratorCurrentNumber(
    int64_t object_store_id,
    int64_t new_number,
    bool was_generated) {
  // The `was_generated` hint is not useful for SQLite as the check and update
  // can be made in a single SQL statement.
  return db_->MaybeUpdateKeyGeneratorCurrentNumber(PassKey(), object_store_id,
                                                   new_number);
}

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

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

StatusOr<blink::IndexedDBKey>
BackingStoreTransactionImpl::GetFirstPrimaryKeyForIndexKey(
    int64_t object_store_id,
    int64_t index_id,
    const blink::IndexedDBKey& key) {
  return db_->GetFirstPrimaryKeyForIndexKey(PassKey(), object_store_id,
                                            index_id, key);
}

StatusOr<uint32_t> BackingStoreTransactionImpl::GetObjectStoreKeyCount(
    int64_t object_store_id,
    blink::IndexedDBKeyRange key_range) {
  return db_->GetObjectStoreKeyCount(PassKey(), object_store_id,
                                     std::move(key_range));
}

StatusOr<uint32_t> BackingStoreTransactionImpl::GetIndexKeyCount(
    int64_t object_store_id,
    int64_t index_id,
    blink::IndexedDBKeyRange key_range) {
  return db_->GetIndexKeyCount(PassKey(), object_store_id, index_id,
                               std::move(key_range));
}

StatusOr<std::unique_ptr<BackingStore::Cursor>>
BackingStoreTransactionImpl::OpenObjectStoreKeyCursor(
    int64_t object_store_id,
    const blink::IndexedDBKeyRange& key_range,
    blink::mojom::IDBCursorDirection direction) {
  return db_->OpenObjectStoreCursor(PassKey(), object_store_id, key_range,
                                    direction, /*key_only=*/true);
}

StatusOr<std::unique_ptr<indexed_db::BackingStore::Cursor>>
BackingStoreTransactionImpl::OpenObjectStoreCursor(
    int64_t object_store_id,
    const blink::IndexedDBKeyRange& key_range,
    blink::mojom::IDBCursorDirection direction) {
  return db_->OpenObjectStoreCursor(PassKey(), object_store_id, key_range,
                                    direction, /*key_only=*/false);
}

StatusOr<std::unique_ptr<indexed_db::BackingStore::Cursor>>
BackingStoreTransactionImpl::OpenIndexKeyCursor(
    int64_t object_store_id,
    int64_t index_id,
    const blink::IndexedDBKeyRange& key_range,
    blink::mojom::IDBCursorDirection direction) {
  return db_->OpenIndexCursor(PassKey(), object_store_id, index_id, key_range,
                              direction, /*key_only=*/true);
}

StatusOr<std::unique_ptr<indexed_db::BackingStore::Cursor>>
BackingStoreTransactionImpl::OpenIndexCursor(
    int64_t object_store_id,
    int64_t index_id,
    const blink::IndexedDBKeyRange& key_range,
    blink::mojom::IDBCursorDirection direction) {
  return db_->OpenIndexCursor(PassKey(), object_store_id, index_id, key_range,
                              direction, /*key_only=*/false);
}

blink::mojom::IDBValuePtr BackingStoreTransactionImpl::BuildMojoValue(
    IndexedDBValue value) {
  auto mojo_value = blink::mojom::IDBValue::New();
  if (!value.empty()) {
    mojo_value->bits = std::move(value.bits);
  }
  if (!value.external_objects.empty()) {
    mojo_value->external_objects =
        db_->CreateAllExternalObjects(PassKey(), value.external_objects);
  }
  return mojo_value;
}

}  // namespace content::indexed_db::sqlite