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

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

Issue 1963293002: Replacing Indexed DB Chromium IPC with Mojo Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Some (incomplete) work on struct traits. Created 4 years, 5 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/database_impl.cc
diff --git a/content/browser/indexed_db/database_impl.cc b/content/browser/indexed_db/database_impl.cc
new file mode 100644
index 0000000000000000000000000000000000000000..1053ccec9d34b2f4aa1d51bec44c1c707bb56766
--- /dev/null
+++ b/content/browser/indexed_db/database_impl.cc
@@ -0,0 +1,236 @@
+// 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/browser/indexed_db/database_impl.h"
+
+#include "content/browser/indexed_db/indexed_db_connection.h"
+#include "content/public/browser/browser_context.h"
+#include "content/public/browser/indexed_db_context.h"
+#include "content/public/browser/storage_partition.h"
+#include "mojo/public/cpp/bindings/binding.h"
+#include "mojo/public/cpp/bindings/interface_request.h"
+
+namespace indexed_db {
+
+using namespace indexed_db::mojom;
+
+DatabaseImpl::DatabaseImpl(content::BrowserContext* context,
+ content::IndexedDBContext* indexed_db_context,
+ mojom::DatabaseRequest request)
+ : context_(context),
+ indexed_db_context_(indexed_db_context),
+ binding_(this, std::move(request)) {
+ // TODO(cmumford): Eventually delete member if not needed.
+ (void)context_;
+}
+
+DatabaseImpl::~DatabaseImpl() = default;
+
+void DatabaseImpl::Create(content::BrowserContext* context,
+ mojom::DatabaseRequest request) {
+ // TODO(cmumford): Is |Default| OK?
+ content::StoragePartition* storage_partition =
+ content::BrowserContext::GetDefaultStoragePartition(context);
+ new DatabaseImpl(context, storage_partition->GetIndexedDBContext(),
+ std::move(request));
+}
+
+void DatabaseImpl::CreateObjectStore(int64_t transaction_id,
+ int64_t object_store_id,
+ const mojo::String& name,
+ const ::content::IndexedDBKeyPath& key_path,
+ bool auto_increment) {}
+
+void DatabaseImpl::DeleteObjectStore(int64_t transaction_id,
+ int64_t object_store_id) {}
+
+void DatabaseImpl::CreateTransaction(int64_t id,
+ mojo::Array<int64_t> scope,
+ mojom::TransactionMode transaction_mode) {}
+
+void DatabaseImpl::DatabaseImpl::Close() {}
+
+void DatabaseImpl::VersionChangeIgnored() {}
+
+void DatabaseImpl::Abort(int64_t transaction_id) {}
+
+void DatabaseImpl::Commit(int64_t transaction_id) {}
+
+void DatabaseImpl::CreateIndex(int64_t transaction_id,
+ int64_t object_store_id,
+ int64_t index_id,
+ const mojo::String& name,
+ const ::content::IndexedDBKeyPath& key_path,
+ bool unique,
+ bool multi_entry) {}
+
+void DatabaseImpl::DeleteIndex(int64_t transaction_id,
+ int64_t object_store_id,
+ int64_t index_id) {}
+
+void DatabaseImpl::Get(int64_t database_id,
+ int64_t transaction_id,
+ int64_t object_store_id,
+ int64_t index_id,
+ mojom::KeyRangePtr key_range,
+ bool key_only,
+ const GetCallback& callback) {
+ DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread());
+ content::IndexedDBConnection* connection =
+ GetOrTerminateProcess(&connection_map_, database_id);
+ if (!connection || !connection->IsConnected())
+ return;
+
+#if 0
+ connection->database()->Get(
+ HostTransactionId(transaction_id), object_store_id,
+ index_id,
+ base::WrapUnique(new IndexedDBKeyRange(key_range)),
+ params.key_only, callbacks);
+#endif
+#if 0
+ DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread());
+ IndexedDBConnection* connection =
+ parent_->GetOrTerminateProcess(&map_, params.ipc_database_id);
+ if (!connection || !connection->IsConnected())
+ return;
+
+ scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks(
+ parent_, params.ipc_thread_id, params.ipc_callbacks_id));
+ connection->database()->Get(
+ parent_->HostTransactionId(params.transaction_id), params.object_store_id,
+ params.index_id,
+ base::WrapUnique(new IndexedDBKeyRange(params.key_range)),
+ params.key_only, callbacks);
+#endif
+
+ GetResultPtr result = GetResult::New();
+ result->type = ResultType::Error;
+ callback.Run(std::move(result));
+}
+
+void DatabaseImpl::GetAll(int64_t transaction_id,
+ int64_t object_store_id,
+ int64_t index_id,
+ mojom::KeyRangePtr key_range,
+ int64_t max_count,
+ bool key_only) {}
+
+void DatabaseImpl::Put(int64_t transaction_id,
+ int64_t object_store_id,
+ mojo::Array<int8_t> value,
+ mojo::Array<mojom::BlobInfoPtr> blob_info,
+ mojom::KeyPtr key,
+ mojom::PutMode put_mode,
+ mojo::Array<int64_t> index_ids,
+ mojo::Array<mojo::Array<mojom::KeyPtr>> index_keys) {}
+
+void DatabaseImpl::DeleteRange(int64_t transaction_id,
+ int64_t object_store_id,
+ mojom::KeyRangePtr key_range) {}
+
+void DatabaseImpl::Clear(int64_t transaction_id, int64_t object_store_id) {}
+
+void DatabaseImpl::SetIndexKeys(
+ int64_t transaction_id,
+ int64_t object_store_id,
+ mojom::KeyPtr primary_key,
+ mojo::Array<int64_t> index_ids,
+ mojo::Array<mojo::Array<mojom::KeyPtr>> index_keys) {}
+
+void DatabaseImpl::SetIndexesReady(int64_t transaction_id,
+ int64_t object_store_id,
+ mojo::Array<int64_t> index_ids) {}
+
+void DatabaseImpl::OpenCursor(int64_t transaction_id,
+ int64_t object_store_id,
+ int64_t index_id,
+ mojom::KeyRangePtr key_range,
+ mojom::CursorDirection direction,
+ bool key_only,
+ mojom::TaskType task_type) {}
+
+void DatabaseImpl::Count(int64_t transaction_id,
+ int64_t object_store_id,
+ int64_t index_id,
+ mojom::KeyRangePtr key_range) {}
+
+void DatabaseImpl::AckReceivedBlobs(mojo::Array<mojo::String> uuids) {}
+
+void DatabaseImpl::CrashRendererAndClosePipe(
+ content::bad_message::BadMessageReason reason) {
+ // TODO(cmumford): Replace with preferred solution once implemented.
+ // https://groups.google.com/a/chromium.org/forum/#!topic/chromium-mojo/aPfAww28ELo
+ content::bad_message::ReceivedBadMessage(GetRenderProcessHost(), reason);
+
+ // Looks like we need to use Binding instead of StrongBinding to get Close().
+ // binding_.Close();
+}
+
+content::RenderProcessHost* DatabaseImpl::GetRenderProcessHost() {
+ // TODO(cmumford): Need to implement this.
+ NOTREACHED();
+ // return render_frame_host_->GetProcess();
+ return nullptr;
+}
+
+//////////////////////////////////////////////////////////////////////
+// Helper templates.
+//
+
+template <typename ObjectType>
+ObjectType* DatabaseImpl::GetOrTerminateProcess(
+ IDMap<ObjectType, IDMapOwnPointer>* map,
+ int32_t ipc_return_object_id) {
+ DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread());
+ ObjectType* return_object = map->Lookup(ipc_return_object_id);
+ if (!return_object) {
+ NOTREACHED() << "Uh oh, couldn't find object with id "
+ << ipc_return_object_id;
+ CrashRendererAndClosePipe(content::bad_message::IDBDH_GET_OR_TERMINATE);
+ }
+ return return_object;
+}
+
+template <typename ObjectType>
+ObjectType* DatabaseImpl::GetOrTerminateProcess(RefIDMap<ObjectType>* map,
+ int32_t ipc_return_object_id) {
+ DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread());
+ ObjectType* return_object = map->Lookup(ipc_return_object_id);
+ if (!return_object) {
+ NOTREACHED() << "Uh oh, couldn't find object with id "
+ << ipc_return_object_id;
+ CrashRendererAndClosePipe(content::bad_message::IDBDH_GET_OR_TERMINATE);
+ }
+ return return_object;
+}
+
+template <typename MapType>
+void DatabaseImpl::DestroyObject(MapType* map, int32_t ipc_object_id) {
+ GetOrTerminateProcess(map, ipc_object_id);
+ map->Remove(ipc_object_id);
+}
+
+#if 0
+int64_t DatabaseImpl::HostTransactionId(int64_t transaction_id) {
+ // Inject the renderer process id into the transaction id, to
+ // uniquely identify this transaction, and effectively bind it to
+ // the renderer that initiated it. The lower 32 bits of
+ // transaction_id are guaranteed to be unique within that renderer.
+ base::ProcessId pid = peer_pid();
+ DCHECK(!(transaction_id >> 32)) << "Transaction ids can only be 32 bits";
+ static_assert(sizeof(base::ProcessId) <= sizeof(int32_t),
+ "Process ID must fit in 32 bits");
+
+ return transaction_id | (static_cast<uint64_t>(pid) << 32);
+}
+
+int64_t DatabaseImpl::RendererTransactionId(int64_t host_transaction_id) {
+ DCHECK(host_transaction_id >> 32 == peer_pid())
+ << "Invalid renderer target for transaction id";
+ return host_transaction_id & 0xffffffff;
+}
+#endif
+
+} // namespace indexed_db

Powered by Google App Engine
This is Rietveld 408576698