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

Unified Diff: content/child/indexed_db/indexed_db_callbacks_impl.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/child/indexed_db/indexed_db_callbacks_impl.cc
diff --git a/content/child/indexed_db/indexed_db_callbacks_impl.cc b/content/child/indexed_db/indexed_db_callbacks_impl.cc
new file mode 100644
index 0000000000000000000000000000000000000000..eb0d19b3d3f38abc0baa89f5beaab65e18fa67a6
--- /dev/null
+++ b/content/child/indexed_db/indexed_db_callbacks_impl.cc
@@ -0,0 +1,217 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/child/indexed_db/indexed_db_callbacks_impl.h"
+
+#include "content/child/indexed_db/indexed_db_dispatcher.h"
+#include "content/child/indexed_db/indexed_db_key_builders.h"
+#include "content/child/thread_safe_sender.h"
+#include "content/common/indexed_db/indexed_db_constants.h"
+#include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBCallbacks.h"
+#include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseError.h"
+#include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBMetadata.h"
+
+using blink::WebIDBCallbacks;
+using blink::WebIDBDatabase;
+using blink::WebIDBMetadata;
+using blink::WebString;
+using blink::WebVector;
+using indexed_db::mojom::DatabaseMetadataPtr;
+
+namespace content {
+
+namespace {
+
+WebIDBMetadata ConvertMetadata(DatabaseMetadataPtr metadata) {
+ WebIDBMetadata web_metadata;
+ web_metadata.id = metadata->id;
+ web_metadata.name = metadata->name;
+ web_metadata.version = metadata->version;
+ web_metadata.maxObjectStoreId = metadata->max_object_store_id;
+ web_metadata.objectStores =
+ WebVector<WebIDBMetadata::ObjectStore>(metadata->object_stores.size());
+
+ for (size_t i = 0; i < metadata->object_stores.size(); ++i) {
+ const indexed_db::mojom::ObjectStoreMetadataPtr& store_metadata =
+ metadata->object_stores[i];
+ WebIDBMetadata::ObjectStore& web_store_metadata =
+ web_metadata.objectStores[i];
+
+ web_store_metadata.id = store_metadata->id;
+ web_store_metadata.name = store_metadata->name;
+ web_store_metadata.keyPath =
+ WebIDBKeyPathBuilder::Build(store_metadata->key_path);
+ web_store_metadata.autoIncrement = store_metadata->auto_increment;
+ web_store_metadata.maxIndexId = store_metadata->max_index_id;
+ web_store_metadata.indexes =
+ WebVector<WebIDBMetadata::Index>(store_metadata->indexes.size());
+
+ for (size_t j = 0; j < store_metadata->indexes.size(); ++j) {
+ const indexed_db::mojom::IndexMetadataPtr& index_metadata =
+ store_metadata->indexes[j];
+ WebIDBMetadata::Index& web_index_metadata = web_store_metadata.indexes[j];
+
+ web_index_metadata.id = index_metadata->id;
+ web_index_metadata.name = index_metadata->name;
+ web_index_metadata.keyPath =
+ WebIDBKeyPathBuilder::Build(index_metadata->key_path);
+ web_index_metadata.unique = index_metadata->unique;
+ web_index_metadata.multiEntry = index_metadata->multi_entry;
+ }
+ }
+
+ return web_metadata;
+}
+
+} // namespace
+
+class IndexedDBCallbacksImpl::InternalState {
+ public:
+ InternalState(blink::WebIDBCallbacks* callbacks,
+ scoped_refptr<ThreadSafeSender> thread_safe_sender);
+ ~InternalState();
+
+ void Blocked(int64_t existing_version);
+ void Error(int32_t code, const base::string16& message);
+ void SuccessDatabase(int32_t database_id,
+ indexed_db::mojom::DatabaseMetadataPtr metadata);
+ void SuccessInteger(int64_t value);
+ void SuccessStringList(const std::vector<base::string16>& value);
+ void UpgradeNeeded(int32_t database_id,
+ int64_t old_version,
+ indexed_db::mojom::DataLoss data_loss,
+ const std::string& data_loss_message,
+ indexed_db::mojom::DatabaseMetadataPtr metadata);
+
+ private:
+ std::unique_ptr<WebIDBCallbacks> callbacks_;
+ scoped_refptr<ThreadSafeSender> thread_safe_sender_;
+};
+
+IndexedDBCallbacksImpl::IndexedDBCallbacksImpl(
+ WebIDBCallbacks* callbacks,
+ scoped_refptr<ThreadSafeSender> thread_safe_sender)
+ : callback_runner_(base::ThreadTaskRunnerHandle::Get()), binding_(this) {
+ internal_state_ = new InternalState(callbacks, std::move(thread_safe_sender));
+}
+
+IndexedDBCallbacksImpl::~IndexedDBCallbacksImpl() {
+ callback_runner_->DeleteSoon(FROM_HERE, internal_state_);
+}
+
+void IndexedDBCallbacksImpl::Bind(
+ indexed_db::mojom::CallbacksAssociatedPtrInfo* ptr_info,
+ mojo::AssociatedGroup* associated_group) {
+ binding_.Bind(ptr_info, associated_group);
+ binding_.set_connection_error_handler(base::Bind(
+ &IndexedDBCallbacksImpl::OnConnectionError, base::Unretained(this)));
+}
+
+void IndexedDBCallbacksImpl::OnConnectionError() {
+ delete this;
+}
+
+void IndexedDBCallbacksImpl::Blocked(int64_t existing_version) {
+ callback_runner_->PostTask(
+ FROM_HERE,
+ base::Bind(&InternalState::Blocked, base::Unretained(internal_state_),
+ existing_version));
+}
+
+void IndexedDBCallbacksImpl::Error(int32_t code,
+ const base::string16& message) {
+ callback_runner_->PostTask(
+ FROM_HERE, base::Bind(&InternalState::Error,
+ base::Unretained(internal_state_), code, message));
+}
+
+void IndexedDBCallbacksImpl::SuccessDatabase(int32_t database_id,
+ DatabaseMetadataPtr metadata) {
+ callback_runner_->PostTask(
+ FROM_HERE, base::Bind(&InternalState::SuccessDatabase,
+ base::Unretained(internal_state_), database_id,
+ base::Passed(&metadata)));
+}
+
+void IndexedDBCallbacksImpl::SuccessInteger(int64_t value) {
+ callback_runner_->PostTask(
+ FROM_HERE, base::Bind(&InternalState::SuccessInteger,
+ base::Unretained(internal_state_), value));
+}
+
+void IndexedDBCallbacksImpl::SuccessStringList(
+ const std::vector<base::string16>& value) {
+ callback_runner_->PostTask(
+ FROM_HERE, base::Bind(&InternalState::SuccessStringList,
+ base::Unretained(internal_state_), value));
+}
+
+void IndexedDBCallbacksImpl::UpgradeNeeded(
+ int32_t database_id,
+ int64_t old_version,
+ indexed_db::mojom::DataLoss data_loss,
+ const std::string& data_loss_message,
+ DatabaseMetadataPtr metadata) {
+ callback_runner_->PostTask(
+ FROM_HERE,
+ base::Bind(&InternalState::UpgradeNeeded,
+ base::Unretained(internal_state_), database_id, old_version,
+ data_loss, data_loss_message, base::Passed(&metadata)));
+}
+
+IndexedDBCallbacksImpl::InternalState::InternalState(
+ blink::WebIDBCallbacks* callbacks,
+ scoped_refptr<ThreadSafeSender> thread_safe_sender)
+ : callbacks_(callbacks),
+ thread_safe_sender_(std::move(thread_safe_sender)) {}
+
+IndexedDBCallbacksImpl::InternalState::~InternalState() {}
+
+void IndexedDBCallbacksImpl::InternalState::Blocked(int64_t existing_version) {
+ callbacks_->onBlocked(existing_version);
+}
+
+void IndexedDBCallbacksImpl::InternalState::Error(
+ int32_t code,
+ const base::string16& message) {
+ callbacks_->onError(blink::WebIDBDatabaseError(code, message));
+}
+
+void IndexedDBCallbacksImpl::InternalState::SuccessDatabase(
+ int32_t database_id,
+ DatabaseMetadataPtr metadata) {
+ WebIDBDatabase* database = nullptr;
+ if (database_id != kNoDatabase) {
+ IndexedDBDispatcher* dispatcher =
+ IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get());
+ database = dispatcher->RegisterDatabase(database_id);
+ }
+ callbacks_->onSuccess(database, ConvertMetadata(std::move(metadata)));
+}
+
+void IndexedDBCallbacksImpl::InternalState::SuccessInteger(int64_t value) {
+ callbacks_->onSuccess(value);
+}
+
+void IndexedDBCallbacksImpl::InternalState::SuccessStringList(
+ const std::vector<base::string16>& value) {
+ callbacks_->onSuccess(WebVector<WebString>(value));
+}
+
+void IndexedDBCallbacksImpl::InternalState::UpgradeNeeded(
+ int32_t database_id,
+ int64_t old_version,
+ indexed_db::mojom::DataLoss data_loss,
+ const std::string& data_loss_message,
+ DatabaseMetadataPtr metadata) {
+ IndexedDBDispatcher* dispatcher =
+ IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get());
+ WebIDBDatabase* database = dispatcher->RegisterDatabase(database_id);
+ callbacks_->onUpgradeNeeded(old_version, database,
+ ConvertMetadata(std::move(metadata)),
+ static_cast<blink::WebIDBDataLoss>(data_loss),
+ WebString::fromUTF8(data_loss_message));
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698