Skip to content

Commit

Permalink
Migrate references of blink::mojom::IDBCallbacks to new Mojo types
Browse files Browse the repository at this point in the history
Convert both the implementation and clients in the browser and renderer
processes for the blink.mojom.IDBCallbacks interface, and
adapt unit tests.

Bug: 955171, 978694
Change-Id: I14aa9ac688dc657b7303b5c04ad50c98e92eda31
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1774440
Commit-Queue: Mario Sanchez Prada <mario@igalia.com>
Reviewed-by: Chase Phillips <cmp@chromium.org>
Reviewed-by: Dominick Ng <dominickn@chromium.org>
Reviewed-by: Oksana Zhuravlova <oksamyt@chromium.org>
Cr-Commit-Position: refs/heads/master@{#692158}
  • Loading branch information
mariospr authored and Commit Bot committed Aug 30, 2019
1 parent 42fe0bd commit dbb915d
Show file tree
Hide file tree
Showing 21 changed files with 134 additions and 99 deletions.
20 changes: 12 additions & 8 deletions content/browser/indexed_db/database_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -392,11 +392,12 @@ void DatabaseImpl::Count(
int64_t object_store_id,
int64_t index_id,
const IndexedDBKeyRange& key_range,
blink::mojom::IDBCallbacksAssociatedPtrInfo callbacks_info) {
mojo::PendingAssociatedRemote<blink::mojom::IDBCallbacks>
pending_callbacks) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
scoped_refptr<IndexedDBCallbacks> callbacks(
new IndexedDBCallbacks(dispatcher_host_->AsWeakPtr(), origin_,
std::move(callbacks_info), idb_runner_));
std::move(pending_callbacks), idb_runner_));
if (!connection_->IsConnected())
return;

Expand All @@ -420,11 +421,12 @@ void DatabaseImpl::DeleteRange(
int64_t transaction_id,
int64_t object_store_id,
const IndexedDBKeyRange& key_range,
blink::mojom::IDBCallbacksAssociatedPtrInfo callbacks_info) {
mojo::PendingAssociatedRemote<blink::mojom::IDBCallbacks>
pending_callbacks) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
scoped_refptr<IndexedDBCallbacks> callbacks(
new IndexedDBCallbacks(dispatcher_host_->AsWeakPtr(), origin_,
std::move(callbacks_info), idb_runner_));
std::move(pending_callbacks), idb_runner_));
if (!connection_->IsConnected())
return;

Expand All @@ -445,11 +447,12 @@ void DatabaseImpl::DeleteRange(
void DatabaseImpl::GetKeyGeneratorCurrentNumber(
int64_t transaction_id,
int64_t object_store_id,
blink::mojom::IDBCallbacksAssociatedPtrInfo callbacks_info) {
mojo::PendingAssociatedRemote<blink::mojom::IDBCallbacks>
pending_callbacks) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
scoped_refptr<IndexedDBCallbacks> callbacks(
new IndexedDBCallbacks(dispatcher_host_->AsWeakPtr(), origin_,
std::move(callbacks_info), idb_runner_));
std::move(pending_callbacks), idb_runner_));
if (!connection_->IsConnected())
return;

Expand All @@ -467,11 +470,12 @@ void DatabaseImpl::GetKeyGeneratorCurrentNumber(
void DatabaseImpl::Clear(
int64_t transaction_id,
int64_t object_store_id,
blink::mojom::IDBCallbacksAssociatedPtrInfo callbacks_info) {
mojo::PendingAssociatedRemote<blink::mojom::IDBCallbacks>
pending_callbacks) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
scoped_refptr<IndexedDBCallbacks> callbacks(
new IndexedDBCallbacks(dispatcher_host_->AsWeakPtr(), origin_,
std::move(callbacks_info), idb_runner_));
std::move(pending_callbacks), idb_runner_));
if (!connection_->IsConnected())
return;

Expand Down
20 changes: 12 additions & 8 deletions content/browser/indexed_db/database_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "base/strings/string16.h"
#include "content/public/browser/browser_thread.h"
#include "mojo/public/cpp/bindings/pending_associated_receiver.h"
#include "mojo/public/cpp/bindings/pending_associated_remote.h"
#include "third_party/blink/public/common/indexeddb/indexeddb_key.h"
#include "third_party/blink/public/common/indexeddb/indexeddb_key_path.h"
#include "third_party/blink/public/mojom/indexeddb/indexeddb.mojom.h"
Expand Down Expand Up @@ -91,19 +92,22 @@ class DatabaseImpl : public blink::mojom::IDBDatabase {
int64_t object_store_id,
int64_t index_id,
const blink::IndexedDBKeyRange& key_range,
blink::mojom::IDBCallbacksAssociatedPtrInfo callbacks) override;
void DeleteRange(
int64_t transaction_id,
int64_t object_store_id,
const blink::IndexedDBKeyRange& key_range,
blink::mojom::IDBCallbacksAssociatedPtrInfo callbacks) override;
mojo::PendingAssociatedRemote<blink::mojom::IDBCallbacks>
pending_callbacks) override;
void DeleteRange(int64_t transaction_id,
int64_t object_store_id,
const blink::IndexedDBKeyRange& key_range,
mojo::PendingAssociatedRemote<blink::mojom::IDBCallbacks>
pending_callbacks) override;
void GetKeyGeneratorCurrentNumber(
int64_t transaction_id,
int64_t object_store_id,
blink::mojom::IDBCallbacksAssociatedPtrInfo callbacks) override;
mojo::PendingAssociatedRemote<blink::mojom::IDBCallbacks>
pending_callbacks) override;
void Clear(int64_t transaction_id,
int64_t object_store_id,
blink::mojom::IDBCallbacksAssociatedPtrInfo callbacks) override;
mojo::PendingAssociatedRemote<blink::mojom::IDBCallbacks>
pending_callbacks) override;
void CreateIndex(int64_t transaction_id,
int64_t object_store_id,
int64_t index_id,
Expand Down
9 changes: 4 additions & 5 deletions content/browser/indexed_db/indexed_db_callbacks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@

using blink::IndexedDBDatabaseMetadata;
using blink::IndexedDBKey;
using blink::mojom::IDBCallbacksAssociatedPtrInfo;
using std::swap;
using storage::ShareableFileReference;

Expand Down Expand Up @@ -214,20 +213,20 @@ bool IndexedDBCallbacks::CreateAllBlobs(
IndexedDBCallbacks::IndexedDBCallbacks(
base::WeakPtr<IndexedDBDispatcherHost> dispatcher_host,
const url::Origin& origin,
blink::mojom::IDBCallbacksAssociatedPtrInfo callbacks_info,
mojo::PendingAssociatedRemote<blink::mojom::IDBCallbacks> pending_callbacks,
scoped_refptr<base::SequencedTaskRunner> idb_runner)
: data_loss_(blink::mojom::IDBDataLoss::None),
dispatcher_host_(std::move(dispatcher_host)),
origin_(origin),
idb_runner_(std::move(idb_runner)) {
DCHECK(idb_runner_->RunsTasksInCurrentSequence());
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (callbacks_info.is_valid()) {
callbacks_.Bind(std::move(callbacks_info));
if (pending_callbacks.is_valid()) {
callbacks_.Bind(std::move(pending_callbacks));
// |callbacks_| is owned by |this|, so if |this| is destroyed, then
// |callbacks_| will also be destroyed. While |callbacks_| is otherwise
// alive, |this| will always be valid.
callbacks_.set_connection_error_handler(base::BindOnce(
callbacks_.set_disconnect_handler(base::BindOnce(
&IndexedDBCallbacks::OnConnectionError, base::Unretained(this)));
}
}
Expand Down
7 changes: 5 additions & 2 deletions content/browser/indexed_db/indexed_db_callbacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include "content/browser/indexed_db/indexed_db_database_error.h"
#include "content/browser/indexed_db/indexed_db_dispatcher_host.h"
#include "content/public/browser/browser_thread.h"
#include "mojo/public/cpp/bindings/associated_remote.h"
#include "mojo/public/cpp/bindings/pending_associated_remote.h"
#include "storage/browser/blob/blob_storage_context.h"
#include "third_party/blink/public/common/indexeddb/indexeddb_key.h"
#include "third_party/blink/public/mojom/indexeddb/indexeddb.mojom.h"
Expand Down Expand Up @@ -85,7 +87,8 @@ class CONTENT_EXPORT IndexedDBCallbacks

IndexedDBCallbacks(base::WeakPtr<IndexedDBDispatcherHost> dispatcher_host,
const url::Origin& origin,
blink::mojom::IDBCallbacksAssociatedPtrInfo callbacks_info,
mojo::PendingAssociatedRemote<blink::mojom::IDBCallbacks>
pending_callbacks,
scoped_refptr<base::SequencedTaskRunner> idb_runner);

virtual void OnError(const IndexedDBDatabaseError& error);
Expand Down Expand Up @@ -144,7 +147,7 @@ class CONTENT_EXPORT IndexedDBCallbacks
base::WeakPtr<IndexedDBDispatcherHost> dispatcher_host_;
url::Origin origin_;
scoped_refptr<base::SequencedTaskRunner> idb_runner_;
blink::mojom::IDBCallbacksAssociatedPtr callbacks_;
mojo::AssociatedRemote<blink::mojom::IDBCallbacks> callbacks_;

SEQUENCE_CHECKER(sequence_checker_);

Expand Down
2 changes: 1 addition & 1 deletion content/browser/indexed_db/indexed_db_database_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ class MockCallbacks : public IndexedDBCallbacks {
MockCallbacks()
: IndexedDBCallbacks(nullptr,
url::Origin(),
nullptr,
mojo::NullAssociatedRemote(),
base::ThreadTaskRunnerHandle::Get()) {}

void OnBlocked(int64_t existing_version) override { blocked_called_ = true; }
Expand Down
18 changes: 10 additions & 8 deletions content/browser/indexed_db/indexed_db_dispatcher_host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -139,33 +139,35 @@ void IndexedDBDispatcherHost::RenderProcessExited(
}

void IndexedDBDispatcherHost::GetDatabaseInfo(
blink::mojom::IDBCallbacksAssociatedPtrInfo callbacks_info) {
mojo::PendingAssociatedRemote<blink::mojom::IDBCallbacks>
pending_callbacks) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);

const auto& context = bindings_.dispatch_context();
scoped_refptr<IndexedDBCallbacks> callbacks(
new IndexedDBCallbacks(this->AsWeakPtr(), context.origin,
std::move(callbacks_info), IDBTaskRunner()));
std::move(pending_callbacks), IDBTaskRunner()));
base::FilePath indexed_db_path = indexed_db_context_->data_path();
indexed_db_context_->GetIDBFactory()->GetDatabaseInfo(
std::move(callbacks), context.origin, indexed_db_path);
}

void IndexedDBDispatcherHost::GetDatabaseNames(
blink::mojom::IDBCallbacksAssociatedPtrInfo callbacks_info) {
mojo::PendingAssociatedRemote<blink::mojom::IDBCallbacks>
pending_callbacks) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);

const auto& context = bindings_.dispatch_context();
scoped_refptr<IndexedDBCallbacks> callbacks(
new IndexedDBCallbacks(this->AsWeakPtr(), context.origin,
std::move(callbacks_info), IDBTaskRunner()));
std::move(pending_callbacks), IDBTaskRunner()));
base::FilePath indexed_db_path = indexed_db_context_->data_path();
indexed_db_context_->GetIDBFactory()->GetDatabaseNames(
std::move(callbacks), context.origin, indexed_db_path);
}

void IndexedDBDispatcherHost::Open(
blink::mojom::IDBCallbacksAssociatedPtrInfo callbacks_info,
mojo::PendingAssociatedRemote<blink::mojom::IDBCallbacks> pending_callbacks,
mojo::PendingAssociatedRemote<blink::mojom::IDBDatabaseCallbacks>
database_callbacks_remote,
const base::string16& name,
Expand All @@ -178,7 +180,7 @@ void IndexedDBDispatcherHost::Open(
const auto& context = bindings_.dispatch_context();
scoped_refptr<IndexedDBCallbacks> callbacks(
new IndexedDBCallbacks(this->AsWeakPtr(), context.origin,
std::move(callbacks_info), IDBTaskRunner()));
std::move(pending_callbacks), IDBTaskRunner()));
scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks(
new IndexedDBDatabaseCallbacks(indexed_db_context_,
std::move(database_callbacks_remote),
Expand All @@ -199,15 +201,15 @@ void IndexedDBDispatcherHost::Open(
}

void IndexedDBDispatcherHost::DeleteDatabase(
blink::mojom::IDBCallbacksAssociatedPtrInfo callbacks_info,
mojo::PendingAssociatedRemote<blink::mojom::IDBCallbacks> pending_callbacks,
const base::string16& name,
bool force_close) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);

const auto& context = bindings_.dispatch_context();
scoped_refptr<IndexedDBCallbacks> callbacks(
new IndexedDBCallbacks(this->AsWeakPtr(), context.origin,
std::move(callbacks_info), IDBTaskRunner()));
std::move(pending_callbacks), IDBTaskRunner()));
base::FilePath indexed_db_path = indexed_db_context_->data_path();
indexed_db_context_->GetIDBFactory()->DeleteDatabase(
name, std::move(callbacks), context.origin, indexed_db_path, force_close);
Expand Down
18 changes: 10 additions & 8 deletions content/browser/indexed_db/indexed_db_dispatcher_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,22 +102,24 @@ class CONTENT_EXPORT IndexedDBDispatcherHost
~IndexedDBDispatcherHost() override;

// blink::mojom::IDBFactory implementation:
void GetDatabaseInfo(
blink::mojom::IDBCallbacksAssociatedPtrInfo callbacks_info) override;
void GetDatabaseInfo(mojo::PendingAssociatedRemote<blink::mojom::IDBCallbacks>
pending_callbacks) override;
void GetDatabaseNames(
blink::mojom::IDBCallbacksAssociatedPtrInfo callbacks_info) override;
void Open(blink::mojom::IDBCallbacksAssociatedPtrInfo callbacks_info,
mojo::PendingAssociatedRemote<blink::mojom::IDBCallbacks>
pending_callbacks) override;
void Open(mojo::PendingAssociatedRemote<blink::mojom::IDBCallbacks>
pending_callbacks,
mojo::PendingAssociatedRemote<blink::mojom::IDBDatabaseCallbacks>
database_callbacks_remote,
const base::string16& name,
int64_t version,
mojo::PendingAssociatedReceiver<blink::mojom::IDBTransaction>
transaction_receiver,
int64_t transaction_id) override;
void DeleteDatabase(
blink::mojom::IDBCallbacksAssociatedPtrInfo callbacks_info,
const base::string16& name,
bool force_close) override;
void DeleteDatabase(mojo::PendingAssociatedRemote<blink::mojom::IDBCallbacks>
pending_callbacks,
const base::string16& name,
bool force_close) override;
void AbortTransactionsAndCompactDatabase(
AbortTransactionsAndCompactDatabaseCallback callback) override;
void AbortTransactionsForDatabase(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@
using blink::IndexedDBDatabaseMetadata;
using blink::IndexedDBIndexKeys;
using blink::IndexedDBKey;
using blink::mojom::IDBCallbacks;
using blink::mojom::IDBCallbacksAssociatedPtrInfo;
using blink::mojom::IDBFactory;
using blink::mojom::IDBFactoryPtr;
using blink::mojom::IDBValue;
Expand Down
2 changes: 1 addition & 1 deletion content/browser/indexed_db/indexed_db_factory_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ class LookingForQuotaErrorMockCallbacks : public IndexedDBCallbacks {
LookingForQuotaErrorMockCallbacks()
: IndexedDBCallbacks(nullptr,
url::Origin(),
nullptr,
mojo::NullAssociatedRemote(),
base::SequencedTaskRunnerHandle::Get()),
error_called_(false) {}
void OnError(const IndexedDBDatabaseError& error) override {
Expand Down
5 changes: 4 additions & 1 deletion content/browser/indexed_db/indexed_db_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,10 @@ class ForceCloseDBCallbacks : public IndexedDBCallbacks {
public:
ForceCloseDBCallbacks(scoped_refptr<IndexedDBContextImpl> idb_context,
const Origin& origin)
: IndexedDBCallbacks(nullptr, origin, nullptr, idb_context->TaskRunner()),
: IndexedDBCallbacks(nullptr,
origin,
mojo::NullAssociatedRemote(),
idb_context->TaskRunner()),
idb_context_(idb_context),
origin_(origin) {}

Expand Down
4 changes: 2 additions & 2 deletions content/browser/indexed_db/mock_indexed_db_callbacks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ namespace content {
MockIndexedDBCallbacks::MockIndexedDBCallbacks()
: IndexedDBCallbacks(nullptr,
url::Origin(),
nullptr,
mojo::NullAssociatedRemote(),
base::SequencedTaskRunnerHandle::Get()) {}
MockIndexedDBCallbacks::MockIndexedDBCallbacks(bool expect_connection)
: IndexedDBCallbacks(nullptr,
url::Origin(),
nullptr,
mojo::NullAssociatedRemote(),
base::SequencedTaskRunnerHandle::Get()),
expect_connection_(expect_connection) {}

Expand Down
10 changes: 4 additions & 6 deletions content/browser/indexed_db/mock_mojo_indexed_db_callbacks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@

namespace content {

MockMojoIndexedDBCallbacks::MockMojoIndexedDBCallbacks() : binding_(this) {}
MockMojoIndexedDBCallbacks::~MockMojoIndexedDBCallbacks() {}
MockMojoIndexedDBCallbacks::MockMojoIndexedDBCallbacks() = default;
MockMojoIndexedDBCallbacks::~MockMojoIndexedDBCallbacks() = default;

blink::mojom::IDBCallbacksAssociatedPtrInfo
mojo::PendingAssociatedRemote<blink::mojom::IDBCallbacks>
MockMojoIndexedDBCallbacks::CreateInterfacePtrAndBind() {
blink::mojom::IDBCallbacksAssociatedPtrInfo ptr_info;
binding_.Bind(::mojo::MakeRequest(&ptr_info));
return ptr_info;
return receiver_.BindNewEndpointAndPassRemote();
}

} // namespace content
8 changes: 5 additions & 3 deletions content/browser/indexed_db/mock_mojo_indexed_db_callbacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
#include <string>

#include "base/macros.h"
#include "mojo/public/cpp/bindings/associated_binding.h"
#include "mojo/public/cpp/bindings/associated_receiver.h"
#include "mojo/public/cpp/bindings/pending_associated_remote.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "third_party/blink/public/common/indexeddb/indexeddb_key.h"
#include "third_party/blink/public/mojom/indexeddb/indexeddb.mojom.h"
Expand All @@ -25,7 +26,8 @@ class MockMojoIndexedDBCallbacks : public blink::mojom::IDBCallbacks {
explicit MockMojoIndexedDBCallbacks();
~MockMojoIndexedDBCallbacks() override;

blink::mojom::IDBCallbacksAssociatedPtrInfo CreateInterfacePtrAndBind();
mojo::PendingAssociatedRemote<blink::mojom::IDBCallbacks>
CreateInterfacePtrAndBind();

MOCK_METHOD2(Error, void(int32_t code, const base::string16& message));

Expand Down Expand Up @@ -70,7 +72,7 @@ class MockMojoIndexedDBCallbacks : public blink::mojom::IDBCallbacks {
MOCK_METHOD0(Success, void());

private:
mojo::AssociatedBinding<blink::mojom::IDBCallbacks> binding_;
mojo::AssociatedReceiver<blink::mojom::IDBCallbacks> receiver_{this};

DISALLOW_COPY_AND_ASSIGN(MockMojoIndexedDBCallbacks);
};
Expand Down
Loading

0 comments on commit dbb915d

Please sign in to comment.