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

Side by Side Diff: content/child/indexed_db/webidbfactory_impl.cc

Issue 2370643004: Port messages sent by WebIDBFactoryImpl to Mojo. (Closed)
Patch Set: Addressed most of dcheng@'s feedback. 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
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_;
cmumford 2016/10/11 18:30:54 DISALLOW_COPY_AND_ASSIGN(IOThreadHelper);
Reilly Grant (use Gerrit) 2016/10/11 23:46:13 Done.
56 };
57
58 WebIDBFactoryImpl::WebIDBFactoryImpl(
59 scoped_refptr<IPC::SyncMessageFilter> sync_message_filter,
60 scoped_refptr<ThreadSafeSender> thread_safe_sender,
61 scoped_refptr<base::SingleThreadTaskRunner> io_runner)
62 : thread_safe_sender_(std::move(thread_safe_sender)),
63 io_runner_(std::move(io_runner)) {
64 helper_ = new IOThreadHelper(std::move(sync_message_filter));
cmumford 2016/10/11 18:30:54 set |helper_| in class initialization section.
Reilly Grant (use Gerrit) 2016/10/11 23:46:13 Done.
65 }
66
67 WebIDBFactoryImpl::~WebIDBFactoryImpl() {
68 io_runner_->DeleteSoon(FROM_HERE, helper_);
69 }
25 70
26 void WebIDBFactoryImpl::getDatabaseNames(WebIDBCallbacks* callbacks, 71 void WebIDBFactoryImpl::getDatabaseNames(WebIDBCallbacks* callbacks,
27 const WebSecurityOrigin& origin) { 72 const WebSecurityOrigin& origin) {
28 IndexedDBDispatcher* dispatcher = 73 auto callbacks_impl =
29 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get()); 74 base::MakeUnique<IndexedDBCallbacksImpl>(callbacks, thread_safe_sender_);
30 dispatcher->RequestIDBFactoryGetDatabaseNames(callbacks, origin); 75 io_runner_->PostTask(
76 FROM_HERE,
77 base::Bind(&IOThreadHelper::GetDatabaseNames, base::Unretained(helper_),
78 base::Passed(&callbacks_impl), url::Origin(origin)));
31 } 79 }
32 80
33 void WebIDBFactoryImpl::open(const WebString& name, 81 void WebIDBFactoryImpl::open(const WebString& name,
34 long long version, 82 long long version,
35 long long transaction_id, 83 long long transaction_id,
36 WebIDBCallbacks* callbacks, 84 WebIDBCallbacks* callbacks,
37 WebIDBDatabaseCallbacks* database_callbacks, 85 WebIDBDatabaseCallbacks* database_callbacks,
38 const WebSecurityOrigin& origin) { 86 const WebSecurityOrigin& origin) {
39 IndexedDBDispatcher* dispatcher = 87 auto callbacks_impl =
40 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get()); 88 base::MakeUnique<IndexedDBCallbacksImpl>(callbacks, thread_safe_sender_);
41 89 auto database_callbacks_impl =
42 dispatcher->RequestIDBFactoryOpen(name, version, transaction_id, callbacks, 90 base::MakeUnique<IndexedDBDatabaseCallbacksImpl>(database_callbacks);
43 database_callbacks, origin); 91 io_runner_->PostTask(
92 FROM_HERE,
93 base::Bind(&IOThreadHelper::Open, base::Unretained(helper_),
94 WorkerThread::GetCurrentId(), base::string16(name), version,
cmumford 2016/10/11 18:30:54 no need to explicitly typecase to base::string16.
Reilly Grant (use Gerrit) 2016/10/11 23:46:13 I do because I want the conversion and copy to hap
95 transaction_id, base::Passed(&callbacks_impl),
96 base::Passed(&database_callbacks_impl), url::Origin(origin)));
44 } 97 }
45 98
46 void WebIDBFactoryImpl::deleteDatabase(const WebString& name, 99 void WebIDBFactoryImpl::deleteDatabase(const WebString& name,
47 WebIDBCallbacks* callbacks, 100 WebIDBCallbacks* callbacks,
48 const WebSecurityOrigin& origin) { 101 const WebSecurityOrigin& origin) {
49 IndexedDBDispatcher* dispatcher = 102 auto callbacks_impl =
50 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get()); 103 base::MakeUnique<IndexedDBCallbacksImpl>(callbacks, thread_safe_sender_);
51 dispatcher->RequestIDBFactoryDeleteDatabase(name, callbacks, origin); 104 io_runner_->PostTask(
105 FROM_HERE,
106 base::Bind(&IOThreadHelper::DeleteDatabase, base::Unretained(helper_),
107 base::string16(name), base::Passed(&callbacks_impl),
108 url::Origin(origin)));
109 }
110
111 WebIDBFactoryImpl::IOThreadHelper::IOThreadHelper(
112 scoped_refptr<IPC::SyncMessageFilter> sync_message_filter)
113 : sync_message_filter_(std::move(sync_message_filter)) {}
114
115 WebIDBFactoryImpl::IOThreadHelper::~IOThreadHelper() {}
116
117 FactoryAssociatedPtr& WebIDBFactoryImpl::IOThreadHelper::GetService() {
118 if (!service_)
119 sync_message_filter_->GetRemoteAssociatedInterface(&service_);
120 return service_;
121 }
122
123 CallbacksAssociatedPtrInfo WebIDBFactoryImpl::IOThreadHelper::GetCallbacksProxy(
124 std::unique_ptr<IndexedDBCallbacksImpl> callbacks) {
125 CallbacksAssociatedPtrInfo ptr_info;
126 indexed_db::mojom::CallbacksAssociatedRequest request;
127 GetService().associated_group()->CreateAssociatedInterface(
128 mojo::AssociatedGroup::WILL_PASS_PTR, &ptr_info, &request);
129 mojo::MakeStrongAssociatedBinding(std::move(callbacks), std::move(request));
130 return ptr_info;
131 }
132
133 DatabaseCallbacksAssociatedPtrInfo
134 WebIDBFactoryImpl::IOThreadHelper::GetDatabaseCallbacksProxy(
135 std::unique_ptr<IndexedDBDatabaseCallbacksImpl> callbacks) {
136 DatabaseCallbacksAssociatedPtrInfo ptr_info;
137 indexed_db::mojom::DatabaseCallbacksAssociatedRequest request;
138 GetService().associated_group()->CreateAssociatedInterface(
139 mojo::AssociatedGroup::WILL_PASS_PTR, &ptr_info, &request);
140 mojo::MakeStrongAssociatedBinding(std::move(callbacks), std::move(request));
141 return ptr_info;
142 }
143
144 void WebIDBFactoryImpl::IOThreadHelper::GetDatabaseNames(
145 std::unique_ptr<IndexedDBCallbacksImpl> callbacks,
146 const url::Origin& origin) {
147 GetService()->GetDatabaseNames(GetCallbacksProxy(std::move(callbacks)),
148 origin);
149 }
150
151 void WebIDBFactoryImpl::IOThreadHelper::Open(
152 int32_t worker_thread,
153 const base::string16& name,
154 int64_t version,
155 int64_t transaction_id,
156 std::unique_ptr<IndexedDBCallbacksImpl> callbacks,
157 std::unique_ptr<IndexedDBDatabaseCallbacksImpl> database_callbacks,
158 const url::Origin& origin) {
159 GetService()->Open(worker_thread, GetCallbacksProxy(std::move(callbacks)),
160 GetDatabaseCallbacksProxy(std::move(database_callbacks)),
161 origin, name, version, transaction_id);
162 }
163
164 void WebIDBFactoryImpl::IOThreadHelper::DeleteDatabase(
165 const base::string16& name,
166 std::unique_ptr<IndexedDBCallbacksImpl> callbacks,
167 const url::Origin& origin) {
168 GetService()->DeleteDatabase(GetCallbacksProxy(std::move(callbacks)), origin,
169 name);
52 } 170 }
53 171
54 } // namespace content 172 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698