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/proxy_webidbdatabase_impl.h" | 5 #include "content/child/indexed_db/proxy_webidbdatabase_impl.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "content/child/thread_safe_sender.h" | 9 #include "content/child/thread_safe_sender.h" |
10 #include "content/child/indexed_db/indexed_db_dispatcher.h" | 10 #include "content/child/indexed_db/indexed_db_dispatcher.h" |
11 #include "content/common/indexed_db/indexed_db_messages.h" | 11 #include "content/common/indexed_db/indexed_db_messages.h" |
12 #include "third_party/WebKit/public/platform/WebIDBKeyPath.h" | 12 #include "third_party/WebKit/public/platform/WebIDBKeyPath.h" |
13 #include "third_party/WebKit/public/platform/WebIDBMetadata.h" | 13 #include "third_party/WebKit/public/platform/WebIDBMetadata.h" |
14 #include "third_party/WebKit/public/platform/WebString.h" | 14 #include "third_party/WebKit/public/platform/WebString.h" |
15 #include "third_party/WebKit/public/platform/WebVector.h" | 15 #include "third_party/WebKit/public/platform/WebVector.h" |
16 #include "webkit/child/worker_task_runner.h" | 16 #include "webkit/child/worker_task_runner.h" |
17 | 17 |
18 using WebKit::WebIDBCallbacks; | 18 using WebKit::WebIDBCallbacks; |
19 using WebKit::WebIDBDatabaseCallbacks; | 19 using WebKit::WebIDBDatabaseCallbacks; |
20 using WebKit::WebIDBMetadata; | 20 using WebKit::WebIDBMetadata; |
| 21 using WebKit::WebIDBKey; |
21 using WebKit::WebIDBKeyPath; | 22 using WebKit::WebIDBKeyPath; |
| 23 using WebKit::WebIDBKeyRange; |
22 using WebKit::WebString; | 24 using WebKit::WebString; |
23 using WebKit::WebVector; | 25 using WebKit::WebVector; |
24 using webkit_glue::WorkerTaskRunner; | 26 using webkit_glue::WorkerTaskRunner; |
25 | 27 |
26 namespace content { | 28 namespace content { |
27 | 29 |
28 RendererWebIDBDatabaseImpl::RendererWebIDBDatabaseImpl( | 30 RendererWebIDBDatabaseImpl::RendererWebIDBDatabaseImpl( |
29 int32 ipc_database_id, | 31 int32 ipc_database_id, |
30 int32 ipc_database_callbacks_id, | 32 int32 ipc_database_callbacks_id, |
31 ThreadSafeSender* thread_safe_sender) | 33 ThreadSafeSender* thread_safe_sender) |
32 : ipc_database_id_(ipc_database_id), | 34 : ipc_database_id_(ipc_database_id), |
33 ipc_database_callbacks_id_(ipc_database_callbacks_id), | 35 ipc_database_callbacks_id_(ipc_database_callbacks_id), |
34 thread_safe_sender_(thread_safe_sender) { | 36 thread_safe_sender_(thread_safe_sender) {} |
35 } | |
36 | 37 |
37 RendererWebIDBDatabaseImpl::~RendererWebIDBDatabaseImpl() { | 38 RendererWebIDBDatabaseImpl::~RendererWebIDBDatabaseImpl() { |
38 // It's not possible for there to be pending callbacks that address this | 39 // It's not possible for there to be pending callbacks that address this |
39 // object since inside WebKit, they hold a reference to the object which owns | 40 // object since inside WebKit, they hold a reference to the object which owns |
40 // this object. But, if that ever changed, then we'd need to invalidate | 41 // this object. But, if that ever changed, then we'd need to invalidate |
41 // any such pointers. | 42 // any such pointers. |
42 thread_safe_sender_->Send(new IndexedDBHostMsg_DatabaseDestroyed( | 43 thread_safe_sender_->Send(new IndexedDBHostMsg_DatabaseDestroyed( |
43 ipc_database_id_)); | 44 ipc_database_id_)); |
44 IndexedDBDispatcher* dispatcher = | 45 IndexedDBDispatcher* dispatcher = |
45 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get()); | 46 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get()); |
46 dispatcher->DatabaseDestroyed(ipc_database_id_); | 47 dispatcher->DatabaseDestroyed(ipc_database_id_); |
47 } | 48 } |
48 | 49 |
49 void RendererWebIDBDatabaseImpl::createObjectStore( | 50 void RendererWebIDBDatabaseImpl::createObjectStore( |
50 long long transaction_id, | 51 long long transaction_id, |
51 long long object_store_id, | 52 long long object_store_id, |
52 const WebKit::WebString& name, | 53 const WebString& name, |
53 const WebKit::WebIDBKeyPath& key_path, | 54 const WebIDBKeyPath& key_path, |
54 bool auto_increment) { | 55 bool auto_increment) { |
55 IndexedDBHostMsg_DatabaseCreateObjectStore_Params params; | 56 IndexedDBHostMsg_DatabaseCreateObjectStore_Params params; |
56 params.ipc_database_id = ipc_database_id_; | 57 params.ipc_database_id = ipc_database_id_; |
57 params.transaction_id = transaction_id; | 58 params.transaction_id = transaction_id; |
58 params.object_store_id = object_store_id; | 59 params.object_store_id = object_store_id; |
59 params.name = name; | 60 params.name = name; |
60 params.key_path = IndexedDBKeyPath(key_path); | 61 params.key_path = IndexedDBKeyPath(key_path); |
61 params.auto_increment = auto_increment; | 62 params.auto_increment = auto_increment; |
62 | 63 |
63 thread_safe_sender_->Send( | 64 thread_safe_sender_->Send( |
64 new IndexedDBHostMsg_DatabaseCreateObjectStore(params)); | 65 new IndexedDBHostMsg_DatabaseCreateObjectStore(params)); |
65 } | 66 } |
66 | 67 |
67 void RendererWebIDBDatabaseImpl::deleteObjectStore( | 68 void RendererWebIDBDatabaseImpl::deleteObjectStore( |
68 long long transaction_id, | 69 long long transaction_id, |
69 long long object_store_id) { | 70 long long object_store_id) { |
70 thread_safe_sender_->Send( | 71 thread_safe_sender_->Send( |
71 new IndexedDBHostMsg_DatabaseDeleteObjectStore( | 72 new IndexedDBHostMsg_DatabaseDeleteObjectStore( |
72 ipc_database_id_, | 73 ipc_database_id_, |
73 transaction_id, | 74 transaction_id, |
74 object_store_id)); | 75 object_store_id)); |
75 } | 76 } |
76 | 77 |
77 void RendererWebIDBDatabaseImpl::createTransaction( | 78 void RendererWebIDBDatabaseImpl::createTransaction( |
78 long long transaction_id, | 79 long long transaction_id, |
79 WebKit::WebIDBDatabaseCallbacks* callbacks, | 80 WebIDBDatabaseCallbacks* callbacks, |
80 const WebVector<long long>& object_store_ids, | 81 const WebVector<long long>& object_store_ids, |
81 unsigned short mode) | 82 unsigned short mode) { |
82 { | |
83 IndexedDBDispatcher* dispatcher = | 83 IndexedDBDispatcher* dispatcher = |
84 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get()); | 84 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get()); |
85 dispatcher->RequestIDBDatabaseCreateTransaction( | 85 dispatcher->RequestIDBDatabaseCreateTransaction( |
86 ipc_database_id_, transaction_id, callbacks, object_store_ids, mode); | 86 ipc_database_id_, transaction_id, callbacks, object_store_ids, mode); |
87 } | 87 } |
88 | 88 |
89 void RendererWebIDBDatabaseImpl::close() { | 89 void RendererWebIDBDatabaseImpl::close() { |
90 IndexedDBDispatcher* dispatcher = | 90 IndexedDBDispatcher* dispatcher = |
91 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get()); | 91 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get()); |
92 dispatcher->RequestIDBDatabaseClose(ipc_database_id_, | 92 dispatcher->RequestIDBDatabaseClose(ipc_database_id_, |
93 ipc_database_callbacks_id_); | 93 ipc_database_callbacks_id_); |
94 } | 94 } |
95 | 95 |
96 void RendererWebIDBDatabaseImpl::get( | 96 void RendererWebIDBDatabaseImpl::get( |
97 long long transaction_id, | 97 long long transaction_id, |
98 long long object_store_id, | 98 long long object_store_id, |
99 long long index_id, | 99 long long index_id, |
100 const WebKit::WebIDBKeyRange& key_range, | 100 const WebIDBKeyRange& key_range, |
101 bool key_only, | 101 bool key_only, |
102 WebIDBCallbacks* callbacks) { | 102 WebIDBCallbacks* callbacks) { |
103 IndexedDBDispatcher* dispatcher = | 103 IndexedDBDispatcher* dispatcher = |
104 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get()); | 104 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get()); |
105 dispatcher->RequestIDBDatabaseGet(ipc_database_id_, | 105 dispatcher->RequestIDBDatabaseGet(ipc_database_id_, |
106 transaction_id, | 106 transaction_id, |
107 object_store_id, | 107 object_store_id, |
108 index_id, | 108 index_id, |
109 IndexedDBKeyRange(key_range), | 109 IndexedDBKeyRange(key_range), |
110 key_only, | 110 key_only, |
111 callbacks); | 111 callbacks); |
112 } | 112 } |
113 | 113 |
114 void RendererWebIDBDatabaseImpl::put( | 114 void RendererWebIDBDatabaseImpl::put( |
115 long long transaction_id, | 115 long long transaction_id, |
116 long long object_store_id, | 116 long long object_store_id, |
117 const WebKit::WebData& value, | 117 const WebKit::WebData& value, |
118 const WebKit::WebIDBKey& key, | 118 const WebIDBKey& key, |
119 PutMode put_mode, | 119 PutMode put_mode, |
120 WebIDBCallbacks* callbacks, | 120 WebIDBCallbacks* callbacks, |
121 const WebVector<long long>& web_index_ids, | 121 const WebVector<long long>& web_index_ids, |
122 const WebVector<WebIndexKeys>& web_index_keys) { | 122 const WebVector<WebIndexKeys>& web_index_keys) { |
123 IndexedDBDispatcher* dispatcher = | 123 IndexedDBDispatcher* dispatcher = |
124 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get()); | 124 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get()); |
125 dispatcher->RequestIDBDatabasePut(ipc_database_id_, | 125 dispatcher->RequestIDBDatabasePut(ipc_database_id_, |
126 transaction_id, | 126 transaction_id, |
127 object_store_id, | 127 object_store_id, |
128 value, | 128 value, |
129 IndexedDBKey(key), | 129 IndexedDBKey(key), |
130 put_mode, | 130 put_mode, |
131 callbacks, | 131 callbacks, |
132 web_index_ids, | 132 web_index_ids, |
133 web_index_keys); | 133 web_index_keys); |
134 } | 134 } |
135 | 135 |
136 void RendererWebIDBDatabaseImpl::setIndexKeys( | 136 void RendererWebIDBDatabaseImpl::setIndexKeys( |
137 long long transaction_id, | 137 long long transaction_id, |
138 long long object_store_id, | 138 long long object_store_id, |
139 const WebKit::WebIDBKey& primary_key, | 139 const WebIDBKey& primary_key, |
140 const WebVector<long long>& index_ids, | 140 const WebVector<long long>& index_ids, |
141 const WebVector<WebIndexKeys>& index_keys) { | 141 const WebVector<WebIndexKeys>& index_keys) { |
142 IndexedDBHostMsg_DatabaseSetIndexKeys_Params params; | 142 IndexedDBHostMsg_DatabaseSetIndexKeys_Params params; |
143 params.ipc_database_id = ipc_database_id_; | 143 params.ipc_database_id = ipc_database_id_; |
144 params.transaction_id = transaction_id; | 144 params.transaction_id = transaction_id; |
145 params.object_store_id = object_store_id; | 145 params.object_store_id = object_store_id; |
146 params.primary_key = IndexedDBKey(primary_key); | 146 params.primary_key = IndexedDBKey(primary_key); |
147 COMPILE_ASSERT(sizeof(params.index_ids[0]) == | 147 COMPILE_ASSERT(sizeof(params.index_ids[0]) == |
148 sizeof(index_ids[0]), Cant_copy); | 148 sizeof(index_ids[0]), Cant_copy); |
149 params.index_ids.assign(index_ids.data(), | 149 params.index_ids.assign(index_ids.data(), |
150 index_ids.data() + index_ids.size()); | 150 index_ids.data() + index_ids.size()); |
151 | 151 |
152 params.index_keys.resize(index_keys.size()); | 152 params.index_keys.resize(index_keys.size()); |
153 for (size_t i = 0; i < index_keys.size(); ++i) { | 153 for (size_t i = 0; i < index_keys.size(); ++i) { |
154 params.index_keys[i].resize(index_keys[i].size()); | 154 params.index_keys[i].resize(index_keys[i].size()); |
155 for (size_t j = 0; j < index_keys[i].size(); ++j) { | 155 for (size_t j = 0; j < index_keys[i].size(); ++j) { |
156 params.index_keys[i][j] = content::IndexedDBKey(index_keys[i][j]); | 156 params.index_keys[i][j] = content::IndexedDBKey(index_keys[i][j]); |
157 } | 157 } |
158 } | 158 } |
159 thread_safe_sender_->Send(new IndexedDBHostMsg_DatabaseSetIndexKeys( | 159 thread_safe_sender_->Send(new IndexedDBHostMsg_DatabaseSetIndexKeys(params)); |
160 params)); | |
161 } | 160 } |
162 | 161 |
163 void RendererWebIDBDatabaseImpl::setIndexesReady( | 162 void RendererWebIDBDatabaseImpl::setIndexesReady( |
164 long long transaction_id, | 163 long long transaction_id, |
165 long long object_store_id, | 164 long long object_store_id, |
166 const WebVector<long long>& web_index_ids) { | 165 const WebVector<long long>& web_index_ids) { |
167 std::vector<int64> index_ids(web_index_ids.data(), | 166 std::vector<int64> index_ids(web_index_ids.data(), |
168 web_index_ids.data() + web_index_ids.size()); | 167 web_index_ids.data() + web_index_ids.size()); |
169 thread_safe_sender_->Send(new IndexedDBHostMsg_DatabaseSetIndexesReady( | 168 thread_safe_sender_->Send(new IndexedDBHostMsg_DatabaseSetIndexesReady( |
170 ipc_database_id_, transaction_id, object_store_id, index_ids)); | 169 ipc_database_id_, transaction_id, object_store_id, index_ids)); |
171 } | 170 } |
172 | 171 |
173 void RendererWebIDBDatabaseImpl::openCursor( | 172 void RendererWebIDBDatabaseImpl::openCursor( |
174 long long transaction_id, | 173 long long transaction_id, |
175 long long object_store_id, | 174 long long object_store_id, |
176 long long index_id, | 175 long long index_id, |
177 const WebKit::WebIDBKeyRange& key_range, | 176 const WebIDBKeyRange& key_range, |
178 unsigned short direction, | 177 unsigned short direction, |
179 bool key_only, | 178 bool key_only, |
180 TaskType task_type, | 179 TaskType task_type, |
181 WebIDBCallbacks* callbacks) { | 180 WebIDBCallbacks* callbacks) { |
182 IndexedDBDispatcher* dispatcher = | 181 IndexedDBDispatcher* dispatcher = |
183 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get()); | 182 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get()); |
184 dispatcher->RequestIDBDatabaseOpenCursor(ipc_database_id_, | 183 dispatcher->RequestIDBDatabaseOpenCursor(ipc_database_id_, |
185 transaction_id, | 184 transaction_id, |
186 object_store_id, | 185 object_store_id, |
187 index_id, | 186 index_id, |
188 IndexedDBKeyRange(key_range), | 187 IndexedDBKeyRange(key_range), |
189 direction, | 188 direction, |
190 key_only, | 189 key_only, |
191 task_type, | 190 task_type, |
192 callbacks); | 191 callbacks); |
193 } | 192 } |
194 | 193 |
195 void RendererWebIDBDatabaseImpl::count( | 194 void RendererWebIDBDatabaseImpl::count( |
196 long long transaction_id, | 195 long long transaction_id, |
197 long long object_store_id, | 196 long long object_store_id, |
198 long long index_id, | 197 long long index_id, |
199 const WebKit::WebIDBKeyRange& key_range, | 198 const WebIDBKeyRange& key_range, |
200 WebIDBCallbacks* callbacks) { | 199 WebIDBCallbacks* callbacks) { |
201 IndexedDBDispatcher* dispatcher = | 200 IndexedDBDispatcher* dispatcher = |
202 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get()); | 201 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get()); |
203 dispatcher->RequestIDBDatabaseCount(ipc_database_id_, | 202 dispatcher->RequestIDBDatabaseCount(ipc_database_id_, |
204 transaction_id, | 203 transaction_id, |
205 object_store_id, | 204 object_store_id, |
206 index_id, | 205 index_id, |
207 IndexedDBKeyRange(key_range), | 206 IndexedDBKeyRange(key_range), |
208 callbacks); | 207 callbacks); |
209 } | 208 } |
210 | 209 |
211 void RendererWebIDBDatabaseImpl::deleteRange( | 210 void RendererWebIDBDatabaseImpl::deleteRange( |
212 long long transaction_id, | 211 long long transaction_id, |
213 long long object_store_id, | 212 long long object_store_id, |
214 const WebKit::WebIDBKeyRange& key_range, | 213 const WebIDBKeyRange& key_range, |
215 WebIDBCallbacks* callbacks) { | 214 WebIDBCallbacks* callbacks) { |
216 IndexedDBDispatcher* dispatcher = | 215 IndexedDBDispatcher* dispatcher = |
217 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get()); | 216 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get()); |
218 dispatcher->RequestIDBDatabaseDeleteRange(ipc_database_id_, | 217 dispatcher->RequestIDBDatabaseDeleteRange(ipc_database_id_, |
219 transaction_id, | 218 transaction_id, |
220 object_store_id, | 219 object_store_id, |
221 IndexedDBKeyRange(key_range), | 220 IndexedDBKeyRange(key_range), |
222 callbacks); | 221 callbacks); |
223 } | 222 } |
224 | 223 |
(...skipping 19 matching lines...) Expand all Loading... |
244 IndexedDBHostMsg_DatabaseCreateIndex_Params params; | 243 IndexedDBHostMsg_DatabaseCreateIndex_Params params; |
245 params.ipc_database_id = ipc_database_id_; | 244 params.ipc_database_id = ipc_database_id_; |
246 params.transaction_id = transaction_id; | 245 params.transaction_id = transaction_id; |
247 params.object_store_id = object_store_id; | 246 params.object_store_id = object_store_id; |
248 params.index_id = index_id; | 247 params.index_id = index_id; |
249 params.name = name; | 248 params.name = name; |
250 params.key_path = IndexedDBKeyPath(key_path); | 249 params.key_path = IndexedDBKeyPath(key_path); |
251 params.unique = unique; | 250 params.unique = unique; |
252 params.multi_entry = multi_entry; | 251 params.multi_entry = multi_entry; |
253 | 252 |
254 thread_safe_sender_->Send( | 253 thread_safe_sender_->Send(new IndexedDBHostMsg_DatabaseCreateIndex(params)); |
255 new IndexedDBHostMsg_DatabaseCreateIndex(params)); | |
256 } | 254 } |
257 | 255 |
258 void RendererWebIDBDatabaseImpl::deleteIndex( | 256 void RendererWebIDBDatabaseImpl::deleteIndex( |
259 long long transaction_id, | 257 long long transaction_id, |
260 long long object_store_id, | 258 long long object_store_id, |
261 long long index_id) | 259 long long index_id) |
262 { | 260 { |
263 thread_safe_sender_->Send( | 261 thread_safe_sender_->Send( |
264 new IndexedDBHostMsg_DatabaseDeleteIndex( | 262 new IndexedDBHostMsg_DatabaseDeleteIndex( |
265 ipc_database_id_, | 263 ipc_database_id_, |
266 transaction_id, | 264 transaction_id, |
267 object_store_id, index_id)); | 265 object_store_id, index_id)); |
268 } | 266 } |
269 | 267 |
270 void RendererWebIDBDatabaseImpl::abort(long long transaction_id) { | 268 void RendererWebIDBDatabaseImpl::abort(long long transaction_id) { |
271 thread_safe_sender_->Send(new IndexedDBHostMsg_DatabaseAbort( | 269 thread_safe_sender_->Send(new IndexedDBHostMsg_DatabaseAbort( |
272 ipc_database_id_, transaction_id)); | 270 ipc_database_id_, transaction_id)); |
273 } | 271 } |
274 | 272 |
275 void RendererWebIDBDatabaseImpl::commit(long long transaction_id) { | 273 void RendererWebIDBDatabaseImpl::commit(long long transaction_id) { |
276 thread_safe_sender_->Send(new IndexedDBHostMsg_DatabaseCommit( | 274 thread_safe_sender_->Send(new IndexedDBHostMsg_DatabaseCommit( |
277 ipc_database_id_, transaction_id)); | 275 ipc_database_id_, transaction_id)); |
278 } | 276 } |
279 | 277 |
280 } // namespace content | 278 } // namespace content |
OLD | NEW |