From dc38e971b4b53dd57216ea26c3885d1e185a7009 Mon Sep 17 00:00:00 2001 From: Evan Stade Date: Fri, 14 Jul 2023 02:04:54 +0000 Subject: [PATCH] IndexedDB: mojoify GetKeyGeneratorCurrentNumber Bug: 843764,627484 Change-Id: I0d4efc0e8d56560d59f7a971e44eaa0b90ac8018 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4632064 Reviewed-by: Daniel Cheng Reviewed-by: Nathan Memmott Commit-Queue: Evan Stade Cr-Commit-Position: refs/heads/main@{#1170293} --- content/browser/indexed_db/database_impl.cc | 16 +- content/browser/indexed_db/database_impl.h | 3 +- .../browser/indexed_db/indexed_db_database.cc | 172 +++++++----------- .../browser/indexed_db/indexed_db_database.h | 2 +- .../indexed_db/indexed_db_database_error.cc | 4 +- .../indexed_db/indexed_db_database_error.h | 3 +- .../indexed_db/indexed_db_index_writer.cc | 13 +- .../indexed_db/indexed_db_index_writer.h | 4 +- .../public/mojom/indexeddb/indexeddb.mojom | 18 +- .../modules/indexeddb/idb_object_store.cc | 4 +- .../renderer/modules/indexeddb/idb_request.cc | 11 ++ .../renderer/modules/indexeddb/idb_request.h | 2 + .../modules/indexeddb/idb_request_test.cc | 3 +- .../modules/indexeddb/mock_idb_database.h | 2 +- .../modules/indexeddb/web_idb_database.cc | 13 +- .../modules/indexeddb/web_idb_database.h | 7 +- 16 files changed, 125 insertions(+), 152 deletions(-) diff --git a/content/browser/indexed_db/database_impl.cc b/content/browser/indexed_db/database_impl.cc index 95163fd358a38c..bf35001f29e621 100644 --- a/content/browser/indexed_db/database_impl.cc +++ b/content/browser/indexed_db/database_impl.cc @@ -13,6 +13,7 @@ #include "base/metrics/histogram_macros.h" #include "base/numerics/safe_math.h" #include "base/sequence_checker.h" +#include "base/strings/utf_string_conversions.h" #include "base/task/sequenced_task_runner.h" #include "content/browser/indexed_db/indexed_db_callback_helpers.h" #include "content/browser/indexed_db/indexed_db_connection.h" @@ -562,14 +563,13 @@ void DatabaseImpl::DeleteRange(int64_t transaction_id, void DatabaseImpl::GetKeyGeneratorCurrentNumber( int64_t transaction_id, int64_t object_store_id, - mojo::PendingAssociatedRemote - pending_callbacks) { + GetKeyGeneratorCurrentNumberCallback callback) { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); - auto callbacks = std::make_unique( - dispatcher_host_->AsWeakPtr(), bucket_info_, std::move(pending_callbacks), - idb_runner_); - if (!connection_->IsConnected()) - return; + auto wrapped_callback = mojo::WrapCallbackWithDefaultInvokeIfNotRun( + std::move(callback), -1, + blink::mojom::IDBError::New( + blink::mojom::IDBException::kIgnorableAbortError, + u"Aborting due to unknown failure.")); IndexedDBTransaction* transaction = connection_->GetTransaction(transaction_id); @@ -588,7 +588,7 @@ void DatabaseImpl::GetKeyGeneratorCurrentNumber( transaction->ScheduleTask(BindWeakOperation( &IndexedDBDatabase::GetKeyGeneratorCurrentNumberOperation, connection_->database()->AsWeakPtr(), object_store_id, - std::move(callbacks))); + std::move(wrapped_callback))); } void DatabaseImpl::Clear(int64_t transaction_id, diff --git a/content/browser/indexed_db/database_impl.h b/content/browser/indexed_db/database_impl.h index 90649c198f77ee..3186c750cb993b 100644 --- a/content/browser/indexed_db/database_impl.h +++ b/content/browser/indexed_db/database_impl.h @@ -108,8 +108,7 @@ class DatabaseImpl : public blink::mojom::IDBDatabase { void GetKeyGeneratorCurrentNumber( int64_t transaction_id, int64_t object_store_id, - mojo::PendingAssociatedRemote - pending_callbacks) override; + GetKeyGeneratorCurrentNumberCallback callback) override; void Clear(int64_t transaction_id, int64_t object_store_id, ClearCallback callback) override; diff --git a/content/browser/indexed_db/indexed_db_database.cc b/content/browser/indexed_db/indexed_db_database.cc index dacc39f6d4d7c1..b86a1c80384325 100644 --- a/content/browser/indexed_db/indexed_db_database.cc +++ b/content/browser/indexed_db/indexed_db_database.cc @@ -21,6 +21,7 @@ #include "base/metrics/histogram_macros.h" #include "base/numerics/safe_conversions.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" @@ -85,18 +86,11 @@ std::vector CreateMojoValues( return mojo_values; } -IndexedDBDatabaseError CreateError(blink::mojom::IDBException code, - const char* message, - IndexedDBTransaction* transaction) { +blink::mojom::IDBErrorPtr CreateIDBErrorPtr(blink::mojom::IDBException code, + const std::string& message, + IndexedDBTransaction* transaction) { transaction->IncrementNumErrorsSent(); - return IndexedDBDatabaseError(code, message); -} - -IndexedDBDatabaseError CreateError(blink::mojom::IDBException code, - const std::u16string& message, - IndexedDBTransaction* transaction) { - transaction->IncrementNumErrorsSent(); - return IndexedDBDatabaseError(code, message); + return blink::mojom::IDBError::New(code, base::UTF8ToUTF16(message)); } std::unique_ptr GenerateKey(IndexedDBBackingStore* backing_store, @@ -781,10 +775,9 @@ Status IndexedDBDatabase::GetOperation( transaction->id()); if (!IsObjectStoreIdAndMaybeIndexIdInMetadata(object_store_id, index_id)) { - IndexedDBDatabaseError error = CreateError( - blink::mojom::IDBException::kUnknownError, "Bad request", transaction); std::move(callback).Run(blink::mojom::IDBDatabaseGetResult::NewErrorResult( - blink::mojom::IDBError::New(error.code(), error.message()))); + CreateIDBErrorPtr(blink::mojom::IDBException::kUnknownError, + "Bad request", transaction))); return leveldb::Status::InvalidArgument( "Invalid object_store_id and/or index_id."); } @@ -798,11 +791,9 @@ Status IndexedDBDatabase::GetOperation( Status s = Status::OK(); if (!dispatcher_host) { - IndexedDBDatabaseError error = - CreateError(blink::mojom::IDBException::kUnknownError, "Unknown error", - transaction); std::move(callback).Run(blink::mojom::IDBDatabaseGetResult::NewErrorResult( - blink::mojom::IDBError::New(error.code(), error.message()))); + CreateIDBErrorPtr(blink::mojom::IDBException::kUnknownError, + "Unknown error", transaction))); return s; } @@ -834,12 +825,10 @@ Status IndexedDBDatabase::GetOperation( } if (!s.ok()) { - IndexedDBDatabaseError error = - CreateError(blink::mojom::IDBException::kUnknownError, - "Corruption detected, unable to continue", transaction); std::move(callback).Run( - blink::mojom::IDBDatabaseGetResult::NewErrorResult( - blink::mojom::IDBError::New(error.code(), error.message()))); + blink::mojom::IDBDatabaseGetResult::NewErrorResult(CreateIDBErrorPtr( + blink::mojom::IDBException::kUnknownError, + "Corruption detected, unable to continue", transaction))); return s; } @@ -859,12 +848,10 @@ Status IndexedDBDatabase::GetOperation( s = backing_store_->GetRecord(transaction->BackingStoreTransaction(), id(), object_store_id, *key, &value); if (!s.ok()) { - IndexedDBDatabaseError error = - CreateError(blink::mojom::IDBException::kUnknownError, - "Unknown error", transaction); std::move(callback).Run( blink::mojom::IDBDatabaseGetResult::NewErrorResult( - blink::mojom::IDBError::New(error.code(), error.message()))); + CreateIDBErrorPtr(blink::mojom::IDBException::kUnknownError, + "Unknown error", transaction))); return s; } @@ -902,11 +889,9 @@ Status IndexedDBDatabase::GetOperation( transaction->BackingStoreTransaction(), id(), object_store_id, index_id, *key, &primary_key); if (!s.ok()) { - IndexedDBDatabaseError error = - CreateError(blink::mojom::IDBException::kUnknownError, "Unknown error", - transaction); std::move(callback).Run(blink::mojom::IDBDatabaseGetResult::NewErrorResult( - blink::mojom::IDBError::New(error.code(), error.message()))); + CreateIDBErrorPtr(blink::mojom::IDBException::kUnknownError, + "Unknown error", transaction))); return s; } @@ -926,11 +911,9 @@ Status IndexedDBDatabase::GetOperation( s = backing_store_->GetRecord(transaction->BackingStoreTransaction(), id(), object_store_id, *primary_key, &value); if (!s.ok()) { - IndexedDBDatabaseError error = - CreateError(blink::mojom::IDBException::kUnknownError, "Unknown error", - transaction); std::move(callback).Run(blink::mojom::IDBDatabaseGetResult::NewErrorResult( - blink::mojom::IDBError::New(error.code(), error.message()))); + CreateIDBErrorPtr(blink::mojom::IDBException::kUnknownError, + "Unknown error", transaction))); return s; } @@ -975,10 +958,8 @@ Status IndexedDBDatabase::GetAllOperation( std::move(callback).Run(result_sink.BindNewPipeAndPassReceiver()); if (!IsObjectStoreIdAndMaybeIndexIdInMetadata(object_store_id, index_id)) { - IndexedDBDatabaseError error = CreateError( - blink::mojom::IDBException::kUnknownError, "Bad request", transaction); - result_sink->OnError( - blink::mojom::IDBError::New(error.code(), error.message())); + result_sink->OnError(CreateIDBErrorPtr( + blink::mojom::IDBException::kUnknownError, "Bad request", transaction)); return leveldb::Status::InvalidArgument("Invalid object_store_id."); } @@ -991,11 +972,9 @@ Status IndexedDBDatabase::GetAllOperation( Status s = Status::OK(); if (!dispatcher_host) { - IndexedDBDatabaseError error = - CreateError(blink::mojom::IDBException::kUnknownError, "Unknown error", - transaction); result_sink->OnError( - blink::mojom::IDBError::New(error.code(), error.message())); + CreateIDBErrorPtr(blink::mojom::IDBException::kUnknownError, + "Unknown error", transaction)); return s; } @@ -1031,11 +1010,9 @@ Status IndexedDBDatabase::GetAllOperation( if (!s.ok()) { DLOG(ERROR) << "Unable to open cursor operation: " << s.ToString(); - IndexedDBDatabaseError error = - CreateError(blink::mojom::IDBException::kUnknownError, - "Corruption detected, unable to continue", transaction); - result_sink->OnError( - blink::mojom::IDBError::New(error.code(), error.message())); + result_sink->OnError(CreateIDBErrorPtr( + blink::mojom::IDBException::kUnknownError, + "Corruption detected, unable to continue", transaction)); return s; } @@ -1070,11 +1047,9 @@ Status IndexedDBDatabase::GetAllOperation( did_first_seek = true; } if (!s.ok()) { - IndexedDBDatabaseError error = - CreateError(blink::mojom::IDBException::kUnknownError, - "Seek failure, unable to continue", transaction); result_sink->OnError( - blink::mojom::IDBError::New(error.code(), error.message())); + CreateIDBErrorPtr(blink::mojom::IDBException::kUnknownError, + "Seek failure, unable to continue", transaction)); return s; } @@ -1140,11 +1115,10 @@ Status IndexedDBDatabase::PutOperation( DCHECK(transaction->in_flight_memory().IsValid()); if (!IsObjectStoreIdInMetadata(params->object_store_id)) { - IndexedDBDatabaseError error = CreateError( - blink::mojom::IDBException::kUnknownError, "Bad request", transaction); std::move(params->callback) .Run(blink::mojom::IDBTransactionPutResult::NewErrorResult( - blink::mojom::IDBError::New(error.code(), error.message()))); + CreateIDBErrorPtr(blink::mojom::IDBException::kUnknownError, + "Bad request", transaction))); return leveldb::Status::InvalidArgument("Invalid object_store_id."); } @@ -1161,12 +1135,11 @@ Status IndexedDBDatabase::PutOperation( GenerateKey(backing_store_, transaction, id(), params->object_store_id); key_was_generated = true; if (!auto_inc_key->IsValid()) { - IndexedDBDatabaseError error = - CreateError(blink::mojom::IDBException::kConstraintError, - "Maximum key generator value reached.", transaction); std::move(params->callback) .Run(blink::mojom::IDBTransactionPutResult::NewErrorResult( - blink::mojom::IDBError::New(error.code(), error.message()))); + CreateIDBErrorPtr(blink::mojom::IDBException::kConstraintError, + "Maximum key generator value reached.", + transaction))); return s; } key = std::move(auto_inc_key); @@ -1187,39 +1160,35 @@ Status IndexedDBDatabase::PutOperation( if (!found_status.ok()) return found_status; if (found) { - IndexedDBDatabaseError error = - CreateError(blink::mojom::IDBException::kConstraintError, - "Key already exists in the object store.", transaction); std::move(params->callback) .Run(blink::mojom::IDBTransactionPutResult::NewErrorResult( - blink::mojom::IDBError::New(error.code(), error.message()))); + CreateIDBErrorPtr(blink::mojom::IDBException::kConstraintError, + "Key already exists in the object store.", + transaction))); return found_status; } } std::vector> index_writers; - std::u16string error_message; + std::string error_message; bool obeys_constraints = false; bool backing_store_success = MakeIndexWriters( transaction, backing_store_, id(), object_store, *key, key_was_generated, params->index_keys, &index_writers, &error_message, &obeys_constraints); if (!backing_store_success) { - IndexedDBDatabaseError error = - CreateError(blink::mojom::IDBException::kUnknownError, - "Internal error: backing store error updating index keys.", - transaction); std::move(params->callback) .Run(blink::mojom::IDBTransactionPutResult::NewErrorResult( - blink::mojom::IDBError::New(error.code(), error.message()))); + CreateIDBErrorPtr( + blink::mojom::IDBException::kUnknownError, + "Internal error: backing store error updating index keys.", + transaction))); return s; } if (!obeys_constraints) { - IndexedDBDatabaseError error = - CreateError(blink::mojom::IDBException::kConstraintError, error_message, - transaction); std::move(params->callback) .Run(blink::mojom::IDBTransactionPutResult::NewErrorResult( - blink::mojom::IDBError::New(error.code(), error.message()))); + CreateIDBErrorPtr(blink::mojom::IDBException::kConstraintError, + error_message, transaction))); return s; } @@ -1288,7 +1257,7 @@ Status IndexedDBDatabase::SetIndexKeysOperation( } std::vector> index_writers; - std::u16string error_message; + std::string error_message; bool obeys_constraints = false; DCHECK(metadata_.object_stores.find(object_store_id) != metadata_.object_stores.end()); @@ -1329,11 +1298,10 @@ Status IndexedDBDatabase::BatchGetAllOperation( transaction->id()); if (!IsObjectStoreIdAndMaybeIndexIdInMetadata(object_store_id, index_id)) { - IndexedDBDatabaseError error = CreateError( - blink::mojom::IDBException::kUnknownError, "Bad request", transaction); std::move(callback).Run( blink::mojom::IDBDatabaseBatchGetAllResult::NewErrorResult( - blink::mojom::IDBError::New(error.code(), error.message()))); + CreateIDBErrorPtr(blink::mojom::IDBException::kUnknownError, + "Bad request", transaction))); return leveldb::Status::InvalidArgument("Invalid object_store_id."); } @@ -1344,12 +1312,10 @@ Status IndexedDBDatabase::BatchGetAllOperation( Status s = Status::OK(); if (!dispatcher_host) { - IndexedDBDatabaseError error = - CreateError(blink::mojom::IDBException::kUnknownError, "Unknown error", - transaction); std::move(callback).Run( blink::mojom::IDBDatabaseBatchGetAllResult::NewErrorResult( - blink::mojom::IDBError::New(error.code(), error.message()))); + CreateIDBErrorPtr(blink::mojom::IDBException::kUnknownError, + "Unknown error", transaction))); return s; } @@ -1375,12 +1341,11 @@ Status IndexedDBDatabase::BatchGetAllOperation( if (!s.ok()) { DLOG(ERROR) << "Unable to open cursor operation: " << s.ToString(); - IndexedDBDatabaseError error = - CreateError(blink::mojom::IDBException::kUnknownError, - "Corruption detected, unable to continue", transaction); std::move(callback).Run( blink::mojom::IDBDatabaseBatchGetAllResult::NewErrorResult( - blink::mojom::IDBError::New(error.code(), error.message()))); + CreateIDBErrorPtr(blink::mojom::IDBException::kUnknownError, + "Corruption detected, unable to continue", + transaction))); return s; } @@ -1406,12 +1371,11 @@ Status IndexedDBDatabase::BatchGetAllOperation( did_first_seek = true; } if (!s.ok()) { - IndexedDBDatabaseError error = - CreateError(blink::mojom::IDBException::kUnknownError, - "Seek failure, unable to continue", transaction); std::move(callback).Run( blink::mojom::IDBDatabaseBatchGetAllResult::NewErrorResult( - blink::mojom::IDBError::New(error.code(), error.message()))); + CreateIDBErrorPtr(blink::mojom::IDBException::kUnknownError, + "Seek failure, unable to continue", + transaction))); return s; } @@ -1428,12 +1392,11 @@ Status IndexedDBDatabase::BatchGetAllOperation( found_values.push_back(std::move(return_value)); if (response_size > GetUsableMessageSizeInBytes()) { - IndexedDBDatabaseError error = - CreateError(blink::mojom::IDBException::kUnknownError, - "Maximum IPC message size exceeded.", transaction); std::move(callback).Run( blink::mojom::IDBDatabaseBatchGetAllResult::NewErrorResult( - blink::mojom::IDBError::New(error.code(), error.message()))); + CreateIDBErrorPtr(blink::mojom::IDBException::kUnknownError, + "Maximum IPC message size exceeded.", + transaction))); return s; } } @@ -1480,12 +1443,10 @@ Status IndexedDBDatabase::OpenCursorOperation( Status s; if (!dispatcher_host) { - IndexedDBDatabaseError error = - CreateError(blink::mojom::IDBException::kUnknownError, - "Dispatcher not connected.", transaction); std::move(params->callback) .Run(blink::mojom::IDBDatabaseOpenCursorResult::NewErrorResult( - blink::mojom::IDBError::New(error.code(), error.message()))); + CreateIDBErrorPtr(blink::mojom::IDBException::kUnknownError, + "Dispatcher not connected.", transaction))); return s; } @@ -1638,11 +1599,12 @@ Status IndexedDBDatabase::DeleteRangeOperation( Status IndexedDBDatabase::GetKeyGeneratorCurrentNumberOperation( int64_t object_store_id, - std::unique_ptr callbacks, + blink::mojom::IDBDatabase::GetKeyGeneratorCurrentNumberCallback callback, IndexedDBTransaction* transaction) { if (!IsObjectStoreIdInMetadata(object_store_id)) { - callbacks->OnError(CreateError(blink::mojom::IDBException::kDataError, - "Object store id not valid.", transaction)); + std::move(callback).Run( + -1, CreateIDBErrorPtr(blink::mojom::IDBException::kDataError, + "Object store id not valid.", transaction)); return leveldb::Status::InvalidArgument("Invalid object_store_id."); } @@ -1651,12 +1613,14 @@ Status IndexedDBDatabase::GetKeyGeneratorCurrentNumberOperation( transaction->BackingStoreTransaction(), id(), object_store_id, ¤t_number); if (!s.ok()) { - callbacks->OnError(CreateError( - blink::mojom::IDBException::kDataError, - "Failed to get the current number of key generator.", transaction)); + std::move(callback).Run( + -1, + CreateIDBErrorPtr(blink::mojom::IDBException::kDataError, + "Failed to get the current number of key generator.", + transaction)); return s; } - callbacks->OnSuccess(current_number); + std::move(callback).Run(current_number, nullptr); return s; } diff --git a/content/browser/indexed_db/indexed_db_database.h b/content/browser/indexed_db/indexed_db_database.h index 0d516619d1c697..6baec4f35d0e97 100644 --- a/content/browser/indexed_db/indexed_db_database.h +++ b/content/browser/indexed_db/indexed_db_database.h @@ -288,7 +288,7 @@ class CONTENT_EXPORT IndexedDBDatabase { leveldb::Status GetKeyGeneratorCurrentNumberOperation( int64_t object_store_id, - std::unique_ptr callbacks, + blink::mojom::IDBDatabase::GetKeyGeneratorCurrentNumberCallback callback, IndexedDBTransaction* transaction); leveldb::Status ClearOperation( diff --git a/content/browser/indexed_db/indexed_db_database_error.cc b/content/browser/indexed_db/indexed_db_database_error.cc index 02c19b74d58c64..53ef48fd3f0d1c 100644 --- a/content/browser/indexed_db/indexed_db_database_error.cc +++ b/content/browser/indexed_db/indexed_db_database_error.cc @@ -14,8 +14,8 @@ IndexedDBDatabaseError::IndexedDBDatabaseError(blink::mojom::IDBException code) : code_(code) {} IndexedDBDatabaseError::IndexedDBDatabaseError(blink::mojom::IDBException code, - const char* message) - : code_(code), message_(base::ASCIIToUTF16(message)) {} + const std::string& message) + : code_(code), message_(base::UTF8ToUTF16(message)) {} IndexedDBDatabaseError::IndexedDBDatabaseError(blink::mojom::IDBException code, const std::u16string& message) diff --git a/content/browser/indexed_db/indexed_db_database_error.h b/content/browser/indexed_db/indexed_db_database_error.h index f78a14771696e0..a45c9d43a79fb7 100644 --- a/content/browser/indexed_db/indexed_db_database_error.h +++ b/content/browser/indexed_db/indexed_db_database_error.h @@ -18,7 +18,8 @@ class CONTENT_EXPORT IndexedDBDatabaseError { public: IndexedDBDatabaseError(); explicit IndexedDBDatabaseError(blink::mojom::IDBException code); - IndexedDBDatabaseError(blink::mojom::IDBException code, const char* message); + IndexedDBDatabaseError(blink::mojom::IDBException code, + const std::string& message); IndexedDBDatabaseError(blink::mojom::IDBException code, const std::u16string& message); ~IndexedDBDatabaseError(); diff --git a/content/browser/indexed_db/indexed_db_index_writer.cc b/content/browser/indexed_db/indexed_db_index_writer.cc index f4527aa2dbd933..ba571d1f5a7ae8 100644 --- a/content/browser/indexed_db/indexed_db_index_writer.cc +++ b/content/browser/indexed_db/indexed_db_index_writer.cc @@ -7,6 +7,7 @@ #include #include +#include "base/strings/utf_string_conversions.h" #include "content/browser/indexed_db/indexed_db_backing_store.h" #include "content/browser/indexed_db/indexed_db_transaction.h" #include "third_party/blink/public/common/indexeddb/indexeddb_metadata.h" @@ -37,7 +38,7 @@ bool IndexWriter::VerifyIndexKeys( int64_t index_id, bool* can_add_keys, const IndexedDBKey& primary_key, - std::u16string* error_message) const { + std::string* error_message) const { *can_add_keys = false; for (const auto& key : keys_) { bool ok = AddingKeyAllowed(backing_store, transaction, database_id, @@ -47,10 +48,10 @@ bool IndexWriter::VerifyIndexKeys( return false; if (!*can_add_keys) { if (error_message) { - *error_message = u"Unable to add key to index '" + - index_metadata_.name + - u"': at least one key does not satisfy the uniqueness " - u"requirements."; + *error_message = "Unable to add key to index '" + + base::UTF16ToUTF8(index_metadata_.name) + + "': at least one key does not satisfy the uniqueness " + "requirements."; } return true; } @@ -116,7 +117,7 @@ bool MakeIndexWriters(IndexedDBTransaction* transaction, bool key_was_generated, const std::vector& index_keys, std::vector>* index_writers, - std::u16string* error_message, + std::string* error_message, bool* completed) { *completed = false; diff --git a/content/browser/indexed_db/indexed_db_index_writer.h b/content/browser/indexed_db/indexed_db_index_writer.h index 681ffe792abcb8..ca90764b93f0a4 100644 --- a/content/browser/indexed_db/indexed_db_index_writer.h +++ b/content/browser/indexed_db/indexed_db_index_writer.h @@ -39,7 +39,7 @@ class IndexWriter { int64_t index_id, bool* can_add_keys, const blink::IndexedDBKey& primary_key, - std::u16string* error_message) const; + std::string* error_message) const; leveldb::Status WriteIndexKeys( const IndexedDBBackingStore::RecordIdentifier& record, @@ -77,7 +77,7 @@ class IndexWriter { bool key_was_generated, const std::vector& index_keys, std::vector>* index_writers, - std::u16string* error_message, + std::string* error_message, bool* completed); } // namespace content diff --git a/third_party/blink/public/mojom/indexeddb/indexeddb.mojom b/third_party/blink/public/mojom/indexeddb/indexeddb.mojom index b144cd1ec91ab4..28088f8af40acf 100644 --- a/third_party/blink/public/mojom/indexeddb/indexeddb.mojom +++ b/third_party/blink/public/mojom/indexeddb/indexeddb.mojom @@ -228,12 +228,9 @@ struct IDBReturnValue { IDBKeyPath key_path; }; -// The IDBCallbacks interface is used to return results for individual requests. -// Some requests may return multiple results before completion, such as -// UpgradeNeeded before SuccessDatabase. -// -// TODO(https://crbug.com/627484): Many of these could be replaced with -// replies associated with particular messages. +// The IDBCallbacks interface is used to return results for requests to open or +// delete databases. +// TODO(estade): this interface should be renamed. interface IDBCallbacks { Error(IDBException code, mojo_base.mojom.String16 message); @@ -416,12 +413,9 @@ interface IDBDatabase { DeleteRange(int64 transaction_id, int64 object_store_id, IDBKeyRange key_range) => (bool success); - // Gets the current number of an IndexedDB ObjectStore's key generator. It - // is implemented in the browser (more priviledged) and handles requests in - // the renderer process: WebIDBDatabaseImpl::GetKeyGeneratorCurrentNumber() - GetKeyGeneratorCurrentNumber(int64 transaction_id, - int64 object_store_id, - pending_associated_remote pending_callbacks); + // Gets the current number of an IndexedDB ObjectStore's key generator. + GetKeyGeneratorCurrentNumber(int64 transaction_id, int64 object_store_id) + => (int64 result, IDBError? error); // Correlates to IDBObjectStore::clear() Clear(int64 transaction_id, int64 object_store_id) => (bool success); diff --git a/third_party/blink/renderer/modules/indexeddb/idb_object_store.cc b/third_party/blink/renderer/modules/indexeddb/idb_object_store.cc index f265dbe7b455c8..d3429fd3756862 100644 --- a/third_party/blink/renderer/modules/indexeddb/idb_object_store.cc +++ b/third_party/blink/renderer/modules/indexeddb/idb_object_store.cc @@ -736,7 +736,9 @@ IDBRequest* IDBObjectStore::getKeyGeneratorCurrentNumber( script_state, this, transaction_.Get(), std::move(metrics)); BackendDB()->GetKeyGeneratorCurrentNumber( - transaction_->Id(), Id(), request->CreateWebCallbacks().release()); + transaction_->Id(), Id(), + WTF::BindOnce(&IDBRequest::OnGotKeyGeneratorCurrentNumber, + WrapWeakPersistent(request))); return request; } diff --git a/third_party/blink/renderer/modules/indexeddb/idb_request.cc b/third_party/blink/renderer/modules/indexeddb/idb_request.cc index 94bbfde06cd073..17b3f197a2719f 100644 --- a/third_party/blink/renderer/modules/indexeddb/idb_request.cc +++ b/third_party/blink/renderer/modules/indexeddb/idb_request.cc @@ -577,6 +577,17 @@ void IDBRequest::OnAdvanceCursor(mojom::blink::IDBCursorResultPtr result) { std::move(result->get_values()->values[0])); } +void IDBRequest::OnGotKeyGeneratorCurrentNumber( + int64_t number, + mojom::blink::IDBErrorPtr error) { + if (error) { + HandleError(std::move(error)); + } else { + DCHECK_GE(number, 0); + HandleResponse(number); + } +} + void IDBRequest::EnqueueResponse(DOMException* error) { TRACE_EVENT0("IndexedDB", "IDBRequest::EnqueueResponse(DOMException)"); if (!ShouldEnqueueEvent()) { diff --git a/third_party/blink/renderer/modules/indexeddb/idb_request.h b/third_party/blink/renderer/modules/indexeddb/idb_request.h index 7f20e8b89f1184..9ce997db281bd3 100644 --- a/third_party/blink/renderer/modules/indexeddb/idb_request.h +++ b/third_party/blink/renderer/modules/indexeddb/idb_request.h @@ -288,6 +288,8 @@ class MODULES_EXPORT IDBRequest : public EventTarget, void OnBatchGetAll(mojom::blink::IDBDatabaseBatchGetAllResultPtr result); void OnOpenCursor(mojom::blink::IDBDatabaseOpenCursorResultPtr result); void OnAdvanceCursor(mojom::blink::IDBCursorResultPtr result); + void OnGotKeyGeneratorCurrentNumber(int64_t number, + mojom::blink::IDBErrorPtr error); // Only IDBOpenDBRequest instances should receive these: virtual void EnqueueBlocked(int64_t old_version) { NOTREACHED(); } diff --git a/third_party/blink/renderer/modules/indexeddb/idb_request_test.cc b/third_party/blink/renderer/modules/indexeddb/idb_request_test.cc index 45ae1b2d6ebcea..16e7932eb12fdd 100644 --- a/third_party/blink/renderer/modules/indexeddb/idb_request_test.cc +++ b/third_party/blink/renderer/modules/indexeddb/idb_request_test.cc @@ -136,8 +136,7 @@ class BackendDatabaseWithMockedClose void GetKeyGeneratorCurrentNumber( int64_t transaction_id, int64_t object_store_id, - mojo::PendingAssociatedRemote - pending_callbacks) override {} + GetKeyGeneratorCurrentNumberCallback callback) override {} void Clear(int64_t transaction_id, int64_t object_store_id, ClearCallback callback) override {} diff --git a/third_party/blink/renderer/modules/indexeddb/mock_idb_database.h b/third_party/blink/renderer/modules/indexeddb/mock_idb_database.h index 679167168fec8a..d361d87ab21483 100644 --- a/third_party/blink/renderer/modules/indexeddb/mock_idb_database.h +++ b/third_party/blink/renderer/modules/indexeddb/mock_idb_database.h @@ -128,7 +128,7 @@ class MockIDBDatabase : public testing::StrictMock { GetKeyGeneratorCurrentNumber, (int64_t transaction_id, int64_t object_store_id, - mojo::PendingAssociatedRemote), + GetKeyGeneratorCurrentNumberCallback), (override)); MOCK_METHOD(void, Clear, diff --git a/third_party/blink/renderer/modules/indexeddb/web_idb_database.cc b/third_party/blink/renderer/modules/indexeddb/web_idb_database.cc index 121c9adc120cf0..ebf347cefac692 100644 --- a/third_party/blink/renderer/modules/indexeddb/web_idb_database.cc +++ b/third_party/blink/renderer/modules/indexeddb/web_idb_database.cc @@ -176,13 +176,12 @@ void WebIDBDatabase::DeleteRange( std::move(key_range_ptr), std::move(success_callback)); } -void WebIDBDatabase::GetKeyGeneratorCurrentNumber(int64_t transaction_id, - int64_t object_store_id, - WebIDBCallbacks* callbacks) { - callbacks->SetState(transaction_id); - database_->GetKeyGeneratorCurrentNumber( - transaction_id, object_store_id, - GetCallbacksProxy(base::WrapUnique(callbacks))); +void WebIDBDatabase::GetKeyGeneratorCurrentNumber( + int64_t transaction_id, + int64_t object_store_id, + mojom::blink::IDBDatabase::GetKeyGeneratorCurrentNumberCallback callback) { + database_->GetKeyGeneratorCurrentNumber(transaction_id, object_store_id, + std::move(callback)); } void WebIDBDatabase::Clear( diff --git a/third_party/blink/renderer/modules/indexeddb/web_idb_database.h b/third_party/blink/renderer/modules/indexeddb/web_idb_database.h index 281f0513224886..34768da1712a9d 100644 --- a/third_party/blink/renderer/modules/indexeddb/web_idb_database.h +++ b/third_party/blink/renderer/modules/indexeddb/web_idb_database.h @@ -91,9 +91,10 @@ class MODULES_EXPORT WebIDBDatabase final { int64_t object_store_id, const IDBKeyRange*, mojom::blink::IDBDatabase::DeleteRangeCallback callback); - void GetKeyGeneratorCurrentNumber(int64_t transaction_id, - int64_t object_store_id, - WebIDBCallbacks*); + void GetKeyGeneratorCurrentNumber( + int64_t transaction_id, + int64_t object_store_id, + mojom::blink::IDBDatabase::GetKeyGeneratorCurrentNumberCallback callback); void Clear(int64_t transaction_id, int64_t object_store_id, mojom::blink::IDBDatabase::ClearCallback callback);