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..c07c1f5b969040a973a86d1bef716895eaeeac93 100644 |
--- a/content/child/indexed_db/webidbfactory_impl.cc |
+++ b/content/child/indexed_db/webidbfactory_impl.cc |
@@ -4,9 +4,13 @@ |
#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 "third_party/WebKit/public/platform/WebSecurityOrigin.h" |
#include "third_party/WebKit/public/platform/WebString.h" |
@@ -18,16 +22,51 @@ using blink::WebString; |
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() {} |
+ void EnsureServiceConnection(); |
+ 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_; |
+ indexed_db::mojom::FactoryAssociatedPtr service_; |
+}; |
+ |
+WebIDBFactoryImpl::WebIDBFactoryImpl( |
+ scoped_refptr<IPC::SyncMessageFilter> sync_message_filter, |
+ scoped_refptr<ThreadSafeSender> thread_safe_sender, |
+ scoped_refptr<base::SingleThreadTaskRunner> io_runner) |
+ : thread_safe_sender_(std::move(thread_safe_sender)), |
+ io_runner_(std::move(io_runner)) { |
+ helper_ = new IOThreadHelper(std::move(sync_message_filter)); |
+} |
+ |
+WebIDBFactoryImpl::~WebIDBFactoryImpl() { |
+ io_runner_->DeleteSoon(FROM_HERE, 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>(callbacks, thread_safe_sender_); |
+ io_runner_->PostTask( |
+ FROM_HERE, |
+ base::Bind(&IOThreadHelper::GetDatabaseNames, base::Unretained(helper_), |
+ base::Passed(&callbacks_impl), url::Origin(origin))); |
} |
void WebIDBFactoryImpl::open(const WebString& name, |
@@ -36,19 +75,83 @@ 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>(callbacks, thread_safe_sender_); |
+ auto database_callbacks_impl = |
+ base::MakeUnique<IndexedDBDatabaseCallbacksImpl>(database_callbacks); |
+ io_runner_->PostTask( |
+ FROM_HERE, |
+ base::Bind(&IOThreadHelper::Open, base::Unretained(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>(callbacks, thread_safe_sender_); |
+ io_runner_->PostTask( |
+ FROM_HERE, |
+ base::Bind(&IOThreadHelper::DeleteDatabase, base::Unretained(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() {} |
+ |
+void WebIDBFactoryImpl::IOThreadHelper::EnsureServiceConnection() { |
Ken Rockot(use gerrit already)
2016/09/28 20:06:44
nit: I think it'd just be cleaner to have an acces
Reilly Grant (use Gerrit)
2016/09/29 06:44:50
I considered that but since I usually need both se
Ken Rockot(use gerrit already)
2016/09/29 22:37:50
Fair enough. You could of course have the lazy get
Reilly Grant (use Gerrit)
2016/09/30 07:24:20
Oh look! Now there's a StrongAssociatedBinding.
|
+ if (!service_) |
+ sync_message_filter_->GetRemoteAssociatedInterface(&service_); |
+} |
+ |
+void WebIDBFactoryImpl::IOThreadHelper::GetDatabaseNames( |
+ std::unique_ptr<IndexedDBCallbacksImpl> callbacks, |
+ const url::Origin& origin) { |
+ EnsureServiceConnection(); |
+ |
+ indexed_db::mojom::CallbacksAssociatedPtrInfo mojo_callbacks; |
+ callbacks.release()->Bind(&mojo_callbacks, service_.associated_group()); |
+ |
+ service_->GetDatabaseNames(std::move(mojo_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) { |
+ EnsureServiceConnection(); |
+ |
+ indexed_db::mojom::CallbacksAssociatedPtrInfo mojo_callbacks; |
+ callbacks.release()->Bind(&mojo_callbacks, service_.associated_group()); |
+ indexed_db::mojom::DatabaseCallbacksAssociatedPtrInfo mojo_database_callbacks; |
+ database_callbacks.release()->Bind(&mojo_database_callbacks, |
+ service_.associated_group()); |
+ |
+ service_->Open(worker_thread, std::move(mojo_callbacks), |
+ std::move(mojo_database_callbacks), origin, name, version, |
+ transaction_id); |
+} |
+ |
+void WebIDBFactoryImpl::IOThreadHelper::DeleteDatabase( |
+ const base::string16& name, |
+ std::unique_ptr<IndexedDBCallbacksImpl> callbacks, |
+ const url::Origin& origin) { |
+ EnsureServiceConnection(); |
+ |
+ indexed_db::mojom::CallbacksAssociatedPtrInfo mojo_callbacks; |
+ callbacks.release()->Bind(&mojo_callbacks, service_.associated_group()); |
+ |
+ service_->DeleteDatabase(std::move(mojo_callbacks), origin, name); |
} |
} // namespace content |