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