Commit 46d3cdb6 authored by Chase Phillips's avatar Chase Phillips Committed by Commit Bot

IndexedDB: Convert IDBDatabase.OpenCursor to use native Mojo callback

As part of this change, also remove IDBCallbacks.SuccessValue and
IDBCallbacks.SuccessCursor which are no longer used.

Bug: 717812
Change-Id: I5bb3b5d77ba7248b2286dc579d8d25805b72cd5b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1626660
Commit-Queue: Chase Phillips <cmp@chromium.org>
Reviewed-by: default avatarDaniel Murphy <dmurph@chromium.org>
Reviewed-by: default avatarTom Sepez <tsepez@chromium.org>
Cr-Commit-Position: refs/heads/master@{#681877}
parent a7c549b9
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "base/sequence_checker.h" #include "base/sequence_checker.h"
#include "base/sequenced_task_runner.h" #include "base/sequenced_task_runner.h"
#include "content/browser/bad_message.h" #include "content/browser/bad_message.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_connection.h"
#include "content/browser/indexed_db/indexed_db_context_impl.h" #include "content/browser/indexed_db/indexed_db_context_impl.h"
#include "content/browser/indexed_db/indexed_db_dispatcher_host.h" #include "content/browser/indexed_db/indexed_db_dispatcher_host.h"
...@@ -169,7 +170,7 @@ void DatabaseImpl::Get(int64_t transaction_id, ...@@ -169,7 +170,7 @@ void DatabaseImpl::Get(int64_t transaction_id,
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (!connection_->IsConnected()) { if (!connection_->IsConnected()) {
IndexedDBDatabaseError error(blink::kWebIDBDatabaseExceptionUnknownError, IndexedDBDatabaseError error(blink::kWebIDBDatabaseExceptionUnknownError,
"Unknown error"); "Not connected.");
std::move(callback).Run(blink::mojom::IDBDatabaseGetResult::NewErrorResult( std::move(callback).Run(blink::mojom::IDBDatabaseGetResult::NewErrorResult(
blink::mojom::IDBError::New(error.code(), error.message()))); blink::mojom::IDBError::New(error.code(), error.message())));
return; return;
...@@ -179,7 +180,7 @@ void DatabaseImpl::Get(int64_t transaction_id, ...@@ -179,7 +180,7 @@ void DatabaseImpl::Get(int64_t transaction_id,
connection_->GetTransaction(transaction_id); connection_->GetTransaction(transaction_id);
if (!transaction) { if (!transaction) {
IndexedDBDatabaseError error(blink::kWebIDBDatabaseExceptionUnknownError, IndexedDBDatabaseError error(blink::kWebIDBDatabaseExceptionUnknownError,
"Unknown error"); "Unknown transaction.");
std::move(callback).Run(blink::mojom::IDBDatabaseGetResult::NewErrorResult( std::move(callback).Run(blink::mojom::IDBDatabaseGetResult::NewErrorResult(
blink::mojom::IDBError::New(error.code(), error.message()))); blink::mojom::IDBError::New(error.code(), error.message())));
return; return;
...@@ -201,7 +202,7 @@ void DatabaseImpl::GetAll(int64_t transaction_id, ...@@ -201,7 +202,7 @@ void DatabaseImpl::GetAll(int64_t transaction_id,
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (!connection_->IsConnected()) { if (!connection_->IsConnected()) {
IndexedDBDatabaseError error(blink::kWebIDBDatabaseExceptionUnknownError, IndexedDBDatabaseError error(blink::kWebIDBDatabaseExceptionUnknownError,
"Unknown error"); "Not connected.");
std::move(callback).Run( std::move(callback).Run(
blink::mojom::IDBDatabaseGetAllResult::NewErrorResult( blink::mojom::IDBDatabaseGetAllResult::NewErrorResult(
blink::mojom::IDBError::New(error.code(), error.message()))); blink::mojom::IDBError::New(error.code(), error.message())));
...@@ -212,7 +213,7 @@ void DatabaseImpl::GetAll(int64_t transaction_id, ...@@ -212,7 +213,7 @@ void DatabaseImpl::GetAll(int64_t transaction_id,
connection_->GetTransaction(transaction_id); connection_->GetTransaction(transaction_id);
if (!transaction) { if (!transaction) {
IndexedDBDatabaseError error(blink::kWebIDBDatabaseExceptionUnknownError, IndexedDBDatabaseError error(blink::kWebIDBDatabaseExceptionUnknownError,
"Unknown error"); "Unknown transaction.");
std::move(callback).Run( std::move(callback).Run(
blink::mojom::IDBDatabaseGetAllResult::NewErrorResult( blink::mojom::IDBDatabaseGetAllResult::NewErrorResult(
blink::mojom::IDBError::New(error.code(), error.message()))); blink::mojom::IDBError::New(error.code(), error.message())));
...@@ -280,18 +281,33 @@ void DatabaseImpl::OpenCursor( ...@@ -280,18 +281,33 @@ void DatabaseImpl::OpenCursor(
blink::mojom::IDBCursorDirection direction, blink::mojom::IDBCursorDirection direction,
bool key_only, bool key_only,
blink::mojom::IDBTaskType task_type, blink::mojom::IDBTaskType task_type,
blink::mojom::IDBCallbacksAssociatedPtrInfo callbacks_info) { blink::mojom::IDBDatabase::OpenCursorCallback callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
scoped_refptr<IndexedDBCallbacks> callbacks( if (!connection_->IsConnected()) {
new IndexedDBCallbacks(dispatcher_host_->AsWeakPtr(), origin_, IndexedDBDatabaseError error(blink::kWebIDBDatabaseExceptionUnknownError,
std::move(callbacks_info), idb_runner_)); "Not connected.");
if (!connection_->IsConnected()) std::move(callback).Run(
blink::mojom::IDBDatabaseOpenCursorResult::NewErrorResult(
blink::mojom::IDBError::New(error.code(), error.message())));
return; return;
}
IndexedDBTransaction* transaction = IndexedDBTransaction* transaction =
connection_->GetTransaction(transaction_id); connection_->GetTransaction(transaction_id);
if (!transaction) if (!transaction) {
IndexedDBDatabaseError error(blink::kWebIDBDatabaseExceptionUnknownError,
"Unknown transaction.");
std::move(callback).Run(
blink::mojom::IDBDatabaseOpenCursorResult::NewErrorResult(
blink::mojom::IDBError::New(error.code(), error.message())));
return; return;
}
blink::mojom::IDBDatabase::OpenCursorCallback aborting_callback =
CreateCallbackAbortOnDestruct<
blink::mojom::IDBDatabase::OpenCursorCallback,
blink::mojom::IDBDatabaseOpenCursorResultPtr>(
std::move(callback), transaction->AsWeakPtr());
if (transaction->mode() != blink::mojom::IDBTransactionMode::VersionChange && if (transaction->mode() != blink::mojom::IDBTransactionMode::VersionChange &&
task_type == blink::mojom::IDBTaskType::Preemptive) { task_type == blink::mojom::IDBTaskType::Preemptive) {
...@@ -304,7 +320,8 @@ void DatabaseImpl::OpenCursor( ...@@ -304,7 +320,8 @@ void DatabaseImpl::OpenCursor(
connection_->database()->OpenCursor( connection_->database()->OpenCursor(
transaction, object_store_id, index_id, transaction, object_store_id, index_id,
std::make_unique<IndexedDBKeyRange>(key_range), direction, key_only, std::make_unique<IndexedDBKeyRange>(key_range), direction, key_only,
task_type, std::move(callbacks)); task_type, std::move(aborting_callback), origin_,
dispatcher_host_->AsWeakPtr(), idb_runner_);
} }
void DatabaseImpl::Count( void DatabaseImpl::Count(
......
...@@ -83,7 +83,7 @@ class DatabaseImpl : public blink::mojom::IDBDatabase { ...@@ -83,7 +83,7 @@ class DatabaseImpl : public blink::mojom::IDBDatabase {
blink::mojom::IDBCursorDirection direction, blink::mojom::IDBCursorDirection direction,
bool key_only, bool key_only,
blink::mojom::IDBTaskType task_type, blink::mojom::IDBTaskType task_type,
blink::mojom::IDBCallbacksAssociatedPtrInfo callbacks_info) override; blink::mojom::IDBDatabase::OpenCursorCallback callback) override;
void Count(int64_t transaction_id, void Count(int64_t transaction_id,
int64_t object_store_id, int64_t object_store_id,
int64_t index_id, int64_t index_id,
......
...@@ -366,80 +366,6 @@ void IndexedDBCallbacks::OnSuccess( ...@@ -366,80 +366,6 @@ void IndexedDBCallbacks::OnSuccess(
complete_ = true; complete_ = true;
} }
void IndexedDBCallbacks::OnSuccess(std::unique_ptr<IndexedDBCursor> cursor,
const IndexedDBKey& key,
const IndexedDBKey& primary_key,
IndexedDBValue* value) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(!complete_);
DCHECK_EQ(blink::mojom::IDBDataLoss::None, data_loss_);
blink::mojom::IDBValuePtr mojo_value;
std::vector<IndexedDBBlobInfo> blob_info;
if (value) {
mojo_value = IndexedDBValue::ConvertAndEraseValue(value);
blob_info.swap(value->blob_info);
}
SafeCursorWrapper cursor_wrapper(std::move(cursor));
if (!callbacks_)
return;
if (!dispatcher_host_) {
OnConnectionError();
return;
}
auto cursor_impl =
std::make_unique<CursorImpl>(std::move(cursor_wrapper.cursor_), origin_,
dispatcher_host_.get(), idb_runner_);
if (mojo_value && !IndexedDBCallbacks::CreateAllBlobs(
dispatcher_host_->blob_storage_context(),
IndexedDBValueBlob::GetIndexedDBValueBlobs(
blob_info, &mojo_value->blob_or_file_info))) {
return;
}
blink::mojom::IDBCursorAssociatedPtrInfo ptr_info;
auto request = mojo::MakeRequest(&ptr_info);
dispatcher_host_->AddCursorBinding(std::move(cursor_impl),
std::move(request));
callbacks_->SuccessCursor(std::move(ptr_info), key, primary_key,
std::move(mojo_value));
complete_ = true;
}
void IndexedDBCallbacks::OnSuccess(IndexedDBReturnValue* value) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(!complete_);
DCHECK_EQ(blink::mojom::IDBDataLoss::None, data_loss_);
blink::mojom::IDBReturnValuePtr mojo_value;
std::vector<IndexedDBBlobInfo> blob_info;
if (value) {
mojo_value = IndexedDBReturnValue::ConvertReturnValue(value);
blob_info = value->blob_info;
}
if (!callbacks_)
return;
if (!dispatcher_host_) {
OnConnectionError();
return;
}
if (mojo_value &&
!IndexedDBCallbacks::CreateAllBlobs(
dispatcher_host_->blob_storage_context(),
IndexedDBValueBlob::GetIndexedDBValueBlobs(
blob_info, &mojo_value->value->blob_or_file_info))) {
return;
}
callbacks_->SuccessValue(std::move(mojo_value));
complete_ = true;
}
void IndexedDBCallbacks::OnSuccess(const IndexedDBKey& value) { void IndexedDBCallbacks::OnSuccess(const IndexedDBKey& value) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(!complete_); DCHECK(!complete_);
......
...@@ -38,7 +38,6 @@ class IndexedDBConnection; ...@@ -38,7 +38,6 @@ class IndexedDBConnection;
class IndexedDBCursor; class IndexedDBCursor;
class IndexedDBDatabase; class IndexedDBDatabase;
struct IndexedDBDataLossInfo; struct IndexedDBDataLossInfo;
struct IndexedDBReturnValue;
struct IndexedDBValue; struct IndexedDBValue;
class CONTENT_EXPORT IndexedDBCallbacks class CONTENT_EXPORT IndexedDBCallbacks
...@@ -109,16 +108,6 @@ class CONTENT_EXPORT IndexedDBCallbacks ...@@ -109,16 +108,6 @@ class CONTENT_EXPORT IndexedDBCallbacks
virtual void OnSuccess(std::unique_ptr<IndexedDBConnection> connection, virtual void OnSuccess(std::unique_ptr<IndexedDBConnection> connection,
const blink::IndexedDBDatabaseMetadata& metadata); const blink::IndexedDBDatabaseMetadata& metadata);
// IndexedDBDatabase::OpenCursor
virtual void OnSuccess(std::unique_ptr<IndexedDBCursor> cursor,
const blink::IndexedDBKey& key,
const blink::IndexedDBKey& primary_key,
IndexedDBValue* value);
// IndexedDBDatabase::Get
// IndexedDBCursor::Advance
virtual void OnSuccess(IndexedDBReturnValue* value);
// IndexedDBDatabase::Put / IndexedDBCursor::Update // IndexedDBDatabase::Put / IndexedDBCursor::Update
virtual void OnSuccess(const blink::IndexedDBKey& key); virtual void OnSuccess(const blink::IndexedDBKey& key);
......
...@@ -20,8 +20,10 @@ ...@@ -20,8 +20,10 @@
#include "base/stl_util.h" #include "base/stl_util.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "content/browser/indexed_db/cursor_impl.h"
#include "content/browser/indexed_db/indexed_db_blob_info.h" #include "content/browser/indexed_db/indexed_db_blob_info.h"
#include "content/browser/indexed_db/indexed_db_callback_helpers.h" #include "content/browser/indexed_db/indexed_db_callback_helpers.h"
#include "content/browser/indexed_db/indexed_db_callbacks.h"
#include "content/browser/indexed_db/indexed_db_class_factory.h" #include "content/browser/indexed_db/indexed_db_class_factory.h"
#include "content/browser/indexed_db/indexed_db_connection.h" #include "content/browser/indexed_db/indexed_db_connection.h"
#include "content/browser/indexed_db/indexed_db_context_impl.h" #include "content/browser/indexed_db/indexed_db_context_impl.h"
...@@ -1753,7 +1755,7 @@ struct IndexedDBDatabase::OpenCursorOperationParams { ...@@ -1753,7 +1755,7 @@ struct IndexedDBDatabase::OpenCursorOperationParams {
blink::mojom::IDBCursorDirection direction; blink::mojom::IDBCursorDirection direction;
indexed_db::CursorType cursor_type; indexed_db::CursorType cursor_type;
blink::mojom::IDBTaskType task_type; blink::mojom::IDBTaskType task_type;
scoped_refptr<IndexedDBCallbacks> callbacks; blink::mojom::IDBDatabase::OpenCursorCallback callback;
private: private:
DISALLOW_COPY_AND_ASSIGN(OpenCursorOperationParams); DISALLOW_COPY_AND_ASSIGN(OpenCursorOperationParams);
...@@ -1767,7 +1769,10 @@ void IndexedDBDatabase::OpenCursor( ...@@ -1767,7 +1769,10 @@ void IndexedDBDatabase::OpenCursor(
blink::mojom::IDBCursorDirection direction, blink::mojom::IDBCursorDirection direction,
bool key_only, bool key_only,
blink::mojom::IDBTaskType task_type, blink::mojom::IDBTaskType task_type,
scoped_refptr<IndexedDBCallbacks> callbacks) { blink::mojom::IDBDatabase::OpenCursorCallback callback,
const url::Origin& origin,
base::WeakPtr<IndexedDBDispatcherHost> dispatcher_host,
scoped_refptr<base::SequencedTaskRunner> idb_runner) {
DCHECK(transaction); DCHECK(transaction);
IDB_TRACE1("IndexedDBDatabase::OpenCursor", "txn.id", transaction->id()); IDB_TRACE1("IndexedDBDatabase::OpenCursor", "txn.id", transaction->id());
...@@ -1783,13 +1788,17 @@ void IndexedDBDatabase::OpenCursor( ...@@ -1783,13 +1788,17 @@ void IndexedDBDatabase::OpenCursor(
params->cursor_type = params->cursor_type =
key_only ? indexed_db::CURSOR_KEY_ONLY : indexed_db::CURSOR_KEY_AND_VALUE; key_only ? indexed_db::CURSOR_KEY_ONLY : indexed_db::CURSOR_KEY_AND_VALUE;
params->task_type = task_type; params->task_type = task_type;
params->callbacks = callbacks; params->callback = std::move(callback);
transaction->ScheduleTask(BindWeakOperation( transaction->ScheduleTask(BindWeakOperation(
&IndexedDBDatabase::OpenCursorOperation, AsWeakPtr(), std::move(params))); &IndexedDBDatabase::OpenCursorOperation, AsWeakPtr(), std::move(params),
origin, std::move(dispatcher_host), std::move(idb_runner)));
} }
Status IndexedDBDatabase::OpenCursorOperation( Status IndexedDBDatabase::OpenCursorOperation(
std::unique_ptr<OpenCursorOperationParams> params, std::unique_ptr<OpenCursorOperationParams> params,
const url::Origin& origin,
base::WeakPtr<IndexedDBDispatcherHost> dispatcher_host,
scoped_refptr<base::SequencedTaskRunner> idb_runner,
IndexedDBTransaction* transaction) { IndexedDBTransaction* transaction) {
IDB_TRACE1("IndexedDBDatabase::OpenCursorOperation", "txn.id", IDB_TRACE1("IndexedDBDatabase::OpenCursorOperation", "txn.id",
transaction->id()); transaction->id());
...@@ -1834,7 +1843,8 @@ Status IndexedDBDatabase::OpenCursorOperation( ...@@ -1834,7 +1843,8 @@ Status IndexedDBDatabase::OpenCursorOperation(
if (!backing_store_cursor) { if (!backing_store_cursor) {
// Occurs when we've reached the end of cursor's data. // Occurs when we've reached the end of cursor's data.
params->callbacks->OnSuccess(nullptr); std::move(params->callback)
.Run(blink::mojom::IDBDatabaseOpenCursorResult::NewEmpty(true));
return s; return s;
} }
...@@ -1843,8 +1853,42 @@ Status IndexedDBDatabase::OpenCursorOperation( ...@@ -1843,8 +1853,42 @@ Status IndexedDBDatabase::OpenCursorOperation(
transaction->AsWeakPtr()); transaction->AsWeakPtr());
IndexedDBCursor* cursor_ptr = cursor.get(); IndexedDBCursor* cursor_ptr = cursor.get();
transaction->RegisterOpenCursor(cursor_ptr); transaction->RegisterOpenCursor(cursor_ptr);
params->callbacks->OnSuccess(std::move(cursor), cursor_ptr->key(),
cursor_ptr->primary_key(), cursor_ptr->Value()); if (!dispatcher_host) {
IndexedDBDatabaseError error =
CreateError(blink::kWebIDBDatabaseExceptionUnknownError,
"Dispatcher not connected.", transaction);
std::move(params->callback)
.Run(blink::mojom::IDBDatabaseOpenCursorResult::NewErrorResult(
blink::mojom::IDBError::New(error.code(), error.message())));
return s;
}
blink::mojom::IDBValuePtr mojo_value;
std::vector<IndexedDBBlobInfo> blob_info;
if (cursor_ptr->Value()) {
mojo_value = IndexedDBValue::ConvertAndEraseValue(cursor_ptr->Value());
blob_info.swap(cursor_ptr->Value()->blob_info);
}
auto cursor_impl = std::make_unique<CursorImpl>(
std::move(cursor), origin, dispatcher_host.get(), idb_runner);
if (mojo_value &&
!IndexedDBCallbacks::CreateAllBlobs(
dispatcher_host->blob_storage_context(),
IndexedDBCallbacks::IndexedDBValueBlob::GetIndexedDBValueBlobs(
blob_info, &mojo_value->blob_or_file_info))) {
return s;
}
blink::mojom::IDBCursorAssociatedPtrInfo ptr_info;
auto request = mojo::MakeRequest(&ptr_info);
dispatcher_host->AddCursorBinding(std::move(cursor_impl), std::move(request));
std::move(params->callback)
.Run(blink::mojom::IDBDatabaseOpenCursorResult::NewValue(
blink::mojom::IDBDatabaseOpenCursorValue::New(
std::move(ptr_info), cursor_ptr->key(), cursor_ptr->primary_key(),
std::move(mojo_value))));
return s; return s;
} }
......
...@@ -194,7 +194,10 @@ class CONTENT_EXPORT IndexedDBDatabase { ...@@ -194,7 +194,10 @@ class CONTENT_EXPORT IndexedDBDatabase {
blink::mojom::IDBCursorDirection, blink::mojom::IDBCursorDirection,
bool key_only, bool key_only,
blink::mojom::IDBTaskType task_type, blink::mojom::IDBTaskType task_type,
scoped_refptr<IndexedDBCallbacks> callbacks); blink::mojom::IDBDatabase::OpenCursorCallback callback,
const url::Origin& origin,
base::WeakPtr<IndexedDBDispatcherHost> dispatcher_host,
scoped_refptr<base::SequencedTaskRunner> idb_runner);
void Count(IndexedDBTransaction* transaction, void Count(IndexedDBTransaction* transaction,
int64_t object_store_id, int64_t object_store_id,
int64_t index_id, int64_t index_id,
...@@ -270,6 +273,9 @@ class CONTENT_EXPORT IndexedDBDatabase { ...@@ -270,6 +273,9 @@ class CONTENT_EXPORT IndexedDBDatabase {
struct OpenCursorOperationParams; struct OpenCursorOperationParams;
leveldb::Status OpenCursorOperation( leveldb::Status OpenCursorOperation(
std::unique_ptr<OpenCursorOperationParams> params, std::unique_ptr<OpenCursorOperationParams> params,
const url::Origin& origin,
base::WeakPtr<IndexedDBDispatcherHost> dispatcher_host,
scoped_refptr<base::SequencedTaskRunner> idb_runner,
IndexedDBTransaction* transaction); IndexedDBTransaction* transaction);
leveldb::Status CountOperation( leveldb::Status CountOperation(
int64_t object_store_id, int64_t object_store_id,
......
...@@ -64,24 +64,6 @@ class MockMojoIndexedDBCallbacks : public blink::mojom::IDBCallbacks { ...@@ -64,24 +64,6 @@ class MockMojoIndexedDBCallbacks : public blink::mojom::IDBCallbacks {
MockedSuccessDatabase(&database_info, metadata); MockedSuccessDatabase(&database_info, metadata);
} }
MOCK_METHOD4(MockedSuccessCursor,
void(blink::mojom::IDBCursorAssociatedPtrInfo* cursor,
const blink::IndexedDBKey& key,
const blink::IndexedDBKey& primary_key,
blink::mojom::IDBValuePtr* value));
void SuccessCursor(blink::mojom::IDBCursorAssociatedPtrInfo cursor,
const blink::IndexedDBKey& key,
const blink::IndexedDBKey& primary_key,
blink::mojom::IDBValuePtr value) override {
MockedSuccessCursor(&cursor, key, primary_key, &value);
}
MOCK_METHOD1(MockedSuccessValue,
void(blink::mojom::IDBReturnValuePtr* value));
void SuccessValue(blink::mojom::IDBReturnValuePtr value) override {
MockedSuccessValue(&value);
}
MOCK_METHOD1(SuccessKey, void(const blink::IndexedDBKey& key)); MOCK_METHOD1(SuccessKey, void(const blink::IndexedDBKey& key));
MOCK_METHOD1(SuccessInteger, void(int64_t value)); MOCK_METHOD1(SuccessInteger, void(int64_t value));
MOCK_METHOD0(Success, void()); MOCK_METHOD0(Success, void());
......
...@@ -227,15 +227,6 @@ interface IDBCallbacks { ...@@ -227,15 +227,6 @@ interface IDBCallbacks {
SuccessDatabase(associated IDBDatabase? database, SuccessDatabase(associated IDBDatabase? database,
IDBDatabaseMetadata metadata); IDBDatabaseMetadata metadata);
// Database::OpenCursor
SuccessCursor(associated IDBCursor cursor,
IDBKey key,
IDBKey primary_key,
IDBValue? value);
// Database::Get / Cursor::Advance
SuccessValue(IDBReturnValue? value);
// Database::Put / Cursor::Update // Database::Put / Cursor::Update
SuccessKey(IDBKey key); SuccessKey(IDBKey key);
...@@ -317,6 +308,19 @@ union IDBDatabaseGetAllResult { ...@@ -317,6 +308,19 @@ union IDBDatabaseGetAllResult {
array<IDBReturnValue> values; array<IDBReturnValue> values;
}; };
struct IDBDatabaseOpenCursorValue {
associated IDBCursor cursor;
IDBKey key;
IDBKey primary_key;
IDBValue? value;
};
union IDBDatabaseOpenCursorResult {
IDBError error_result; // |error| is reserved, so call this |error_result|.
bool empty; // Only true values are allowed.
IDBDatabaseOpenCursorValue value;
};
interface IDBDatabase { interface IDBDatabase {
RenameObjectStore(int64 transaction_id, RenameObjectStore(int64 transaction_id,
int64 object_store_id, int64 object_store_id,
...@@ -360,8 +364,8 @@ interface IDBDatabase { ...@@ -360,8 +364,8 @@ interface IDBDatabase {
IDBKeyRange key_range, IDBKeyRange key_range,
IDBCursorDirection direction, IDBCursorDirection direction,
bool key_only, bool key_only,
IDBTaskType task_type, IDBTaskType task_type)
associated IDBCallbacks callbacks); => (IDBDatabaseOpenCursorResult result);
Count(int64 transaction_id, Count(int64 transaction_id,
int64 object_store_id, int64 object_store_id,
int64 index_id, int64 index_id,
......
...@@ -124,7 +124,7 @@ class BackendDatabaseWithMockedClose ...@@ -124,7 +124,7 @@ class BackendDatabaseWithMockedClose
mojom::blink::IDBCursorDirection direction, mojom::blink::IDBCursorDirection direction,
bool key_only, bool key_only,
mojom::blink::IDBTaskType task_type, mojom::blink::IDBTaskType task_type,
mojom::blink::IDBCallbacksAssociatedPtrInfo callbacks) override {} mojom::blink::IDBDatabase::OpenCursorCallback callback) override {}
void Count(int64_t transaction_id, void Count(int64_t transaction_id,
int64_t object_store_id, int64_t object_store_id,
int64_t index_id, int64_t index_id,
......
...@@ -45,11 +45,17 @@ class WebIDBCallbacks : public mojom::blink::IDBCallbacks { ...@@ -45,11 +45,17 @@ class WebIDBCallbacks : public mojom::blink::IDBCallbacks {
virtual void DetachRequestFromCallback() = 0; virtual void DetachRequestFromCallback() = 0;
virtual void SetState(base::WeakPtr<WebIDBCursorImpl> cursor, virtual void SetState(base::WeakPtr<WebIDBCursorImpl> cursor,
int64_t transaction_id) = 0; int64_t transaction_id) = 0;
virtual void SuccessCursor(
mojom::blink::IDBCursorAssociatedPtrInfo cursor_info,
std::unique_ptr<IDBKey> key,
std::unique_ptr<IDBKey> primary_key,
base::Optional<std::unique_ptr<IDBValue>> optional_value) = 0;
virtual void SuccessCursorContinue( virtual void SuccessCursorContinue(
std::unique_ptr<IDBKey>, std::unique_ptr<IDBKey>,
std::unique_ptr<IDBKey> primary_key, std::unique_ptr<IDBKey> primary_key,
base::Optional<std::unique_ptr<IDBValue>>) = 0; base::Optional<std::unique_ptr<IDBValue>>) = 0;
virtual void SuccessArray(Vector<mojom::blink::IDBReturnValuePtr> values) = 0; virtual void SuccessArray(Vector<mojom::blink::IDBReturnValuePtr> values) = 0;
virtual void SuccessValue(mojom::blink::IDBReturnValuePtr value) = 0;
}; };
} // namespace blink } // namespace blink
......
...@@ -177,7 +177,8 @@ void WebIDBDatabaseImpl::OpenCursor(int64_t transaction_id, ...@@ -177,7 +177,8 @@ void WebIDBDatabaseImpl::OpenCursor(int64_t transaction_id,
mojom::IDBCursorDirection direction, mojom::IDBCursorDirection direction,
bool key_only, bool key_only,
mojom::IDBTaskType task_type, mojom::IDBTaskType task_type,
WebIDBCallbacks* callbacks) { WebIDBCallbacks* callbacks_ptr) {
std::unique_ptr<WebIDBCallbacks> callbacks(callbacks_ptr);
IndexedDBDispatcher::ResetCursorPrefetchCaches(transaction_id, nullptr); IndexedDBDispatcher::ResetCursorPrefetchCaches(transaction_id, nullptr);
mojom::blink::IDBKeyRangePtr key_range_ptr = mojom::blink::IDBKeyRangePtr key_range_ptr =
...@@ -186,7 +187,33 @@ void WebIDBDatabaseImpl::OpenCursor(int64_t transaction_id, ...@@ -186,7 +187,33 @@ void WebIDBDatabaseImpl::OpenCursor(int64_t transaction_id,
database_->OpenCursor(transaction_id, object_store_id, index_id, database_->OpenCursor(transaction_id, object_store_id, index_id,
std::move(key_range_ptr), direction, key_only, std::move(key_range_ptr), direction, key_only,
task_type, task_type,
GetCallbacksProxy(base::WrapUnique(callbacks))); WTF::Bind(&WebIDBDatabaseImpl::OpenCursorCallback,
WTF::Unretained(this), std::move(callbacks)));
}
void WebIDBDatabaseImpl::OpenCursorCallback(
std::unique_ptr<WebIDBCallbacks> callbacks,
mojom::blink::IDBDatabaseOpenCursorResultPtr result) {
if (result->is_error_result()) {
callbacks->Error(result->get_error_result()->error_code,
std::move(result->get_error_result()->error_message));
callbacks.reset();
return;
}
if (result->is_empty()) {
CHECK(result->get_empty()); // Only true values are allowed.
callbacks->SuccessValue(nullptr);
callbacks.reset();
return;
}
CHECK(result->is_value());
callbacks->SuccessCursor(std::move(result->get_value()->cursor),
std::move(result->get_value()->key),
std::move(result->get_value()->primary_key),
std::move(result->get_value()->value));
callbacks.reset();
} }
void WebIDBDatabaseImpl::Count(int64_t transaction_id, void WebIDBDatabaseImpl::Count(int64_t transaction_id,
......
...@@ -77,6 +77,8 @@ class MODULES_EXPORT WebIDBDatabaseImpl : public WebIDBDatabase { ...@@ -77,6 +77,8 @@ class MODULES_EXPORT WebIDBDatabaseImpl : public WebIDBDatabase {
bool key_only, bool key_only,
mojom::IDBTaskType, mojom::IDBTaskType,
WebIDBCallbacks*) override; WebIDBCallbacks*) override;
void OpenCursorCallback(std::unique_ptr<WebIDBCallbacks> callbacks,
mojom::blink::IDBDatabaseOpenCursorResultPtr result);
void Count(int64_t transaction_id, void Count(int64_t transaction_id,
int64_t object_store_id, int64_t object_store_id,
int64_t index_id, int64_t index_id,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment