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

Side by Side Diff: content/renderer/indexed_db/indexed_db_dispatcher.cc

Issue 9368053: Move indexed db files from content/renderer to content/common. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove unneccesary include Created 8 years, 10 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 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/renderer/indexed_db/indexed_db_dispatcher.h"
6
7 #include "base/lazy_instance.h"
8 #include "base/threading/thread_local.h"
9 #include "content/common/indexed_db/indexed_db_messages.h"
10 #include "content/renderer/indexed_db/renderer_webidbcursor_impl.h"
11 #include "content/renderer/indexed_db/renderer_webidbdatabase_impl.h"
12 #include "content/renderer/indexed_db/renderer_webidbindex_impl.h"
13 #include "content/renderer/indexed_db/renderer_webidbobjectstore_impl.h"
14 #include "content/renderer/indexed_db/renderer_webidbtransaction_impl.h"
15 #include "content/renderer/render_thread_impl.h"
16 #include "content/renderer/render_view_impl.h"
17 #include "ipc/ipc_channel.h"
18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBDatabaseCallbac ks.h"
20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBDatabaseError.h "
21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBKeyRange.h"
22
23 using base::ThreadLocalPointer;
24 using WebKit::WebDOMStringList;
25 using WebKit::WebExceptionCode;
26 using WebKit::WebFrame;
27 using WebKit::WebIDBCallbacks;
28 using WebKit::WebIDBKeyRange;
29 using WebKit::WebIDBDatabase;
30 using WebKit::WebIDBDatabaseCallbacks;
31 using WebKit::WebIDBDatabaseError;
32 using WebKit::WebIDBTransaction;
33 using WebKit::WebIDBTransactionCallbacks;
34 using webkit_glue::WorkerTaskRunner;
35
36 static base::LazyInstance<ThreadLocalPointer<IndexedDBDispatcher> >::Leaky
37 g_idb_dispatcher_tls = LAZY_INSTANCE_INITIALIZER;
38
39 namespace {
40
41 int32 CurrentWorkerId() {
42 return WorkerTaskRunner::Instance()->CurrentWorkerId();
43 }
44
45 } // unnamed namespace
46
47 IndexedDBDispatcher::IndexedDBDispatcher() {
48 g_idb_dispatcher_tls.Pointer()->Set(this);
49 }
50
51 IndexedDBDispatcher::~IndexedDBDispatcher() {
52 g_idb_dispatcher_tls.Pointer()->Set(NULL);
53 }
54
55 IndexedDBDispatcher* IndexedDBDispatcher::ThreadSpecificInstance() {
56 if (g_idb_dispatcher_tls.Pointer()->Get())
57 return g_idb_dispatcher_tls.Pointer()->Get();
58
59 IndexedDBDispatcher* dispatcher = new IndexedDBDispatcher;
60 if (WorkerTaskRunner::Instance()->CurrentWorkerId())
61 webkit_glue::WorkerTaskRunner::Instance()->AddStopObserver(dispatcher);
62 return dispatcher;
63 }
64
65 void IndexedDBDispatcher::OnWorkerRunLoopStopped() {
66 delete this;
67 }
68
69 void IndexedDBDispatcher::OnMessageReceived(const IPC::Message& msg) {
70 bool handled = true;
71 IPC_BEGIN_MESSAGE_MAP(IndexedDBDispatcher, msg)
72 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessIDBCursor,
73 OnSuccessOpenCursor)
74 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessCursorContinue,
75 OnSuccessCursorContinue)
76 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessCursorPrefetch,
77 OnSuccessCursorPrefetch)
78 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessIDBDatabase,
79 OnSuccessIDBDatabase)
80 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessIndexedDBKey,
81 OnSuccessIndexedDBKey)
82 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessIDBTransaction,
83 OnSuccessIDBTransaction)
84 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessStringList,
85 OnSuccessStringList)
86 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessSerializedScriptValue,
87 OnSuccessSerializedScriptValue)
88 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksError, OnError)
89 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksBlocked, OnBlocked)
90 IPC_MESSAGE_HANDLER(IndexedDBMsg_TransactionCallbacksAbort, OnAbort)
91 IPC_MESSAGE_HANDLER(IndexedDBMsg_TransactionCallbacksComplete, OnComplete)
92 IPC_MESSAGE_HANDLER(IndexedDBMsg_DatabaseCallbacksVersionChange,
93 OnVersionChange)
94 IPC_MESSAGE_UNHANDLED(handled = false)
95 IPC_END_MESSAGE_MAP()
96 // If a message gets here, IndexedDBMessageFilter already determined that it
97 // is an IndexedDB message.
98 DCHECK(handled);
99 }
100
101 void IndexedDBDispatcher::Send(IPC::Message* msg) {
102 ChildThread::current()->Send(msg);
103 }
104
105 void IndexedDBDispatcher::RequestIDBCursorUpdate(
106 const content::SerializedScriptValue& value,
107 WebIDBCallbacks* callbacks_ptr,
108 int32 idb_cursor_id,
109 WebExceptionCode* ec) {
110 ResetCursorPrefetchCaches();
111 scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr);
112
113 int32 response_id = pending_callbacks_.Add(callbacks.release());
114 Send(
115 new IndexedDBHostMsg_CursorUpdate(idb_cursor_id, CurrentWorkerId(),
116 response_id, value, ec));
117 if (*ec)
118 pending_callbacks_.Remove(response_id);
119 }
120
121 void IndexedDBDispatcher::RequestIDBCursorContinue(
122 const IndexedDBKey& key,
123 WebIDBCallbacks* callbacks_ptr,
124 int32 idb_cursor_id,
125 WebExceptionCode* ec) {
126 // Reset all cursor prefetch caches except for this cursor.
127 ResetCursorPrefetchCaches(idb_cursor_id);
128
129 scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr);
130
131 int32 response_id = pending_callbacks_.Add(callbacks.release());
132 Send(
133 new IndexedDBHostMsg_CursorContinue(idb_cursor_id, CurrentWorkerId(),
134 response_id, key, ec));
135 if (*ec)
136 pending_callbacks_.Remove(response_id);
137 }
138
139 void IndexedDBDispatcher::RequestIDBCursorPrefetch(
140 int n,
141 WebIDBCallbacks* callbacks_ptr,
142 int32 idb_cursor_id,
143 WebExceptionCode* ec) {
144 scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr);
145
146 int32 response_id = pending_callbacks_.Add(callbacks.release());
147 Send(new IndexedDBHostMsg_CursorPrefetch(idb_cursor_id, CurrentWorkerId(),
148 response_id, n, ec));
149 if (*ec)
150 pending_callbacks_.Remove(response_id);
151 }
152
153 void IndexedDBDispatcher::RequestIDBCursorPrefetchReset(
154 int used_prefetches, int unused_prefetches, int32 idb_cursor_id) {
155 Send(new IndexedDBHostMsg_CursorPrefetchReset(idb_cursor_id,
156 used_prefetches,
157 unused_prefetches));
158 }
159
160 void IndexedDBDispatcher::RequestIDBCursorDelete(
161 WebIDBCallbacks* callbacks_ptr,
162 int32 idb_cursor_id,
163 WebExceptionCode* ec) {
164 ResetCursorPrefetchCaches();
165 scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr);
166
167 int32 response_id = pending_callbacks_.Add(callbacks.release());
168 Send(new IndexedDBHostMsg_CursorDelete(idb_cursor_id, CurrentWorkerId(),
169 response_id, ec));
170 if (*ec)
171 pending_callbacks_.Remove(response_id);
172 }
173
174 void IndexedDBDispatcher::RequestIDBFactoryOpen(
175 const string16& name,
176 WebIDBCallbacks* callbacks_ptr,
177 const string16& origin,
178 WebFrame* web_frame) {
179 ResetCursorPrefetchCaches();
180 scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr);
181
182 if (!web_frame)
183 return; // We must be shutting down.
184 RenderViewImpl* render_view = RenderViewImpl::FromWebView(web_frame->view());
185 if (!render_view)
186 return; // We must be shutting down.
187
188 IndexedDBHostMsg_FactoryOpen_Params params;
189 params.thread_id = CurrentWorkerId();
190 params.response_id = pending_callbacks_.Add(callbacks.release());
191 params.origin = origin;
192 params.name = name;
193 Send(new IndexedDBHostMsg_FactoryOpen(params));
194 }
195
196 void IndexedDBDispatcher::RequestIDBFactoryGetDatabaseNames(
197 WebIDBCallbacks* callbacks_ptr,
198 const string16& origin,
199 WebFrame* web_frame) {
200 ResetCursorPrefetchCaches();
201 scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr);
202
203 if (!web_frame)
204 return; // We must be shutting down.
205 RenderViewImpl* render_view = RenderViewImpl::FromWebView(web_frame->view());
206 if (!render_view)
207 return; // We must be shutting down.
208
209 IndexedDBHostMsg_FactoryGetDatabaseNames_Params params;
210 params.thread_id = CurrentWorkerId();
211 params.response_id = pending_callbacks_.Add(callbacks.release());
212 params.origin = origin;
213 Send(new IndexedDBHostMsg_FactoryGetDatabaseNames(params));
214 }
215
216 void IndexedDBDispatcher::RequestIDBFactoryDeleteDatabase(
217 const string16& name,
218 WebIDBCallbacks* callbacks_ptr,
219 const string16& origin,
220 WebFrame* web_frame) {
221 ResetCursorPrefetchCaches();
222 scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr);
223
224 if (!web_frame)
225 return; // We must be shutting down.
226 RenderViewImpl* render_view = RenderViewImpl::FromWebView(web_frame->view());
227 if (!render_view)
228 return; // We must be shutting down.
229
230 IndexedDBHostMsg_FactoryDeleteDatabase_Params params;
231 params.thread_id = CurrentWorkerId();
232 params.response_id = pending_callbacks_.Add(callbacks.release());
233 params.origin = origin;
234 params.name = name;
235 Send(new IndexedDBHostMsg_FactoryDeleteDatabase(params));
236 }
237
238 void IndexedDBDispatcher::RequestIDBDatabaseClose(int32 idb_database_id) {
239 ResetCursorPrefetchCaches();
240 Send(new IndexedDBHostMsg_DatabaseClose(idb_database_id));
241 pending_database_callbacks_.Remove(idb_database_id);
242 }
243
244 void IndexedDBDispatcher::RequestIDBDatabaseOpen(
245 WebIDBDatabaseCallbacks* callbacks_ptr,
246 int32 idb_database_id) {
247 ResetCursorPrefetchCaches();
248 scoped_ptr<WebIDBDatabaseCallbacks> callbacks(callbacks_ptr);
249
250 DCHECK(!pending_database_callbacks_.Lookup(idb_database_id));
251 pending_database_callbacks_.AddWithID(callbacks.release(), idb_database_id);
252 Send(new IndexedDBHostMsg_DatabaseOpen(idb_database_id, CurrentWorkerId(),
253 idb_database_id));
254 }
255
256 void IndexedDBDispatcher::RequestIDBDatabaseSetVersion(
257 const string16& version,
258 WebIDBCallbacks* callbacks_ptr,
259 int32 idb_database_id,
260 WebExceptionCode* ec) {
261 ResetCursorPrefetchCaches();
262 scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr);
263
264 int32 response_id = pending_callbacks_.Add(callbacks.release());
265 Send(new IndexedDBHostMsg_DatabaseSetVersion(idb_database_id,
266 CurrentWorkerId(),
267 response_id, version, ec));
268 if (*ec)
269 pending_callbacks_.Remove(response_id);
270 }
271
272 void IndexedDBDispatcher::RequestIDBIndexOpenObjectCursor(
273 const WebIDBKeyRange& idb_key_range,
274 unsigned short direction,
275 WebIDBCallbacks* callbacks_ptr,
276 int32 idb_index_id,
277 const WebIDBTransaction& transaction,
278 WebExceptionCode* ec) {
279 ResetCursorPrefetchCaches();
280 scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr);
281 IndexedDBHostMsg_IndexOpenCursor_Params params;
282 params.thread_id = CurrentWorkerId();
283 params.response_id = pending_callbacks_.Add(callbacks.release());
284 params.lower_key.Set(idb_key_range.lower());
285 params.upper_key.Set(idb_key_range.upper());
286 params.lower_open = idb_key_range.lowerOpen();
287 params.upper_open = idb_key_range.upperOpen();
288 params.direction = direction;
289 params.idb_index_id = idb_index_id;
290 params.transaction_id = TransactionId(transaction);
291 Send(new IndexedDBHostMsg_IndexOpenObjectCursor(params, ec));
292 if (*ec)
293 pending_callbacks_.Remove(params.response_id);
294 }
295
296 void IndexedDBDispatcher::RequestIDBIndexOpenKeyCursor(
297 const WebIDBKeyRange& idb_key_range,
298 unsigned short direction,
299 WebIDBCallbacks* callbacks_ptr,
300 int32 idb_index_id,
301 const WebIDBTransaction& transaction,
302 WebExceptionCode* ec) {
303 ResetCursorPrefetchCaches();
304 scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr);
305 IndexedDBHostMsg_IndexOpenCursor_Params params;
306 params.thread_id = CurrentWorkerId();
307 params.response_id = pending_callbacks_.Add(callbacks.release());
308 // TODO(jorlow): We really should just create a Chromium abstraction for
309 // KeyRange rather than doing it ad-hoc like this.
310 params.lower_key.Set(idb_key_range.lower());
311 params.upper_key.Set(idb_key_range.upper());
312 params.lower_open = idb_key_range.lowerOpen();
313 params.upper_open = idb_key_range.upperOpen();
314 params.direction = direction;
315 params.idb_index_id = idb_index_id;
316 params.transaction_id = TransactionId(transaction);
317 Send(new IndexedDBHostMsg_IndexOpenKeyCursor(params, ec));
318 if (*ec)
319 pending_callbacks_.Remove(params.response_id);
320 }
321
322 void IndexedDBDispatcher::RequestIDBIndexCount(
323 const WebIDBKeyRange& idb_key_range,
324 WebIDBCallbacks* callbacks_ptr,
325 int32 idb_index_id,
326 const WebIDBTransaction& transaction,
327 WebExceptionCode* ec) {
328 ResetCursorPrefetchCaches();
329 scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr);
330 IndexedDBHostMsg_IndexCount_Params params;
331 params.thread_id = CurrentWorkerId();
332 params.response_id = pending_callbacks_.Add(callbacks.release());
333 params.lower_key.Set(idb_key_range.lower());
334 params.upper_key.Set(idb_key_range.upper());
335 params.lower_open = idb_key_range.lowerOpen();
336 params.upper_open = idb_key_range.upperOpen();
337 params.idb_index_id = idb_index_id;
338 params.transaction_id = TransactionId(transaction);
339 Send(new IndexedDBHostMsg_IndexCount(params, ec));
340 if (*ec)
341 pending_callbacks_.Remove(params.response_id);
342 }
343
344 void IndexedDBDispatcher::RequestIDBIndexGetObject(
345 const IndexedDBKey& key,
346 WebIDBCallbacks* callbacks_ptr,
347 int32 idb_index_id,
348 const WebIDBTransaction& transaction,
349 WebExceptionCode* ec) {
350 ResetCursorPrefetchCaches();
351 scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr);
352 int32 response_id = pending_callbacks_.Add(callbacks.release());
353 Send(new IndexedDBHostMsg_IndexGetObject(idb_index_id, CurrentWorkerId(),
354 response_id, key,
355 TransactionId(transaction), ec));
356 if (*ec)
357 pending_callbacks_.Remove(response_id);
358 }
359
360 void IndexedDBDispatcher::RequestIDBIndexGetKey(
361 const IndexedDBKey& key,
362 WebIDBCallbacks* callbacks_ptr,
363 int32 idb_index_id,
364 const WebIDBTransaction& transaction,
365 WebExceptionCode* ec) {
366 ResetCursorPrefetchCaches();
367 scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr);
368 int32 response_id = pending_callbacks_.Add(callbacks.release());
369 Send(new IndexedDBHostMsg_IndexGetKey(
370 idb_index_id, CurrentWorkerId(), response_id, key,
371 TransactionId(transaction), ec));
372 if (*ec)
373 pending_callbacks_.Remove(response_id);
374 }
375
376 void IndexedDBDispatcher::RequestIDBObjectStoreGet(
377 const IndexedDBKey& key,
378 WebIDBCallbacks* callbacks_ptr,
379 int32 idb_object_store_id,
380 const WebIDBTransaction& transaction,
381 WebExceptionCode* ec) {
382 ResetCursorPrefetchCaches();
383 scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr);
384
385 int32 response_id = pending_callbacks_.Add(callbacks.release());
386 Send(new IndexedDBHostMsg_ObjectStoreGet(
387 idb_object_store_id, CurrentWorkerId(), response_id,
388 key, TransactionId(transaction), ec));
389 if (*ec)
390 pending_callbacks_.Remove(response_id);
391 }
392
393 void IndexedDBDispatcher::RequestIDBObjectStorePut(
394 const content::SerializedScriptValue& value,
395 const IndexedDBKey& key,
396 WebKit::WebIDBObjectStore::PutMode put_mode,
397 WebIDBCallbacks* callbacks_ptr,
398 int32 idb_object_store_id,
399 const WebIDBTransaction& transaction,
400 WebExceptionCode* ec) {
401 ResetCursorPrefetchCaches();
402 scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr);
403 IndexedDBHostMsg_ObjectStorePut_Params params;
404 params.thread_id = CurrentWorkerId();
405 params.idb_object_store_id = idb_object_store_id;
406 params.response_id = pending_callbacks_.Add(callbacks.release());
407 params.serialized_value = value;
408 params.key = key;
409 params.put_mode = put_mode;
410 params.transaction_id = TransactionId(transaction);
411 Send(new IndexedDBHostMsg_ObjectStorePut(params, ec));
412 if (*ec)
413 pending_callbacks_.Remove(params.response_id);
414 }
415
416 void IndexedDBDispatcher::RequestIDBObjectStoreDelete(
417 const IndexedDBKey& key,
418 WebIDBCallbacks* callbacks_ptr,
419 int32 idb_object_store_id,
420 const WebIDBTransaction& transaction,
421 WebExceptionCode* ec) {
422 ResetCursorPrefetchCaches();
423 scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr);
424
425 int32 response_id = pending_callbacks_.Add(callbacks.release());
426 Send(new IndexedDBHostMsg_ObjectStoreDelete(
427 idb_object_store_id, CurrentWorkerId(), response_id, key,
428 TransactionId(transaction), ec));
429 if (*ec)
430 pending_callbacks_.Remove(response_id);
431 }
432
433 void IndexedDBDispatcher::RequestIDBObjectStoreClear(
434 WebIDBCallbacks* callbacks_ptr,
435 int32 idb_object_store_id,
436 const WebIDBTransaction& transaction,
437 WebExceptionCode* ec) {
438 ResetCursorPrefetchCaches();
439 scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr);
440
441 int32 response_id = pending_callbacks_.Add(callbacks.release());
442 Send(new IndexedDBHostMsg_ObjectStoreClear(
443 idb_object_store_id, CurrentWorkerId(), response_id,
444 TransactionId(transaction), ec));
445 if (*ec)
446 pending_callbacks_.Remove(response_id);
447 }
448
449 void IndexedDBDispatcher::RequestIDBObjectStoreOpenCursor(
450 const WebIDBKeyRange& idb_key_range,
451 unsigned short direction,
452 WebIDBCallbacks* callbacks_ptr,
453 int32 idb_object_store_id,
454 const WebIDBTransaction& transaction,
455 WebExceptionCode* ec) {
456 ResetCursorPrefetchCaches();
457 scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr);
458 IndexedDBHostMsg_ObjectStoreOpenCursor_Params params;
459 params.thread_id = CurrentWorkerId();
460 params.response_id = pending_callbacks_.Add(callbacks.release());
461 params.lower_key.Set(idb_key_range.lower());
462 params.upper_key.Set(idb_key_range.upper());
463 params.lower_open = idb_key_range.lowerOpen();
464 params.upper_open = idb_key_range.upperOpen();
465 params.direction = direction;
466 params.idb_object_store_id = idb_object_store_id;
467 params.transaction_id = TransactionId(transaction);
468 Send(new IndexedDBHostMsg_ObjectStoreOpenCursor(params, ec));
469 if (*ec)
470 pending_callbacks_.Remove(params.response_id);
471 }
472
473 void IndexedDBDispatcher::RequestIDBObjectStoreCount(
474 const WebIDBKeyRange& idb_key_range,
475 WebIDBCallbacks* callbacks_ptr,
476 int32 idb_object_store_id,
477 const WebIDBTransaction& transaction,
478 WebExceptionCode* ec) {
479 ResetCursorPrefetchCaches();
480 scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr);
481 IndexedDBHostMsg_ObjectStoreCount_Params params;
482 params.thread_id = CurrentWorkerId();
483 params.response_id = pending_callbacks_.Add(callbacks.release());
484 params.lower_key.Set(idb_key_range.lower());
485 params.upper_key.Set(idb_key_range.upper());
486 params.lower_open = idb_key_range.lowerOpen();
487 params.upper_open = idb_key_range.upperOpen();
488 params.idb_object_store_id = idb_object_store_id;
489 params.transaction_id = TransactionId(transaction);
490 Send(new IndexedDBHostMsg_ObjectStoreCount(params, ec));
491 if (*ec)
492 pending_callbacks_.Remove(params.response_id);
493 }
494
495 void IndexedDBDispatcher::RegisterWebIDBTransactionCallbacks(
496 WebIDBTransactionCallbacks* callbacks,
497 int32 id) {
498 pending_transaction_callbacks_.AddWithID(callbacks, id);
499 }
500
501 void IndexedDBDispatcher::CursorDestroyed(int32 cursor_id) {
502 cursors_.erase(cursor_id);
503 }
504
505 int32 IndexedDBDispatcher::TransactionId(
506 const WebIDBTransaction& transaction) {
507 const RendererWebIDBTransactionImpl* impl =
508 static_cast<const RendererWebIDBTransactionImpl*>(&transaction);
509 return impl->id();
510 }
511
512 void IndexedDBDispatcher::OnSuccessIDBDatabase(int32 thread_id,
513 int32 response_id,
514 int32 object_id) {
515 DCHECK_EQ(thread_id, CurrentWorkerId());
516 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(response_id);
517 if (!callbacks)
518 return;
519 callbacks->onSuccess(new RendererWebIDBDatabaseImpl(object_id));
520 pending_callbacks_.Remove(response_id);
521 }
522
523 void IndexedDBDispatcher::OnSuccessIndexedDBKey(int32 thread_id,
524 int32 response_id,
525 const IndexedDBKey& key) {
526 DCHECK_EQ(thread_id, CurrentWorkerId());
527 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(response_id);
528 if (!callbacks)
529 return;
530 callbacks->onSuccess(key);
531 pending_callbacks_.Remove(response_id);
532 }
533
534 void IndexedDBDispatcher::OnSuccessIDBTransaction(int32 thread_id,
535 int32 response_id,
536 int32 object_id) {
537 DCHECK_EQ(thread_id, CurrentWorkerId());
538 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(response_id);
539 if (!callbacks)
540 return;
541 callbacks->onSuccess(new RendererWebIDBTransactionImpl(object_id));
542 pending_callbacks_.Remove(response_id);
543 }
544
545 void IndexedDBDispatcher::OnSuccessStringList(
546 int32 thread_id, int32 response_id, const std::vector<string16>& value) {
547 DCHECK_EQ(thread_id, CurrentWorkerId());
548 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(response_id);
549 if (!callbacks)
550 return;
551 WebDOMStringList string_list;
552 for (std::vector<string16>::const_iterator it = value.begin();
553 it != value.end(); ++it)
554 string_list.append(*it);
555 callbacks->onSuccess(string_list);
556 pending_callbacks_.Remove(response_id);
557 }
558
559 void IndexedDBDispatcher::OnSuccessSerializedScriptValue(
560 int32 thread_id, int32 response_id,
561 const content::SerializedScriptValue& value) {
562 DCHECK_EQ(thread_id, CurrentWorkerId());
563 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(response_id);
564 if (!callbacks)
565 return;
566 callbacks->onSuccess(value);
567 pending_callbacks_.Remove(response_id);
568 }
569
570 void IndexedDBDispatcher::OnSuccessOpenCursor(
571 const IndexedDBMsg_CallbacksSuccessIDBCursor_Params& p) {
572 DCHECK_EQ(p.thread_id, CurrentWorkerId());
573 int32 response_id = p.response_id;
574 int32 object_id = p.cursor_id;
575 const IndexedDBKey& key = p.key;
576 const IndexedDBKey& primary_key = p.primary_key;
577 const content::SerializedScriptValue& value = p.serialized_value;
578
579 WebIDBCallbacks* callbacks =
580 pending_callbacks_.Lookup(response_id);
581 if (!callbacks)
582 return;
583
584 RendererWebIDBCursorImpl* cursor = new RendererWebIDBCursorImpl(object_id);
585 cursors_[object_id] = cursor;
586 cursor->SetKeyAndValue(key, primary_key, value);
587 callbacks->onSuccess(cursor);
588
589 pending_callbacks_.Remove(response_id);
590 }
591
592 void IndexedDBDispatcher::OnSuccessCursorContinue(
593 const IndexedDBMsg_CallbacksSuccessCursorContinue_Params& p) {
594 DCHECK_EQ(p.thread_id, CurrentWorkerId());
595 int32 response_id = p.response_id;
596 int32 cursor_id = p.cursor_id;
597 const IndexedDBKey& key = p.key;
598 const IndexedDBKey& primary_key = p.primary_key;
599 const content::SerializedScriptValue& value = p.serialized_value;
600
601 RendererWebIDBCursorImpl* cursor = cursors_[cursor_id];
602 DCHECK(cursor);
603 cursor->SetKeyAndValue(key, primary_key, value);
604
605 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(response_id);
606 if (!callbacks)
607 return;
608 callbacks->onSuccessWithContinuation();
609
610 pending_callbacks_.Remove(response_id);
611 }
612
613 void IndexedDBDispatcher::OnSuccessCursorPrefetch(
614 const IndexedDBMsg_CallbacksSuccessCursorPrefetch_Params& p) {
615 DCHECK_EQ(p.thread_id, CurrentWorkerId());
616 int32 response_id = p.response_id;
617 int32 cursor_id = p.cursor_id;
618 const std::vector<IndexedDBKey>& keys = p.keys;
619 const std::vector<IndexedDBKey>& primary_keys = p.primary_keys;
620 const std::vector<content::SerializedScriptValue>& values = p.values;
621 RendererWebIDBCursorImpl* cursor = cursors_[cursor_id];
622 DCHECK(cursor);
623 cursor->SetPrefetchData(keys, primary_keys, values);
624
625 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(response_id);
626 DCHECK(callbacks);
627 cursor->CachedContinue(callbacks);
628 pending_callbacks_.Remove(response_id);
629 }
630
631 void IndexedDBDispatcher::OnBlocked(int32 thread_id, int32 response_id) {
632 DCHECK_EQ(thread_id, CurrentWorkerId());
633 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(response_id);
634 DCHECK(callbacks);
635 callbacks->onBlocked();
636 }
637
638 void IndexedDBDispatcher::OnError(int32 thread_id, int32 response_id, int code,
639 const string16& message) {
640 DCHECK_EQ(thread_id, CurrentWorkerId());
641 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(response_id);
642 if (!callbacks)
643 return;
644 callbacks->onError(WebIDBDatabaseError(code, message));
645 pending_callbacks_.Remove(response_id);
646 }
647
648 void IndexedDBDispatcher::OnAbort(int32 thread_id, int32 transaction_id) {
649 DCHECK_EQ(thread_id, CurrentWorkerId());
650 WebIDBTransactionCallbacks* callbacks =
651 pending_transaction_callbacks_.Lookup(transaction_id);
652 if (!callbacks)
653 return;
654 callbacks->onAbort();
655 pending_transaction_callbacks_.Remove(transaction_id);
656 }
657
658 void IndexedDBDispatcher::OnComplete(int32 thread_id, int32 transaction_id) {
659 DCHECK_EQ(thread_id, CurrentWorkerId());
660 WebIDBTransactionCallbacks* callbacks =
661 pending_transaction_callbacks_.Lookup(transaction_id);
662 if (!callbacks)
663 return;
664 callbacks->onComplete();
665 pending_transaction_callbacks_.Remove(transaction_id);
666 }
667
668 void IndexedDBDispatcher::OnVersionChange(int32 thread_id,
669 int32 database_id,
670 const string16& newVersion) {
671 DCHECK_EQ(thread_id, CurrentWorkerId());
672 WebIDBDatabaseCallbacks* callbacks =
673 pending_database_callbacks_.Lookup(database_id);
674 // callbacks would be NULL if a versionchange event is received after close
675 // has been called.
676 if (!callbacks)
677 return;
678 callbacks->onVersionChange(newVersion);
679 }
680
681 void IndexedDBDispatcher::ResetCursorPrefetchCaches(int32 exception_cursor_id) {
682 typedef std::map<int32, RendererWebIDBCursorImpl*>::iterator Iterator;
683 for (Iterator i = cursors_.begin(); i != cursors_.end(); ++i) {
684 if (i->first == exception_cursor_id)
685 continue;
686 i->second->ResetPrefetchCache();
687 }
688 }
OLDNEW
« no previous file with comments | « content/renderer/indexed_db/indexed_db_dispatcher.h ('k') | content/renderer/indexed_db/indexed_db_message_filter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698