#include "content/browser/indexed_db/indexed_db_database.h"
#include <math.h>
#include <algorithm>
#include <cstddef>
#include <utility>
#include "base/auto_reset.h"
#include "base/containers/contains.h"
#include "base/containers/flat_set.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/logging.h"
#include "base/memory/scoped_refptr.h"
#include "base/memory/weak_ptr.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/numerics/safe_conversions.h"
#include "base/stl_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "base/trace_event/base_tracing.h"
#include "components/services/storage/indexed_db/locks/partitioned_lock.h"
#include "components/services/storage/indexed_db/locks/partitioned_lock_id.h"
#include "components/services/storage/indexed_db/locks/partitioned_lock_manager.h"
#include "components/services/storage/indexed_db/scopes/leveldb_scope.h"
#include "components/services/storage/indexed_db/scopes/leveldb_scopes.h"
#include "components/services/storage/indexed_db/transactional_leveldb/transactional_leveldb_database.h"
#include "components/services/storage/indexed_db/transactional_leveldb/transactional_leveldb_transaction.h"
#include "content/browser/indexed_db/indexed_db_bucket_context.h"
#include "content/browser/indexed_db/indexed_db_bucket_context_handle.h"
#include "content/browser/indexed_db/indexed_db_callback_helpers.h"
#include "content/browser/indexed_db/indexed_db_connection.h"
#include "content/browser/indexed_db/indexed_db_cursor.h"
#include "content/browser/indexed_db/indexed_db_database_callbacks.h"
#include "content/browser/indexed_db/indexed_db_external_object.h"
#include "content/browser/indexed_db/indexed_db_factory_client.h"
#include "content/browser/indexed_db/indexed_db_index_writer.h"
#include "content/browser/indexed_db/indexed_db_lock_request_data.h"
#include "content/browser/indexed_db/indexed_db_pending_connection.h"
#include "content/browser/indexed_db/indexed_db_return_value.h"
#include "content/browser/indexed_db/indexed_db_transaction.h"
#include "content/browser/indexed_db/indexed_db_value.h"
#include "ipc/ipc_channel.h"
#include "storage/browser/blob/blob_data_handle.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/common/storage_key/storage_key.h"
#include "third_party/blink/public/mojom/indexeddb/indexeddb.mojom.h"
#include "third_party/leveldatabase/env_chromium.h"
#include "url/origin.h"
IndexedDBDatabaseMetadata;
IndexedDBIndexKeys;
IndexedDBIndexMetadata;
IndexedDBKey;
IndexedDBKeyPath;
IndexedDBKeyRange;
IndexedDBObjectStoreMetadata;
Status;
namespace content {
namespace {
std::vector<blink::mojom::IDBReturnValuePtr> CreateMojoValues(
std::vector<IndexedDBReturnValue>&& found_values,
IndexedDBBucketContext& bucket_context) { … }
blink::mojom::IDBErrorPtr CreateIDBErrorPtr(blink::mojom::IDBException code,
const std::string& message,
IndexedDBTransaction* transaction) { … }
std::unique_ptr<IndexedDBKey> GenerateKey(IndexedDBBackingStore* backing_store,
IndexedDBTransaction* transaction,
int64_t database_id,
int64_t object_store_id) { … }
Status UpdateKeyGenerator(IndexedDBBackingStore* backing_store,
IndexedDBTransaction* transaction,
int64_t database_id,
int64_t object_store_id,
const IndexedDBKey& key,
bool check_current) { … }
}
IndexedDBDatabase::PutOperationParams::PutOperationParams() = default;
IndexedDBDatabase::PutOperationParams::~PutOperationParams() = default;
IndexedDBDatabase::OpenCursorOperationParams::OpenCursorOperationParams() =
default;
IndexedDBDatabase::OpenCursorOperationParams::~OpenCursorOperationParams() =
default;
IndexedDBDatabase::IndexedDBDatabase(const std::u16string& name,
IndexedDBBucketContext& bucket_context,
const Identifier& unique_identifier)
: … { … }
IndexedDBDatabase::~IndexedDBDatabase() = default;
IndexedDBBackingStore* IndexedDBDatabase::backing_store() { … }
PartitionedLockManager& IndexedDBDatabase::lock_manager() { … }
void IndexedDBDatabase::RequireBlockingTransactionClientsToBeActive(
IndexedDBTransaction* current_transaction,
std::vector<PartitionedLockManager::PartitionedLockRequest>&
lock_requests) { … }
void IndexedDBDatabase::RegisterAndScheduleTransaction(
IndexedDBTransaction* transaction) { … }
std::tuple<IndexedDBDatabase::RunTasksResult, leveldb::Status>
IndexedDBDatabase::RunTasks() { … }
leveldb::Status IndexedDBDatabase::ForceCloseAndRunTasks() { … }
void IndexedDBDatabase::ScheduleOpenConnection(
std::unique_ptr<IndexedDBPendingConnection> connection) { … }
void IndexedDBDatabase::ScheduleDeleteDatabase(
std::unique_ptr<IndexedDBFactoryClient> factory_client,
base::OnceClosure on_deletion_complete) { … }
void IndexedDBDatabase::AddObjectStoreToMetadata(
IndexedDBObjectStoreMetadata object_store,
int64_t new_max_object_store_id) { … }
IndexedDBObjectStoreMetadata IndexedDBDatabase::RemoveObjectStoreFromMetadata(
int64_t object_store_id) { … }
void IndexedDBDatabase::AddIndexToMetadata(int64_t object_store_id,
IndexedDBIndexMetadata index,
int64_t new_max_index_id) { … }
IndexedDBIndexMetadata IndexedDBDatabase::RemoveIndexFromMetadata(
int64_t object_store_id,
int64_t index_id) { … }
leveldb::Status IndexedDBDatabase::CreateObjectStoreOperation(
int64_t object_store_id,
const std::u16string& name,
const IndexedDBKeyPath& key_path,
bool auto_increment,
IndexedDBTransaction* transaction) { … }
void IndexedDBDatabase::CreateObjectStoreAbortOperation(
int64_t object_store_id) { … }
Status IndexedDBDatabase::DeleteObjectStoreOperation(
int64_t object_store_id,
IndexedDBTransaction* transaction) { … }
void IndexedDBDatabase::DeleteObjectStoreAbortOperation(
IndexedDBObjectStoreMetadata object_store_metadata) { … }
leveldb::Status IndexedDBDatabase::RenameObjectStoreOperation(
int64_t object_store_id,
const std::u16string& new_name,
IndexedDBTransaction* transaction) { … }
void IndexedDBDatabase::RenameObjectStoreAbortOperation(
int64_t object_store_id,
std::u16string old_name) { … }
Status IndexedDBDatabase::VersionChangeOperation(
int64_t version,
IndexedDBTransaction* transaction) { … }
void IndexedDBDatabase::VersionChangeAbortOperation(int64_t previous_version) { … }
leveldb::Status IndexedDBDatabase::CreateIndexOperation(
int64_t object_store_id,
int64_t index_id,
const std::u16string& name,
const IndexedDBKeyPath& key_path,
bool unique,
bool multi_entry,
IndexedDBTransaction* transaction) { … }
void IndexedDBDatabase::CreateIndexAbortOperation(int64_t object_store_id,
int64_t index_id) { … }
Status IndexedDBDatabase::DeleteIndexOperation(
int64_t object_store_id,
int64_t index_id,
IndexedDBTransaction* transaction) { … }
void IndexedDBDatabase::DeleteIndexAbortOperation(
int64_t object_store_id,
IndexedDBIndexMetadata index_metadata) { … }
leveldb::Status IndexedDBDatabase::RenameIndexOperation(
int64_t object_store_id,
int64_t index_id,
const std::u16string& new_name,
IndexedDBTransaction* transaction) { … }
void IndexedDBDatabase::RenameIndexAbortOperation(int64_t object_store_id,
int64_t index_id,
std::u16string old_name) { … }
Status IndexedDBDatabase::GetOperation(
int64_t object_store_id,
int64_t index_id,
std::unique_ptr<IndexedDBKeyRange> key_range,
indexed_db::CursorType cursor_type,
blink::mojom::IDBDatabase::GetCallback callback,
IndexedDBTransaction* transaction) { … }
IndexedDBTransaction::Operation IndexedDBDatabase::CreateGetAllOperation(
int64_t object_store_id,
int64_t index_id,
std::unique_ptr<blink::IndexedDBKeyRange> key_range,
indexed_db::CursorType cursor_type,
int64_t max_count,
blink::mojom::IDBDatabase::GetAllCallback callback,
IndexedDBTransaction* transaction) { … }
static_assert …;
static_assert …;
IndexedDBDatabase::GetAllResultSinkWrapper::GetAllResultSinkWrapper(
base::WeakPtr<IndexedDBTransaction> transaction,
blink::mojom::IDBDatabase::GetAllCallback callback)
: … { … }
IndexedDBDatabase::GetAllResultSinkWrapper::~GetAllResultSinkWrapper() { … }
mojo::AssociatedRemote<blink::mojom::IDBDatabaseGetAllResultSink>&
IndexedDBDatabase::GetAllResultSinkWrapper::Get() { … }
Status IndexedDBDatabase::GetAllOperation(
int64_t object_store_id,
int64_t index_id,
std::unique_ptr<IndexedDBKeyRange> key_range,
indexed_db::CursorType cursor_type,
int64_t max_count,
std::unique_ptr<GetAllResultSinkWrapper> result_sink,
IndexedDBTransaction* transaction) { … }
Status IndexedDBDatabase::PutOperation(
std::unique_ptr<PutOperationParams> params,
IndexedDBTransaction* transaction) { … }
Status IndexedDBDatabase::SetIndexKeysOperation(
int64_t object_store_id,
std::unique_ptr<IndexedDBKey> primary_key,
const std::vector<IndexedDBIndexKeys>& index_keys,
IndexedDBTransaction* transaction) { … }
Status IndexedDBDatabase::SetIndexesReadyOperation(
size_t index_count,
IndexedDBTransaction* transaction) { … }
Status IndexedDBDatabase::OpenCursorOperation(
std::unique_ptr<OpenCursorOperationParams> params,
const storage::BucketLocator& bucket_locator,
IndexedDBTransaction* transaction) { … }
Status IndexedDBDatabase::CountOperation(
int64_t object_store_id,
int64_t index_id,
std::unique_ptr<IndexedDBKeyRange> key_range,
blink::mojom::IDBDatabase::CountCallback callback,
IndexedDBTransaction* transaction) { … }
Status IndexedDBDatabase::DeleteRangeOperation(
int64_t object_store_id,
std::unique_ptr<IndexedDBKeyRange> key_range,
blink::mojom::IDBDatabase::DeleteRangeCallback success_callback,
IndexedDBTransaction* transaction) { … }
Status IndexedDBDatabase::GetKeyGeneratorCurrentNumberOperation(
int64_t object_store_id,
blink::mojom::IDBDatabase::GetKeyGeneratorCurrentNumberCallback callback,
IndexedDBTransaction* transaction) { … }
Status IndexedDBDatabase::ClearOperation(
int64_t object_store_id,
blink::mojom::IDBDatabase::ClearCallback success_callback,
IndexedDBTransaction* transaction) { … }
bool IndexedDBDatabase::IsObjectStoreIdInMetadata(
int64_t object_store_id) const { … }
bool IndexedDBDatabase::IsObjectStoreIdAndIndexIdInMetadata(
int64_t object_store_id,
int64_t index_id) const { … }
bool IndexedDBDatabase::IsObjectStoreIdAndMaybeIndexIdInMetadata(
int64_t object_store_id,
int64_t index_id) const { … }
bool IndexedDBDatabase::IsObjectStoreIdInMetadataAndIndexNotInMetadata(
int64_t object_store_id,
int64_t index_id) const { … }
storage::mojom::IdbDatabaseMetadataPtr
IndexedDBDatabase::GetIdbInternalsMetadata() const { … }
void IndexedDBDatabase::NotifyOfIdbInternalsRelevantChange() { … }
static_assert …;
void IndexedDBDatabase::CallUpgradeTransactionStartedForTesting(
int64_t old_version) { … }
Status IndexedDBDatabase::OpenInternal() { … }
std::unique_ptr<IndexedDBConnection> IndexedDBDatabase::CreateConnection(
std::unique_ptr<IndexedDBDatabaseCallbacks> database_callbacks,
mojo::Remote<storage::mojom::IndexedDBClientStateChecker>
client_state_checker,
base::UnguessableToken client_token) { … }
void IndexedDBDatabase::VersionChangeIgnored() { … }
bool IndexedDBDatabase::HasNoConnections() const { … }
void IndexedDBDatabase::SendVersionChangeToAllConnections(int64_t old_version,
int64_t new_version) { … }
void IndexedDBDatabase::ConnectionClosed(IndexedDBConnection* connection) { … }
bool IndexedDBDatabase::CanBeDestroyed() { … }
}