| Index: content/browser/indexed_db/database_factory_impl.cc
|
| diff --git a/content/browser/indexed_db/database_factory_impl.cc b/content/browser/indexed_db/database_factory_impl.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..16ba73308ab22ad8e9542569b9ac7787b88a8624
|
| --- /dev/null
|
| +++ b/content/browser/indexed_db/database_factory_impl.cc
|
| @@ -0,0 +1,160 @@
|
| +// 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_factory_impl.h"
|
| +
|
| +#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_database_callbacks.h"
|
| +#include "content/browser/indexed_db/indexed_db_database_error.h"
|
| +#include "content/browser/indexed_db/indexed_db_open_request_observer.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/common/common_type_converters.h"
|
| +#include "mojo/public/cpp/bindings/binding.h"
|
| +#include "mojo/public/cpp/bindings/interface_request.h"
|
| +#include "net/url_request/url_request_context_getter.h"
|
| +
|
| +namespace {
|
| +
|
| +bool IsValidOrigin(const url::Origin& origin) {
|
| + return !origin.unique();
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +namespace indexed_db {
|
| +
|
| +DatabaseFactoryImpl::DatabaseFactoryImpl(
|
| + content::BrowserContext* context,
|
| + content::IndexedDBContextImpl* indexed_db_context,
|
| + net::URLRequestContext* request_context,
|
| + mojom::DatabaseFactoryRequest request)
|
| + : context_(context),
|
| + indexed_db_context_(indexed_db_context),
|
| + request_context_(request_context),
|
| + binding_(this, std::move(request)) {
|
| + DCHECK(request_context != nullptr);
|
| + // TODO(cmumford): Eventually delete member if not needed.
|
| + (void)context_;
|
| +}
|
| +
|
| +DatabaseFactoryImpl::~DatabaseFactoryImpl() = default;
|
| +
|
| +void DatabaseFactoryImpl::Create(
|
| + content::BrowserContext* context,
|
| + net::URLRequestContextGetter* request_context_getter,
|
| + mojom::DatabaseFactoryRequest request) {
|
| + // TODO(cmumford): Is |Default| OK?
|
| + content::StoragePartition* storage_partition =
|
| + content::BrowserContext::GetDefaultStoragePartition(context);
|
| + content::IndexedDBContextImpl* indexed_db_context =
|
| + reinterpret_cast<content::IndexedDBContextImpl*>(
|
| + storage_partition->GetIndexedDBContext());
|
| + new DatabaseFactoryImpl(context, indexed_db_context,
|
| + request_context_getter->GetURLRequestContext(),
|
| + std::move(request));
|
| +}
|
| +
|
| +void DatabaseFactoryImpl::GetDatabaseNames(const url::Origin& origin) {}
|
| +
|
| +void DatabaseFactoryImpl::OnOpenResult(
|
| + const base::TimeTicks& begin_time,
|
| + const OpenCallback& mojo_callback,
|
| + std::unique_ptr<content::IndexedDBConnection> connection,
|
| + const content::IndexedDBDatabaseMetadata& metadata,
|
| + const content::IndexedDBDatabaseError& error) {
|
| + // mojo_callback.Run();
|
| +}
|
| +
|
| +void DatabaseFactoryImpl::Open(const mojo::String& name,
|
| + int64_t version,
|
| + int64_t transaction_id,
|
| + const url::Origin& origin,
|
| + mojom::OpenRequestObserverPtr open_observer,
|
| + mojom::DatabaseObserverPtr database_handler,
|
| + const OpenCallback& callback) {
|
| + if (!IsValidOrigin(origin)) {
|
| + CrashRendererAndClosePipe(content::bad_message::IDBDH_INVALID_ORIGIN);
|
| + return;
|
| + }
|
| +
|
| + base::TimeTicks begin_time = base::TimeTicks::Now();
|
| + base::FilePath indexed_db_path = indexed_db_context_->data_path();
|
| +
|
| + int64_t host_transaction_id = HostTransactionId(transaction_id);
|
| +
|
| + content::OpenResultCallback open_result_cb = base::Bind(
|
| + &DatabaseFactoryImpl::OnOpenResult, AsWeakPtr(), begin_time, callback);
|
| +
|
| +#if 0
|
| + // TODO(dgrogan): Don't let a non-existing database be opened (and therefore
|
| + // created) if this origin is already over quota.
|
| + scoped_refptr<IndexedDBCallbacks> callbacks = new IndexedDBCallbacks(
|
| + this, params.ipc_thread_id, params.ipc_callbacks_id,
|
| + params.ipc_database_callbacks_id, host_transaction_id, params.origin);
|
| + callbacks->SetConnectionOpenStartTime(begin_time);
|
| +#endif
|
| + scoped_refptr<content::IndexedDBDatabaseCallbacks> database_callbacks =
|
| + new content::IndexedDBDatabaseCallbacks(std::move(database_handler));
|
| + NOTREACHED() << "Get the child process ID";
|
| + int child_process_id = 0;
|
| + content::IndexedDBPendingConnection connection(
|
| + open_result_cb, database_callbacks,
|
| + new content::IndexedDBOpenRequestObserver(std::move(open_observer)),
|
| + child_process_id, host_transaction_id, version);
|
| +
|
| + DCHECK(request_context_);
|
| + indexed_db_context_->GetIDBFactory()->Open(name.To<base::string16>(),
|
| + connection, request_context_,
|
| + origin, indexed_db_path);
|
| +}
|
| +
|
| +void DatabaseFactoryImpl::DeleteDatabase(const mojo::String& name,
|
| + const url::Origin& origin) {}
|
| +
|
| +base::ProcessId DatabaseFactoryImpl::peer_pid() const {
|
| + NOTREACHED() << "Implement this function";
|
| + return 0;
|
| +}
|
| +
|
| +int64_t DatabaseFactoryImpl::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 DatabaseFactoryImpl::RendererTransactionId(
|
| + int64_t host_transaction_id) {
|
| + DCHECK(host_transaction_id >> 32 == peer_pid())
|
| + << "Invalid renderer target for transaction id";
|
| + return host_transaction_id & 0xffffffff;
|
| +}
|
| +
|
| +void DatabaseFactoryImpl::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* DatabaseFactoryImpl::GetRenderProcessHost() {
|
| + // TODO(cmumford): Need to implement this.
|
| + NOTREACHED();
|
| + // return render_frame_host_->GetProcess();
|
| + return nullptr;
|
| +}
|
| +
|
| +} // namespace indexed_db
|
|
|