Commit 6053bbb2 authored by Chase Phillips's avatar Chase Phillips Committed by Commit Bot

IndexedDB: Refactor AddCursorBinding into CreateCursorBinding

As part of cleanup from CL https://crrev.com/c/1626660, this CL
moves creation of CursorImpl into IndexedDBDispatcherHost by
refactoring AddCursorBinding into CreateCursorBinding.

As a result, the OpenCursor calling path no longer needs to pass
the origin and sequenced task runner into the OpenCursorOperation
task and ownership of CursorImpl and the mojo binding steps is
made simpler.

Bug: 988868
Change-Id: Iab0be1d24d98fc6b0088d01c67c1b778c5c13318
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1725318Reviewed-by: default avatarDaniel Murphy <dmurph@chromium.org>
Commit-Queue: Chase Phillips <cmp@chromium.org>
Cr-Commit-Position: refs/heads/master@{#682428}
parent 3b9e31d6
......@@ -320,8 +320,7 @@ void DatabaseImpl::OpenCursor(
connection_->database()->OpenCursor(
transaction, object_store_id, index_id,
std::make_unique<IndexedDBKeyRange>(key_range), direction, key_only,
task_type, std::move(aborting_callback), origin_,
dispatcher_host_->AsWeakPtr(), idb_runner_);
task_type, std::move(aborting_callback), dispatcher_host_->AsWeakPtr());
}
void DatabaseImpl::Count(
......
......@@ -1813,9 +1813,7 @@ void IndexedDBDatabase::OpenCursor(
bool key_only,
blink::mojom::IDBTaskType task_type,
blink::mojom::IDBDatabase::OpenCursorCallback callback,
const url::Origin& origin,
base::WeakPtr<IndexedDBDispatcherHost> dispatcher_host,
scoped_refptr<base::SequencedTaskRunner> idb_runner) {
base::WeakPtr<IndexedDBDispatcherHost> dispatcher_host) {
DCHECK(transaction);
IDB_TRACE1("IndexedDBDatabase::OpenCursor", "txn.id", transaction->id());
......@@ -1832,20 +1830,29 @@ void IndexedDBDatabase::OpenCursor(
key_only ? indexed_db::CURSOR_KEY_ONLY : indexed_db::CURSOR_KEY_AND_VALUE;
params->task_type = task_type;
params->callback = std::move(callback);
transaction->ScheduleTask(BindWeakOperation(
&IndexedDBDatabase::OpenCursorOperation, AsWeakPtr(), std::move(params),
origin, std::move(dispatcher_host), std::move(idb_runner)));
transaction->ScheduleTask(
BindWeakOperation(&IndexedDBDatabase::OpenCursorOperation, AsWeakPtr(),
std::move(params), std::move(dispatcher_host)));
}
Status IndexedDBDatabase::OpenCursorOperation(
std::unique_ptr<OpenCursorOperationParams> params,
const url::Origin& origin,
base::WeakPtr<IndexedDBDispatcherHost> dispatcher_host,
scoped_refptr<base::SequencedTaskRunner> idb_runner,
IndexedDBTransaction* transaction) {
IDB_TRACE1("IndexedDBDatabase::OpenCursorOperation", "txn.id",
transaction->id());
Status s = Status::OK();
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;
}
// The frontend has begun indexing, so this pauses the transaction
// until the indexing is complete. This can't happen any earlier
// because we don't want to switch to early mode in case multiple
......@@ -1853,7 +1860,6 @@ Status IndexedDBDatabase::OpenCursorOperation(
if (params->task_type == blink::mojom::IDBTaskType::Preemptive)
transaction->AddPreemptiveEvent();
Status s = Status::OK();
std::unique_ptr<IndexedDBBackingStore::Cursor> backing_store_cursor;
if (params->index_id == IndexedDBIndexMetadata::kInvalidId) {
if (params->cursor_type == indexed_db::CURSOR_KEY_ONLY) {
......@@ -1897,16 +1903,6 @@ Status IndexedDBDatabase::OpenCursorOperation(
IndexedDBCursor* cursor_ptr = cursor.get();
transaction->RegisterOpenCursor(cursor_ptr);
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()) {
......@@ -1914,8 +1910,6 @@ Status IndexedDBDatabase::OpenCursorOperation(
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(),
......@@ -1924,13 +1918,11 @@ Status IndexedDBDatabase::OpenCursorOperation(
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(),
dispatcher_host->CreateCursorBinding(std::move(cursor)),
cursor_ptr->key(), cursor_ptr->primary_key(),
std::move(mojo_value))));
return s;
}
......
......@@ -195,9 +195,7 @@ class CONTENT_EXPORT IndexedDBDatabase {
bool key_only,
blink::mojom::IDBTaskType task_type,
blink::mojom::IDBDatabase::OpenCursorCallback callback,
const url::Origin& origin,
base::WeakPtr<IndexedDBDispatcherHost> dispatcher_host,
scoped_refptr<base::SequencedTaskRunner> idb_runner);
base::WeakPtr<IndexedDBDispatcherHost> dispatcher_host);
void Count(IndexedDBTransaction* transaction,
int64_t object_store_id,
int64_t index_id,
......@@ -273,9 +271,7 @@ class CONTENT_EXPORT IndexedDBDatabase {
struct OpenCursorOperationParams;
leveldb::Status OpenCursorOperation(
std::unique_ptr<OpenCursorOperationParams> params,
const url::Origin& origin,
base::WeakPtr<IndexedDBDispatcherHost> dispatcher_host,
scoped_refptr<base::SequencedTaskRunner> idb_runner,
IndexedDBTransaction* transaction);
leveldb::Status CountOperation(
int64_t object_store_id,
......
......@@ -17,6 +17,7 @@
#include "content/browser/indexed_db/indexed_db_callbacks.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_cursor.h"
#include "content/browser/indexed_db/indexed_db_database_callbacks.h"
#include "content/browser/indexed_db/indexed_db_factory_impl.h"
#include "content/browser/indexed_db/indexed_db_pending_connection.h"
......@@ -93,16 +94,21 @@ void IndexedDBDispatcherHost::AddDatabaseBinding(
database_bindings_.AddBinding(std::move(database), std::move(request));
}
void IndexedDBDispatcherHost::AddCursorBinding(
std::unique_ptr<CursorImpl> cursor,
blink::mojom::IDBCursorAssociatedRequest request) {
blink::mojom::IDBCursorAssociatedPtrInfo
IndexedDBDispatcherHost::CreateCursorBinding(
std::unique_ptr<IndexedDBCursor> cursor) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
auto* cursor_ptr = cursor.get();
mojo::BindingId binding_id =
cursor_bindings_.AddBinding(std::move(cursor), std::move(request));
cursor_ptr->OnRemoveBinding(
const auto& context = bindings_.dispatch_context();
auto cursor_impl = std::make_unique<CursorImpl>(
std::move(cursor), context.origin, this, IDBTaskRunner());
auto* cursor_impl_ptr = cursor_impl.get();
blink::mojom::IDBCursorAssociatedPtrInfo ptr_info;
mojo::BindingId binding_id = cursor_bindings_.AddBinding(
std::move(cursor_impl), mojo::MakeRequest(&ptr_info));
cursor_impl_ptr->OnRemoveBinding(
base::BindOnce(&IndexedDBDispatcherHost::RemoveCursorBinding,
weak_factory_.GetWeakPtr(), binding_id));
return ptr_info;
}
void IndexedDBDispatcherHost::RemoveCursorBinding(mojo::BindingId binding_id) {
......
......@@ -33,8 +33,8 @@ class Origin;
}
namespace content {
class CursorImpl;
class IndexedDBContextImpl;
class IndexedDBCursor;
class IndexedDBTransaction;
// Constructed on UI thread. All remaining calls (including destruction) should
......@@ -55,8 +55,8 @@ class CONTENT_EXPORT IndexedDBDispatcherHost
void AddDatabaseBinding(std::unique_ptr<blink::mojom::IDBDatabase> database,
blink::mojom::IDBDatabaseAssociatedRequest request);
void AddCursorBinding(std::unique_ptr<CursorImpl> cursor,
blink::mojom::IDBCursorAssociatedRequest request);
blink::mojom::IDBCursorAssociatedPtrInfo CreateCursorBinding(
std::unique_ptr<IndexedDBCursor> cursor);
void RemoveCursorBinding(mojo::BindingId binding_id);
void AddTransactionBinding(
......
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