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( ...@@ -320,8 +320,7 @@ 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(aborting_callback), origin_, task_type, std::move(aborting_callback), dispatcher_host_->AsWeakPtr());
dispatcher_host_->AsWeakPtr(), idb_runner_);
} }
void DatabaseImpl::Count( void DatabaseImpl::Count(
......
...@@ -1813,9 +1813,7 @@ void IndexedDBDatabase::OpenCursor( ...@@ -1813,9 +1813,7 @@ void IndexedDBDatabase::OpenCursor(
bool key_only, bool key_only,
blink::mojom::IDBTaskType task_type, blink::mojom::IDBTaskType task_type,
blink::mojom::IDBDatabase::OpenCursorCallback callback, blink::mojom::IDBDatabase::OpenCursorCallback callback,
const url::Origin& origin, base::WeakPtr<IndexedDBDispatcherHost> dispatcher_host) {
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());
...@@ -1832,20 +1830,29 @@ void IndexedDBDatabase::OpenCursor( ...@@ -1832,20 +1830,29 @@ void IndexedDBDatabase::OpenCursor(
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->callback = std::move(callback); params->callback = std::move(callback);
transaction->ScheduleTask(BindWeakOperation( transaction->ScheduleTask(
&IndexedDBDatabase::OpenCursorOperation, AsWeakPtr(), std::move(params), BindWeakOperation(&IndexedDBDatabase::OpenCursorOperation, AsWeakPtr(),
origin, std::move(dispatcher_host), std::move(idb_runner))); std::move(params), std::move(dispatcher_host)));
} }
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, 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());
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 // The frontend has begun indexing, so this pauses the transaction
// until the indexing is complete. This can't happen any earlier // until the indexing is complete. This can't happen any earlier
// because we don't want to switch to early mode in case multiple // because we don't want to switch to early mode in case multiple
...@@ -1853,7 +1860,6 @@ Status IndexedDBDatabase::OpenCursorOperation( ...@@ -1853,7 +1860,6 @@ Status IndexedDBDatabase::OpenCursorOperation(
if (params->task_type == blink::mojom::IDBTaskType::Preemptive) if (params->task_type == blink::mojom::IDBTaskType::Preemptive)
transaction->AddPreemptiveEvent(); transaction->AddPreemptiveEvent();
Status s = Status::OK();
std::unique_ptr<IndexedDBBackingStore::Cursor> backing_store_cursor; std::unique_ptr<IndexedDBBackingStore::Cursor> backing_store_cursor;
if (params->index_id == IndexedDBIndexMetadata::kInvalidId) { if (params->index_id == IndexedDBIndexMetadata::kInvalidId) {
if (params->cursor_type == indexed_db::CURSOR_KEY_ONLY) { if (params->cursor_type == indexed_db::CURSOR_KEY_ONLY) {
...@@ -1897,16 +1903,6 @@ Status IndexedDBDatabase::OpenCursorOperation( ...@@ -1897,16 +1903,6 @@ Status IndexedDBDatabase::OpenCursorOperation(
IndexedDBCursor* cursor_ptr = cursor.get(); IndexedDBCursor* cursor_ptr = cursor.get();
transaction->RegisterOpenCursor(cursor_ptr); 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; blink::mojom::IDBValuePtr mojo_value;
std::vector<IndexedDBBlobInfo> blob_info; std::vector<IndexedDBBlobInfo> blob_info;
if (cursor_ptr->Value()) { if (cursor_ptr->Value()) {
...@@ -1914,8 +1910,6 @@ Status IndexedDBDatabase::OpenCursorOperation( ...@@ -1914,8 +1910,6 @@ Status IndexedDBDatabase::OpenCursorOperation(
blob_info.swap(cursor_ptr->Value()->blob_info); 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 && if (mojo_value &&
!IndexedDBCallbacks::CreateAllBlobs( !IndexedDBCallbacks::CreateAllBlobs(
dispatcher_host->blob_storage_context(), dispatcher_host->blob_storage_context(),
...@@ -1924,13 +1918,11 @@ Status IndexedDBDatabase::OpenCursorOperation( ...@@ -1924,13 +1918,11 @@ Status IndexedDBDatabase::OpenCursorOperation(
return s; 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) std::move(params->callback)
.Run(blink::mojom::IDBDatabaseOpenCursorResult::NewValue( .Run(blink::mojom::IDBDatabaseOpenCursorResult::NewValue(
blink::mojom::IDBDatabaseOpenCursorValue::New( 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)))); std::move(mojo_value))));
return s; return s;
} }
......
...@@ -195,9 +195,7 @@ class CONTENT_EXPORT IndexedDBDatabase { ...@@ -195,9 +195,7 @@ class CONTENT_EXPORT IndexedDBDatabase {
bool key_only, bool key_only,
blink::mojom::IDBTaskType task_type, blink::mojom::IDBTaskType task_type,
blink::mojom::IDBDatabase::OpenCursorCallback callback, blink::mojom::IDBDatabase::OpenCursorCallback callback,
const url::Origin& origin, base::WeakPtr<IndexedDBDispatcherHost> dispatcher_host);
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,
...@@ -273,9 +271,7 @@ class CONTENT_EXPORT IndexedDBDatabase { ...@@ -273,9 +271,7 @@ 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, 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,
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "content/browser/indexed_db/indexed_db_callbacks.h" #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_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_cursor.h"
#include "content/browser/indexed_db/indexed_db_database_callbacks.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_factory_impl.h"
#include "content/browser/indexed_db/indexed_db_pending_connection.h" #include "content/browser/indexed_db/indexed_db_pending_connection.h"
...@@ -93,16 +94,21 @@ void IndexedDBDispatcherHost::AddDatabaseBinding( ...@@ -93,16 +94,21 @@ void IndexedDBDispatcherHost::AddDatabaseBinding(
database_bindings_.AddBinding(std::move(database), std::move(request)); database_bindings_.AddBinding(std::move(database), std::move(request));
} }
void IndexedDBDispatcherHost::AddCursorBinding( blink::mojom::IDBCursorAssociatedPtrInfo
std::unique_ptr<CursorImpl> cursor, IndexedDBDispatcherHost::CreateCursorBinding(
blink::mojom::IDBCursorAssociatedRequest request) { std::unique_ptr<IndexedDBCursor> cursor) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
auto* cursor_ptr = cursor.get(); const auto& context = bindings_.dispatch_context();
mojo::BindingId binding_id = auto cursor_impl = std::make_unique<CursorImpl>(
cursor_bindings_.AddBinding(std::move(cursor), std::move(request)); std::move(cursor), context.origin, this, IDBTaskRunner());
cursor_ptr->OnRemoveBinding( 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, base::BindOnce(&IndexedDBDispatcherHost::RemoveCursorBinding,
weak_factory_.GetWeakPtr(), binding_id)); weak_factory_.GetWeakPtr(), binding_id));
return ptr_info;
} }
void IndexedDBDispatcherHost::RemoveCursorBinding(mojo::BindingId binding_id) { void IndexedDBDispatcherHost::RemoveCursorBinding(mojo::BindingId binding_id) {
......
...@@ -33,8 +33,8 @@ class Origin; ...@@ -33,8 +33,8 @@ class Origin;
} }
namespace content { namespace content {
class CursorImpl;
class IndexedDBContextImpl; class IndexedDBContextImpl;
class IndexedDBCursor;
class IndexedDBTransaction; class IndexedDBTransaction;
// Constructed on UI thread. All remaining calls (including destruction) should // Constructed on UI thread. All remaining calls (including destruction) should
...@@ -55,8 +55,8 @@ class CONTENT_EXPORT IndexedDBDispatcherHost ...@@ -55,8 +55,8 @@ class CONTENT_EXPORT IndexedDBDispatcherHost
void AddDatabaseBinding(std::unique_ptr<blink::mojom::IDBDatabase> database, void AddDatabaseBinding(std::unique_ptr<blink::mojom::IDBDatabase> database,
blink::mojom::IDBDatabaseAssociatedRequest request); blink::mojom::IDBDatabaseAssociatedRequest request);
void AddCursorBinding(std::unique_ptr<CursorImpl> cursor, blink::mojom::IDBCursorAssociatedPtrInfo CreateCursorBinding(
blink::mojom::IDBCursorAssociatedRequest request); std::unique_ptr<IndexedDBCursor> cursor);
void RemoveCursorBinding(mojo::BindingId binding_id); void RemoveCursorBinding(mojo::BindingId binding_id);
void AddTransactionBinding( 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