| 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..2a1c1a9f9d1aac51bae2432fafdcbcb381a328d9
|
| --- /dev/null
|
| +++ b/content/browser/indexed_db/database_impl.cc
|
| @@ -0,0 +1,249 @@
|
| +// 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 <string>
|
| +#include <utility>
|
| +#include <vector>
|
| +
|
| +#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 content {
|
| +
|
| +using ::indexed_db::mojom::BlobInfoPtr;
|
| +using ::indexed_db::mojom::CursorDirection;
|
| +using ::indexed_db::mojom::DatabaseRequest;
|
| +using ::indexed_db::mojom::GetResult;
|
| +using ::indexed_db::mojom::GetResultPtr;
|
| +using ::indexed_db::mojom::KeyPtr;
|
| +using ::indexed_db::mojom::KeyRangePtr;
|
| +using ::indexed_db::mojom::PutMode;
|
| +using ::indexed_db::mojom::TaskType;
|
| +using ::indexed_db::mojom::TransactionMode;
|
| +
|
| +DatabaseImpl::DatabaseImpl(BrowserContext* context,
|
| + IndexedDBContext* indexed_db_context,
|
| + 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(BrowserContext* context, DatabaseRequest request) {
|
| + // TODO(cmumford): Is |Default| OK?
|
| + StoragePartition* storage_partition =
|
| + 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 std::string& name,
|
| + const IndexedDBKeyPath& key_path,
|
| + bool auto_increment) {}
|
| +
|
| +void DatabaseImpl::DeleteObjectStore(int64_t transaction_id,
|
| + int64_t object_store_id) {}
|
| +
|
| +void DatabaseImpl::CreateTransaction(int64_t id,
|
| + const std::vector<int64_t>& scope,
|
| + 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 std::string& name,
|
| + const 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 transaction_id,
|
| + int64_t object_store_id,
|
| + int64_t index_id,
|
| + KeyRangePtr key_range,
|
| + bool key_only,
|
| + const GetCallback& callback) {
|
| + DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread());
|
| +#if 0
|
| + IndexedDBConnection* connection =
|
| + GetOrTerminateProcess(&connection_map_, database_id);
|
| + if (!connection || !connection->IsConnected())
|
| + return;
|
| +
|
| + 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
|
| +
|
| + // TODO(cmumford): Set the error data.
|
| + IndexedDBDatabaseError error;
|
| + // TODO(cmumford): Can we somehow use GetResult::From()?
|
| + GetResultPtr result = GetResult::New();
|
| + result->set_error(error);
|
| + callback.Run(std::move(result));
|
| +}
|
| +
|
| +void DatabaseImpl::GetAll(int64_t transaction_id,
|
| + int64_t object_store_id,
|
| + int64_t index_id,
|
| + KeyRangePtr key_range,
|
| + int64_t max_count,
|
| + bool key_only) {}
|
| +
|
| +void DatabaseImpl::Put(int64_t transaction_id,
|
| + int64_t object_store_id,
|
| + const std::vector<int8_t>& value,
|
| + std::vector<BlobInfoPtr> blob_info,
|
| + KeyPtr key,
|
| + PutMode put_mode,
|
| + const std::vector<int64_t>& index_ids,
|
| + std::vector<std::vector<KeyPtr>> index_keys) {}
|
| +
|
| +void DatabaseImpl::DeleteRange(int64_t transaction_id,
|
| + int64_t object_store_id,
|
| + 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,
|
| + KeyPtr primary_key,
|
| + const std::vector<int64_t>& index_ids,
|
| + std::vector<std::vector<KeyPtr>> index_keys) {}
|
| +
|
| +void DatabaseImpl::SetIndexesReady(int64_t transaction_id,
|
| + int64_t object_store_id,
|
| + const std::vector<int64_t>& index_ids) {}
|
| +
|
| +void DatabaseImpl::OpenCursor(int64_t transaction_id,
|
| + int64_t object_store_id,
|
| + int64_t index_id,
|
| + KeyRangePtr key_range,
|
| + CursorDirection direction,
|
| + bool key_only,
|
| + TaskType task_type) {}
|
| +
|
| +void DatabaseImpl::Count(int64_t transaction_id,
|
| + int64_t object_store_id,
|
| + int64_t index_id,
|
| + KeyRangePtr key_range) {}
|
| +
|
| +void DatabaseImpl::AckReceivedBlobs(const std::vector<std::string>& uuids) {}
|
| +
|
| +void DatabaseImpl::CrashRendererAndClosePipe(
|
| + bad_message::BadMessageReason reason) {
|
| + // TODO(cmumford): Replace with preferred solution once implemented.
|
| + // https://groups.google.com/a/chromium.org/forum/#!topic/chromium-mojo/aPfAww28ELo
|
| + bad_message::ReceivedBadMessage(GetRenderProcessHost(), reason);
|
| +
|
| + // Looks like we need to use Binding instead of StrongBinding to get Close().
|
| + // binding_.Close();
|
| +}
|
| +
|
| +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(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(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 content
|
|
|