OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/child/indexed_db/webidbfactory_impl.h" | 5 #include "content/child/indexed_db/webidbfactory_impl.h" |
6 | 6 |
7 #include "content/child/indexed_db/indexed_db_dispatcher.h" | 7 #include "content/child/child_thread_impl.h" |
| 8 #include "content/child/indexed_db/indexed_db_callbacks_impl.h" |
| 9 #include "content/child/indexed_db/indexed_db_database_callbacks_impl.h" |
8 #include "content/child/storage_util.h" | 10 #include "content/child/storage_util.h" |
9 #include "content/child/thread_safe_sender.h" | 11 #include "content/child/thread_safe_sender.h" |
| 12 #include "content/public/child/worker_thread.h" |
| 13 #include "ipc/ipc_sync_channel.h" |
| 14 #include "mojo/public/cpp/bindings/strong_associated_binding.h" |
10 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" | 15 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" |
11 #include "third_party/WebKit/public/platform/WebString.h" | 16 #include "third_party/WebKit/public/platform/WebString.h" |
12 | 17 |
13 using blink::WebIDBCallbacks; | 18 using blink::WebIDBCallbacks; |
14 using blink::WebIDBDatabase; | 19 using blink::WebIDBDatabase; |
15 using blink::WebIDBDatabaseCallbacks; | 20 using blink::WebIDBDatabaseCallbacks; |
16 using blink::WebSecurityOrigin; | 21 using blink::WebSecurityOrigin; |
17 using blink::WebString; | 22 using blink::WebString; |
| 23 using indexed_db::mojom::CallbacksAssociatedPtrInfo; |
| 24 using indexed_db::mojom::DatabaseCallbacksAssociatedPtrInfo; |
| 25 using indexed_db::mojom::FactoryAssociatedPtr; |
18 | 26 |
19 namespace content { | 27 namespace content { |
20 | 28 |
21 WebIDBFactoryImpl::WebIDBFactoryImpl(ThreadSafeSender* thread_safe_sender) | 29 class WebIDBFactoryImpl::IOThreadHelper { |
22 : thread_safe_sender_(thread_safe_sender) {} | 30 public: |
| 31 IOThreadHelper(scoped_refptr<IPC::SyncMessageFilter> sync_message_filter); |
| 32 ~IOThreadHelper(); |
23 | 33 |
24 WebIDBFactoryImpl::~WebIDBFactoryImpl() {} | 34 FactoryAssociatedPtr& GetService(); |
| 35 CallbacksAssociatedPtrInfo GetCallbacksProxy( |
| 36 std::unique_ptr<IndexedDBCallbacksImpl> callbacks); |
| 37 DatabaseCallbacksAssociatedPtrInfo GetDatabaseCallbacksProxy( |
| 38 std::unique_ptr<IndexedDBDatabaseCallbacksImpl> callbacks); |
| 39 |
| 40 void GetDatabaseNames(std::unique_ptr<IndexedDBCallbacksImpl> callbacks, |
| 41 const url::Origin& origin); |
| 42 void Open(int32_t worker_thread, |
| 43 const base::string16& name, |
| 44 int64_t version, |
| 45 int64_t transaction_id, |
| 46 std::unique_ptr<IndexedDBCallbacksImpl> callbacks, |
| 47 std::unique_ptr<IndexedDBDatabaseCallbacksImpl> database_callbacks, |
| 48 const url::Origin& origin); |
| 49 void DeleteDatabase(const base::string16& name, |
| 50 std::unique_ptr<IndexedDBCallbacksImpl> callbacks, |
| 51 const url::Origin& origin); |
| 52 |
| 53 private: |
| 54 scoped_refptr<IPC::SyncMessageFilter> sync_message_filter_; |
| 55 FactoryAssociatedPtr service_; |
| 56 |
| 57 DISALLOW_COPY_AND_ASSIGN(IOThreadHelper); |
| 58 }; |
| 59 |
| 60 WebIDBFactoryImpl::WebIDBFactoryImpl( |
| 61 scoped_refptr<IPC::SyncMessageFilter> sync_message_filter, |
| 62 scoped_refptr<ThreadSafeSender> thread_safe_sender, |
| 63 scoped_refptr<base::SingleThreadTaskRunner> io_runner) |
| 64 : io_helper_(new IOThreadHelper(std::move(sync_message_filter))), |
| 65 thread_safe_sender_(std::move(thread_safe_sender)), |
| 66 io_runner_(std::move(io_runner)) {} |
| 67 |
| 68 WebIDBFactoryImpl::~WebIDBFactoryImpl() { |
| 69 io_runner_->DeleteSoon(FROM_HERE, io_helper_); |
| 70 } |
25 | 71 |
26 void WebIDBFactoryImpl::getDatabaseNames(WebIDBCallbacks* callbacks, | 72 void WebIDBFactoryImpl::getDatabaseNames(WebIDBCallbacks* callbacks, |
27 const WebSecurityOrigin& origin) { | 73 const WebSecurityOrigin& origin) { |
28 IndexedDBDispatcher* dispatcher = | 74 auto callbacks_impl = |
29 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get()); | 75 base::MakeUnique<IndexedDBCallbacksImpl>(callbacks, thread_safe_sender_); |
30 dispatcher->RequestIDBFactoryGetDatabaseNames(callbacks, origin); | 76 io_runner_->PostTask(FROM_HERE, base::Bind(&IOThreadHelper::GetDatabaseNames, |
| 77 base::Unretained(io_helper_), |
| 78 base::Passed(&callbacks_impl), |
| 79 url::Origin(origin))); |
31 } | 80 } |
32 | 81 |
33 void WebIDBFactoryImpl::open(const WebString& name, | 82 void WebIDBFactoryImpl::open(const WebString& name, |
34 long long version, | 83 long long version, |
35 long long transaction_id, | 84 long long transaction_id, |
36 WebIDBCallbacks* callbacks, | 85 WebIDBCallbacks* callbacks, |
37 WebIDBDatabaseCallbacks* database_callbacks, | 86 WebIDBDatabaseCallbacks* database_callbacks, |
38 const WebSecurityOrigin& origin) { | 87 const WebSecurityOrigin& origin) { |
39 IndexedDBDispatcher* dispatcher = | 88 auto callbacks_impl = |
40 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get()); | 89 base::MakeUnique<IndexedDBCallbacksImpl>(callbacks, thread_safe_sender_); |
41 | 90 auto database_callbacks_impl = |
42 dispatcher->RequestIDBFactoryOpen(name, version, transaction_id, callbacks, | 91 base::MakeUnique<IndexedDBDatabaseCallbacksImpl>(database_callbacks); |
43 database_callbacks, origin); | 92 io_runner_->PostTask( |
| 93 FROM_HERE, |
| 94 base::Bind(&IOThreadHelper::Open, base::Unretained(io_helper_), |
| 95 WorkerThread::GetCurrentId(), base::string16(name), version, |
| 96 transaction_id, base::Passed(&callbacks_impl), |
| 97 base::Passed(&database_callbacks_impl), url::Origin(origin))); |
44 } | 98 } |
45 | 99 |
46 void WebIDBFactoryImpl::deleteDatabase(const WebString& name, | 100 void WebIDBFactoryImpl::deleteDatabase(const WebString& name, |
47 WebIDBCallbacks* callbacks, | 101 WebIDBCallbacks* callbacks, |
48 const WebSecurityOrigin& origin) { | 102 const WebSecurityOrigin& origin) { |
49 IndexedDBDispatcher* dispatcher = | 103 auto callbacks_impl = |
50 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get()); | 104 base::MakeUnique<IndexedDBCallbacksImpl>(callbacks, thread_safe_sender_); |
51 dispatcher->RequestIDBFactoryDeleteDatabase(name, callbacks, origin); | 105 io_runner_->PostTask( |
| 106 FROM_HERE, |
| 107 base::Bind(&IOThreadHelper::DeleteDatabase, base::Unretained(io_helper_), |
| 108 base::string16(name), base::Passed(&callbacks_impl), |
| 109 url::Origin(origin))); |
| 110 } |
| 111 |
| 112 WebIDBFactoryImpl::IOThreadHelper::IOThreadHelper( |
| 113 scoped_refptr<IPC::SyncMessageFilter> sync_message_filter) |
| 114 : sync_message_filter_(std::move(sync_message_filter)) {} |
| 115 |
| 116 WebIDBFactoryImpl::IOThreadHelper::~IOThreadHelper() {} |
| 117 |
| 118 FactoryAssociatedPtr& WebIDBFactoryImpl::IOThreadHelper::GetService() { |
| 119 if (!service_) |
| 120 sync_message_filter_->GetRemoteAssociatedInterface(&service_); |
| 121 return service_; |
| 122 } |
| 123 |
| 124 CallbacksAssociatedPtrInfo WebIDBFactoryImpl::IOThreadHelper::GetCallbacksProxy( |
| 125 std::unique_ptr<IndexedDBCallbacksImpl> callbacks) { |
| 126 CallbacksAssociatedPtrInfo ptr_info; |
| 127 indexed_db::mojom::CallbacksAssociatedRequest request; |
| 128 GetService().associated_group()->CreateAssociatedInterface( |
| 129 mojo::AssociatedGroup::WILL_PASS_PTR, &ptr_info, &request); |
| 130 mojo::MakeStrongAssociatedBinding(std::move(callbacks), std::move(request)); |
| 131 return ptr_info; |
| 132 } |
| 133 |
| 134 DatabaseCallbacksAssociatedPtrInfo |
| 135 WebIDBFactoryImpl::IOThreadHelper::GetDatabaseCallbacksProxy( |
| 136 std::unique_ptr<IndexedDBDatabaseCallbacksImpl> callbacks) { |
| 137 DatabaseCallbacksAssociatedPtrInfo ptr_info; |
| 138 indexed_db::mojom::DatabaseCallbacksAssociatedRequest request; |
| 139 GetService().associated_group()->CreateAssociatedInterface( |
| 140 mojo::AssociatedGroup::WILL_PASS_PTR, &ptr_info, &request); |
| 141 mojo::MakeStrongAssociatedBinding(std::move(callbacks), std::move(request)); |
| 142 return ptr_info; |
| 143 } |
| 144 |
| 145 void WebIDBFactoryImpl::IOThreadHelper::GetDatabaseNames( |
| 146 std::unique_ptr<IndexedDBCallbacksImpl> callbacks, |
| 147 const url::Origin& origin) { |
| 148 GetService()->GetDatabaseNames(GetCallbacksProxy(std::move(callbacks)), |
| 149 origin); |
| 150 } |
| 151 |
| 152 void WebIDBFactoryImpl::IOThreadHelper::Open( |
| 153 int32_t worker_thread, |
| 154 const base::string16& name, |
| 155 int64_t version, |
| 156 int64_t transaction_id, |
| 157 std::unique_ptr<IndexedDBCallbacksImpl> callbacks, |
| 158 std::unique_ptr<IndexedDBDatabaseCallbacksImpl> database_callbacks, |
| 159 const url::Origin& origin) { |
| 160 GetService()->Open(worker_thread, GetCallbacksProxy(std::move(callbacks)), |
| 161 GetDatabaseCallbacksProxy(std::move(database_callbacks)), |
| 162 origin, name, version, transaction_id); |
| 163 } |
| 164 |
| 165 void WebIDBFactoryImpl::IOThreadHelper::DeleteDatabase( |
| 166 const base::string16& name, |
| 167 std::unique_ptr<IndexedDBCallbacksImpl> callbacks, |
| 168 const url::Origin& origin) { |
| 169 GetService()->DeleteDatabase(GetCallbacksProxy(std::move(callbacks)), origin, |
| 170 name); |
52 } | 171 } |
53 | 172 |
54 } // namespace content | 173 } // namespace content |
OLD | NEW |