NS_IMETHODIMP IDBDatabase::DeleteObjectStore(const nsAString& aName) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); IDBTransaction* transaction = AsyncConnectionHelper::GetCurrentTransaction(); if (!transaction || transaction->Mode() != nsIIDBTransaction::VERSION_CHANGE) { return NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR; } DatabaseInfo* info = transaction->DBInfo(); ObjectStoreInfo* objectStoreInfo = info->GetObjectStore(aName); if (!objectStoreInfo) { return NS_ERROR_DOM_INDEXEDDB_NOT_FOUND_ERR; } nsRefPtr<DeleteObjectStoreHelper> helper = new DeleteObjectStoreHelper(transaction, objectStoreInfo->id); nsresult rv = helper->DispatchToTransactionPool(); NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR); transaction->RemoveObjectStore(aName); return NS_OK; }
nsresult IDBTransaction::AbortInternal(nsresult aAbortCode, already_AddRefed<nsIDOMDOMError> aError) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); nsCOMPtr<nsIDOMDOMError> error = aError; if (IsFinished()) { return NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR; } if (mActorChild) { NS_ASSERTION(!IndexedDatabaseManager::IsMainProcess(), "Wrong process!"); mActorChild->SendAbort(aAbortCode); } bool needToCommitOrRollback = mReadyState == IDBTransaction::INITIAL; mAbortCode = aAbortCode; mReadyState = IDBTransaction::DONE; mError = error.forget(); if (GetMode() == IDBTransaction::VERSION_CHANGE) { // If a version change transaction is aborted, we must revert the world // back to its previous state. mDatabase->RevertToPreviousState(); DatabaseInfo* dbInfo = mDatabase->Info(); for (PRUint32 i = 0; i < mCreatedObjectStores.Length(); i++) { nsRefPtr<IDBObjectStore>& objectStore = mCreatedObjectStores[i]; ObjectStoreInfo* info = dbInfo->GetObjectStore(objectStore->Name()); if (!info) { info = new ObjectStoreInfo(*objectStore->Info()); info->indexes.Clear(); } objectStore->SetInfo(info); } for (PRUint32 i = 0; i < mDeletedObjectStores.Length(); i++) { nsRefPtr<IDBObjectStore>& objectStore = mDeletedObjectStores[i]; ObjectStoreInfo* info = dbInfo->GetObjectStore(objectStore->Name()); if (!info) { info = new ObjectStoreInfo(*objectStore->Info()); info->indexes.Clear(); } objectStore->SetInfo(info); } // and then the db must be closed mDatabase->Close(); } // Fire the abort event if there are no outstanding requests. Otherwise the // abort event will be fired when all outstanding requests finish. if (needToCommitOrRollback) { return CommitOrRollback(); } return NS_OK; }