Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(963)

Unified Diff: content/browser/indexed_db/indexed_db_callbacks.cc

Issue 2370643004: Port messages sent by WebIDBFactoryImpl to Mojo. (Closed)
Patch Set: Allow cpp_only to be set by the invoker. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/indexed_db/indexed_db_callbacks.cc
diff --git a/content/browser/indexed_db/indexed_db_callbacks.cc b/content/browser/indexed_db/indexed_db_callbacks.cc
index 8ec899b7337334f28f8db9813bebaed259ba0869..a5ad99cfd89903cc929f4d64524de065920e8dcb 100644
--- a/content/browser/indexed_db/indexed_db_callbacks.cc
+++ b/content/browser/indexed_db/indexed_db_callbacks.cc
@@ -18,7 +18,6 @@
#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_database_error.h"
#include "content/browser/indexed_db/indexed_db_metadata.h"
#include "content/browser/indexed_db/indexed_db_return_value.h"
@@ -30,15 +29,71 @@
#include "storage/browser/blob/shareable_file_reference.h"
#include "storage/browser/quota/quota_manager.h"
+using indexed_db::mojom::CallbacksAssociatedPtrInfo;
using storage::ShareableFileReference;
namespace content {
namespace {
+
const int32_t kNoCursor = -1;
-const int32_t kNoDatabaseCallbacks = -1;
const int64_t kNoTransaction = -1;
+
+::indexed_db::mojom::DatabaseMetadataPtr ConvertMetadata(
+ const content::IndexedDBDatabaseMetadata& web_metadata) {
+ auto metadata = ::indexed_db::mojom::DatabaseMetadata::New();
+ metadata->id = web_metadata.id;
+ metadata->name = web_metadata.name;
+ metadata->version = web_metadata.version;
+ metadata->max_object_store_id = web_metadata.max_object_store_id;
+
+ for (const auto& iter : web_metadata.object_stores) {
+ const content::IndexedDBObjectStoreMetadata& web_store_metadata =
+ iter.second;
+ auto store_metadata = ::indexed_db::mojom::ObjectStoreMetadata::New();
+ store_metadata->id = web_store_metadata.id;
+ store_metadata->name = web_store_metadata.name;
+ store_metadata->key_path = web_store_metadata.key_path;
+ store_metadata->auto_increment = web_store_metadata.auto_increment;
+ store_metadata->max_index_id = web_store_metadata.max_index_id;
+
+ for (const auto& index_iter : web_store_metadata.indexes) {
+ const content::IndexedDBIndexMetadata& web_index_metadata =
+ index_iter.second;
+ auto index_metadata = ::indexed_db::mojom::IndexMetadata::New();
+ index_metadata->id = web_index_metadata.id;
+ index_metadata->name = web_index_metadata.name;
+ index_metadata->key_path = web_index_metadata.key_path;
+ index_metadata->unique = web_index_metadata.unique;
+ index_metadata->multi_entry = web_index_metadata.multi_entry;
+ store_metadata->indexes.push_back(std::move(index_metadata));
+ }
+ metadata->object_stores.push_back(std::move(store_metadata));
+ }
+ return metadata;
}
+}
+
+class IndexedDBCallbacks::IOThreadHelper {
+ public:
+ IOThreadHelper(CallbacksAssociatedPtrInfo callbacks_info);
+ ~IOThreadHelper();
+
+ void SendBlocked(int64_t existing_version);
+ void SendError(const IndexedDBDatabaseError& error);
+ void SendSuccessDatabase(int32_t database_id,
+ ::indexed_db::mojom::DatabaseMetadataPtr metadata);
+ void SendSuccessInteger(int64_t value);
+ void SendSuccessStringList(const std::vector<base::string16>& value);
+ void SendUpgradeNeeded(int32_t database_id,
+ int64_t old_version,
+ blink::WebIDBDataLoss data_loss,
+ const std::string& data_loss_message,
+ ::indexed_db::mojom::DatabaseMetadataPtr metadata);
+
+ private:
+ ::indexed_db::mojom::CallbacksAssociatedPtr callbacks_;
+};
IndexedDBCallbacks::IndexedDBCallbacks(IndexedDBDispatcherHost* dispatcher_host,
int32_t ipc_thread_id,
@@ -49,9 +104,9 @@ IndexedDBCallbacks::IndexedDBCallbacks(IndexedDBDispatcherHost* dispatcher_host,
ipc_cursor_id_(kNoCursor),
host_transaction_id_(kNoTransaction),
ipc_database_id_(kNoDatabase),
- ipc_database_callbacks_id_(kNoDatabaseCallbacks),
data_loss_(blink::WebIDBDataLossNone),
- sent_blocked_(false) {}
+ sent_blocked_(false),
+ helper_(nullptr) {}
IndexedDBCallbacks::IndexedDBCallbacks(IndexedDBDispatcherHost* dispatcher_host,
int32_t ipc_thread_id,
@@ -63,34 +118,42 @@ IndexedDBCallbacks::IndexedDBCallbacks(IndexedDBDispatcherHost* dispatcher_host,
ipc_cursor_id_(ipc_cursor_id),
host_transaction_id_(kNoTransaction),
ipc_database_id_(kNoDatabase),
- ipc_database_callbacks_id_(kNoDatabaseCallbacks),
data_loss_(blink::WebIDBDataLossNone),
- sent_blocked_(false) {}
+ sent_blocked_(false),
+ helper_(nullptr) {}
-IndexedDBCallbacks::IndexedDBCallbacks(IndexedDBDispatcherHost* dispatcher_host,
- int32_t ipc_thread_id,
- int32_t ipc_callbacks_id,
- int32_t ipc_database_callbacks_id,
- int64_t host_transaction_id,
- const url::Origin& origin)
+IndexedDBCallbacks::IndexedDBCallbacks(
+ IndexedDBDispatcherHost* dispatcher_host,
+ const url::Origin& origin,
+ ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info)
: dispatcher_host_(dispatcher_host),
- ipc_callbacks_id_(ipc_callbacks_id),
- ipc_thread_id_(ipc_thread_id),
ipc_cursor_id_(kNoCursor),
- host_transaction_id_(host_transaction_id),
+ host_transaction_id_(kNoTransaction),
origin_(origin),
ipc_database_id_(kNoDatabase),
- ipc_database_callbacks_id_(ipc_database_callbacks_id),
data_loss_(blink::WebIDBDataLossNone),
- sent_blocked_(false) {}
+ sent_blocked_(false),
+ helper_(nullptr) {
+ if (callbacks_info.is_valid())
+ helper_ = new IOThreadHelper(std::move(callbacks_info));
+}
-IndexedDBCallbacks::~IndexedDBCallbacks() {}
+IndexedDBCallbacks::~IndexedDBCallbacks() {
+ if (helper_)
+ BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, helper_);
+}
void IndexedDBCallbacks::OnError(const IndexedDBDatabaseError& error) {
DCHECK(dispatcher_host_.get());
- dispatcher_host_->Send(new IndexedDBMsg_CallbacksError(
- ipc_thread_id_, ipc_callbacks_id_, error.code(), error.message()));
+ if (helper_) {
+ BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
+ base::Bind(&IOThreadHelper::SendError,
+ base::Unretained(helper_), error));
+ } else {
+ dispatcher_host_->Send(new IndexedDBMsg_CallbacksError(
+ ipc_thread_id_, ipc_callbacks_id_, error.code(), error.message()));
+ }
dispatcher_host_ = NULL;
if (!connection_open_start_time_.is_null()) {
@@ -103,37 +166,31 @@ void IndexedDBCallbacks::OnError(const IndexedDBDatabaseError& error) {
void IndexedDBCallbacks::OnSuccess(const std::vector<base::string16>& value) {
DCHECK(dispatcher_host_.get());
-
+ DCHECK(helper_);
DCHECK_EQ(kNoCursor, ipc_cursor_id_);
DCHECK_EQ(kNoTransaction, host_transaction_id_);
DCHECK_EQ(kNoDatabase, ipc_database_id_);
- DCHECK_EQ(kNoDatabaseCallbacks, ipc_database_callbacks_id_);
- DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_);
- std::vector<base::string16> list;
- for (unsigned i = 0; i < value.size(); ++i)
- list.push_back(value[i]);
-
- dispatcher_host_->Send(new IndexedDBMsg_CallbacksSuccessStringList(
- ipc_thread_id_, ipc_callbacks_id_, list));
+ BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
+ base::Bind(&IOThreadHelper::SendSuccessStringList,
+ base::Unretained(helper_), value));
dispatcher_host_ = NULL;
}
void IndexedDBCallbacks::OnBlocked(int64_t existing_version) {
DCHECK(dispatcher_host_.get());
-
+ DCHECK(helper_);
DCHECK_EQ(kNoCursor, ipc_cursor_id_);
- // No transaction/db callbacks for DeleteDatabase.
- DCHECK_EQ(kNoTransaction == host_transaction_id_,
- kNoDatabaseCallbacks == ipc_database_callbacks_id_);
- DCHECK_EQ(kNoDatabase, ipc_database_id_);
if (sent_blocked_)
return;
sent_blocked_ = true;
- dispatcher_host_->Send(new IndexedDBMsg_CallbacksIntBlocked(
- ipc_thread_id_, ipc_callbacks_id_, existing_version));
+
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ base::Bind(&IOThreadHelper::SendBlocked, base::Unretained(helper_),
+ existing_version));
if (!connection_open_start_time_.is_null()) {
UMA_HISTOGRAM_MEDIUM_TIMES(
@@ -149,29 +206,26 @@ void IndexedDBCallbacks::OnUpgradeNeeded(
const IndexedDBDatabaseMetadata& metadata,
const IndexedDBDataLossInfo& data_loss_info) {
DCHECK(dispatcher_host_.get());
-
- DCHECK_EQ(kNoCursor, ipc_cursor_id_);
+ DCHECK(helper_);
DCHECK_NE(kNoTransaction, host_transaction_id_);
+ DCHECK_EQ(kNoCursor, ipc_cursor_id_);
DCHECK_EQ(kNoDatabase, ipc_database_id_);
- DCHECK_NE(kNoDatabaseCallbacks, ipc_database_callbacks_id_);
data_loss_ = data_loss_info.status;
dispatcher_host_->RegisterTransactionId(host_transaction_id_, origin_);
int32_t ipc_database_id =
- dispatcher_host_->Add(connection.release(), ipc_thread_id_, origin_);
+ dispatcher_host_->Add(connection.release(), origin_);
if (ipc_database_id < 0)
return;
+
ipc_database_id_ = ipc_database_id;
- IndexedDBMsg_CallbacksUpgradeNeeded_Params params;
- params.ipc_thread_id = ipc_thread_id_;
- params.ipc_callbacks_id = ipc_callbacks_id_;
- params.ipc_database_id = ipc_database_id;
- params.ipc_database_callbacks_id = ipc_database_callbacks_id_;
- params.old_version = old_version;
- params.idb_metadata = IndexedDBDispatcherHost::ConvertMetadata(metadata);
- params.data_loss = data_loss_info.status;
- params.data_loss_message = data_loss_info.message;
- dispatcher_host_->Send(new IndexedDBMsg_CallbacksUpgradeNeeded(params));
+
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ base::Bind(&IOThreadHelper::SendUpgradeNeeded, base::Unretained(helper_),
+ ipc_database_id, old_version, data_loss_info.status,
+ data_loss_info.message,
+ base::Passed(ConvertMetadata(metadata))));
if (!connection_open_start_time_.is_null()) {
UMA_HISTOGRAM_MEDIUM_TIMES(
@@ -185,27 +239,23 @@ void IndexedDBCallbacks::OnSuccess(
std::unique_ptr<IndexedDBConnection> connection,
const IndexedDBDatabaseMetadata& metadata) {
DCHECK(dispatcher_host_.get());
-
+ DCHECK(helper_);
DCHECK_EQ(kNoCursor, ipc_cursor_id_);
DCHECK_NE(kNoTransaction, host_transaction_id_);
DCHECK_NE(ipc_database_id_ == kNoDatabase, !connection);
- DCHECK_NE(kNoDatabaseCallbacks, ipc_database_callbacks_id_);
scoped_refptr<IndexedDBCallbacks> self(this);
int32_t ipc_object_id = kNoDatabase;
// Only register if the connection was not previously sent in OnUpgradeNeeded.
if (ipc_database_id_ == kNoDatabase) {
- ipc_object_id =
- dispatcher_host_->Add(connection.release(), ipc_thread_id_, origin_);
+ ipc_object_id = dispatcher_host_->Add(connection.release(), origin_);
}
- dispatcher_host_->Send(new IndexedDBMsg_CallbacksSuccessIDBDatabase(
- ipc_thread_id_,
- ipc_callbacks_id_,
- ipc_database_callbacks_id_,
- ipc_object_id,
- IndexedDBDispatcherHost::ConvertMetadata(metadata)));
+ BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
+ base::Bind(&IOThreadHelper::SendSuccessDatabase,
+ base::Unretained(helper_), ipc_object_id,
+ base::Passed(ConvertMetadata(metadata))));
dispatcher_host_ = NULL;
if (!connection_open_start_time_.is_null()) {
@@ -335,12 +385,12 @@ void IndexedDBCallbacks::OnSuccess(scoped_refptr<IndexedDBCursor> cursor,
const IndexedDBKey& key,
const IndexedDBKey& primary_key,
IndexedDBValue* value) {
+ DCHECK(!helper_);
DCHECK(dispatcher_host_.get());
DCHECK_EQ(kNoCursor, ipc_cursor_id_);
DCHECK_EQ(kNoTransaction, host_transaction_id_);
DCHECK_EQ(kNoDatabase, ipc_database_id_);
- DCHECK_EQ(kNoDatabaseCallbacks, ipc_database_callbacks_id_);
DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_);
int32_t ipc_object_id = dispatcher_host_->Add(cursor.get());
@@ -374,12 +424,12 @@ void IndexedDBCallbacks::OnSuccess(scoped_refptr<IndexedDBCursor> cursor,
void IndexedDBCallbacks::OnSuccess(const IndexedDBKey& key,
const IndexedDBKey& primary_key,
IndexedDBValue* value) {
+ DCHECK(!helper_);
DCHECK(dispatcher_host_.get());
DCHECK_NE(kNoCursor, ipc_cursor_id_);
DCHECK_EQ(kNoTransaction, host_transaction_id_);
DCHECK_EQ(kNoDatabase, ipc_database_id_);
- DCHECK_EQ(kNoDatabaseCallbacks, ipc_database_callbacks_id_);
DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_);
IndexedDBCursor* idb_cursor =
@@ -422,6 +472,7 @@ void IndexedDBCallbacks::OnSuccessWithPrefetch(
const std::vector<IndexedDBKey>& keys,
const std::vector<IndexedDBKey>& primary_keys,
std::vector<IndexedDBValue>* values) {
+ DCHECK(!helper_);
DCHECK_EQ(keys.size(), primary_keys.size());
DCHECK_EQ(keys.size(), values->size());
@@ -430,7 +481,6 @@ void IndexedDBCallbacks::OnSuccessWithPrefetch(
DCHECK_NE(kNoCursor, ipc_cursor_id_);
DCHECK_EQ(kNoTransaction, host_transaction_id_);
DCHECK_EQ(kNoDatabase, ipc_database_id_);
- DCHECK_EQ(kNoDatabaseCallbacks, ipc_database_callbacks_id_);
DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_);
std::vector<IndexedDBKey> msg_keys;
@@ -479,6 +529,7 @@ void IndexedDBCallbacks::OnSuccessWithPrefetch(
}
void IndexedDBCallbacks::OnSuccess(IndexedDBReturnValue* value) {
+ DCHECK(!helper_);
DCHECK(dispatcher_host_.get());
if (value && value->primary_key.IsValid()) {
@@ -488,7 +539,6 @@ void IndexedDBCallbacks::OnSuccess(IndexedDBReturnValue* value) {
}
DCHECK_EQ(kNoTransaction, host_transaction_id_);
DCHECK_EQ(kNoDatabase, ipc_database_id_);
- DCHECK_EQ(kNoDatabaseCallbacks, ipc_database_callbacks_id_);
DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_);
std::unique_ptr<IndexedDBMsg_CallbacksSuccessValue_Params> params(
@@ -520,11 +570,11 @@ void IndexedDBCallbacks::OnSuccess(IndexedDBReturnValue* value) {
void IndexedDBCallbacks::OnSuccessArray(
std::vector<IndexedDBReturnValue>* values,
const IndexedDBKeyPath& key_path) {
+ DCHECK(!helper_);
DCHECK(dispatcher_host_.get());
DCHECK_EQ(kNoTransaction, host_transaction_id_);
DCHECK_EQ(kNoDatabase, ipc_database_id_);
- DCHECK_EQ(kNoDatabaseCallbacks, ipc_database_callbacks_id_);
DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_);
std::unique_ptr<IndexedDBMsg_CallbacksSuccessArray_Params> params(
@@ -563,12 +613,12 @@ void IndexedDBCallbacks::OnSuccessArray(
}
void IndexedDBCallbacks::OnSuccess(const IndexedDBKey& value) {
+ DCHECK(!helper_);
DCHECK(dispatcher_host_.get());
DCHECK_EQ(kNoCursor, ipc_cursor_id_);
DCHECK_EQ(kNoTransaction, host_transaction_id_);
DCHECK_EQ(kNoDatabase, ipc_database_id_);
- DCHECK_EQ(kNoDatabaseCallbacks, ipc_database_callbacks_id_);
DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_);
dispatcher_host_->Send(new IndexedDBMsg_CallbacksSuccessIndexedDBKey(
@@ -578,25 +628,29 @@ void IndexedDBCallbacks::OnSuccess(const IndexedDBKey& value) {
void IndexedDBCallbacks::OnSuccess(int64_t value) {
DCHECK(dispatcher_host_.get());
+ if (helper_) {
+ BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
+ base::Bind(&IOThreadHelper::SendSuccessInteger,
+ base::Unretained(helper_), value));
+ } else {
+ DCHECK_EQ(kNoCursor, ipc_cursor_id_);
+ DCHECK_EQ(kNoTransaction, host_transaction_id_);
+ DCHECK_EQ(kNoDatabase, ipc_database_id_);
+ DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_);
- DCHECK_EQ(kNoCursor, ipc_cursor_id_);
- DCHECK_EQ(kNoTransaction, host_transaction_id_);
- DCHECK_EQ(kNoDatabase, ipc_database_id_);
- DCHECK_EQ(kNoDatabaseCallbacks, ipc_database_callbacks_id_);
- DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_);
-
- dispatcher_host_->Send(new IndexedDBMsg_CallbacksSuccessInteger(
- ipc_thread_id_, ipc_callbacks_id_, value));
+ dispatcher_host_->Send(new IndexedDBMsg_CallbacksSuccessInteger(
+ ipc_thread_id_, ipc_callbacks_id_, value));
+ }
dispatcher_host_ = NULL;
}
void IndexedDBCallbacks::OnSuccess() {
+ DCHECK(!helper_);
DCHECK(dispatcher_host_.get());
DCHECK_EQ(kNoCursor, ipc_cursor_id_);
DCHECK_EQ(kNoTransaction, host_transaction_id_);
DCHECK_EQ(kNoDatabase, ipc_database_id_);
- DCHECK_EQ(kNoDatabaseCallbacks, ipc_database_callbacks_id_);
DCHECK_EQ(blink::WebIDBDataLossNone, data_loss_);
dispatcher_host_->Send(new IndexedDBMsg_CallbacksSuccessUndefined(
@@ -609,4 +663,47 @@ void IndexedDBCallbacks::SetConnectionOpenStartTime(
connection_open_start_time_ = start_time;
}
+IndexedDBCallbacks::IOThreadHelper::IOThreadHelper(
+ CallbacksAssociatedPtrInfo callbacks_info) {
+ callbacks_.Bind(std::move(callbacks_info));
+}
+
+IndexedDBCallbacks::IOThreadHelper::~IOThreadHelper() {}
+
+void IndexedDBCallbacks::IOThreadHelper::SendBlocked(int64_t existing_version) {
+ callbacks_->Blocked(existing_version);
+}
+
+void IndexedDBCallbacks::IOThreadHelper::SendError(
+ const IndexedDBDatabaseError& error) {
+ callbacks_->Error(error.code(), error.message());
+}
+
+void IndexedDBCallbacks::IOThreadHelper::SendSuccessDatabase(
+ int32_t database_id,
+ ::indexed_db::mojom::DatabaseMetadataPtr metadata) {
+ callbacks_->SuccessDatabase(database_id, std::move(metadata));
+}
+
+void IndexedDBCallbacks::IOThreadHelper::SendSuccessInteger(int64_t value) {
+ callbacks_->SuccessInteger(value);
+}
+
+void IndexedDBCallbacks::IOThreadHelper::SendSuccessStringList(
+ const std::vector<base::string16>& value) {
+ callbacks_->SuccessStringList(value);
+}
+
+void IndexedDBCallbacks::IOThreadHelper::SendUpgradeNeeded(
+ int32_t database_id,
+ int64_t old_version,
+ blink::WebIDBDataLoss data_loss,
+ const std::string& data_loss_message,
+ ::indexed_db::mojom::DatabaseMetadataPtr metadata) {
+ callbacks_->UpgradeNeeded(
+ database_id, old_version,
+ static_cast<::indexed_db::mojom::DataLoss>(data_loss), data_loss_message,
+ std::move(metadata));
+}
+
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698