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

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

Issue 10829013: Chrome side changes for integer versions (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add #include that windows needs Created 8 years, 4 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
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
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)
105 IPC_MESSAGE_HANDLER(IndexedDBMsg_CallbacksUpgradeNeeded, OnUpgradeNeeded)
104 IPC_MESSAGE_HANDLER(IndexedDBMsg_TransactionCallbacksAbort, OnAbort) 106 IPC_MESSAGE_HANDLER(IndexedDBMsg_TransactionCallbacksAbort, OnAbort)
105 IPC_MESSAGE_HANDLER(IndexedDBMsg_TransactionCallbacksComplete, OnComplete) 107 IPC_MESSAGE_HANDLER(IndexedDBMsg_TransactionCallbacksComplete, OnComplete)
108 IPC_MESSAGE_HANDLER(IndexedDBMsg_DatabaseCallbacksIntVersionChange,
109 OnIntVersionChange)
106 IPC_MESSAGE_HANDLER(IndexedDBMsg_DatabaseCallbacksVersionChange, 110 IPC_MESSAGE_HANDLER(IndexedDBMsg_DatabaseCallbacksVersionChange,
107 OnVersionChange) 111 OnVersionChange)
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
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
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
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 an upgrade was performed, count will be non-zero.
572 if (!databases_.count(object_id))
573 databases_[object_id] = new RendererWebIDBDatabaseImpl(object_id);
574 DCHECK_EQ(databases_.count(object_id), 1u);
575 callbacks->onSuccess(databases_[object_id]);
557 pending_callbacks_.Remove(response_id); 576 pending_callbacks_.Remove(response_id);
558 } 577 }
559 578
560 void IndexedDBDispatcher::OnSuccessIndexedDBKey( 579 void IndexedDBDispatcher::OnSuccessIndexedDBKey(
561 int32 thread_id, 580 int32 thread_id,
562 int32 response_id, 581 int32 response_id,
563 const IndexedDBKey& key) { 582 const IndexedDBKey& key) {
564 DCHECK_EQ(thread_id, CurrentWorkerId()); 583 DCHECK_EQ(thread_id, CurrentWorkerId());
565 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(response_id); 584 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(response_id);
566 if (!callbacks) 585 if (!callbacks)
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
666 pending_callbacks_.Remove(response_id); 685 pending_callbacks_.Remove(response_id);
667 } 686 }
668 687
669 void IndexedDBDispatcher::OnBlocked(int32 thread_id, int32 response_id) { 688 void IndexedDBDispatcher::OnBlocked(int32 thread_id, int32 response_id) {
670 DCHECK_EQ(thread_id, CurrentWorkerId()); 689 DCHECK_EQ(thread_id, CurrentWorkerId());
671 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(response_id); 690 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(response_id);
672 DCHECK(callbacks); 691 DCHECK(callbacks);
673 callbacks->onBlocked(); 692 callbacks->onBlocked();
674 } 693 }
675 694
695 void IndexedDBDispatcher::OnIntBlocked(int32 thread_id,
696 int32 response_id,
697 int64 existing_version) {
698 DCHECK_EQ(thread_id, CurrentWorkerId());
699 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(response_id);
700 DCHECK(callbacks);
701 callbacks->onBlocked(existing_version);
702 }
703
704 void IndexedDBDispatcher::OnUpgradeNeeded(int32 thread_id,
705 int32 response_id,
706 int32 transaction_id,
707 int32 database_id,
708 int64 old_version) {
709 DCHECK_EQ(thread_id, CurrentWorkerId());
710 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(response_id);
711 DCHECK(callbacks);
712 DCHECK(!databases_.count(database_id));
713 databases_[database_id] = new RendererWebIDBDatabaseImpl(database_id);
714 callbacks->onUpgradeNeeded(old_version,
715 new RendererWebIDBTransactionImpl(transaction_id),
716 databases_[database_id]);
717 }
718
676 void IndexedDBDispatcher::OnError(int32 thread_id, int32 response_id, int code, 719 void IndexedDBDispatcher::OnError(int32 thread_id, int32 response_id, int code,
677 const string16& message) { 720 const string16& message) {
678 DCHECK_EQ(thread_id, CurrentWorkerId()); 721 DCHECK_EQ(thread_id, CurrentWorkerId());
679 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(response_id); 722 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(response_id);
680 if (!callbacks) 723 if (!callbacks)
681 return; 724 return;
682 callbacks->onError(WebIDBDatabaseError(code, message)); 725 callbacks->onError(WebIDBDatabaseError(code, message));
683 pending_callbacks_.Remove(response_id); 726 pending_callbacks_.Remove(response_id);
684 } 727 }
685 728
(...skipping 10 matching lines...) Expand all
696 void IndexedDBDispatcher::OnComplete(int32 thread_id, int32 transaction_id) { 739 void IndexedDBDispatcher::OnComplete(int32 thread_id, int32 transaction_id) {
697 DCHECK_EQ(thread_id, CurrentWorkerId()); 740 DCHECK_EQ(thread_id, CurrentWorkerId());
698 WebIDBTransactionCallbacks* callbacks = 741 WebIDBTransactionCallbacks* callbacks =
699 pending_transaction_callbacks_.Lookup(transaction_id); 742 pending_transaction_callbacks_.Lookup(transaction_id);
700 if (!callbacks) 743 if (!callbacks)
701 return; 744 return;
702 callbacks->onComplete(); 745 callbacks->onComplete();
703 pending_transaction_callbacks_.Remove(transaction_id); 746 pending_transaction_callbacks_.Remove(transaction_id);
704 } 747 }
705 748
749 void IndexedDBDispatcher::OnIntVersionChange(int32 thread_id,
750 int32 database_id,
751 int64 old_version,
752 int64 new_version) {
753 DCHECK_EQ(thread_id, CurrentWorkerId());
754 WebIDBDatabaseCallbacks* callbacks =
755 pending_database_callbacks_.Lookup(database_id);
756 // callbacks would be NULL if a versionchange event is received after close
757 // has been called.
758 if (!callbacks)
759 return;
760 callbacks->onVersionChange(old_version, new_version);
761 }
762
706 void IndexedDBDispatcher::OnVersionChange(int32 thread_id, 763 void IndexedDBDispatcher::OnVersionChange(int32 thread_id,
707 int32 database_id, 764 int32 database_id,
708 const string16& newVersion) { 765 const string16& newVersion) {
709 DCHECK_EQ(thread_id, CurrentWorkerId()); 766 DCHECK_EQ(thread_id, CurrentWorkerId());
710 WebIDBDatabaseCallbacks* callbacks = 767 WebIDBDatabaseCallbacks* callbacks =
711 pending_database_callbacks_.Lookup(database_id); 768 pending_database_callbacks_.Lookup(database_id);
712 // callbacks would be NULL if a versionchange event is received after close 769 // callbacks would be NULL if a versionchange event is received after close
713 // has been called. 770 // has been called.
714 if (!callbacks) 771 if (!callbacks)
715 return; 772 return;
716 callbacks->onVersionChange(newVersion); 773 callbacks->onVersionChange(newVersion);
717 } 774 }
718 775
719 void IndexedDBDispatcher::ResetCursorPrefetchCaches(int32 exception_cursor_id) { 776 void IndexedDBDispatcher::ResetCursorPrefetchCaches(int32 exception_cursor_id) {
720 typedef std::map<int32, RendererWebIDBCursorImpl*>::iterator Iterator; 777 typedef std::map<int32, RendererWebIDBCursorImpl*>::iterator Iterator;
721 for (Iterator i = cursors_.begin(); i != cursors_.end(); ++i) { 778 for (Iterator i = cursors_.begin(); i != cursors_.end(); ++i) {
722 if (i->first == exception_cursor_id) 779 if (i->first == exception_cursor_id)
723 continue; 780 continue;
724 i->second->ResetPrefetchCache(); 781 i->second->ResetPrefetchCache();
725 } 782 }
726 } 783 }
OLDNEW
« no previous file with comments | « content/common/indexed_db/indexed_db_dispatcher.h ('k') | content/common/indexed_db/indexed_db_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698