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

Unified Diff: content/child/indexed_db/webidbfactory_impl.cc

Issue 2370643004: Port messages sent by WebIDBFactoryImpl to Mojo. (Closed)
Patch Set: Address last nits and fix leaks in unit tests. Created 4 years, 2 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/child/indexed_db/webidbfactory_impl.h ('k') | content/common/BUILD.gn » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/child/indexed_db/webidbfactory_impl.cc
diff --git a/content/child/indexed_db/webidbfactory_impl.cc b/content/child/indexed_db/webidbfactory_impl.cc
index b803dc2b1330c0fbd72afdc9a810a18ab801a1f7..84db9cfa1d0d5300b4b5c69701576978fc092208 100644
--- a/content/child/indexed_db/webidbfactory_impl.cc
+++ b/content/child/indexed_db/webidbfactory_impl.cc
@@ -4,9 +4,14 @@
#include "content/child/indexed_db/webidbfactory_impl.h"
-#include "content/child/indexed_db/indexed_db_dispatcher.h"
+#include "content/child/child_thread_impl.h"
+#include "content/child/indexed_db/indexed_db_callbacks_impl.h"
+#include "content/child/indexed_db/indexed_db_database_callbacks_impl.h"
#include "content/child/storage_util.h"
#include "content/child/thread_safe_sender.h"
+#include "content/public/child/worker_thread.h"
+#include "ipc/ipc_sync_channel.h"
+#include "mojo/public/cpp/bindings/strong_associated_binding.h"
#include "third_party/WebKit/public/platform/WebSecurityOrigin.h"
#include "third_party/WebKit/public/platform/WebString.h"
@@ -15,19 +20,63 @@ using blink::WebIDBDatabase;
using blink::WebIDBDatabaseCallbacks;
using blink::WebSecurityOrigin;
using blink::WebString;
+using indexed_db::mojom::CallbacksAssociatedPtrInfo;
+using indexed_db::mojom::DatabaseCallbacksAssociatedPtrInfo;
+using indexed_db::mojom::FactoryAssociatedPtr;
namespace content {
-WebIDBFactoryImpl::WebIDBFactoryImpl(ThreadSafeSender* thread_safe_sender)
- : thread_safe_sender_(thread_safe_sender) {}
+class WebIDBFactoryImpl::IOThreadHelper {
+ public:
+ IOThreadHelper(scoped_refptr<IPC::SyncMessageFilter> sync_message_filter);
+ ~IOThreadHelper();
-WebIDBFactoryImpl::~WebIDBFactoryImpl() {}
+ FactoryAssociatedPtr& GetService();
+ CallbacksAssociatedPtrInfo GetCallbacksProxy(
+ std::unique_ptr<IndexedDBCallbacksImpl> callbacks);
+ DatabaseCallbacksAssociatedPtrInfo GetDatabaseCallbacksProxy(
+ std::unique_ptr<IndexedDBDatabaseCallbacksImpl> callbacks);
+
+ void GetDatabaseNames(std::unique_ptr<IndexedDBCallbacksImpl> callbacks,
+ const url::Origin& origin);
+ void Open(int32_t worker_thread,
+ const base::string16& name,
+ int64_t version,
+ int64_t transaction_id,
+ std::unique_ptr<IndexedDBCallbacksImpl> callbacks,
+ std::unique_ptr<IndexedDBDatabaseCallbacksImpl> database_callbacks,
+ const url::Origin& origin);
+ void DeleteDatabase(const base::string16& name,
+ std::unique_ptr<IndexedDBCallbacksImpl> callbacks,
+ const url::Origin& origin);
+
+ private:
+ scoped_refptr<IPC::SyncMessageFilter> sync_message_filter_;
+ FactoryAssociatedPtr service_;
+
+ DISALLOW_COPY_AND_ASSIGN(IOThreadHelper);
+};
+
+WebIDBFactoryImpl::WebIDBFactoryImpl(
+ scoped_refptr<IPC::SyncMessageFilter> sync_message_filter,
+ scoped_refptr<ThreadSafeSender> thread_safe_sender,
+ scoped_refptr<base::SingleThreadTaskRunner> io_runner)
+ : io_helper_(new IOThreadHelper(std::move(sync_message_filter))),
+ thread_safe_sender_(std::move(thread_safe_sender)),
+ io_runner_(std::move(io_runner)) {}
+
+WebIDBFactoryImpl::~WebIDBFactoryImpl() {
+ io_runner_->DeleteSoon(FROM_HERE, io_helper_);
+}
void WebIDBFactoryImpl::getDatabaseNames(WebIDBCallbacks* callbacks,
const WebSecurityOrigin& origin) {
- IndexedDBDispatcher* dispatcher =
- IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get());
- dispatcher->RequestIDBFactoryGetDatabaseNames(callbacks, origin);
+ auto callbacks_impl = base::MakeUnique<IndexedDBCallbacksImpl>(
+ base::WrapUnique(callbacks), thread_safe_sender_);
+ io_runner_->PostTask(FROM_HERE, base::Bind(&IOThreadHelper::GetDatabaseNames,
+ base::Unretained(io_helper_),
+ base::Passed(&callbacks_impl),
+ url::Origin(origin)));
}
void WebIDBFactoryImpl::open(const WebString& name,
@@ -36,19 +85,90 @@ void WebIDBFactoryImpl::open(const WebString& name,
WebIDBCallbacks* callbacks,
WebIDBDatabaseCallbacks* database_callbacks,
const WebSecurityOrigin& origin) {
- IndexedDBDispatcher* dispatcher =
- IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get());
-
- dispatcher->RequestIDBFactoryOpen(name, version, transaction_id, callbacks,
- database_callbacks, origin);
+ auto callbacks_impl = base::MakeUnique<IndexedDBCallbacksImpl>(
+ base::WrapUnique(callbacks), thread_safe_sender_);
+ auto database_callbacks_impl =
+ base::MakeUnique<IndexedDBDatabaseCallbacksImpl>(
+ base::WrapUnique(database_callbacks), thread_safe_sender_);
+ io_runner_->PostTask(
+ FROM_HERE,
+ base::Bind(&IOThreadHelper::Open, base::Unretained(io_helper_),
+ WorkerThread::GetCurrentId(), base::string16(name), version,
+ transaction_id, base::Passed(&callbacks_impl),
+ base::Passed(&database_callbacks_impl), url::Origin(origin)));
}
void WebIDBFactoryImpl::deleteDatabase(const WebString& name,
WebIDBCallbacks* callbacks,
const WebSecurityOrigin& origin) {
- IndexedDBDispatcher* dispatcher =
- IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get());
- dispatcher->RequestIDBFactoryDeleteDatabase(name, callbacks, origin);
+ auto callbacks_impl = base::MakeUnique<IndexedDBCallbacksImpl>(
+ base::WrapUnique(callbacks), thread_safe_sender_);
+ io_runner_->PostTask(
+ FROM_HERE,
+ base::Bind(&IOThreadHelper::DeleteDatabase, base::Unretained(io_helper_),
+ base::string16(name), base::Passed(&callbacks_impl),
+ url::Origin(origin)));
+}
+
+WebIDBFactoryImpl::IOThreadHelper::IOThreadHelper(
+ scoped_refptr<IPC::SyncMessageFilter> sync_message_filter)
+ : sync_message_filter_(std::move(sync_message_filter)) {}
+
+WebIDBFactoryImpl::IOThreadHelper::~IOThreadHelper() {}
+
+FactoryAssociatedPtr& WebIDBFactoryImpl::IOThreadHelper::GetService() {
+ if (!service_)
+ sync_message_filter_->GetRemoteAssociatedInterface(&service_);
+ return service_;
+}
+
+CallbacksAssociatedPtrInfo WebIDBFactoryImpl::IOThreadHelper::GetCallbacksProxy(
+ std::unique_ptr<IndexedDBCallbacksImpl> callbacks) {
+ CallbacksAssociatedPtrInfo ptr_info;
+ indexed_db::mojom::CallbacksAssociatedRequest request;
+ GetService().associated_group()->CreateAssociatedInterface(
+ mojo::AssociatedGroup::WILL_PASS_PTR, &ptr_info, &request);
+ mojo::MakeStrongAssociatedBinding(std::move(callbacks), std::move(request));
+ return ptr_info;
+}
+
+DatabaseCallbacksAssociatedPtrInfo
+WebIDBFactoryImpl::IOThreadHelper::GetDatabaseCallbacksProxy(
+ std::unique_ptr<IndexedDBDatabaseCallbacksImpl> callbacks) {
+ DatabaseCallbacksAssociatedPtrInfo ptr_info;
+ indexed_db::mojom::DatabaseCallbacksAssociatedRequest request;
+ GetService().associated_group()->CreateAssociatedInterface(
+ mojo::AssociatedGroup::WILL_PASS_PTR, &ptr_info, &request);
+ mojo::MakeStrongAssociatedBinding(std::move(callbacks), std::move(request));
+ return ptr_info;
+}
+
+void WebIDBFactoryImpl::IOThreadHelper::GetDatabaseNames(
+ std::unique_ptr<IndexedDBCallbacksImpl> callbacks,
+ const url::Origin& origin) {
+ GetService()->GetDatabaseNames(GetCallbacksProxy(std::move(callbacks)),
+ origin);
+}
+
+void WebIDBFactoryImpl::IOThreadHelper::Open(
+ int32_t worker_thread,
+ const base::string16& name,
+ int64_t version,
+ int64_t transaction_id,
+ std::unique_ptr<IndexedDBCallbacksImpl> callbacks,
+ std::unique_ptr<IndexedDBDatabaseCallbacksImpl> database_callbacks,
+ const url::Origin& origin) {
+ GetService()->Open(worker_thread, GetCallbacksProxy(std::move(callbacks)),
+ GetDatabaseCallbacksProxy(std::move(database_callbacks)),
+ origin, name, version, transaction_id);
+}
+
+void WebIDBFactoryImpl::IOThreadHelper::DeleteDatabase(
+ const base::string16& name,
+ std::unique_ptr<IndexedDBCallbacksImpl> callbacks,
+ const url::Origin& origin) {
+ GetService()->DeleteDatabase(GetCallbacksProxy(std::move(callbacks)), origin,
+ name);
}
} // namespace content
« no previous file with comments | « content/child/indexed_db/webidbfactory_impl.h ('k') | content/common/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698