OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/common/indexed_db/indexed_db_dispatcher.h" | 5 #include "content/common/indexed_db/indexed_db_dispatcher.h" |
6 | 6 |
7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
8 #include "base/threading/thread_local.h" | 8 #include "base/threading/thread_local.h" |
9 #include "content/common/child_thread.h" | 9 #include "content/common/child_thread.h" |
10 #include "content/common/indexed_db/indexed_db_messages.h" | 10 #include "content/common/indexed_db/indexed_db_messages.h" |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
94 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessIndexedDBKey, | 94 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessIndexedDBKey, |
95 OnSuccessIndexedDBKey) | 95 OnSuccessIndexedDBKey) |
96 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessIDBTransaction, | 96 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessIDBTransaction, |
97 OnSuccessIDBTransaction) | 97 OnSuccessIDBTransaction) |
98 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessStringList, | 98 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessStringList, |
99 OnSuccessStringList) | 99 OnSuccessStringList) |
100 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessSerializedScriptValue, | 100 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksSuccessSerializedScriptValue, |
101 OnSuccessSerializedScriptValue) | 101 OnSuccessSerializedScriptValue) |
102 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksError, OnError) | 102 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksError, OnError) |
103 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksBlocked, OnBlocked) | 103 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksBlocked, OnBlocked) |
104 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksIntBlocked, OnIntBlocked) | |
104 IPC_MESSAGE_HANDLER(IndexedDBMsg_TransactionCallbacksAbort, OnAbort) | 105 IPC_MESSAGE_HANDLER(IndexedDBMsg_TransactionCallbacksAbort, OnAbort) |
105 IPC_MESSAGE_HANDLER(IndexedDBMsg_TransactionCallbacksComplete, OnComplete) | 106 IPC_MESSAGE_HANDLER(IndexedDBMsg_TransactionCallbacksComplete, OnComplete) |
107 IPC_MESSAGE_HANDLER(IndexedDBMsg_DatabaseCallbacksIntVersionChange, | |
108 OnIntVersionChange) | |
106 IPC_MESSAGE_HANDLER(IndexedDBMsg_DatabaseCallbacksVersionChange, | 109 IPC_MESSAGE_HANDLER(IndexedDBMsg_DatabaseCallbacksVersionChange, |
107 OnVersionChange) | 110 OnVersionChange) |
111 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksUpgradeNeeded, OnUpgradeNeeded) | |
jsbell
2012/07/25 22:12:16
Can you put this with the other _Callbacks message
dgrogan
2012/07/25 23:59:59
Done.
| |
108 IPC_MESSAGE_UNHANDLED(handled = false) | 112 IPC_MESSAGE_UNHANDLED(handled = false) |
109 IPC_END_MESSAGE_MAP() | 113 IPC_END_MESSAGE_MAP() |
110 // If a message gets here, IndexedDBMessageFilter already determined that it | 114 // If a message gets here, IndexedDBMessageFilter already determined that it |
111 // is an IndexedDB message. | 115 // is an IndexedDB message. |
112 DCHECK(handled); | 116 DCHECK(handled) << "Didn't handle a message defined at line " |
117 << IPC_MESSAGE_ID_LINE(msg.type()); | |
113 } | 118 } |
114 | 119 |
115 bool IndexedDBDispatcher::Send(IPC::Message* msg) { | 120 bool IndexedDBDispatcher::Send(IPC::Message* msg) { |
116 if (CurrentWorkerId()) { | 121 if (CurrentWorkerId()) { |
117 scoped_refptr<IPC::SyncMessageFilter> filter( | 122 scoped_refptr<IPC::SyncMessageFilter> filter( |
118 ChildThread::current()->sync_message_filter()); | 123 ChildThread::current()->sync_message_filter()); |
119 return filter->Send(msg); | 124 return filter->Send(msg); |
120 } | 125 } |
121 return ChildThread::current()->Send(msg); | 126 return ChildThread::current()->Send(msg); |
122 } | 127 } |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
206 | 211 |
207 int32 response_id = pending_callbacks_.Add(callbacks.release()); | 212 int32 response_id = pending_callbacks_.Add(callbacks.release()); |
208 Send(new IndexedDBHostMsg_CursorDelete(idb_cursor_id, CurrentWorkerId(), | 213 Send(new IndexedDBHostMsg_CursorDelete(idb_cursor_id, CurrentWorkerId(), |
209 response_id, ec)); | 214 response_id, ec)); |
210 if (*ec) | 215 if (*ec) |
211 pending_callbacks_.Remove(response_id); | 216 pending_callbacks_.Remove(response_id); |
212 } | 217 } |
213 | 218 |
214 void IndexedDBDispatcher::RequestIDBFactoryOpen( | 219 void IndexedDBDispatcher::RequestIDBFactoryOpen( |
215 const string16& name, | 220 const string16& name, |
221 int64 version, | |
216 WebIDBCallbacks* callbacks_ptr, | 222 WebIDBCallbacks* callbacks_ptr, |
217 const string16& origin, | 223 const string16& origin, |
218 WebFrame* web_frame) { | 224 WebFrame* web_frame) { |
219 ResetCursorPrefetchCaches(); | 225 ResetCursorPrefetchCaches(); |
220 scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr); | 226 scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr); |
221 | 227 |
222 if (!CurrentWorkerId() && | 228 if (!CurrentWorkerId() && |
223 !ChildThread::current()->IsWebFrameValid(web_frame)) | 229 !ChildThread::current()->IsWebFrameValid(web_frame)) |
224 return; | 230 return; |
225 | 231 |
226 IndexedDBHostMsg_FactoryOpen_Params params; | 232 IndexedDBHostMsg_FactoryOpen_Params params; |
227 params.thread_id = CurrentWorkerId(); | 233 params.thread_id = CurrentWorkerId(); |
228 params.response_id = pending_callbacks_.Add(callbacks.release()); | 234 params.response_id = pending_callbacks_.Add(callbacks.release()); |
229 params.origin = origin; | 235 params.origin = origin; |
230 params.name = name; | 236 params.name = name; |
237 params.version = version; | |
231 Send(new IndexedDBHostMsg_FactoryOpen(params)); | 238 Send(new IndexedDBHostMsg_FactoryOpen(params)); |
232 } | 239 } |
233 | 240 |
234 void IndexedDBDispatcher::RequestIDBFactoryGetDatabaseNames( | 241 void IndexedDBDispatcher::RequestIDBFactoryGetDatabaseNames( |
235 WebIDBCallbacks* callbacks_ptr, | 242 WebIDBCallbacks* callbacks_ptr, |
236 const string16& origin, | 243 const string16& origin, |
237 WebFrame* web_frame) { | 244 WebFrame* web_frame) { |
238 ResetCursorPrefetchCaches(); | 245 ResetCursorPrefetchCaches(); |
239 scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr); | 246 scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr); |
240 | 247 |
(...skipping 24 matching lines...) Expand all Loading... | |
265 params.thread_id = CurrentWorkerId(); | 272 params.thread_id = CurrentWorkerId(); |
266 params.response_id = pending_callbacks_.Add(callbacks.release()); | 273 params.response_id = pending_callbacks_.Add(callbacks.release()); |
267 params.origin = origin; | 274 params.origin = origin; |
268 params.name = name; | 275 params.name = name; |
269 Send(new IndexedDBHostMsg_FactoryDeleteDatabase(params)); | 276 Send(new IndexedDBHostMsg_FactoryDeleteDatabase(params)); |
270 } | 277 } |
271 | 278 |
272 void IndexedDBDispatcher::RequestIDBDatabaseClose(int32 idb_database_id) { | 279 void IndexedDBDispatcher::RequestIDBDatabaseClose(int32 idb_database_id) { |
273 ResetCursorPrefetchCaches(); | 280 ResetCursorPrefetchCaches(); |
274 Send(new IndexedDBHostMsg_DatabaseClose(idb_database_id)); | 281 Send(new IndexedDBHostMsg_DatabaseClose(idb_database_id)); |
275 pending_database_callbacks_.Remove(idb_database_id); | 282 // There won't be pending database callbacks if the transaction was aborted in |
283 // the initial upgradeneeded event handler. | |
284 if (pending_database_callbacks_.Lookup(idb_database_id)) | |
285 pending_database_callbacks_.Remove(idb_database_id); | |
276 } | 286 } |
277 | 287 |
278 void IndexedDBDispatcher::RequestIDBDatabaseOpen( | 288 void IndexedDBDispatcher::RequestIDBDatabaseOpen( |
279 WebIDBDatabaseCallbacks* callbacks_ptr, | 289 WebIDBDatabaseCallbacks* callbacks_ptr, |
280 int32 idb_database_id) { | 290 int32 idb_database_id) { |
281 ResetCursorPrefetchCaches(); | 291 ResetCursorPrefetchCaches(); |
282 scoped_ptr<WebIDBDatabaseCallbacks> callbacks(callbacks_ptr); | 292 scoped_ptr<WebIDBDatabaseCallbacks> callbacks(callbacks_ptr); |
283 | 293 |
284 DCHECK(!pending_database_callbacks_.Lookup(idb_database_id)); | 294 DCHECK(!pending_database_callbacks_.Lookup(idb_database_id)); |
285 pending_database_callbacks_.AddWithID(callbacks.release(), idb_database_id); | 295 pending_database_callbacks_.AddWithID(callbacks.release(), idb_database_id); |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
532 void IndexedDBDispatcher::RegisterWebIDBTransactionCallbacks( | 542 void IndexedDBDispatcher::RegisterWebIDBTransactionCallbacks( |
533 WebIDBTransactionCallbacks* callbacks, | 543 WebIDBTransactionCallbacks* callbacks, |
534 int32 id) { | 544 int32 id) { |
535 pending_transaction_callbacks_.AddWithID(callbacks, id); | 545 pending_transaction_callbacks_.AddWithID(callbacks, id); |
536 } | 546 } |
537 | 547 |
538 void IndexedDBDispatcher::CursorDestroyed(int32 cursor_id) { | 548 void IndexedDBDispatcher::CursorDestroyed(int32 cursor_id) { |
539 cursors_.erase(cursor_id); | 549 cursors_.erase(cursor_id); |
540 } | 550 } |
541 | 551 |
552 void IndexedDBDispatcher::DatabaseDestroyed(int32 database_id) { | |
553 DCHECK_EQ(databases_.count(database_id), 1u); | |
554 databases_.erase(database_id); | |
555 } | |
556 | |
542 int32 IndexedDBDispatcher::TransactionId( | 557 int32 IndexedDBDispatcher::TransactionId( |
543 const WebIDBTransaction& transaction) { | 558 const WebIDBTransaction& transaction) { |
544 const RendererWebIDBTransactionImpl* impl = | 559 const RendererWebIDBTransactionImpl* impl = |
545 static_cast<const RendererWebIDBTransactionImpl*>(&transaction); | 560 static_cast<const RendererWebIDBTransactionImpl*>(&transaction); |
546 return impl->id(); | 561 return impl->id(); |
547 } | 562 } |
548 | 563 |
549 void IndexedDBDispatcher::OnSuccessIDBDatabase(int32 thread_id, | 564 void IndexedDBDispatcher::OnSuccessIDBDatabase(int32 thread_id, |
550 int32 response_id, | 565 int32 response_id, |
551 int32 object_id) { | 566 int32 object_id) { |
552 DCHECK_EQ(thread_id, CurrentWorkerId()); | 567 DCHECK_EQ(thread_id, CurrentWorkerId()); |
553 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(response_id); | 568 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(response_id); |
554 if (!callbacks) | 569 if (!callbacks) |
555 return; | 570 return; |
556 callbacks->onSuccess(new RendererWebIDBDatabaseImpl(object_id)); | 571 if (!databases_.count(object_id)) |
jsbell
2012/07/25 22:12:16
Add comment here that count will be non-zero if an
dgrogan
2012/07/25 23:59:59
Done.
| |
572 databases_[object_id] = new RendererWebIDBDatabaseImpl(object_id); | |
573 callbacks->onSuccess(databases_[object_id]); | |
557 pending_callbacks_.Remove(response_id); | 574 pending_callbacks_.Remove(response_id); |
558 } | 575 } |
559 | 576 |
560 void IndexedDBDispatcher::OnSuccessIndexedDBKey( | 577 void IndexedDBDispatcher::OnSuccessIndexedDBKey( |
561 int32 thread_id, | 578 int32 thread_id, |
562 int32 response_id, | 579 int32 response_id, |
563 const IndexedDBKey& key) { | 580 const IndexedDBKey& key) { |
564 DCHECK_EQ(thread_id, CurrentWorkerId()); | 581 DCHECK_EQ(thread_id, CurrentWorkerId()); |
565 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(response_id); | 582 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(response_id); |
566 if (!callbacks) | 583 if (!callbacks) |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
659 RendererWebIDBCursorImpl* cursor = cursors_[cursor_id]; | 676 RendererWebIDBCursorImpl* cursor = cursors_[cursor_id]; |
660 DCHECK(cursor); | 677 DCHECK(cursor); |
661 cursor->SetPrefetchData(keys, primary_keys, values); | 678 cursor->SetPrefetchData(keys, primary_keys, values); |
662 | 679 |
663 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(response_id); | 680 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(response_id); |
664 DCHECK(callbacks); | 681 DCHECK(callbacks); |
665 cursor->CachedContinue(callbacks); | 682 cursor->CachedContinue(callbacks); |
666 pending_callbacks_.Remove(response_id); | 683 pending_callbacks_.Remove(response_id); |
667 } | 684 } |
668 | 685 |
686 void IndexedDBDispatcher::OnIntBlocked(int32 thread_id, | |
687 int32 response_id, | |
688 int64 existing_version) { | |
689 DCHECK_EQ(thread_id, CurrentWorkerId()); | |
690 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(response_id); | |
691 DCHECK(callbacks); | |
692 callbacks->onBlocked(existing_version); | |
jsbell
2012/07/25 22:12:16
Will the non-int OnBlocked plumbing be removed bef
dgrogan
2012/07/25 23:59:59
Probably both in parallel for a while.
(Wondering
| |
693 } | |
694 | |
669 void IndexedDBDispatcher::OnBlocked(int32 thread_id, int32 response_id) { | 695 void IndexedDBDispatcher::OnBlocked(int32 thread_id, int32 response_id) { |
670 DCHECK_EQ(thread_id, CurrentWorkerId()); | 696 DCHECK_EQ(thread_id, CurrentWorkerId()); |
671 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(response_id); | 697 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(response_id); |
672 DCHECK(callbacks); | 698 DCHECK(callbacks); |
673 callbacks->onBlocked(); | 699 callbacks->onBlocked(); |
674 } | 700 } |
675 | 701 |
676 void IndexedDBDispatcher::OnError(int32 thread_id, int32 response_id, int code, | 702 void IndexedDBDispatcher::OnError(int32 thread_id, int32 response_id, int code, |
677 const string16& message) { | 703 const string16& message) { |
678 DCHECK_EQ(thread_id, CurrentWorkerId()); | 704 DCHECK_EQ(thread_id, CurrentWorkerId()); |
(...skipping 17 matching lines...) Expand all Loading... | |
696 void IndexedDBDispatcher::OnComplete(int32 thread_id, int32 transaction_id) { | 722 void IndexedDBDispatcher::OnComplete(int32 thread_id, int32 transaction_id) { |
697 DCHECK_EQ(thread_id, CurrentWorkerId()); | 723 DCHECK_EQ(thread_id, CurrentWorkerId()); |
698 WebIDBTransactionCallbacks* callbacks = | 724 WebIDBTransactionCallbacks* callbacks = |
699 pending_transaction_callbacks_.Lookup(transaction_id); | 725 pending_transaction_callbacks_.Lookup(transaction_id); |
700 if (!callbacks) | 726 if (!callbacks) |
701 return; | 727 return; |
702 callbacks->onComplete(); | 728 callbacks->onComplete(); |
703 pending_transaction_callbacks_.Remove(transaction_id); | 729 pending_transaction_callbacks_.Remove(transaction_id); |
704 } | 730 } |
705 | 731 |
732 void IndexedDBDispatcher::OnIntVersionChange(int32 thread_id, | |
733 int32 database_id, | |
734 int64 old_version, | |
735 int64 new_version) { | |
736 DCHECK_EQ(thread_id, CurrentWorkerId()); | |
737 WebIDBDatabaseCallbacks* callbacks = | |
738 pending_database_callbacks_.Lookup(database_id); | |
739 // callbacks would be NULL if a versionchange event is received after close | |
740 // has been called. | |
741 if (!callbacks) | |
742 return; | |
743 callbacks->onVersionChange(old_version, new_version); | |
744 } | |
745 | |
706 void IndexedDBDispatcher::OnVersionChange(int32 thread_id, | 746 void IndexedDBDispatcher::OnVersionChange(int32 thread_id, |
707 int32 database_id, | 747 int32 database_id, |
708 const string16& newVersion) { | 748 const string16& newVersion) { |
709 DCHECK_EQ(thread_id, CurrentWorkerId()); | 749 DCHECK_EQ(thread_id, CurrentWorkerId()); |
710 WebIDBDatabaseCallbacks* callbacks = | 750 WebIDBDatabaseCallbacks* callbacks = |
711 pending_database_callbacks_.Lookup(database_id); | 751 pending_database_callbacks_.Lookup(database_id); |
712 // callbacks would be NULL if a versionchange event is received after close | 752 // callbacks would be NULL if a versionchange event is received after close |
713 // has been called. | 753 // has been called. |
714 if (!callbacks) | 754 if (!callbacks) |
715 return; | 755 return; |
716 callbacks->onVersionChange(newVersion); | 756 callbacks->onVersionChange(newVersion); |
717 } | 757 } |
718 | 758 |
759 void IndexedDBDispatcher::OnUpgradeNeeded(int32 thread_id, | |
760 int32 response_id, | |
761 int32 transaction_id, | |
762 int32 database_id, | |
763 int64 old_version) { | |
764 DCHECK_EQ(thread_id, CurrentWorkerId()); | |
765 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(response_id); | |
766 DCHECK(callbacks); | |
767 DCHECK(!databases_.count(database_id)); | |
768 databases_[database_id] = new RendererWebIDBDatabaseImpl(database_id); | |
769 callbacks->onUpgradeNeeded(old_version, | |
770 new RendererWebIDBTransactionImpl(transaction_id), | |
771 databases_[database_id]); | |
772 } | |
773 | |
719 void IndexedDBDispatcher::ResetCursorPrefetchCaches(int32 exception_cursor_id) { | 774 void IndexedDBDispatcher::ResetCursorPrefetchCaches(int32 exception_cursor_id) { |
720 typedef std::map<int32, RendererWebIDBCursorImpl*>::iterator Iterator; | 775 typedef std::map<int32, RendererWebIDBCursorImpl*>::iterator Iterator; |
721 for (Iterator i = cursors_.begin(); i != cursors_.end(); ++i) { | 776 for (Iterator i = cursors_.begin(); i != cursors_.end(); ++i) { |
722 if (i->first == exception_cursor_id) | 777 if (i->first == exception_cursor_id) |
723 continue; | 778 continue; |
724 i->second->ResetPrefetchCache(); | 779 i->second->ResetPrefetchCache(); |
725 } | 780 } |
726 } | 781 } |
OLD | NEW |