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

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

Issue 1963293002: Replacing Indexed DB Chromium IPC with Mojo Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Refactoring after Passing URLRequestContextGetter. Created 4 years, 4 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "content/child/indexed_db/webidbdatabase_impl.h"
6
7 #include <stddef.h>
8
9 #include <string>
10 #include <vector>
11
12 #include "base/stl_util.h"
13 #include "content/child/indexed_db/indexed_db_dispatcher.h"
14 #include "content/child/indexed_db/indexed_db_key_builders.h"
15 #include "content/child/thread_safe_sender.h"
16 #include "content/child/worker_thread_registry.h"
17 #include "content/common/indexed_db/indexed_db_messages.h"
18 #include "third_party/WebKit/public/platform/WebBlobInfo.h"
19 #include "third_party/WebKit/public/platform/WebString.h"
20 #include "third_party/WebKit/public/platform/WebVector.h"
21 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBKeyPath.h"
22 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBMetadata.h"
23
24 using blink::WebBlobInfo;
25 using blink::WebIDBCallbacks;
26 using blink::WebIDBCursor;
27 using blink::WebIDBDatabase;
28 using blink::WebIDBDatabaseCallbacks;
29 using blink::WebIDBMetadata;
30 using blink::WebIDBKey;
31 using blink::WebIDBKeyPath;
32 using blink::WebIDBKeyRange;
33 using blink::WebIDBObserver;
34 using blink::WebString;
35 using blink::WebVector;
36
37 namespace content {
38
39 WebIDBDatabaseImpl::WebIDBDatabaseImpl(int32_t ipc_database_id,
40 int32_t ipc_database_callbacks_id,
41 ThreadSafeSender* thread_safe_sender)
42 : ipc_database_id_(ipc_database_id),
43 ipc_database_callbacks_id_(ipc_database_callbacks_id),
44 thread_safe_sender_(thread_safe_sender) {}
45
46 WebIDBDatabaseImpl::~WebIDBDatabaseImpl() {
47 // It's not possible for there to be pending callbacks that address this
48 // object since inside WebKit, they hold a reference to the object which owns
49 // this object. But, if that ever changed, then we'd need to invalidate
50 // any such pointers.
51 thread_safe_sender_->Send(
52 new IndexedDBHostMsg_DatabaseDestroyed(ipc_database_id_));
53 IndexedDBDispatcher* dispatcher =
54 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get());
55 dispatcher->DatabaseDestroyed(ipc_database_id_);
56 }
57
58 void WebIDBDatabaseImpl::createObjectStore(long long transaction_id,
59 long long object_store_id,
60 const WebString& name,
61 const WebIDBKeyPath& key_path,
62 bool auto_increment) {
63 IndexedDBHostMsg_DatabaseCreateObjectStore_Params params;
64 params.ipc_database_id = ipc_database_id_;
65 params.transaction_id = transaction_id;
66 params.object_store_id = object_store_id;
67 params.name = name;
68 params.key_path = IndexedDBKeyPathBuilder::Build(key_path);
69 params.auto_increment = auto_increment;
70
71 thread_safe_sender_->Send(
72 new IndexedDBHostMsg_DatabaseCreateObjectStore(params));
73 }
74
75 void WebIDBDatabaseImpl::deleteObjectStore(long long transaction_id,
76 long long object_store_id) {
77 thread_safe_sender_->Send(new IndexedDBHostMsg_DatabaseDeleteObjectStore(
78 ipc_database_id_, transaction_id, object_store_id));
79 }
80
81 void WebIDBDatabaseImpl::createTransaction(
82 long long transaction_id,
83 WebIDBDatabaseCallbacks* callbacks,
84 const WebVector<long long>& object_store_ids,
85 blink::WebIDBTransactionMode mode) {
86 IndexedDBDispatcher* dispatcher =
87 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get());
88 dispatcher->RequestIDBDatabaseCreateTransaction(
89 ipc_database_id_, transaction_id, callbacks, object_store_ids, mode);
90 }
91
92 void WebIDBDatabaseImpl::close() {
93 IndexedDBDispatcher* dispatcher =
94 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get());
95 dispatcher->RemoveIDBObservers(observer_ids_);
96 dispatcher->RequestIDBDatabaseClose(ipc_database_id_,
97 ipc_database_callbacks_id_);
98 }
99
100 void WebIDBDatabaseImpl::versionChangeIgnored() {
101 IndexedDBDispatcher* dispatcher =
102 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get());
103 dispatcher->NotifyIDBDatabaseVersionChangeIgnored(ipc_database_id_);
104 }
105
106 int32_t WebIDBDatabaseImpl::addObserver(
107 std::unique_ptr<WebIDBObserver> observer,
108 long long transaction_id) {
109 IndexedDBDispatcher* dispatcher =
110 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get());
111
112 int32_t observer_id = dispatcher->AddIDBObserver(
113 ipc_database_id_, transaction_id, std::move(observer));
114 observer_ids_.insert(observer_id);
115 return observer_id;
116 }
117
118 void WebIDBDatabaseImpl::removeObservers(
119 const WebVector<int32_t>& observer_ids_to_remove) {
120 std::vector<int32_t> remove_observer_ids(
121 observer_ids_to_remove.data(),
122 observer_ids_to_remove.data() + observer_ids_to_remove.size());
123 for (int32_t id : observer_ids_to_remove)
124 observer_ids_.erase(id);
125
126 IndexedDBDispatcher* dispatcher =
127 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get());
128 dispatcher->RemoveIDBObserversFromDatabase(ipc_database_id_,
129 remove_observer_ids);
130 }
131
132 void WebIDBDatabaseImpl::get(long long transaction_id,
133 long long object_store_id,
134 long long index_id,
135 const WebIDBKeyRange& key_range,
136 bool key_only,
137 WebIDBCallbacks* callbacks) {
138 IndexedDBDispatcher* dispatcher =
139 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get());
140 dispatcher->RequestIDBDatabaseGet(ipc_database_id_,
141 transaction_id,
142 object_store_id,
143 index_id,
144 IndexedDBKeyRangeBuilder::Build(key_range),
145 key_only,
146 callbacks);
147 }
148
149 void WebIDBDatabaseImpl::getAll(long long transaction_id,
150 long long object_store_id,
151 long long index_id,
152 const WebIDBKeyRange& key_range,
153 long long max_count,
154 bool key_only,
155 WebIDBCallbacks* callbacks) {
156 IndexedDBDispatcher* dispatcher =
157 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get());
158 dispatcher->RequestIDBDatabaseGetAll(
159 ipc_database_id_, transaction_id, object_store_id, index_id,
160 IndexedDBKeyRangeBuilder::Build(key_range), key_only, max_count,
161 callbacks);
162 }
163
164 void WebIDBDatabaseImpl::put(long long transaction_id,
165 long long object_store_id,
166 const blink::WebData& value,
167 const blink::WebVector<WebBlobInfo>& web_blob_info,
168 const WebIDBKey& key,
169 blink::WebIDBPutMode put_mode,
170 WebIDBCallbacks* callbacks,
171 const WebVector<long long>& web_index_ids,
172 const WebVector<WebIndexKeys>& web_index_keys) {
173 IndexedDBDispatcher* dispatcher =
174 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get());
175 dispatcher->RequestIDBDatabasePut(ipc_database_id_,
176 transaction_id,
177 object_store_id,
178 value,
179 web_blob_info,
180 IndexedDBKeyBuilder::Build(key),
181 put_mode,
182 callbacks,
183 web_index_ids,
184 web_index_keys);
185 }
186
187 void WebIDBDatabaseImpl::setIndexKeys(
188 long long transaction_id,
189 long long object_store_id,
190 const WebIDBKey& primary_key,
191 const WebVector<long long>& index_ids,
192 const WebVector<WebIndexKeys>& index_keys) {
193 IndexedDBHostMsg_DatabaseSetIndexKeys_Params params;
194 params.ipc_database_id = ipc_database_id_;
195 params.transaction_id = transaction_id;
196 params.object_store_id = object_store_id;
197 params.primary_key = IndexedDBKeyBuilder::Build(primary_key);
198
199 DCHECK_EQ(index_ids.size(), index_keys.size());
200 params.index_keys.resize(index_ids.size());
201 for (size_t i = 0, len = index_ids.size(); i < len; ++i) {
202 params.index_keys[i].first = index_ids[i];
203 params.index_keys[i].second.resize(index_keys[i].size());
204 for (size_t j = 0; j < index_keys[i].size(); ++j) {
205 params.index_keys[i].second[j] =
206 IndexedDBKey(IndexedDBKeyBuilder::Build(index_keys[i][j]));
207 }
208 }
209
210 thread_safe_sender_->Send(new IndexedDBHostMsg_DatabaseSetIndexKeys(params));
211 }
212
213 void WebIDBDatabaseImpl::setIndexesReady(
214 long long transaction_id,
215 long long object_store_id,
216 const WebVector<long long>& web_index_ids) {
217 std::vector<int64_t> index_ids(web_index_ids.data(),
218 web_index_ids.data() + web_index_ids.size());
219 thread_safe_sender_->Send(new IndexedDBHostMsg_DatabaseSetIndexesReady(
220 ipc_database_id_, transaction_id, object_store_id, index_ids));
221 }
222
223 void WebIDBDatabaseImpl::openCursor(long long transaction_id,
224 long long object_store_id,
225 long long index_id,
226 const WebIDBKeyRange& key_range,
227 blink::WebIDBCursorDirection direction,
228 bool key_only,
229 blink::WebIDBTaskType task_type,
230 WebIDBCallbacks* callbacks) {
231 IndexedDBDispatcher* dispatcher =
232 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get());
233 dispatcher->RequestIDBDatabaseOpenCursor(
234 ipc_database_id_,
235 transaction_id,
236 object_store_id,
237 index_id,
238 IndexedDBKeyRangeBuilder::Build(key_range),
239 direction,
240 key_only,
241 task_type,
242 callbacks);
243 }
244
245 void WebIDBDatabaseImpl::count(long long transaction_id,
246 long long object_store_id,
247 long long index_id,
248 const WebIDBKeyRange& key_range,
249 WebIDBCallbacks* callbacks) {
250 IndexedDBDispatcher* dispatcher =
251 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get());
252 dispatcher->RequestIDBDatabaseCount(
253 ipc_database_id_,
254 transaction_id,
255 object_store_id,
256 index_id,
257 IndexedDBKeyRangeBuilder::Build(key_range),
258 callbacks);
259 }
260
261 void WebIDBDatabaseImpl::deleteRange(long long transaction_id,
262 long long object_store_id,
263 const WebIDBKeyRange& key_range,
264 WebIDBCallbacks* callbacks) {
265 IndexedDBDispatcher* dispatcher =
266 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get());
267 dispatcher->RequestIDBDatabaseDeleteRange(
268 ipc_database_id_,
269 transaction_id,
270 object_store_id,
271 IndexedDBKeyRangeBuilder::Build(key_range),
272 callbacks);
273 }
274
275 void WebIDBDatabaseImpl::clear(long long transaction_id,
276 long long object_store_id,
277 WebIDBCallbacks* callbacks) {
278 IndexedDBDispatcher* dispatcher =
279 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get());
280 dispatcher->RequestIDBDatabaseClear(
281 ipc_database_id_, transaction_id, object_store_id, callbacks);
282 }
283
284 void WebIDBDatabaseImpl::createIndex(long long transaction_id,
285 long long object_store_id,
286 long long index_id,
287 const WebString& name,
288 const WebIDBKeyPath& key_path,
289 bool unique,
290 bool multi_entry) {
291 IndexedDBHostMsg_DatabaseCreateIndex_Params params;
292 params.ipc_database_id = ipc_database_id_;
293 params.transaction_id = transaction_id;
294 params.object_store_id = object_store_id;
295 params.index_id = index_id;
296 params.name = name;
297 params.key_path = IndexedDBKeyPathBuilder::Build(key_path);
298 params.unique = unique;
299 params.multi_entry = multi_entry;
300
301 thread_safe_sender_->Send(new IndexedDBHostMsg_DatabaseCreateIndex(params));
302 }
303
304 void WebIDBDatabaseImpl::deleteIndex(long long transaction_id,
305 long long object_store_id,
306 long long index_id) {
307 thread_safe_sender_->Send(new IndexedDBHostMsg_DatabaseDeleteIndex(
308 ipc_database_id_, transaction_id, object_store_id, index_id));
309 }
310
311 void WebIDBDatabaseImpl::abort(long long transaction_id) {
312 thread_safe_sender_->Send(
313 new IndexedDBHostMsg_DatabaseAbort(ipc_database_id_, transaction_id));
314 }
315
316 void WebIDBDatabaseImpl::commit(long long transaction_id) {
317 thread_safe_sender_->Send(
318 new IndexedDBHostMsg_DatabaseCommit(ipc_database_id_, transaction_id));
319 }
320
321 void WebIDBDatabaseImpl::ackReceivedBlobs(const WebVector<WebString>& uuids) {
322 DCHECK(uuids.size());
323 std::vector<std::string> param(uuids.size());
324 for (size_t i = 0; i < uuids.size(); ++i)
325 param[i] = uuids[i].latin1().data();
326 thread_safe_sender_->Send(new IndexedDBHostMsg_AckReceivedBlobs(param));
327 }
328
329 } // namespace content
OLDNEW
« no previous file with comments | « content/child/indexed_db/webidbdatabase_impl.h ('k') | content/child/indexed_db/webidbfactory_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698