| 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..d050e3c9baa71b5959fcbbb82047abeab634ab1f
|
| --- /dev/null
|
| +++ b/content/browser/indexed_db/database_factory_impl.cc
|
| @@ -0,0 +1,134 @@
|
| +// 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 "base/strings/utf_string_conversions.h"
|
| +#include "content/browser/indexed_db/indexed_db_callbacks.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_dispatcher_host.h"
|
| +#include "content/browser/indexed_db/indexed_db_pending_connection.h"
|
| +#include "mojo/public/cpp/bindings/message.h"
|
| +
|
| +namespace content {
|
| +
|
| +namespace {
|
| +
|
| +bool IsValidOrigin(const url::Origin& origin) {
|
| + return !origin.unique();
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +class DatabaseFactoryImpl::IDBThreadHelper {
|
| + public:
|
| + IDBThreadHelper(IndexedDBContextImpl* indexed_db_context,
|
| + net::URLRequestContextGetter* request_context_getter,
|
| + int ipc_process_id,
|
| + scoped_refptr<IndexedDBDispatcherHost> dispatcher_host);
|
| + ~IDBThreadHelper();
|
| +
|
| + void Open(const std::string& name,
|
| + int64_t version,
|
| + int64_t transaction_id,
|
| + const url::Origin& origin,
|
| + ::indexed_db::mojom::DatabaseClientAssociatedPtr client,
|
| + int64_t thread_id,
|
| + int64_t callbacks_id);
|
| +
|
| + private:
|
| + IndexedDBContextImpl* indexed_db_context_;
|
| + net::URLRequestContextGetter* request_context_getter_;
|
| + int ipc_process_id_;
|
| + scoped_refptr<IndexedDBDispatcherHost> dispatcher_host_;
|
| +};
|
| +
|
| +DatabaseFactoryImpl::DatabaseFactoryImpl(
|
| + net::URLRequestContextGetter* request_context_getter,
|
| + IndexedDBContextImpl* indexed_db_context,
|
| + int ipc_process_id,
|
| + scoped_refptr<IndexedDBDispatcherHost> dispatcher_host)
|
| + : BrowserAssociatedInterface<::indexed_db::mojom::DatabaseFactory>(
|
| + dispatcher_host.get(),
|
| + this),
|
| + idb_task_runner_(indexed_db_context->TaskRunner()) {
|
| + idb_thread_helper_ =
|
| + new IDBThreadHelper(indexed_db_context, request_context_getter,
|
| + ipc_process_id, dispatcher_host);
|
| +}
|
| +
|
| +DatabaseFactoryImpl::~DatabaseFactoryImpl() {
|
| + idb_task_runner_->DeleteSoon(FROM_HERE, idb_thread_helper_);
|
| +}
|
| +
|
| +void DatabaseFactoryImpl::Open(
|
| + const std::string& name,
|
| + int64_t version,
|
| + int64_t transaction_id,
|
| + const url::Origin& origin,
|
| + ::indexed_db::mojom::DatabaseClientAssociatedPtrInfo clientInfo,
|
| + int64_t thread_id,
|
| + int64_t callbacks_id) {
|
| + if (!IsValidOrigin(origin)) {
|
| + mojo::ReportBadMessage("Origin is not valid.");
|
| + return;
|
| + }
|
| +
|
| + ::indexed_db::mojom::DatabaseClientAssociatedPtr client;
|
| + client.Bind(std::move(clientInfo));
|
| +
|
| + idb_task_runner_->PostTask(
|
| + FROM_HERE,
|
| + base::Bind(&IDBThreadHelper::Open, base::Unretained(idb_thread_helper_),
|
| + name, version, transaction_id, origin, base::Passed(&client),
|
| + thread_id, callbacks_id));
|
| +}
|
| +
|
| +DatabaseFactoryImpl::IDBThreadHelper::IDBThreadHelper(
|
| + IndexedDBContextImpl* indexed_db_context,
|
| + net::URLRequestContextGetter* request_context_getter,
|
| + int ipc_process_id,
|
| + scoped_refptr<IndexedDBDispatcherHost> dispatcher_host)
|
| + : indexed_db_context_(indexed_db_context),
|
| + request_context_getter_(request_context_getter),
|
| + ipc_process_id_(ipc_process_id),
|
| + dispatcher_host_(dispatcher_host) {}
|
| +
|
| +DatabaseFactoryImpl::IDBThreadHelper::~IDBThreadHelper() = default;
|
| +
|
| +void DatabaseFactoryImpl::IDBThreadHelper::Open(
|
| + const std::string& name,
|
| + int64_t version,
|
| + int64_t transaction_id,
|
| + const url::Origin& origin,
|
| + ::indexed_db::mojom::DatabaseClientAssociatedPtr client,
|
| + int64_t thread_id,
|
| + int64_t callbacks_id) {
|
| + base::TimeTicks begin_time = base::TimeTicks::Now();
|
| + int64_t host_transaction_id =
|
| + dispatcher_host_->HostTransactionId(transaction_id);
|
| +
|
| + // 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(dispatcher_host_.get(), thread_id, callbacks_id,
|
| + host_transaction_id, origin);
|
| + callbacks->SetConnectionOpenStartTime(begin_time);
|
| +
|
| + scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks =
|
| + new IndexedDBDatabaseCallbacks(dispatcher_host_.get(), thread_id,
|
| + std::move(client));
|
| +
|
| + std::unique_ptr<IndexedDBPendingConnection> connection =
|
| + base::MakeUnique<IndexedDBPendingConnection>(
|
| + callbacks, database_callbacks, ipc_process_id_, host_transaction_id,
|
| + version);
|
| +
|
| + indexed_db_context_->GetIDBFactory()->Open(
|
| + base::UTF8ToUTF16(name), std::move(connection), request_context_getter_,
|
| + origin, indexed_db_context_->data_path());
|
| +}
|
| +
|
| +} // namespace content
|
|
|