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

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

Issue 1963293002: Replacing Indexed DB Chromium IPC with Mojo Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Refactoring after Passing URLRequestContextGetter. Created 4 years, 4 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
« no previous file with comments | « content/browser/indexed_db/database_factory_impl.h ('k') | content/browser/indexed_db/database_impl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..94e42bb4c6136631efb42cd1a959848b62a3e2c1
--- /dev/null
+++ b/content/browser/indexed_db/database_factory_impl.cc
@@ -0,0 +1,158 @@
+// 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 <string>
+#include <utility>
+
+#include "base/strings/utf_string_conversions.h"
+#include "content/browser/indexed_db/indexed_db_callbacks.h"
+#include "content/browser/indexed_db/indexed_db_change_handler_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_error.h"
+#include "content/browser/indexed_db/indexed_db_open_request_observer_impl.h"
+#include "content/browser/indexed_db/indexed_db_pending_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/common/common_type_converters.h"
+#include "mojo/public/cpp/bindings/binding.h"
+#include "net/url_request/url_request_context_getter.h"
+#include "services/shell/public/cpp/interface_registry.h"
+
+using indexed_db::mojom::DatabaseFactory;
+using indexed_db::mojom::DatabaseObserverPtr;
+using indexed_db::mojom::DatabaseOpenData;
+using indexed_db::mojom::DatabaseOpenDataPtr;
+using indexed_db::mojom::OpenRequestObserverPtr;
+using indexed_db::mojom::OpenResult;
+using indexed_db::mojom::OpenResultPtr;
+
+namespace {
+
+bool IsValidOrigin(const url::Origin& origin) {
+ return !origin.unique();
+}
+
+} // namespace
+
+namespace content {
+
+DatabaseFactoryImpl::DatabaseFactoryImpl(
+ IndexedDBContextImpl* indexed_db_context,
+ net::URLRequestContextGetter* url_request_context_getter,
+ int render_process_host_id)
+ : render_process_host_id_(render_process_host_id),
+ indexed_db_context_(indexed_db_context),
+ request_context_getter_(url_request_context_getter) {}
+
+DatabaseFactoryImpl::~DatabaseFactoryImpl() = default;
+
+std::unique_ptr<DatabaseFactoryImpl> DatabaseFactoryImpl::Create(
+ IndexedDBContextImpl* indexed_db_context,
+ net::URLRequestContextGetter* url_request_context,
+ int render_process_host_id) {
+ return base::WrapUnique(new DatabaseFactoryImpl(
+ indexed_db_context, url_request_context, render_process_host_id));
+}
+
+void DatabaseFactoryImpl::GetDatabaseNames(const url::Origin& origin) {}
+
+void DatabaseFactoryImpl::OnOpenResult(
+ const base::TimeTicks& begin_time,
+ const OpenCallback& mojo_callback,
+ std::unique_ptr<IndexedDBConnection> connection,
+ const IndexedDBDatabaseMetadata& metadata,
+ const IndexedDBDatabaseError& error) {
+ OpenResultPtr result = OpenResult::New();
+ if (connection) {
+ DCHECK_EQ(error.code(), 0);
+ ::indexed_db::mojom::DatabasePtr interface;
+ connection->Bind(GetProxy(&interface));
+ connections_.insert(std::move(connection));
+ DatabaseOpenDataPtr open_data = DatabaseOpenData::New();
+ open_data->database = std::move(interface);
+ open_data->metadata = metadata;
+ result->set_data(std::move(open_data));
+ } else {
+ DCHECK_NE(error.code(), 0);
+ result->set_error(error);
+ }
+ mojo_callback.Run(std::move(result));
+}
+
+void DatabaseFactoryImpl::Open(const std::string& name,
+ int64_t version,
+ int64_t transaction_id,
+ const url::Origin& origin,
+ OpenRequestObserverPtr open_observer,
+ DatabaseObserverPtr database_observer,
+ const OpenCallback& callback) {
+ if (!IsValidOrigin(origin)) {
+ CrashRendererAndClosePipe(bad_message::IDBDH_INVALID_ORIGIN);
+ return;
+ }
+
+ // TODO(cmumford): Don't let a non-existing database be opened (and therefore
+ // created) if this origin is already over quota.
+ scoped_refptr<IndexedDBChangeHandler> change_handler =
+ new IndexedDBChangeHandlerImpl(std::move(database_observer));
+
+ OpenResultCallback open_result_cb =
+ base::Bind(&DatabaseFactoryImpl::OnOpenResult, AsWeakPtr(),
+ base::TimeTicks::Now(), std::move(callback));
+
+ std::unique_ptr<IndexedDBPendingConnection> connection =
+ base::WrapUnique(new IndexedDBPendingConnection(
+ open_result_cb, change_handler,
+ new IndexedDBOpenRequestObserverImpl(std::move(open_observer)),
+ render_process_host_id_, transaction_id, version, origin));
+
+ DCHECK(request_context_getter_);
+ indexed_db_context_->GetIDBFactory()->Open(
+ base::UTF8ToUTF16(name), std::move(connection), request_context_getter_,
+ origin, indexed_db_context_->data_path());
+}
+
+void DatabaseFactoryImpl::DeleteDatabase(const std::string& name,
+ const url::Origin& origin) {}
+
+void DatabaseFactoryImpl::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* DatabaseFactoryImpl::GetRenderProcessHost() {
+ // TODO(cmumford): Need to implement this.
+ NOTREACHED();
+ // return render_frame_host_->GetProcess();
+ return nullptr;
+}
+
+void DatabaseFactoryImpl::Bind(
+ ::indexed_db::mojom::DatabaseFactoryRequest request) {
+ binding_.AddBinding(this, std::move(request));
+}
+
+void DatabaseFactoryImpl::AddMojoServiceOnIDBThread(
+ shell::InterfaceRegistry* registry) {
+ registry->AddInterface(
+ base::Bind(&DatabaseFactoryImpl::Bind, base::Unretained(this)));
+}
+
+void DatabaseFactoryImpl::AddMojoService(shell::InterfaceRegistry* registry) {
+ indexed_db_context_->TaskRunner()->PostTask(
+ FROM_HERE,
+ base::Bind(&DatabaseFactoryImpl::AddMojoServiceOnIDBThread,
+ base::Unretained(this), base::Unretained(registry)));
+}
+
+} // namespace content
« no previous file with comments | « content/browser/indexed_db/database_factory_impl.h ('k') | content/browser/indexed_db/database_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698