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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 = base::MakeUnique<IndexedDBCallbacksImpl>(
29 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get()); 75 base::WrapUnique(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 = base::MakeUnique<IndexedDBCallbacksImpl>(
40 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get()); 89 base::WrapUnique(callbacks), thread_safe_sender_);
41 90 auto database_callbacks_impl =
42 dispatcher->RequestIDBFactoryOpen(name, version, transaction_id, callbacks, 91 base::MakeUnique<IndexedDBDatabaseCallbacksImpl>(
43 database_callbacks, origin); 92 base::WrapUnique(database_callbacks), thread_safe_sender_);
93 io_runner_->PostTask(
94 FROM_HERE,
95 base::Bind(&IOThreadHelper::Open, base::Unretained(io_helper_),
96 WorkerThread::GetCurrentId(), base::string16(name), version,
97 transaction_id, base::Passed(&callbacks_impl),
98 base::Passed(&database_callbacks_impl), url::Origin(origin)));
44 } 99 }
45 100
46 void WebIDBFactoryImpl::deleteDatabase(const WebString& name, 101 void WebIDBFactoryImpl::deleteDatabase(const WebString& name,
47 WebIDBCallbacks* callbacks, 102 WebIDBCallbacks* callbacks,
48 const WebSecurityOrigin& origin) { 103 const WebSecurityOrigin& origin) {
49 IndexedDBDispatcher* dispatcher = 104 auto callbacks_impl = base::MakeUnique<IndexedDBCallbacksImpl>(
50 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get()); 105 base::WrapUnique(callbacks), thread_safe_sender_);
51 dispatcher->RequestIDBFactoryDeleteDatabase(name, callbacks, origin); 106 io_runner_->PostTask(
107 FROM_HERE,
108 base::Bind(&IOThreadHelper::DeleteDatabase, base::Unretained(io_helper_),
109 base::string16(name), base::Passed(&callbacks_impl),
110 url::Origin(origin)));
111 }
112
113 WebIDBFactoryImpl::IOThreadHelper::IOThreadHelper(
114 scoped_refptr<IPC::SyncMessageFilter> sync_message_filter)
115 : sync_message_filter_(std::move(sync_message_filter)) {}
116
117 WebIDBFactoryImpl::IOThreadHelper::~IOThreadHelper() {}
118
119 FactoryAssociatedPtr& WebIDBFactoryImpl::IOThreadHelper::GetService() {
120 if (!service_)
121 sync_message_filter_->GetRemoteAssociatedInterface(&service_);
122 return service_;
123 }
124
125 CallbacksAssociatedPtrInfo WebIDBFactoryImpl::IOThreadHelper::GetCallbacksProxy(
126 std::unique_ptr<IndexedDBCallbacksImpl> callbacks) {
127 CallbacksAssociatedPtrInfo ptr_info;
128 indexed_db::mojom::CallbacksAssociatedRequest request;
129 GetService().associated_group()->CreateAssociatedInterface(
130 mojo::AssociatedGroup::WILL_PASS_PTR, &ptr_info, &request);
131 mojo::MakeStrongAssociatedBinding(std::move(callbacks), std::move(request));
132 return ptr_info;
133 }
134
135 DatabaseCallbacksAssociatedPtrInfo
136 WebIDBFactoryImpl::IOThreadHelper::GetDatabaseCallbacksProxy(
137 std::unique_ptr<IndexedDBDatabaseCallbacksImpl> callbacks) {
138 DatabaseCallbacksAssociatedPtrInfo ptr_info;
139 indexed_db::mojom::DatabaseCallbacksAssociatedRequest request;
140 GetService().associated_group()->CreateAssociatedInterface(
141 mojo::AssociatedGroup::WILL_PASS_PTR, &ptr_info, &request);
142 mojo::MakeStrongAssociatedBinding(std::move(callbacks), std::move(request));
143 return ptr_info;
144 }
145
146 void WebIDBFactoryImpl::IOThreadHelper::GetDatabaseNames(
147 std::unique_ptr<IndexedDBCallbacksImpl> callbacks,
148 const url::Origin& origin) {
149 GetService()->GetDatabaseNames(GetCallbacksProxy(std::move(callbacks)),
150 origin);
151 }
152
153 void WebIDBFactoryImpl::IOThreadHelper::Open(
154 int32_t worker_thread,
155 const base::string16& name,
156 int64_t version,
157 int64_t transaction_id,
158 std::unique_ptr<IndexedDBCallbacksImpl> callbacks,
159 std::unique_ptr<IndexedDBDatabaseCallbacksImpl> database_callbacks,
160 const url::Origin& origin) {
161 GetService()->Open(worker_thread, GetCallbacksProxy(std::move(callbacks)),
162 GetDatabaseCallbacksProxy(std::move(database_callbacks)),
163 origin, name, version, transaction_id);
164 }
165
166 void WebIDBFactoryImpl::IOThreadHelper::DeleteDatabase(
167 const base::string16& name,
168 std::unique_ptr<IndexedDBCallbacksImpl> callbacks,
169 const url::Origin& origin) {
170 GetService()->DeleteDatabase(GetCallbacksProxy(std::move(callbacks)), origin,
171 name);
52 } 172 }
53 173
54 } // namespace content 174 } // namespace content
OLDNEW
« 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