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.
5 #include "content/child/indexed_db/proxy_webidbdatabase_impl.h"
9 #include "content/child/thread_safe_sender.h"
10 #include "content/child/indexed_db/indexed_db_dispatcher.h"
11 #include "content/child/indexed_db/indexed_db_key_builders.h"
12 #include "content/common/indexed_db/indexed_db_messages.h"
13 #include "third_party/WebKit/public/platform/WebIDBKeyPath.h"
14 #include "third_party/WebKit/public/platform/WebIDBMetadata.h"
15 #include "third_party/WebKit/public/platform/WebString.h"
16 #include "third_party/WebKit/public/platform/WebVector.h"
17 #include "webkit/child/worker_task_runner.h"
19 using WebKit::WebIDBCallbacks
;
20 using WebKit::WebIDBDatabaseCallbacks
;
21 using WebKit::WebIDBMetadata
;
22 using WebKit::WebIDBKey
;
23 using WebKit::WebIDBKeyPath
;
24 using WebKit::WebIDBKeyRange
;
25 using WebKit::WebString
;
26 using WebKit::WebVector
;
27 using webkit_glue::WorkerTaskRunner
;
31 RendererWebIDBDatabaseImpl::RendererWebIDBDatabaseImpl(
32 int32 ipc_database_id
,
33 int32 ipc_database_callbacks_id
,
34 ThreadSafeSender
* thread_safe_sender
)
35 : ipc_database_id_(ipc_database_id
),
36 ipc_database_callbacks_id_(ipc_database_callbacks_id
),
37 thread_safe_sender_(thread_safe_sender
) {}
39 RendererWebIDBDatabaseImpl::~RendererWebIDBDatabaseImpl() {
40 // It's not possible for there to be pending callbacks that address this
41 // object since inside WebKit, they hold a reference to the object which owns
42 // this object. But, if that ever changed, then we'd need to invalidate
44 thread_safe_sender_
->Send(new IndexedDBHostMsg_DatabaseDestroyed(
46 IndexedDBDispatcher
* dispatcher
=
47 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_
.get());
48 dispatcher
->DatabaseDestroyed(ipc_database_id_
);
51 void RendererWebIDBDatabaseImpl::createObjectStore(
52 long long transaction_id
,
53 long long object_store_id
,
54 const WebString
& name
,
55 const WebIDBKeyPath
& key_path
,
56 bool auto_increment
) {
57 IndexedDBHostMsg_DatabaseCreateObjectStore_Params params
;
58 params
.ipc_database_id
= ipc_database_id_
;
59 params
.transaction_id
= transaction_id
;
60 params
.object_store_id
= object_store_id
;
62 params
.key_path
= IndexedDBKeyPathBuilder::Build(key_path
);
63 params
.auto_increment
= auto_increment
;
65 thread_safe_sender_
->Send(
66 new IndexedDBHostMsg_DatabaseCreateObjectStore(params
));
69 void RendererWebIDBDatabaseImpl::deleteObjectStore(
70 long long transaction_id
,
71 long long object_store_id
) {
72 thread_safe_sender_
->Send(
73 new IndexedDBHostMsg_DatabaseDeleteObjectStore(
79 void RendererWebIDBDatabaseImpl::createTransaction(
80 long long transaction_id
,
81 WebIDBDatabaseCallbacks
* callbacks
,
82 const WebVector
<long long>& object_store_ids
,
83 unsigned short mode
) {
84 IndexedDBDispatcher
* dispatcher
=
85 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_
.get());
86 dispatcher
->RequestIDBDatabaseCreateTransaction(
87 ipc_database_id_
, transaction_id
, callbacks
, object_store_ids
, mode
);
90 void RendererWebIDBDatabaseImpl::close() {
91 IndexedDBDispatcher
* dispatcher
=
92 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_
.get());
93 dispatcher
->RequestIDBDatabaseClose(ipc_database_id_
,
94 ipc_database_callbacks_id_
);
97 void RendererWebIDBDatabaseImpl::get(
98 long long transaction_id
,
99 long long object_store_id
,
101 const WebIDBKeyRange
& key_range
,
103 WebIDBCallbacks
* callbacks
) {
104 IndexedDBDispatcher
* dispatcher
=
105 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_
.get());
106 dispatcher
->RequestIDBDatabaseGet(
111 IndexedDBKeyRangeBuilder::Build(key_range
),
116 void RendererWebIDBDatabaseImpl::put(
117 long long transaction_id
,
118 long long object_store_id
,
119 const WebKit::WebData
& value
,
120 const WebIDBKey
& key
,
122 WebIDBCallbacks
* callbacks
,
123 const WebVector
<long long>& web_index_ids
,
124 const WebVector
<WebIndexKeys
>& web_index_keys
) {
125 IndexedDBDispatcher
* dispatcher
=
126 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_
.get());
127 dispatcher
->RequestIDBDatabasePut(ipc_database_id_
,
131 IndexedDBKeyBuilder::Build(key
),
138 void RendererWebIDBDatabaseImpl::setIndexKeys(
139 long long transaction_id
,
140 long long object_store_id
,
141 const WebIDBKey
& primary_key
,
142 const WebVector
<long long>& index_ids
,
143 const WebVector
<WebIndexKeys
>& index_keys
) {
144 IndexedDBHostMsg_DatabaseSetIndexKeys_Params params
;
145 params
.ipc_database_id
= ipc_database_id_
;
146 params
.transaction_id
= transaction_id
;
147 params
.object_store_id
= object_store_id
;
148 params
.primary_key
= IndexedDBKeyBuilder::Build(primary_key
);
149 COMPILE_ASSERT(sizeof(params
.index_ids
[0]) ==
150 sizeof(index_ids
[0]), Cant_copy
);
151 params
.index_ids
.assign(index_ids
.data(),
152 index_ids
.data() + index_ids
.size());
154 params
.index_keys
.resize(index_keys
.size());
155 for (size_t i
= 0; i
< index_keys
.size(); ++i
) {
156 params
.index_keys
[i
].resize(index_keys
[i
].size());
157 for (size_t j
= 0; j
< index_keys
[i
].size(); ++j
) {
158 params
.index_keys
[i
][j
] = IndexedDBKeyBuilder::Build(index_keys
[i
][j
]);
161 thread_safe_sender_
->Send(new IndexedDBHostMsg_DatabaseSetIndexKeys(params
));
164 void RendererWebIDBDatabaseImpl::setIndexesReady(
165 long long transaction_id
,
166 long long object_store_id
,
167 const WebVector
<long long>& web_index_ids
) {
168 std::vector
<int64
> index_ids(web_index_ids
.data(),
169 web_index_ids
.data() + web_index_ids
.size());
170 thread_safe_sender_
->Send(new IndexedDBHostMsg_DatabaseSetIndexesReady(
171 ipc_database_id_
, transaction_id
, object_store_id
, index_ids
));
174 void RendererWebIDBDatabaseImpl::openCursor(
175 long long transaction_id
,
176 long long object_store_id
,
178 const WebIDBKeyRange
& key_range
,
179 unsigned short direction
,
182 WebIDBCallbacks
* callbacks
) {
183 IndexedDBDispatcher
* dispatcher
=
184 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_
.get());
185 dispatcher
->RequestIDBDatabaseOpenCursor(
190 IndexedDBKeyRangeBuilder::Build(key_range
),
197 void RendererWebIDBDatabaseImpl::count(
198 long long transaction_id
,
199 long long object_store_id
,
201 const WebIDBKeyRange
& key_range
,
202 WebIDBCallbacks
* callbacks
) {
203 IndexedDBDispatcher
* dispatcher
=
204 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_
.get());
205 dispatcher
->RequestIDBDatabaseCount(
210 IndexedDBKeyRangeBuilder::Build(key_range
),
214 void RendererWebIDBDatabaseImpl::deleteRange(
215 long long transaction_id
,
216 long long object_store_id
,
217 const WebIDBKeyRange
& key_range
,
218 WebIDBCallbacks
* callbacks
) {
219 IndexedDBDispatcher
* dispatcher
=
220 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_
.get());
221 dispatcher
->RequestIDBDatabaseDeleteRange(
225 IndexedDBKeyRangeBuilder::Build(key_range
),
229 void RendererWebIDBDatabaseImpl::clear(
230 long long transaction_id
,
231 long long object_store_id
,
232 WebIDBCallbacks
* callbacks
) {
233 IndexedDBDispatcher
* dispatcher
=
234 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_
.get());
235 dispatcher
->RequestIDBDatabaseClear(
236 ipc_database_id_
, transaction_id
, object_store_id
, callbacks
);
239 void RendererWebIDBDatabaseImpl::createIndex(
240 long long transaction_id
,
241 long long object_store_id
,
243 const WebString
& name
,
244 const WebIDBKeyPath
& key_path
,
248 IndexedDBHostMsg_DatabaseCreateIndex_Params params
;
249 params
.ipc_database_id
= ipc_database_id_
;
250 params
.transaction_id
= transaction_id
;
251 params
.object_store_id
= object_store_id
;
252 params
.index_id
= index_id
;
254 params
.key_path
= IndexedDBKeyPathBuilder::Build(key_path
);
255 params
.unique
= unique
;
256 params
.multi_entry
= multi_entry
;
258 thread_safe_sender_
->Send(new IndexedDBHostMsg_DatabaseCreateIndex(params
));
261 void RendererWebIDBDatabaseImpl::deleteIndex(
262 long long transaction_id
,
263 long long object_store_id
,
266 thread_safe_sender_
->Send(
267 new IndexedDBHostMsg_DatabaseDeleteIndex(
270 object_store_id
, index_id
));
273 void RendererWebIDBDatabaseImpl::abort(long long transaction_id
) {
274 thread_safe_sender_
->Send(new IndexedDBHostMsg_DatabaseAbort(
275 ipc_database_id_
, transaction_id
));
278 void RendererWebIDBDatabaseImpl::commit(long long transaction_id
) {
279 thread_safe_sender_
->Send(new IndexedDBHostMsg_DatabaseCommit(
280 ipc_database_id_
, transaction_id
));
283 } // namespace content