nsresult IDBTransaction::AbortWithCode(nsresult aAbortCode) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); // We can't use IsOpen here since we need it to be possible to call Abort() // even from outside of transaction callbacks. if (mReadyState != IDBTransaction::INITIAL && mReadyState != IDBTransaction::LOADING) { 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; if (Mode() == IDBTransaction::VERSION_CHANGE) { // If a version change transaction is aborted, 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; }
void IDBTransaction::OnRequestFinished() { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); NS_ASSERTION(mPendingRequests, "Mismatched calls!"); --mPendingRequests; if (!mPendingRequests) { NS_ASSERTION(mAbortCode || mReadyState == IDBTransaction::LOADING, "Bad state!"); mReadyState = IDBTransaction::COMMITTING; CommitOrRollback(); } }
void IDBTransaction::OnRequestFinished() { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); NS_ASSERTION(mPendingRequests, "Mismatched calls!"); --mPendingRequests; if (!mPendingRequests) { if (!mAborted) { NS_ASSERTION(mReadyState == nsIIDBTransaction::LOADING, "Bad state!"); } mReadyState = nsIIDBTransaction::DONE; CommitOrRollback(); } }
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; }