diff --git a/dom/indexedDB/ActorsChild.cpp b/dom/indexedDB/ActorsChild.cpp index 8c86166377ba..e768ca5a8b0f 100644 --- a/dom/indexedDB/ActorsChild.cpp +++ b/dom/indexedDB/ActorsChild.cpp @@ -3438,10 +3438,9 @@ void BackgroundCursorChild::SendContinueInternal( // This is accompanied by invalidating cached entries at proper locations to // make it correct. To avoid this, further changes are necessary, see Bug // 1580499. - nsCOMPtr continueRunnable = new DelayedActionRunnable( - this, &BackgroundCursorChild::CompleteContinueRequestFromCache); - MOZ_ALWAYS_TRUE( - NS_SUCCEEDED(NS_DispatchToCurrentThread(continueRunnable.forget()))); + MOZ_ALWAYS_SUCCEEDS( + NS_DispatchToCurrentThread(MakeAndAddRef( + this, &BackgroundCursorChild::CompleteContinueRequestFromCache))); // TODO: Could we preload further entries in the background when the size of // mCachedResponses falls under some threshold? Or does the response @@ -3588,10 +3587,10 @@ void BackgroundCursorChild::HandleResponse(const void_t& aResponse) { DispatchSuccessEvent(&helper); if (!mCursor) { - nsCOMPtr deleteRunnable = new DelayedActionRunnable( - this, &BackgroundCursorChild::SendDeleteMeInternal); MOZ_ALWAYS_SUCCEEDS(this->GetActorEventTarget()->Dispatch( - deleteRunnable.forget(), NS_DISPATCH_NORMAL)); + MakeAndAddRef( + this, &BackgroundCursorChild::SendDeleteMeInternal), + NS_DISPATCH_NORMAL)); } } diff --git a/dom/indexedDB/ActorsParent.cpp b/dom/indexedDB/ActorsParent.cpp index 631d6c12fd79..087c1bfd53b6 100644 --- a/dom/indexedDB/ActorsParent.cpp +++ b/dom/indexedDB/ActorsParent.cpp @@ -10804,11 +10804,9 @@ void DatabaseConnection::UpdateRefcountFunction::Reset() { // quota usage) before we fire the commit event. for (const auto& entry : mFileInfoEntries) { FileInfoEntry* const value = entry.GetData(); - MOZ_ASSERT(value); FileInfo* const fileInfo = value->mFileInfo.forget().take(); - MOZ_ASSERT(fileInfo); CustomCleanupCallback customCleanupCallback; @@ -11417,9 +11415,8 @@ void ConnectionPool::WaitForDatabasesToComplete( return; } - nsAutoPtr callback( + mCompleteCallbacks.EmplaceBack( new DatabasesCompleteCallback(std::move(aDatabaseIds), aCallback)); - mCompleteCallbacks.AppendElement(callback.forget()); } void ConnectionPool::Shutdown() { @@ -11464,10 +11461,13 @@ void ConnectionPool::Cleanup() { if (!mCompleteCallbacks.IsEmpty()) { // Run all callbacks manually now. + // TODO: Can a callback cause another entry to be added to + // mCompleteCallbacks? This would be skipped when iterating like this. for (uint32_t count = mCompleteCallbacks.Length(), index = 0; index < count; index++) { - nsAutoPtr completeCallback( - mCompleteCallbacks[index].forget()); + // TODO: Why do we need to move the callback here to a local variable? + // mCompleteCallbacks is cleared afterwards anyway. + const auto completeCallback = std::move(mCompleteCallbacks[index]); MOZ_ASSERT(completeCallback); MOZ_ASSERT(completeCallback->mCallback); @@ -11730,13 +11730,8 @@ bool ConnectionPool::ScheduleTransaction(TransactionInfo* aTransactionInfo, if (!queuedRunnables.IsEmpty()) { for (auto& queuedRunnable : queuedRunnables) { - // TODO: Why do we need this? queuedRunnables is cleared afterwards - // anyway. - nsCOMPtr runnable; - queuedRunnable.swap(runnable); - MOZ_ALWAYS_SUCCEEDS(dbInfo->mThreadInfo.mThread->Dispatch( - runnable.forget(), NS_DISPATCH_NORMAL)); + queuedRunnable.forget(), NS_DISPATCH_NORMAL)); } queuedRunnables.Clear(); @@ -12011,8 +12006,7 @@ void ConnectionPool::PerformIdleDatabaseMaintenance( MOZ_ASSERT(mIdleDatabases.Contains(aDatabaseInfo)); MOZ_ASSERT(!mDatabasesPerformingIdleMaintenance.Contains(aDatabaseInfo)); - nsCOMPtr runnable = new IdleConnectionRunnable( - aDatabaseInfo, aDatabaseInfo->mNeedsCheckpoint); + const bool neededCheckpoint = aDatabaseInfo->mNeedsCheckpoint; aDatabaseInfo->mNeedsCheckpoint = false; aDatabaseInfo->mIdle = false; @@ -12020,7 +12014,8 @@ void ConnectionPool::PerformIdleDatabaseMaintenance( mDatabasesPerformingIdleMaintenance.AppendElement(aDatabaseInfo); MOZ_ALWAYS_SUCCEEDS(aDatabaseInfo->mThreadInfo.mThread->Dispatch( - runnable.forget(), NS_DISPATCH_NORMAL)); + MakeAndAddRef(aDatabaseInfo, neededCheckpoint), + NS_DISPATCH_NORMAL)); } void ConnectionPool::CloseDatabase(DatabaseInfo* aDatabaseInfo) { @@ -12035,10 +12030,9 @@ void ConnectionPool::CloseDatabase(DatabaseInfo* aDatabaseInfo) { aDatabaseInfo->mNeedsCheckpoint = false; aDatabaseInfo->mClosing = true; - nsCOMPtr runnable = new CloseConnectionRunnable(aDatabaseInfo); - MOZ_ALWAYS_SUCCEEDS(aDatabaseInfo->mThreadInfo.mThread->Dispatch( - runnable.forget(), NS_DISPATCH_NORMAL)); + MakeAndAddRef(aDatabaseInfo), + NS_DISPATCH_NORMAL)); } bool ConnectionPool::CloseDatabaseWhenIdleInternal( @@ -12625,9 +12619,7 @@ already_AddRefed Factory::Create(const LoggingInfo& aLoggingInfo) { loggingInfo); } - RefPtr actor = new Factory(loggingInfo.forget()); - - return actor.forget(); + return RefPtr(new Factory(loggingInfo.forget())).forget(); } void Factory::ActorDestroy(ActorDestroyReason aWhy) { @@ -12722,12 +12714,15 @@ Factory::AllocPBackgroundIDBFactoryRequestParent( RefPtr contentParent = BackgroundParent::GetContentParent(Manager()); - RefPtr actor; - if (aParams.type() == FactoryRequestParams::TOpenDatabaseRequestParams) { - actor = new OpenDatabaseOp(this, contentParent.forget(), *commonParams); - } else { - actor = new DeleteDatabaseOp(this, contentParent.forget(), *commonParams); - } + auto actor = [&]() -> RefPtr { + if (aParams.type() == FactoryRequestParams::TOpenDatabaseRequestParams) { + return MakeRefPtr(this, contentParent.forget(), + *commonParams); + } else { + return MakeRefPtr(this, contentParent.forget(), + *commonParams); + } + }(); gFactoryOps->AppendElement(actor); @@ -16685,9 +16680,7 @@ void QuotaClient::StartIdleMaintenance() { mBackgroundThread = GetCurrentThreadEventTarget(); - RefPtr maintenance = new Maintenance(this); - - mMaintenanceQueue.AppendElement(maintenance.forget()); + mMaintenanceQueue.EmplaceBack(MakeRefPtr(this)); ProcessMaintenanceQueue(); } diff --git a/dom/indexedDB/IDBDatabase.cpp b/dom/indexedDB/IDBDatabase.cpp index b56994e795b0..a853a5614443 100644 --- a/dom/indexedDB/IDBDatabase.cpp +++ b/dom/indexedDB/IDBDatabase.cpp @@ -299,9 +299,9 @@ void IDBDatabase::RevertToPreviousState() { // Hold the current spec alive until RefreshTransactionsSpecEnumerator has // finished! - nsAutoPtr currentSpec(mSpec.forget()); + auto currentSpec = std::move(mSpec); - mSpec = mPreviousSpec.forget(); + mSpec = std::move(mPreviousSpec); RefreshSpec(/* aMayDelete */ true); }