diff --git a/docshell/shistory/nsSHistory.cpp b/docshell/shistory/nsSHistory.cpp index ff81a3a3ab96..5bfac6bc9f68 100644 --- a/docshell/shistory/nsSHistory.cpp +++ b/docshell/shistory/nsSHistory.cpp @@ -1383,8 +1383,10 @@ nsSHistory::RemoveEntries(nsTArray& aIDs, int32_t aStartIndex) --index; } if (didRemove && mRootDocShell) { - NS_DispatchToCurrentThread(NewRunnableMethod(static_cast(mRootDocShell), - &nsDocShell::FireDummyOnLocationChange)); + nsCOMPtr ev = + NS_NewRunnableMethod(static_cast(mRootDocShell), + &nsDocShell::FireDummyOnLocationChange); + NS_DispatchToCurrentThread(ev); } } diff --git a/dom/animation/Animation.cpp b/dom/animation/Animation.cpp index c24fe0c99a5b..c4299a19f060 100644 --- a/dom/animation/Animation.cpp +++ b/dom/animation/Animation.cpp @@ -1236,7 +1236,7 @@ Animation::DoFinishNotification(SyncNotifyFlag aSyncNotifyFlag) DoFinishNotificationImmediately(); } else if (!mFinishNotificationTask.IsPending()) { RefPtr> runnable = - NewRunnableMethod(this, &Animation::DoFinishNotificationImmediately); + NS_NewRunnableMethod(this, &Animation::DoFinishNotificationImmediately); runtime->DispatchToMicroTask(runnable); mFinishNotificationTask = runnable; } diff --git a/dom/archivereader/ArchiveEvent.cpp b/dom/archivereader/ArchiveEvent.cpp index b1b3dcd82384..164a03eb2d4d 100644 --- a/dom/archivereader/ArchiveEvent.cpp +++ b/dom/archivereader/ArchiveEvent.cpp @@ -86,7 +86,8 @@ ArchiveReaderEvent::RunShare(nsresult aStatus) { mStatus = aStatus; - NS_DispatchToMainThread(NewRunnableMethod(this, &ArchiveReaderEvent::ShareMainThread)); + nsCOMPtr event = NS_NewRunnableMethod(this, &ArchiveReaderEvent::ShareMainThread); + NS_DispatchToMainThread(event); return NS_OK; } diff --git a/dom/base/Element.cpp b/dom/base/Element.cpp index d3fab39ea3e7..657cfb2daaa5 100644 --- a/dom/base/Element.cpp +++ b/dom/base/Element.cpp @@ -517,7 +517,7 @@ Element::WrapObject(JSContext *aCx, JS::Handle aGivenProto) } else { nsContentUtils::AddScriptRunner( - NewRunnableMethod(binding, &nsXBLBinding::ExecuteAttachedHandler)); + NS_NewRunnableMethod(binding, &nsXBLBinding::ExecuteAttachedHandler)); } } } diff --git a/dom/base/EventSource.cpp b/dom/base/EventSource.cpp index 142116ec2f5b..c99a3351c679 100644 --- a/dom/base/EventSource.cpp +++ b/dom/base/EventSource.cpp @@ -364,7 +364,11 @@ EventSource::OnStartRequest(nsIRequest *aRequest, return NS_ERROR_ABORT; } - rv = NS_DispatchToMainThread(NewRunnableMethod(this, &EventSource::AnnounceConnection)); + nsCOMPtr event = + NS_NewRunnableMethod(this, &EventSource::AnnounceConnection); + NS_ENSURE_STATE(event); + + rv = NS_DispatchToMainThread(event); NS_ENSURE_SUCCESS(rv, rv); mStatus = PARSE_STATE_BEGIN_OF_STREAM; @@ -470,7 +474,11 @@ EventSource::OnStopRequest(nsIRequest *aRequest, ClearFields(); - rv = NS_DispatchToMainThread(NewRunnableMethod(this, &EventSource::ReestablishConnection)); + nsCOMPtr event = + NS_NewRunnableMethod(this, &EventSource::ReestablishConnection); + NS_ENSURE_STATE(event); + + rv = NS_DispatchToMainThread(event); NS_ENSURE_SUCCESS(rv, rv); return NS_OK; @@ -899,8 +907,11 @@ EventSource::ConsoleError() nsresult EventSource::DispatchFailConnection() { + nsCOMPtr event = + NS_NewRunnableMethod(this, &EventSource::FailConnection); + NS_ENSURE_STATE(event); - return NS_DispatchToMainThread(NewRunnableMethod(this, &EventSource::FailConnection)); + return NS_DispatchToMainThread(event); } void @@ -974,7 +985,7 @@ EventSource::Thaw() nsresult rv; if (!mGoingToDispatchAllMessages && mMessagesToDispatch.GetSize() > 0) { nsCOMPtr event = - NewRunnableMethod(this, &EventSource::DispatchAllMessageEvents); + NS_NewRunnableMethod(this, &EventSource::DispatchAllMessageEvents); NS_ENSURE_STATE(event); mGoingToDispatchAllMessages = true; @@ -1034,7 +1045,7 @@ EventSource::DispatchCurrentMessageEvent() if (!mGoingToDispatchAllMessages) { nsCOMPtr event = - NewRunnableMethod(this, &EventSource::DispatchAllMessageEvents); + NS_NewRunnableMethod(this, &EventSource::DispatchAllMessageEvents); NS_ENSURE_STATE(event); mGoingToDispatchAllMessages = true; diff --git a/dom/base/ScreenOrientation.cpp b/dom/base/ScreenOrientation.cpp index 5ed7a825e007..42990759fbf7 100644 --- a/dom/base/ScreenOrientation.cpp +++ b/dom/base/ScreenOrientation.cpp @@ -540,7 +540,7 @@ ScreenOrientation::Notify(const hal::ScreenConfiguration& aConfiguration) doc->SetOrientationPendingPromise(nullptr); } - nsCOMPtr runnable = NewRunnableMethod(this, + nsCOMPtr runnable = NS_NewRunnableMethod(this, &ScreenOrientation::DispatchChangeEvent); rv = NS_DispatchToMainThread(runnable); NS_WARN_IF(NS_FAILED(rv)); @@ -615,7 +615,7 @@ ScreenOrientation::VisibleEventListener::HandleEvent(nsIDOMEvent* aEvent) doc->SetOrientationPendingPromise(nullptr); } - nsCOMPtr runnable = NewRunnableMethod(orientation, + nsCOMPtr runnable = NS_NewRunnableMethod(orientation, &ScreenOrientation::DispatchChangeEvent); rv = NS_DispatchToMainThread(runnable); if (NS_WARN_IF(rv.Failed())) { diff --git a/dom/base/nsContentSink.cpp b/dom/base/nsContentSink.cpp index 1c2f62d2f74e..90fc285268fa 100644 --- a/dom/base/nsContentSink.cpp +++ b/dom/base/nsContentSink.cpp @@ -271,7 +271,7 @@ nsContentSink::ProcessHTTPHeaders(nsIChannel* aChannel) "Already dispatched an event?"); mProcessLinkHeaderEvent = - NewNonOwningRunnableMethod(this, + NS_NewNonOwningRunnableMethod(this, &nsContentSink::DoProcessLinkHeader); rv = NS_DispatchToCurrentThread(mProcessLinkHeaderEvent.get()); if (NS_FAILED(rv)) { diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp index ec5aaedfb872..2d4d3114cc29 100644 --- a/dom/base/nsContentUtils.cpp +++ b/dom/base/nsContentUtils.cpp @@ -5042,29 +5042,22 @@ nsContentUtils::WarnScriptWasIgnored(nsIDocument* aDocument) /* static */ bool -nsContentUtils::AddScriptRunner(already_AddRefed aRunnable) +nsContentUtils::AddScriptRunner(nsIRunnable* aRunnable) { - nsCOMPtr runnable = aRunnable; - if (!runnable) { + if (!aRunnable) { return false; } if (sScriptBlockerCount) { - return sBlockedScriptRunners->AppendElement(runnable.forget()) != nullptr; + return sBlockedScriptRunners->AppendElement(aRunnable) != nullptr; } - runnable->Run(); + nsCOMPtr run = aRunnable; + run->Run(); return true; } -/* static */ -bool -nsContentUtils::AddScriptRunner(nsIRunnable* aRunnable) { - nsCOMPtr runnable = aRunnable; - return AddScriptRunner(runnable.forget()); -} - /* static */ void nsContentUtils::RunInStableState(already_AddRefed aRunnable) diff --git a/dom/base/nsContentUtils.h b/dom/base/nsContentUtils.h index dde5f041243e..c4c3a3aa6674 100644 --- a/dom/base/nsContentUtils.h +++ b/dom/base/nsContentUtils.h @@ -1608,7 +1608,6 @@ public: * has not yet been AddRefed. * @return false on out of memory, true otherwise. */ - static bool AddScriptRunner(already_AddRefed aRunnable); static bool AddScriptRunner(nsIRunnable* aRunnable); /** diff --git a/dom/base/nsDOMWindowUtils.cpp b/dom/base/nsDOMWindowUtils.cpp index 7a541890ca62..113ca25917a1 100644 --- a/dom/base/nsDOMWindowUtils.cpp +++ b/dom/base/nsDOMWindowUtils.cpp @@ -1008,7 +1008,7 @@ nsDOMWindowUtils::SendNativeKeyEvent(int32_t aNativeKeyboardLayout, if (!widget) return NS_ERROR_FAILURE; - NS_DispatchToMainThread(NewRunnableMethod + NS_DispatchToMainThread(NS_NewRunnableMethodWithArgs (widget, &nsIWidget::SynthesizeNativeKeyEvent, aNativeKeyboardLayout, aNativeKeyCode, aModifiers, aCharacters, aUnmodifiedCharacters, aObserver)); @@ -1028,7 +1028,7 @@ nsDOMWindowUtils::SendNativeMouseEvent(int32_t aScreenX, if (!widget) return NS_ERROR_FAILURE; - NS_DispatchToMainThread(NewRunnableMethod + NS_DispatchToMainThread(NS_NewRunnableMethodWithArgs (widget, &nsIWidget::SynthesizeNativeMouseEvent, LayoutDeviceIntPoint(aScreenX, aScreenY), aNativeMessage, aModifierFlags, @@ -1047,7 +1047,7 @@ nsDOMWindowUtils::SendNativeMouseMove(int32_t aScreenX, if (!widget) return NS_ERROR_FAILURE; - NS_DispatchToMainThread(NewRunnableMethod + NS_DispatchToMainThread(NS_NewRunnableMethodWithArgs (widget, &nsIWidget::SynthesizeNativeMouseMove, LayoutDeviceIntPoint(aScreenX, aScreenY), aObserver)); @@ -1072,7 +1072,7 @@ nsDOMWindowUtils::SendNativeMouseScrollEvent(int32_t aScreenX, return NS_ERROR_FAILURE; } - NS_DispatchToMainThread(NewRunnableMethod + NS_DispatchToMainThread(NS_NewRunnableMethodWithArgs (widget, &nsIWidget::SynthesizeNativeMouseScrollEvent, LayoutDeviceIntPoint(aScreenX, aScreenY), aNativeMessage, aDeltaX, aDeltaY, @@ -1098,7 +1098,7 @@ nsDOMWindowUtils::SendNativeTouchPoint(uint32_t aPointerId, return NS_ERROR_INVALID_ARG; } - NS_DispatchToMainThread(NewRunnableMethod + NS_DispatchToMainThread(NS_NewRunnableMethodWithArgs (widget, &nsIWidget::SynthesizeNativeTouchPoint, aPointerId, (nsIWidget::TouchPointerState)aTouchState, @@ -1118,7 +1118,7 @@ nsDOMWindowUtils::SendNativeTouchTap(int32_t aScreenX, return NS_ERROR_FAILURE; } - NS_DispatchToMainThread(NewRunnableMethod + NS_DispatchToMainThread(NS_NewRunnableMethodWithArgs (widget, &nsIWidget::SynthesizeNativeTouchTap, LayoutDeviceIntPoint(aScreenX, aScreenY), aLongTap, aObserver)); @@ -1133,7 +1133,7 @@ nsDOMWindowUtils::ClearNativeTouchSequence(nsIObserver* aObserver) return NS_ERROR_FAILURE; } - NS_DispatchToMainThread(NewRunnableMethod + NS_DispatchToMainThread(NS_NewRunnableMethodWithArgs (widget, &nsIWidget::ClearNativeTouchSequence, aObserver)); return NS_OK; } diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp index 651ac9d5a7f8..1cae937b2984 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -4352,7 +4352,7 @@ nsDocument::SetStyleSheetApplicableState(StyleSheetHandle aSheet, } if (!mSSApplicableStateNotificationPending) { - nsCOMPtr notification = NewRunnableMethod(this, + nsCOMPtr notification = NS_NewRunnableMethod(this, &nsDocument::NotifyStyleSheetApplicableStateChanged); mSSApplicableStateNotificationPending = NS_SUCCEEDED(NS_DispatchToCurrentThread(notification)); @@ -4961,7 +4961,7 @@ nsDocument::MaybeEndOutermostXBLUpdate() BindingManager()->EndOutermostUpdate(); } else if (!mInDestructor) { nsContentUtils::AddScriptRunner( - NewRunnableMethod(this, &nsDocument::MaybeEndOutermostXBLUpdate)); + NS_NewRunnableMethod(this, &nsDocument::MaybeEndOutermostXBLUpdate)); } } } @@ -5279,7 +5279,7 @@ nsDocument::UnblockDOMContentLoaded() MOZ_ASSERT(mReadyState == READYSTATE_INTERACTIVE); if (!mSynchronousDOMContentLoaded) { nsCOMPtr ev = - NewRunnableMethod(this, &nsDocument::DispatchContentLoadedEvents); + NS_NewRunnableMethod(this, &nsDocument::DispatchContentLoadedEvents); NS_DispatchToCurrentThread(ev); } else { DispatchContentLoadedEvents(); @@ -7262,7 +7262,7 @@ nsDocument::NotifyPossibleTitleChange(bool aBoundTitleElement) return; RefPtr > event = - NewNonOwningRunnableMethod(this, + NS_NewNonOwningRunnableMethod(this, &nsDocument::DoNotifyPossibleTitleChange); nsresult rv = NS_DispatchToCurrentThread(event); if (NS_SUCCEEDED(rv)) { @@ -7411,7 +7411,7 @@ nsDocument::InitializeFrameLoader(nsFrameLoader* aLoader) mInitializableFrameLoaders.AppendElement(aLoader); if (!mFrameLoaderRunner) { mFrameLoaderRunner = - NewRunnableMethod(this, &nsDocument::MaybeInitializeFinalizeFrameLoaders); + NS_NewRunnableMethod(this, &nsDocument::MaybeInitializeFinalizeFrameLoaders); NS_ENSURE_TRUE(mFrameLoaderRunner, NS_ERROR_OUT_OF_MEMORY); nsContentUtils::AddScriptRunner(mFrameLoaderRunner); } @@ -7429,7 +7429,7 @@ nsDocument::FinalizeFrameLoader(nsFrameLoader* aLoader, nsIRunnable* aFinalizer) mFrameLoaderFinalizers.AppendElement(aFinalizer); if (!mFrameLoaderRunner) { mFrameLoaderRunner = - NewRunnableMethod(this, &nsDocument::MaybeInitializeFinalizeFrameLoaders); + NS_NewRunnableMethod(this, &nsDocument::MaybeInitializeFinalizeFrameLoaders); NS_ENSURE_TRUE(mFrameLoaderRunner, NS_ERROR_OUT_OF_MEMORY); nsContentUtils::AddScriptRunner(mFrameLoaderRunner); } @@ -7453,7 +7453,7 @@ nsDocument::MaybeInitializeFinalizeFrameLoaders() (mInitializableFrameLoaders.Length() || mFrameLoaderFinalizers.Length())) { mFrameLoaderRunner = - NewRunnableMethod(this, &nsDocument::MaybeInitializeFinalizeFrameLoaders); + NS_NewRunnableMethod(this, &nsDocument::MaybeInitializeFinalizeFrameLoaders); nsContentUtils::AddScriptRunner(mFrameLoaderRunner); } return; @@ -9064,7 +9064,7 @@ nsDocument::BlockOnload() ++mAsyncOnloadBlockCount; if (mAsyncOnloadBlockCount == 1) { bool success = nsContentUtils::AddScriptRunner( - NewRunnableMethod(this, &nsDocument::AsyncBlockOnload)); + NS_NewRunnableMethod(this, &nsDocument::AsyncBlockOnload)); // The script runner shouldn't fail to add. But if somebody broke // something and it does, we'll thrash at 100% cpu forever. The best @@ -12772,7 +12772,7 @@ nsDocument::GetVisibilityState() const nsDocument::PostVisibilityUpdateEvent() { nsCOMPtr event = - NewRunnableMethod(this, &nsDocument::UpdateVisibilityState); + NS_NewRunnableMethod(this, &nsDocument::UpdateVisibilityState); NS_DispatchToMainThread(event); } @@ -13503,7 +13503,7 @@ nsIDocument::RebuildUserFontSet() // change reflow). if (!mPostedFlushUserFontSet) { nsCOMPtr ev = - NewRunnableMethod(this, &nsIDocument::HandleRebuildUserFontSet); + NS_NewRunnableMethod(this, &nsIDocument::HandleRebuildUserFontSet); if (NS_SUCCEEDED(NS_DispatchToCurrentThread(ev))) { mPostedFlushUserFontSet = true; } diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index 485d6de21266..61fe3daea9f8 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -2494,7 +2494,7 @@ nsGlobalWindow::SetNewDocument(nsIDocument* aDocument, under normal circumstances, but bug 49615 describes a case.) */ nsContentUtils::AddScriptRunner( - NewRunnableMethod(this, &nsGlobalWindow::ClearStatus)); + NS_NewRunnableMethod(this, &nsGlobalWindow::ClearStatus)); // Sometimes, WouldReuseInnerWindow() returns true even if there's no inner // window (see bug 776497). Be safe. @@ -2799,8 +2799,8 @@ nsGlobalWindow::SetNewDocument(nsIDocument* aDocument, // up with the outer. See bug 969156. if (createdInnerWindow) { nsContentUtils::AddScriptRunner( - NewRunnableMethod(newInnerWindow, - &nsGlobalWindow::FireOnNewGlobalObject)); + NS_NewRunnableMethod(newInnerWindow, + &nsGlobalWindow::FireOnNewGlobalObject)); } if (newInnerWindow && !newInnerWindow->mHasNotifiedGlobalCreated && mDoc) { @@ -2813,7 +2813,7 @@ nsGlobalWindow::SetNewDocument(nsIDocument* aDocument, nsContentUtils::IsSystemPrincipal(mDoc->NodePrincipal())) { newInnerWindow->mHasNotifiedGlobalCreated = true; nsContentUtils::AddScriptRunner( - NewRunnableMethod(this, &nsGlobalWindow::DispatchDOMWindowCreated)); + NS_NewRunnableMethod(this, &nsGlobalWindow::DispatchDOMWindowCreated)); } } @@ -11476,7 +11476,7 @@ public: ~AutoUnblockScriptClosing() { void (nsGlobalWindow::*run)() = &nsGlobalWindow::UnblockScriptedClosing; - NS_DispatchToCurrentThread(NewRunnableMethod(mWin, run)); + NS_DispatchToCurrentThread(NS_NewRunnableMethod(mWin, run)); } }; diff --git a/dom/base/nsScriptLoader.cpp b/dom/base/nsScriptLoader.cpp index 0556a42c00ae..7770c01f8842 100644 --- a/dom/base/nsScriptLoader.cpp +++ b/dom/base/nsScriptLoader.cpp @@ -503,8 +503,8 @@ nsScriptLoader::ProcessScriptElement(nsIScriptElement *aElement) if (!scriptURI) { // Asynchronously report the failure to create a URI object NS_DispatchToCurrentThread( - NewRunnableMethod(aElement, - &nsIScriptElement::FireErrorEvent)); + NS_NewRunnableMethod(aElement, + &nsIScriptElement::FireErrorEvent)); return false; } @@ -570,8 +570,8 @@ nsScriptLoader::ProcessScriptElement(nsIScriptElement *aElement) if (NS_FAILED(rv)) { // Asynchronously report the load failure NS_DispatchToCurrentThread( - NewRunnableMethod(aElement, - &nsIScriptElement::FireErrorEvent)); + NS_NewRunnableMethod(aElement, + &nsIScriptElement::FireErrorEvent)); return false; } } @@ -1150,8 +1150,10 @@ void nsScriptLoader::ProcessPendingRequestsAsync() { if (mParserBlockingRequest || !mPendingChildLoaders.IsEmpty()) { - NS_DispatchToCurrentThread(NewRunnableMethod(this, - &nsScriptLoader::ProcessPendingRequests)); + nsCOMPtr ev = NS_NewRunnableMethod(this, + &nsScriptLoader::ProcessPendingRequests); + + NS_DispatchToCurrentThread(ev); } } diff --git a/dom/base/nsTextNode.cpp b/dom/base/nsTextNode.cpp index 25c2d3525678..2ee7b82b158b 100644 --- a/dom/base/nsTextNode.cpp +++ b/dom/base/nsTextNode.cpp @@ -273,7 +273,8 @@ nsAttributeTextNode::AttributeChanged(nsIDocument* aDocument, // that if we get unbound while the event is up that's ok -- we'll just // have no grandparent when it fires, and will do nothing. void (nsAttributeTextNode::*update)() = &nsAttributeTextNode::UpdateText; - nsContentUtils::AddScriptRunner(NewRunnableMethod(this, update)); + nsCOMPtr ev = NS_NewRunnableMethod(this, update); + nsContentUtils::AddScriptRunner(ev); } } diff --git a/dom/cache/Context.cpp b/dom/cache/Context.cpp index a27287af82f9..4c778c3aa1fa 100644 --- a/dom/cache/Context.cpp +++ b/dom/cache/Context.cpp @@ -740,7 +740,7 @@ Context::ThreadsafeHandle::AllowToClose() // Dispatch is guaranteed to succeed here because we block shutdown until // all Contexts have been destroyed. nsCOMPtr runnable = - NewRunnableMethod(this, &ThreadsafeHandle::AllowToCloseOnOwningThread); + NS_NewRunnableMethod(this, &ThreadsafeHandle::AllowToCloseOnOwningThread); MOZ_ALWAYS_SUCCEEDS( mOwningThread->Dispatch(runnable, nsIThread::DISPATCH_NORMAL)); } @@ -756,7 +756,7 @@ Context::ThreadsafeHandle::InvalidateAndAllowToClose() // Dispatch is guaranteed to succeed here because we block shutdown until // all Contexts have been destroyed. nsCOMPtr runnable = - NewRunnableMethod(this, &ThreadsafeHandle::InvalidateAndAllowToCloseOnOwningThread); + NS_NewRunnableMethod(this, &ThreadsafeHandle::InvalidateAndAllowToCloseOnOwningThread); MOZ_ALWAYS_SUCCEEDS( mOwningThread->Dispatch(runnable, nsIThread::DISPATCH_NORMAL)); } @@ -780,7 +780,10 @@ Context::ThreadsafeHandle::~ThreadsafeHandle() // Dispatch is guaranteed to succeed here because we block shutdown until // all Contexts have been destroyed. - NS_ProxyRelease(mOwningThread, mStrongRef.forget()); + nsCOMPtr runnable = + NS_NewNonOwningRunnableMethod(mStrongRef.forget().take(), &Context::Release); + MOZ_ALWAYS_SUCCEEDS( + mOwningThread->Dispatch(runnable, nsIThread::DISPATCH_NORMAL)); } void diff --git a/dom/cache/Manager.cpp b/dom/cache/Manager.cpp index c60ccb901ef6..7eff4a057f79 100644 --- a/dom/cache/Manager.cpp +++ b/dom/cache/Manager.cpp @@ -912,7 +912,7 @@ private: // May be on any thread, including STS event target. Non-owning runnable // here since we are guaranteed the Action will survive until // CompleteOnInitiatingThread is called. - nsCOMPtr runnable = NewNonOwningRunnableMethod( + nsCOMPtr runnable = NS_NewNonOwningRunnableMethodWithArgs( this, &CachePutAllAction::OnAsyncCopyComplete, aRv); MOZ_ALWAYS_SUCCEEDS( mTargetThread->Dispatch(runnable, nsIThread::DISPATCH_NORMAL)); @@ -1761,7 +1761,9 @@ Manager::~Manager() // Don't spin the event loop in the destructor waiting for the thread to // shutdown. Defer this to the main thread, instead. - MOZ_ALWAYS_SUCCEEDS(NS_DispatchToMainThread(NewRunnableMethod(ioThread, &nsIThread::Shutdown))); + nsCOMPtr runnable = + NS_NewRunnableMethod(ioThread, &nsIThread::Shutdown); + MOZ_ALWAYS_SUCCEEDS(NS_DispatchToMainThread(runnable)); } void diff --git a/dom/camera/CameraPreviewMediaStream.cpp b/dom/camera/CameraPreviewMediaStream.cpp index 0233c5e518f3..32af686eac3a 100644 --- a/dom/camera/CameraPreviewMediaStream.cpp +++ b/dom/camera/CameraPreviewMediaStream.cpp @@ -171,7 +171,9 @@ CameraPreviewMediaStream::SetCurrentFrame(const gfx::IntSize& aIntrinsicSize, Im ++mInvalidatePending; } - NS_DispatchToMainThread(NewRunnableMethod(this, &CameraPreviewMediaStream::Invalidate)); + nsCOMPtr event = + NS_NewRunnableMethod(this, &CameraPreviewMediaStream::Invalidate); + NS_DispatchToMainThread(event); } void @@ -182,7 +184,9 @@ CameraPreviewMediaStream::ClearCurrentFrame() for (nsTArray >::size_type i = 0; i < mVideoOutputs.Length(); ++i) { VideoFrameContainer* output = mVideoOutputs[i]; output->ClearCurrentFrame(); - NS_DispatchToMainThread(NewRunnableMethod(output, &VideoFrameContainer::Invalidate)); + nsCOMPtr event = + NS_NewRunnableMethod(output, &VideoFrameContainer::Invalidate); + NS_DispatchToMainThread(event); } } diff --git a/dom/camera/DOMCameraControl.cpp b/dom/camera/DOMCameraControl.cpp index 2505bf28d07c..f34055b22275 100755 --- a/dom/camera/DOMCameraControl.cpp +++ b/dom/camera/DOMCameraControl.cpp @@ -73,8 +73,10 @@ public: TrackID aInputTrackID) override { if (aTrackEvents & TRACK_EVENT_CREATED) { - aGraph->DispatchToMainThreadAfterStreamStateUpdate(NewRunnableMethod( - this, &TrackCreatedListener::DoNotifyTrackCreated, aID)); + nsCOMPtr runnable = + NS_NewRunnableMethodWithArgs( + this, &TrackCreatedListener::DoNotifyTrackCreated, aID); + aGraph->DispatchToMainThreadAfterStreamStateUpdate(runnable.forget()); } } diff --git a/dom/camera/DOMCameraManager.cpp b/dom/camera/DOMCameraManager.cpp index 68054dc5db7d..8583494c104d 100644 --- a/dom/camera/DOMCameraManager.cpp +++ b/dom/camera/DOMCameraManager.cpp @@ -233,11 +233,11 @@ CameraPermissionRequest::DispatchCallback(uint32_t aPermission) { nsCOMPtr callbackRunnable; if (aPermission == nsIPermissionManager::ALLOW_ACTION) { - callbackRunnable = NewRunnableMethod(this, &CameraPermissionRequest::CallAllow); + callbackRunnable = NS_NewRunnableMethod(this, &CameraPermissionRequest::CallAllow); } else { - callbackRunnable = NewRunnableMethod(this, &CameraPermissionRequest::CallCancel); + callbackRunnable = NS_NewRunnableMethod(this, &CameraPermissionRequest::CallCancel); } - return NS_DispatchToMainThread(callbackRunnable.forget()); + return NS_DispatchToMainThread(callbackRunnable); } void diff --git a/dom/devicestorage/DeviceStorageStatics.cpp b/dom/devicestorage/DeviceStorageStatics.cpp index b8de88f5ff70..f02d904fdce5 100644 --- a/dom/devicestorage/DeviceStorageStatics.cpp +++ b/dom/devicestorage/DeviceStorageStatics.cpp @@ -488,7 +488,7 @@ DeviceStorageStatics::AddListener(nsDOMDeviceStorage* aListener) MOZ_ASSERT(sInstance->mInitialized); if (sInstance->mListeners.IsEmpty()) { NS_DispatchToMainThread( - NewRunnableMethod(sInstance.get(), &DeviceStorageStatics::Register)); + NS_NewRunnableMethod(sInstance.get(), &DeviceStorageStatics::Register)); } RefPtr wrapper = @@ -519,7 +519,7 @@ DeviceStorageStatics::RemoveListener(nsDOMDeviceStorage* aListener) if (removed && sInstance->mListeners.IsEmpty()) { NS_DispatchToMainThread( - NewRunnableMethod(sInstance.get(), &DeviceStorageStatics::Deregister)); + NS_NewRunnableMethod(sInstance.get(), &DeviceStorageStatics::Deregister)); } } diff --git a/dom/events/EventListenerService.cpp b/dom/events/EventListenerService.cpp index 9b154d4ed228..dee437b4223f 100644 --- a/dom/events/EventListenerService.cpp +++ b/dom/events/EventListenerService.cpp @@ -371,8 +371,9 @@ EventListenerService::NotifyAboutMainThreadListenerChangeInternal(dom::EventTarg if (!mPendingListenerChanges) { mPendingListenerChanges = nsArrayBase::Create(); - NS_DispatchToCurrentThread(NewRunnableMethod(this, - &EventListenerService::NotifyPendingChanges)); + nsCOMPtr runnable = NS_NewRunnableMethod(this, + &EventListenerService::NotifyPendingChanges); + NS_DispatchToCurrentThread(runnable); } RefPtr changes = mPendingListenerChangesSet.Get(aTarget); diff --git a/dom/fetch/FetchDriver.cpp b/dom/fetch/FetchDriver.cpp index 4c4eb08b10a9..e036346894d3 100644 --- a/dom/fetch/FetchDriver.cpp +++ b/dom/fetch/FetchDriver.cpp @@ -83,7 +83,9 @@ FetchDriver::Fetch(FetchDriverObserver* aObserver) MOZ_RELEASE_ASSERT(!mRequest->IsSynchronous(), "Synchronous fetch not supported"); - return NS_DispatchToCurrentThread(NewRunnableMethod(this, &FetchDriver::ContinueFetch)); + nsCOMPtr r = + NS_NewRunnableMethod(this, &FetchDriver::ContinueFetch); + return NS_DispatchToCurrentThread(r); } nsresult diff --git a/dom/html/HTMLCanvasElement.cpp b/dom/html/HTMLCanvasElement.cpp index d61fbd8ae36e..835a114f6e89 100644 --- a/dom/html/HTMLCanvasElement.cpp +++ b/dom/html/HTMLCanvasElement.cpp @@ -223,7 +223,7 @@ HTMLCanvasPrintState::Done() mCanvas->InvalidateCanvas(); } RefPtr > doneEvent = - NewRunnableMethod(this, &HTMLCanvasPrintState::NotifyDone); + NS_NewRunnableMethod(this, &HTMLCanvasPrintState::NotifyDone); if (NS_SUCCEEDED(NS_DispatchToCurrentThread(doneEvent))) { mPendingNotify = true; } @@ -503,7 +503,7 @@ HTMLCanvasElement::DispatchPrintCallback(nsITimerCallback* aCallback) mPrintState = new HTMLCanvasPrintState(this, mCurrentContext, aCallback); RefPtr > renderEvent = - NewRunnableMethod(this, &HTMLCanvasElement::CallPrintCallback); + NS_NewRunnableMethod(this, &HTMLCanvasElement::CallPrintCallback); return NS_DispatchToCurrentThread(renderEvent); } diff --git a/dom/html/HTMLImageElement.cpp b/dom/html/HTMLImageElement.cpp index c5d45f5f9d4b..645ea14071db 100644 --- a/dom/html/HTMLImageElement.cpp +++ b/dom/html/HTMLImageElement.cpp @@ -618,7 +618,7 @@ HTMLImageElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent, // loading. if (LoadingEnabled()) { nsContentUtils::AddScriptRunner( - NewRunnableMethod(this, &HTMLImageElement::MaybeLoadImage)); + NS_NewRunnableMethod(this, &HTMLImageElement::MaybeLoadImage)); } } @@ -825,7 +825,7 @@ HTMLImageElement::CopyInnerTo(Element* aDest) if (!dest->InResponsiveMode() && dest->HasAttr(kNameSpaceID_None, nsGkAtoms::src)) { nsContentUtils::AddScriptRunner( - NewRunnableMethod(dest, &HTMLImageElement::MaybeLoadImage)); + NS_NewRunnableMethod(dest, &HTMLImageElement::MaybeLoadImage)); } } diff --git a/dom/html/HTMLInputElement.cpp b/dom/html/HTMLInputElement.cpp index d6a3bd04d075..fae89d3aa64f 100644 --- a/dom/html/HTMLInputElement.cpp +++ b/dom/html/HTMLInputElement.cpp @@ -4354,7 +4354,7 @@ HTMLInputElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent, ClearBrokenState(); RemoveStatesSilently(NS_EVENT_STATE_BROKEN); nsContentUtils::AddScriptRunner( - NewRunnableMethod(this, &HTMLInputElement::MaybeLoadImage)); + NS_NewRunnableMethod(this, &HTMLInputElement::MaybeLoadImage)); } } diff --git a/dom/html/HTMLLinkElement.cpp b/dom/html/HTMLLinkElement.cpp index 8de01a6f08bf..ab7a37d9ee1c 100644 --- a/dom/html/HTMLLinkElement.cpp +++ b/dom/html/HTMLLinkElement.cpp @@ -184,10 +184,10 @@ HTMLLinkElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent, } void (HTMLLinkElement::*update)() = &HTMLLinkElement::UpdateStyleSheetInternal; - nsContentUtils::AddScriptRunner(NewRunnableMethod(this, update)); + nsContentUtils::AddScriptRunner(NS_NewRunnableMethod(this, update)); void (HTMLLinkElement::*updateImport)() = &HTMLLinkElement::UpdateImport; - nsContentUtils::AddScriptRunner(NewRunnableMethod(this, updateImport)); + nsContentUtils::AddScriptRunner(NS_NewRunnableMethod(this, updateImport)); CreateAndDispatchEvent(aDocument, NS_LITERAL_STRING("DOMLinkAdded")); diff --git a/dom/html/HTMLMediaElement.cpp b/dom/html/HTMLMediaElement.cpp index 66990d5f35ec..373bb4cf140f 100644 --- a/dom/html/HTMLMediaElement.cpp +++ b/dom/html/HTMLMediaElement.cpp @@ -842,8 +842,8 @@ void HTMLMediaElement::QueueLoadFromSourceTask() { ChangeDelayLoadStatus(true); ChangeNetworkState(nsIDOMHTMLMediaElement::NETWORK_LOADING); - RefPtr r = NewRunnableMethod(this, &HTMLMediaElement::LoadFromSourceChildren); - RunInStableState(r); + RunInStableState( + NS_NewRunnableMethod(this, &HTMLMediaElement::LoadFromSourceChildren)); } void HTMLMediaElement::QueueSelectResourceTask() @@ -853,8 +853,8 @@ void HTMLMediaElement::QueueSelectResourceTask() return; mHaveQueuedSelectResource = true; ChangeNetworkState(nsIDOMHTMLMediaElement::NETWORK_NO_SOURCE); - RefPtr r = NewRunnableMethod(this, &HTMLMediaElement::SelectResourceWrapper); - RunInStableState(r); + RunInStableState( + NS_NewRunnableMethod(this, &HTMLMediaElement::SelectResourceWrapper)); } NS_IMETHODIMP HTMLMediaElement::Load() @@ -3186,9 +3186,9 @@ public: { nsCOMPtr event; if (aBlocked == BLOCKED) { - event = NewRunnableMethod(this, &StreamListener::DoNotifyBlocked); + event = NS_NewRunnableMethod(this, &StreamListener::DoNotifyBlocked); } else { - event = NewRunnableMethod(this, &StreamListener::DoNotifyUnblocked); + event = NS_NewRunnableMethod(this, &StreamListener::DoNotifyUnblocked); } aGraph->DispatchToMainThreadAfterStreamStateUpdate(event.forget()); } @@ -3197,7 +3197,7 @@ public: { if (event == EVENT_FINISHED) { nsCOMPtr event = - NewRunnableMethod(this, &StreamListener::DoNotifyFinished); + NS_NewRunnableMethod(this, &StreamListener::DoNotifyFinished); aGraph->DispatchToMainThreadAfterStreamStateUpdate(event.forget()); } } @@ -3205,7 +3205,7 @@ public: { MutexAutoLock lock(mMutex); nsCOMPtr event = - NewRunnableMethod(this, &StreamListener::DoNotifyHaveCurrentData); + NS_NewRunnableMethod(this, &StreamListener::DoNotifyHaveCurrentData); aGraph->DispatchToMainThreadAfterStreamStateUpdate(event.forget()); } virtual void NotifyOutput(MediaStreamGraph* aGraph, @@ -3216,7 +3216,7 @@ public: return; mPendingNotifyOutput = true; nsCOMPtr event = - NewRunnableMethod(this, &StreamListener::DoNotifyOutput); + NS_NewRunnableMethod(this, &StreamListener::DoNotifyOutput); aGraph->DispatchToMainThreadAfterStreamStateUpdate(event.forget()); } @@ -3268,7 +3268,7 @@ public: if (c->mFrame.GetIntrinsicSize() != gfx::IntSize(0,0)) { mInitialSizeFound = true; nsCOMPtr event = - NewRunnableMethod( + NS_NewRunnableMethodWithArgs( this, &StreamSizeListener::ReceivedSize, c->mFrame.GetIntrinsicSize()); aGraph->DispatchToMainThreadAfterStreamStateUpdate(event.forget()); @@ -4622,7 +4622,7 @@ void HTMLMediaElement::AddRemoveSelfReference() // Dispatch Release asynchronously so that we don't destroy this object // inside a call stack of method calls on this object nsCOMPtr event = - NewRunnableMethod(this, &HTMLMediaElement::DoRemoveSelfReference); + NS_NewRunnableMethod(this, &HTMLMediaElement::DoRemoveSelfReference); NS_DispatchToMainThread(event); } } diff --git a/dom/html/HTMLObjectElement.cpp b/dom/html/HTMLObjectElement.cpp index 1f2fda346d12..543c5dc09367 100644 --- a/dom/html/HTMLObjectElement.cpp +++ b/dom/html/HTMLObjectElement.cpp @@ -280,7 +280,7 @@ HTMLObjectElement::BindToTree(nsIDocument *aDocument, // If we already have all the children, start the load. if (mIsDoneAddingChildren && !pluginDoc) { void (HTMLObjectElement::*start)() = &HTMLObjectElement::StartObjectLoad; - nsContentUtils::AddScriptRunner(NewRunnableMethod(this, start)); + nsContentUtils::AddScriptRunner(NS_NewRunnableMethod(this, start)); } return NS_OK; diff --git a/dom/html/HTMLSharedObjectElement.cpp b/dom/html/HTMLSharedObjectElement.cpp index 3b2c793fdbb0..54e1bf22740c 100644 --- a/dom/html/HTMLSharedObjectElement.cpp +++ b/dom/html/HTMLSharedObjectElement.cpp @@ -153,7 +153,7 @@ HTMLSharedObjectElement::BindToTree(nsIDocument *aDocument, if (mIsDoneAddingChildren && !pluginDoc) { void (HTMLSharedObjectElement::*start)() = &HTMLSharedObjectElement::StartObjectLoad; - nsContentUtils::AddScriptRunner(NewRunnableMethod(this, start)); + nsContentUtils::AddScriptRunner(NS_NewRunnableMethod(this, start)); } return NS_OK; diff --git a/dom/html/HTMLStyleElement.cpp b/dom/html/HTMLStyleElement.cpp index ba44c9600cf8..ec690fc0b4d1 100644 --- a/dom/html/HTMLStyleElement.cpp +++ b/dom/html/HTMLStyleElement.cpp @@ -147,7 +147,7 @@ HTMLStyleElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent, NS_ENSURE_SUCCESS(rv, rv); void (HTMLStyleElement::*update)() = &HTMLStyleElement::UpdateStyleSheetInternal; - nsContentUtils::AddScriptRunner(NewRunnableMethod(this, update)); + nsContentUtils::AddScriptRunner(NS_NewRunnableMethod(this, update)); return rv; } diff --git a/dom/html/HTMLTrackElement.cpp b/dom/html/HTMLTrackElement.cpp index 7f2982688afa..5a660b1d35f3 100644 --- a/dom/html/HTMLTrackElement.cpp +++ b/dom/html/HTMLTrackElement.cpp @@ -260,8 +260,8 @@ HTMLTrackElement::BindToTree(nsIDocument* aDocument, media->NotifyAddedSource(); LOG(LogLevel::Debug, ("Track element sent notification to parent.")); - RefPtr r = NewRunnableMethod(this, &HTMLTrackElement::LoadResource); - mMediaParent->RunInStableState(r); + mMediaParent->RunInStableState( + NS_NewRunnableMethod(this, &HTMLTrackElement::LoadResource)); } return NS_OK; @@ -314,7 +314,7 @@ void HTMLTrackElement::DispatchTrackRunnable(const nsString& aEventName) { nsCOMPtr runnable = - NewRunnableMethod + NS_NewRunnableMethodWithArg (this, &HTMLTrackElement::DispatchTrustedEvent, aEventName); diff --git a/dom/html/ImageDocument.cpp b/dom/html/ImageDocument.cpp index 11d55a8e78dd..2087bf56756c 100644 --- a/dom/html/ImageDocument.cpp +++ b/dom/html/ImageDocument.cpp @@ -491,7 +491,7 @@ ImageDocument::Notify(imgIRequest* aRequest, int32_t aType, const nsIntRect* aDa // come during painting and this will trigger invalidation. if (aType == imgINotificationObserver::HAS_TRANSPARENCY) { nsCOMPtr runnable = - NewRunnableMethod(this, &ImageDocument::OnHasTransparency); + NS_NewRunnableMethod(this, &ImageDocument::OnHasTransparency); nsContentUtils::AddScriptRunner(runnable); } @@ -554,7 +554,7 @@ ImageDocument::OnSizeAvailable(imgIRequest* aRequest, imgIContainer* aImage) aImage->GetHeight(&mImageHeight); nsCOMPtr runnable = - NewRunnableMethod(this, &ImageDocument::DefaultCheckOverflowing); + NS_NewRunnableMethod(this, &ImageDocument::DefaultCheckOverflowing); nsContentUtils::AddScriptRunner(runnable); UpdateTitleAndCharset(); diff --git a/dom/html/nsHTMLDocument.cpp b/dom/html/nsHTMLDocument.cpp index a22286f98ae7..fb8c2eeb5260 100644 --- a/dom/html/nsHTMLDocument.cpp +++ b/dom/html/nsHTMLDocument.cpp @@ -2505,7 +2505,7 @@ nsHTMLDocument::MaybeEditingStateChanged() EditingStateChanged(); } else if (!mInDestructor) { nsContentUtils::AddScriptRunner( - NewRunnableMethod(this, &nsHTMLDocument::MaybeEditingStateChanged)); + NS_NewRunnableMethod(this, &nsHTMLDocument::MaybeEditingStateChanged)); } } } diff --git a/dom/indexedDB/ActorsParent.cpp b/dom/indexedDB/ActorsParent.cpp index fa0653dcb82e..1c3510686a3a 100644 --- a/dom/indexedDB/ActorsParent.cpp +++ b/dom/indexedDB/ActorsParent.cpp @@ -11823,7 +11823,7 @@ ConnectionPool::ShutdownThread(ThreadInfo& aThreadInfo) MOZ_ALWAYS_SUCCEEDS(thread->Dispatch(runnable, NS_DISPATCH_NORMAL)); nsCOMPtr shutdownRunnable = - NewRunnableMethod(thread, &nsIThread::Shutdown); + NS_NewRunnableMethod(thread, &nsIThread::Shutdown); MOZ_ALWAYS_SUCCEEDS(NS_DispatchToMainThread(shutdownRunnable)); mTotalThreadCount--; @@ -13668,7 +13668,7 @@ Database::MaybeCloseConnection() IsClosed() && mDirectoryLock) { nsCOMPtr callback = - NewRunnableMethod(this, &Database::ConnectionClosedCallback); + NS_NewRunnableMethod(this, &Database::ConnectionClosedCallback); RefPtr helper = new WaitForTransactionsHelper(Id(), callback); @@ -21414,7 +21414,7 @@ OpenDatabaseOp::SendResults() mDatabase = nullptr; } else if (mDirectoryLock) { nsCOMPtr callback = - NewRunnableMethod(this, &OpenDatabaseOp::ConnectionClosedCallback); + NS_NewRunnableMethod(this, &OpenDatabaseOp::ConnectionClosedCallback); RefPtr helper = new WaitForTransactionsHelper(mDatabaseId, callback); diff --git a/dom/indexedDB/FileSnapshot.cpp b/dom/indexedDB/FileSnapshot.cpp index f4f0d6dd57c3..3faecdd62e24 100644 --- a/dom/indexedDB/FileSnapshot.cpp +++ b/dom/indexedDB/FileSnapshot.cpp @@ -87,7 +87,7 @@ private: } nsCOMPtr destroyRunnable = - NewNonOwningRunnableMethod(this, &StreamWrapper::Destroy); + NS_NewNonOwningRunnableMethod(this, &StreamWrapper::Destroy); MOZ_ALWAYS_SUCCEEDS(mOwningThread->Dispatch(destroyRunnable, NS_DISPATCH_NORMAL)); diff --git a/dom/indexedDB/IDBDatabase.cpp b/dom/indexedDB/IDBDatabase.cpp index 2f934c9d4ebb..d056486347c8 100644 --- a/dom/indexedDB/IDBDatabase.cpp +++ b/dom/indexedDB/IDBDatabase.cpp @@ -1036,9 +1036,9 @@ IDBDatabase::DelayedMaybeExpireFileActors() } nsCOMPtr runnable = - NewRunnableMethod(this, - &IDBDatabase::ExpireFileActors, - /* aExpireAll */ false); + NS_NewRunnableMethodWithArg(this, + &IDBDatabase::ExpireFileActors, + /* aExpireAll */ false); MOZ_ASSERT(runnable); if (!NS_IsMainThread()) { diff --git a/dom/ipc/Blob.cpp b/dom/ipc/Blob.cpp index 994113912278..1701609e9b5c 100644 --- a/dom/ipc/Blob.cpp +++ b/dom/ipc/Blob.cpp @@ -293,7 +293,7 @@ ReleaseOnTarget(SmartPtr& aDoomed, nsIEventTarget* aTarget) auto* doomedSupports = static_cast(doomedRaw); nsCOMPtr releaseRunnable = - NewNonOwningRunnableMethod(doomedSupports, &nsISupports::Release); + NS_NewNonOwningRunnableMethod(doomedSupports, &nsISupports::Release); MOZ_ASSERT(releaseRunnable); if (aTarget) { @@ -1600,7 +1600,11 @@ private: NS_WARN_IF_FALSE(NS_SUCCEEDED(stream->Close()), "Failed to close stream!"); - MOZ_ALWAYS_SUCCEEDS(NS_DispatchToMainThread(NewRunnableMethod(ioTarget, &nsIThread::Shutdown))); + nsCOMPtr shutdownRunnable = + NS_NewRunnableMethod(ioTarget, &nsIThread::Shutdown); + MOZ_ASSERT(shutdownRunnable); + + MOZ_ALWAYS_SUCCEEDS(NS_DispatchToMainThread(shutdownRunnable)); return NS_OK; } @@ -2134,7 +2138,7 @@ RemoteBlobImpl::Destroy() } nsCOMPtr destroyRunnable = - NewNonOwningRunnableMethod(this, &RemoteBlobImpl::Destroy); + NS_NewNonOwningRunnableMethod(this, &RemoteBlobImpl::Destroy); if (mActorTarget) { destroyRunnable = @@ -2562,7 +2566,7 @@ RemoteBlobImpl::Destroy() } nsCOMPtr destroyRunnable = - NewNonOwningRunnableMethod(this, &RemoteBlobImpl::Destroy); + NS_NewNonOwningRunnableMethod(this, &RemoteBlobImpl::Destroy); if (mActorTarget) { destroyRunnable = @@ -3418,7 +3422,7 @@ BlobChild::NoteDyingRemoteBlobImpl() // on the owning thread, so we proxy here if necessary. if (!IsOnOwningThread()) { nsCOMPtr runnable = - NewNonOwningRunnableMethod(this, &BlobChild::NoteDyingRemoteBlobImpl); + NS_NewNonOwningRunnableMethod(this, &BlobChild::NoteDyingRemoteBlobImpl); if (mEventTarget) { runnable = new CancelableRunnableWrapper(runnable, mEventTarget); @@ -3997,7 +4001,7 @@ BlobParent::NoteDyingRemoteBlobImpl() // on the main thread, so we proxy here if necessary. if (!IsOnOwningThread()) { nsCOMPtr runnable = - NewNonOwningRunnableMethod(this, &BlobParent::NoteDyingRemoteBlobImpl); + NS_NewNonOwningRunnableMethod(this, &BlobParent::NoteDyingRemoteBlobImpl); if (mEventTarget) { runnable = new CancelableRunnableWrapper(runnable, mEventTarget); diff --git a/dom/ipc/ContentBridgeChild.cpp b/dom/ipc/ContentBridgeChild.cpp index d40d9d5a2d66..6d6b4f44bb2b 100644 --- a/dom/ipc/ContentBridgeChild.cpp +++ b/dom/ipc/ContentBridgeChild.cpp @@ -34,7 +34,8 @@ ContentBridgeChild::~ContentBridgeChild() void ContentBridgeChild::ActorDestroy(ActorDestroyReason aWhy) { - MessageLoop::current()->PostTask(NewRunnableMethod(this, &ContentBridgeChild::DeferredDestroy)); + RefPtr runnable = NS_NewRunnableMethod(this, &ContentBridgeChild::DeferredDestroy); + MessageLoop::current()->PostTask(runnable.forget()); } /*static*/ ContentBridgeChild* diff --git a/dom/ipc/ContentBridgeParent.cpp b/dom/ipc/ContentBridgeParent.cpp index e71febd056f3..7fd22c7a51a6 100644 --- a/dom/ipc/ContentBridgeParent.cpp +++ b/dom/ipc/ContentBridgeParent.cpp @@ -37,7 +37,8 @@ ContentBridgeParent::ActorDestroy(ActorDestroyReason aWhy) if (os) { os->RemoveObserver(this, "content-child-shutdown"); } - MessageLoop::current()->PostTask(NewRunnableMethod(this, &ContentBridgeParent::DeferredDestroy)); + RefPtr runnable = NS_NewRunnableMethod(this, &ContentBridgeParent::DeferredDestroy); + MessageLoop::current()->PostTask(runnable.forget()); } /*static*/ ContentBridgeParent* @@ -167,7 +168,8 @@ ContentBridgeParent::NotifyTabDestroyed() { int32_t numLiveTabs = ManagedPBrowserParent().Count(); if (numLiveTabs == 1) { - MessageLoop::current()->PostTask(NewRunnableMethod(this, &ContentBridgeParent::Close)); + RefPtr runnable = NS_NewRunnableMethod(this, &ContentBridgeParent::Close); + MessageLoop::current()->PostTask(runnable.forget()); } } diff --git a/dom/ipc/ContentBridgeParent.h b/dom/ipc/ContentBridgeParent.h index 18c46d4325ea..abff80392b20 100644 --- a/dom/ipc/ContentBridgeParent.h +++ b/dom/ipc/ContentBridgeParent.h @@ -81,7 +81,7 @@ protected: void Close() { - // Trick NewRunnableMethod + // Trick NS_NewRunnableMethod PContentBridgeParent::Close(); } diff --git a/dom/ipc/ContentParent.cpp b/dom/ipc/ContentParent.cpp index dd357fbb705d..3ad093c2165e 100644 --- a/dom/ipc/ContentParent.cpp +++ b/dom/ipc/ContentParent.cpp @@ -2177,10 +2177,10 @@ ContentParent::ActorDestroy(ActorDestroyReason why) // Destroy any processes created by this ContentParent for(uint32_t i = 0; i < childIDArray.Length(); i++) { ContentParent* cp = cpm->GetContentProcessById(childIDArray[i]); - MessageLoop::current()->PostTask(NewRunnableMethod - (cp, - &ContentParent::ShutDownProcess, - SEND_SHUTDOWN_MESSAGE)); + RefPtr runnable = + NS_NewRunnableMethodWithArgs(cp, &ContentParent::ShutDownProcess, + SEND_SHUTDOWN_MESSAGE); + MessageLoop::current()->PostTask(runnable.forget()); } cpm->RemoveContentProcess(this->ChildID()); @@ -2261,10 +2261,10 @@ ContentParent::NotifyTabDestroyed(const TabId& aTabId, if (tabIds.Length() == 1) { // In the case of normal shutdown, send a shutdown message to child to // allow it to perform shutdown tasks. - MessageLoop::current()->PostTask(NewRunnableMethod - (this, - &ContentParent::ShutDownProcess, - SEND_SHUTDOWN_MESSAGE)); + RefPtr runnable = + NS_NewRunnableMethodWithArgs(this, &ContentParent::ShutDownProcess, + SEND_SHUTDOWN_MESSAGE); + MessageLoop::current()->PostTask(runnable.forget()); } } diff --git a/dom/ipc/PreallocatedProcessManager.cpp b/dom/ipc/PreallocatedProcessManager.cpp index 8486d7e35a69..edb438aeca86 100644 --- a/dom/ipc/PreallocatedProcessManager.cpp +++ b/dom/ipc/PreallocatedProcessManager.cpp @@ -204,8 +204,9 @@ PreallocatedProcessManagerImpl::AllocateAfterDelay() return; } + RefPtr runnable = NS_NewRunnableMethod(this, &PreallocatedProcessManagerImpl::AllocateOnIdle); MessageLoop::current()->PostDelayedTask( - NewRunnableMethod(this, &PreallocatedProcessManagerImpl::AllocateOnIdle), + runnable.forget(), Preferences::GetUint("dom.ipc.processPrelaunch.delayMs", DEFAULT_ALLOCATE_DELAY)); } @@ -217,7 +218,8 @@ PreallocatedProcessManagerImpl::AllocateOnIdle() return; } - MessageLoop::current()->PostIdleTask(NewRunnableMethod(this, &PreallocatedProcessManagerImpl::AllocateNow)); + RefPtr runnable = NS_NewRunnableMethod(this, &PreallocatedProcessManagerImpl::AllocateNow); + MessageLoop::current()->PostIdleTask(runnable.forget()); } void diff --git a/dom/ipc/ProcessHangMonitor.cpp b/dom/ipc/ProcessHangMonitor.cpp index c7171ee78f4f..c26436cdcdfa 100644 --- a/dom/ipc/ProcessHangMonitor.cpp +++ b/dom/ipc/ProcessHangMonitor.cpp @@ -287,7 +287,8 @@ HangMonitorChild::ActorDestroy(ActorDestroyReason aWhy) // We use a task here to ensure that IPDL is finished with this // HangMonitorChild before it gets deleted on the main thread. - MonitorLoop()->PostTask(NewNonOwningRunnableMethod(this, &HangMonitorChild::ShutdownOnThread)); + RefPtr runnable = NS_NewNonOwningRunnableMethod(this, &HangMonitorChild::ShutdownOnThread); + MonitorLoop()->PostTask(runnable.forget()); } bool @@ -373,10 +374,14 @@ HangMonitorChild::NotifySlowScript(nsITabChild* aTabChild, } nsAutoCString filename(aFileName); - MonitorLoop()->PostTask(NewNonOwningRunnableMethod - (this, - &HangMonitorChild::NotifySlowScriptAsync, - id, filename, aLineNo)); + RefPtr runnable = + NS_NewNonOwningRunnableMethodWithArgs(this, + &HangMonitorChild::NotifySlowScriptAsync, + id, filename, aLineNo); + MonitorLoop()->PostTask(runnable.forget()); + return SlowScriptAction::Continue; } @@ -404,9 +409,11 @@ HangMonitorChild::NotifyPluginHang(uint32_t aPluginId) mSentReport = true; // bounce to background thread - MonitorLoop()->PostTask(NewNonOwningRunnableMethod(this, - &HangMonitorChild::NotifyPluginHangAsync, - aPluginId)); + RefPtr runnable = + NS_NewNonOwningRunnableMethodWithArgs(this, + &HangMonitorChild::NotifyPluginHangAsync, + aPluginId); + MonitorLoop()->PostTask(runnable.forget()); } void @@ -428,7 +435,8 @@ HangMonitorChild::ClearHang() if (mSentReport) { // bounce to background thread - MonitorLoop()->PostTask(NewNonOwningRunnableMethod(this, &HangMonitorChild::ClearHangAsync)); + RefPtr runnable = NS_NewNonOwningRunnableMethod(this, &HangMonitorChild::ClearHangAsync); + MonitorLoop()->PostTask(runnable.forget()); MonitorAutoLock lock(mMonitor); mSentReport = false; @@ -493,8 +501,8 @@ HangMonitorParent::Shutdown() mProcess = nullptr; } - MonitorLoop()->PostTask(NewNonOwningRunnableMethod(this, - &HangMonitorParent::ShutdownOnThread)); + RefPtr runnable = NS_NewNonOwningRunnableMethod(this, &HangMonitorParent::ShutdownOnThread); + MonitorLoop()->PostTask(runnable.forget()); while (!mShutdownDone) { mMonitor.Wait(); @@ -814,8 +822,8 @@ HangMonitoredProcess::TerminateScript() return NS_ERROR_UNEXPECTED; } - ProcessHangMonitor::Get()->MonitorLoop()->PostTask(NewNonOwningRunnableMethod(mActor, - &HangMonitorParent::TerminateScript)); + RefPtr runnable = NS_NewNonOwningRunnableMethod(mActor, &HangMonitorParent::TerminateScript); + ProcessHangMonitor::Get()->MonitorLoop()->PostTask(runnable.forget()); return NS_OK; } @@ -831,8 +839,8 @@ HangMonitoredProcess::BeginStartingDebugger() return NS_ERROR_UNEXPECTED; } - ProcessHangMonitor::Get()->MonitorLoop()->PostTask(NewNonOwningRunnableMethod(mActor, - &HangMonitorParent::BeginStartingDebugger)); + RefPtr runnable = NS_NewNonOwningRunnableMethod(mActor, &HangMonitorParent::BeginStartingDebugger); + ProcessHangMonitor::Get()->MonitorLoop()->PostTask(runnable.forget()); return NS_OK; } @@ -848,8 +856,8 @@ HangMonitoredProcess::EndStartingDebugger() return NS_ERROR_UNEXPECTED; } - ProcessHangMonitor::Get()->MonitorLoop()->PostTask(NewNonOwningRunnableMethod(mActor, - &HangMonitorParent::EndStartingDebugger)); + RefPtr runnable = NS_NewNonOwningRunnableMethod(mActor, &HangMonitorParent::EndStartingDebugger); + ProcessHangMonitor::Get()->MonitorLoop()->PostTask(runnable.forget()); return NS_OK; } @@ -1027,13 +1035,14 @@ mozilla::CreateHangMonitorParent(ContentParent* aContentParent, HangMonitoredProcess* process = new HangMonitoredProcess(parent, aContentParent); parent->SetProcess(process); - monitor->MonitorLoop()->PostTask(NewNonOwningRunnableMethod - (parent, - &HangMonitorParent::Open, - aTransport, aOtherPid, - XRE_GetIOMessageLoop())); + RefPtr runnable = + NS_NewNonOwningRunnableMethodWithArgs(parent, + &HangMonitorParent::Open, + aTransport, aOtherPid, + XRE_GetIOMessageLoop()); + monitor->MonitorLoop()->PostTask(runnable.forget()); return parent; } @@ -1047,13 +1056,14 @@ mozilla::CreateHangMonitorChild(mozilla::ipc::Transport* aTransport, ProcessHangMonitor* monitor = ProcessHangMonitor::GetOrCreate(); HangMonitorChild* child = new HangMonitorChild(monitor); - monitor->MonitorLoop()->PostTask(NewNonOwningRunnableMethod - (child, - &HangMonitorChild::Open, - aTransport, aOtherPid, - XRE_GetIOMessageLoop())); + RefPtr runnable = + NS_NewNonOwningRunnableMethodWithArgs(child, + &HangMonitorChild::Open, + aTransport, aOtherPid, + XRE_GetIOMessageLoop()); + monitor->MonitorLoop()->PostTask(runnable.forget()); return child; } diff --git a/dom/jsurl/nsJSProtocolHandler.cpp b/dom/jsurl/nsJSProtocolHandler.cpp index 543a1785732a..9a753d0872bf 100644 --- a/dom/jsurl/nsJSProtocolHandler.cpp +++ b/dom/jsurl/nsJSProtocolHandler.cpp @@ -659,7 +659,8 @@ nsJSChannel::AsyncOpen(nsIStreamListener *aListener, nsISupports *aContext) method = &nsJSChannel::NotifyListener; } - nsresult rv = NS_DispatchToCurrentThread(mozilla::NewRunnableMethod(this, method)); + nsCOMPtr ev = NS_NewRunnableMethod(this, method); + nsresult rv = NS_DispatchToCurrentThread(ev); if (NS_FAILED(rv)) { loadGroup->RemoveRequest(this, nullptr, rv); diff --git a/dom/media/AbstractMediaDecoder.h b/dom/media/AbstractMediaDecoder.h index c4d2ed02cf9c..f4764bbbd3f6 100644 --- a/dom/media/AbstractMediaDecoder.h +++ b/dom/media/AbstractMediaDecoder.h @@ -74,9 +74,10 @@ protected: public: void DispatchUpdateEstimatedMediaDuration(int64_t aDuration) { - NS_DispatchToMainThread(NewRunnableMethod(this, - &AbstractMediaDecoder::UpdateEstimatedMediaDuration, - aDuration)); + nsCOMPtr r = + NS_NewRunnableMethodWithArg(this, &AbstractMediaDecoder::UpdateEstimatedMediaDuration, + aDuration); + NS_DispatchToMainThread(r); } virtual VideoFrameContainer* GetVideoFrameContainer() = 0; diff --git a/dom/media/DOMMediaStream.cpp b/dom/media/DOMMediaStream.cpp index a42f08553c9f..c557663f9245 100644 --- a/dom/media/DOMMediaStream.cpp +++ b/dom/media/DOMMediaStream.cpp @@ -191,13 +191,13 @@ public: { if (aTrackEvents & TRACK_EVENT_CREATED) { nsCOMPtr runnable = - NewRunnableMethod( + NS_NewRunnableMethodWithArgs( this, &OwnedStreamListener::DoNotifyTrackCreated, aID, aQueuedMedia.GetType(), aInputStream, aInputTrackID); aGraph->DispatchToMainThreadAfterStreamStateUpdate(runnable.forget()); } else if (aTrackEvents & TRACK_EVENT_ENDED) { nsCOMPtr runnable = - NewRunnableMethod( + NS_NewRunnableMethodWithArgs( this, &OwnedStreamListener::DoNotifyTrackEnded, aInputStream, aInputTrackID); aGraph->DispatchToMainThreadAfterStreamStateUpdate(runnable.forget()); @@ -281,7 +281,7 @@ public: { if (aTrackEvents & TRACK_EVENT_ENDED) { nsCOMPtr runnable = - NewRunnableMethod, TrackID>( + NS_NewRunnableMethodWithArgs, TrackID>( this, &PlaybackStreamListener::DoNotifyTrackEnded, aInputStream, aInputTrackID); aGraph->DispatchToMainThreadAfterStreamStateUpdate(runnable.forget()); } @@ -290,7 +290,7 @@ public: void NotifyFinishedTrackCreation(MediaStreamGraph* aGraph) override { nsCOMPtr runnable = - NewRunnableMethod(this, &PlaybackStreamListener::DoNotifyFinishedTrackCreation); + NS_NewRunnableMethod(this, &PlaybackStreamListener::DoNotifyFinishedTrackCreation); aGraph->DispatchToMainThreadAfterStreamStateUpdate(runnable.forget()); } diff --git a/dom/media/MediaDecoderReader.cpp b/dom/media/MediaDecoderReader.cpp index 17db94596375..65a06c57f699 100644 --- a/dom/media/MediaDecoderReader.cpp +++ b/dom/media/MediaDecoderReader.cpp @@ -85,7 +85,8 @@ MediaDecoderReader::MediaDecoderReader(AbstractMediaDecoder* aDecoder) } // Dispatch initialization that needs to happen on that task queue. - mTaskQueue->Dispatch(NewRunnableMethod(this, &MediaDecoderReader::InitializationTask)); + nsCOMPtr r = NS_NewRunnableMethod(this, &MediaDecoderReader::InitializationTask); + mTaskQueue->Dispatch(r.forget()); } void diff --git a/dom/media/MediaDecoderReaderWrapper.cpp b/dom/media/MediaDecoderReaderWrapper.cpp index fd85d4c35c91..5866158bcc7e 100644 --- a/dom/media/MediaDecoderReaderWrapper.cpp +++ b/dom/media/MediaDecoderReaderWrapper.cpp @@ -260,7 +260,7 @@ MediaDecoderReaderWrapper::ReleaseMediaResources() { MOZ_ASSERT(mOwnerThread->IsCurrentThreadIn()); nsCOMPtr r = - NewRunnableMethod(mReader, &MediaDecoderReader::ReleaseMediaResources); + NS_NewRunnableMethod(mReader, &MediaDecoderReader::ReleaseMediaResources); mReader->OwnerThread()->Dispatch(r.forget()); } @@ -269,7 +269,7 @@ MediaDecoderReaderWrapper::SetIdle() { MOZ_ASSERT(mOwnerThread->IsCurrentThreadIn()); nsCOMPtr r = - NewRunnableMethod(mReader, &MediaDecoderReader::SetIdle); + NS_NewRunnableMethod(mReader, &MediaDecoderReader::SetIdle); mReader->OwnerThread()->Dispatch(r.forget()); } @@ -278,7 +278,7 @@ MediaDecoderReaderWrapper::ResetDecode() { MOZ_ASSERT(mOwnerThread->IsCurrentThreadIn()); nsCOMPtr r = - NewRunnableMethod(mReader, &MediaDecoderReader::ResetDecode); + NS_NewRunnableMethod(mReader, &MediaDecoderReader::ResetDecode); mReader->OwnerThread()->Dispatch(r.forget()); } diff --git a/dom/media/MediaDecoderStateMachine.cpp b/dom/media/MediaDecoderStateMachine.cpp index 4790c21fdf2e..870b37867502 100644 --- a/dom/media/MediaDecoderStateMachine.cpp +++ b/dom/media/MediaDecoderStateMachine.cpp @@ -898,7 +898,7 @@ nsresult MediaDecoderStateMachine::Init(MediaDecoder* aDecoder) MOZ_ASSERT(NS_IsMainThread()); // Dispatch initialization that needs to happen on that task queue. - nsCOMPtr r = NewRunnableMethod>( + nsCOMPtr r = NS_NewRunnableMethodWithArg>( this, &MediaDecoderStateMachine::InitializationTask, aDecoder); mTaskQueue->Dispatch(r.forget()); @@ -921,7 +921,8 @@ nsresult MediaDecoderStateMachine::Init(MediaDecoder* aDecoder) nsresult rv = mReader->Init(); NS_ENSURE_SUCCESS(rv, rv); - OwnerThread()->Dispatch(NewRunnableMethod(this, &MediaDecoderStateMachine::ReadMetadata)); + r = NS_NewRunnableMethod(this, &MediaDecoderStateMachine::ReadMetadata); + OwnerThread()->Dispatch(r.forget()); return NS_OK; } @@ -1095,7 +1096,7 @@ void MediaDecoderStateMachine::RecomputeDuration() void MediaDecoderStateMachine::DispatchSetDormant(bool aDormant) { - nsCOMPtr r = NewRunnableMethod( + nsCOMPtr r = NS_NewRunnableMethodWithArg( this, &MediaDecoderStateMachine::SetDormant, aDormant); OwnerThread()->Dispatch(r.forget()); } @@ -2421,7 +2422,9 @@ MediaDecoderStateMachine::ScheduleStateMachine() } mDispatchedStateMachine = true; - OwnerThread()->Dispatch(NewRunnableMethod(this, &MediaDecoderStateMachine::RunStateMachine)); + nsCOMPtr task = + NS_NewRunnableMethod(this, &MediaDecoderStateMachine::RunStateMachine); + OwnerThread()->Dispatch(task.forget()); } void @@ -2680,7 +2683,7 @@ void MediaDecoderStateMachine::AddOutputStream(ProcessedMediaStream* aStream, MOZ_ASSERT(NS_IsMainThread()); DECODER_LOG("AddOutputStream aStream=%p!", aStream); mOutputStreamManager->Add(aStream, aFinishWhenEnded); - nsCOMPtr r = NewRunnableMethod( + nsCOMPtr r = NS_NewRunnableMethodWithArg( this, &MediaDecoderStateMachine::SetAudioCaptured, true); OwnerThread()->Dispatch(r.forget()); } @@ -2691,7 +2694,7 @@ void MediaDecoderStateMachine::RemoveOutputStream(MediaStream* aStream) DECODER_LOG("RemoveOutputStream=%p!", aStream); mOutputStreamManager->Remove(aStream); if (mOutputStreamManager->IsEmpty()) { - nsCOMPtr r = NewRunnableMethod( + nsCOMPtr r = NS_NewRunnableMethodWithArg( this, &MediaDecoderStateMachine::SetAudioCaptured, false); OwnerThread()->Dispatch(r.forget()); } diff --git a/dom/media/MediaFormatReader.cpp b/dom/media/MediaFormatReader.cpp index 9fce3ff6ca2a..9ce80a7afb3a 100644 --- a/dom/media/MediaFormatReader.cpp +++ b/dom/media/MediaFormatReader.cpp @@ -767,7 +767,7 @@ MediaFormatReader::ScheduleUpdate(TrackType aTrack) LOGV("SchedulingUpdate(%s)", TrackTypeToStr(aTrack)); decoder.mUpdateScheduled = true; RefPtr task( - NewRunnableMethod(this, &MediaFormatReader::Update, aTrack)); + NS_NewRunnableMethodWithArg(this, &MediaFormatReader::Update, aTrack)); OwnerThread()->Dispatch(task.forget()); } @@ -1288,7 +1288,7 @@ MediaFormatReader::Output(TrackType aTrack, MediaData* aSample) } RefPtr task = - NewRunnableMethod( + NS_NewRunnableMethodWithArgs( this, &MediaFormatReader::NotifyNewOutput, aTrack, aSample); OwnerThread()->Dispatch(task.forget()); } @@ -1297,7 +1297,7 @@ void MediaFormatReader::DrainComplete(TrackType aTrack) { RefPtr task = - NewRunnableMethod( + NS_NewRunnableMethodWithArg( this, &MediaFormatReader::NotifyDrainComplete, aTrack); OwnerThread()->Dispatch(task.forget()); } @@ -1306,7 +1306,7 @@ void MediaFormatReader::InputExhausted(TrackType aTrack) { RefPtr task = - NewRunnableMethod( + NS_NewRunnableMethodWithArg( this, &MediaFormatReader::NotifyInputExhausted, aTrack); OwnerThread()->Dispatch(task.forget()); } @@ -1315,7 +1315,7 @@ void MediaFormatReader::Error(TrackType aTrack) { RefPtr task = - NewRunnableMethod( + NS_NewRunnableMethodWithArg( this, &MediaFormatReader::NotifyError, aTrack); OwnerThread()->Dispatch(task.forget()); } @@ -1435,7 +1435,9 @@ MediaFormatReader::Seek(SeekTarget aTarget, int64_t aUnused) RefPtr p = mSeekPromise.Ensure(__func__); - OwnerThread()->Dispatch(NewRunnableMethod(this, &MediaFormatReader::AttemptSeek)); + RefPtr task( + NS_NewRunnableMethod(this, &MediaFormatReader::AttemptSeek)); + OwnerThread()->Dispatch(task.forget()); return p; } diff --git a/dom/media/MediaFormatReader.h b/dom/media/MediaFormatReader.h index 7b672860a1d6..3207d81cf87b 100644 --- a/dom/media/MediaFormatReader.h +++ b/dom/media/MediaFormatReader.h @@ -82,7 +82,7 @@ public: mDemuxOnly = aDemuxedOnly; return; } - nsCOMPtr r = NewRunnableMethod( + nsCOMPtr r = NS_NewRunnableMethodWithArg( this, &MediaDecoderReader::SetDemuxOnly, aDemuxedOnly); OwnerThread()->Dispatch(r.forget()); } diff --git a/dom/media/MediaManager.h b/dom/media/MediaManager.h index 7aa3b10bb3fa..e8d5db855331 100644 --- a/dom/media/MediaManager.h +++ b/dom/media/MediaManager.h @@ -277,11 +277,11 @@ public: switch (aEvent) { case EVENT_FINISHED: NS_DispatchToMainThread( - NewRunnableMethod(this, &GetUserMediaCallbackMediaStreamListener::NotifyFinished)); + NS_NewRunnableMethod(this, &GetUserMediaCallbackMediaStreamListener::NotifyFinished)); break; case EVENT_REMOVED: NS_DispatchToMainThread( - NewRunnableMethod(this, &GetUserMediaCallbackMediaStreamListener::NotifyRemoved)); + NS_NewRunnableMethod(this, &GetUserMediaCallbackMediaStreamListener::NotifyRemoved)); break; case EVENT_HAS_DIRECT_LISTENERS: NotifyDirectListeners(aGraph, true); diff --git a/dom/media/MediaRecorder.cpp b/dom/media/MediaRecorder.cpp index 2d25a7570074..b366681cef26 100644 --- a/dom/media/MediaRecorder.cpp +++ b/dom/media/MediaRecorder.cpp @@ -819,8 +819,10 @@ private: new DispatchStartEventRunnable(this, NS_LITERAL_STRING("start"))); if (NS_FAILED(rv)) { - NS_DispatchToMainThread(NewRunnableMethod(mRecorder, - &MediaRecorder::NotifyError, rv)); + nsCOMPtr runnable = + NS_NewRunnableMethodWithArg(mRecorder, + &MediaRecorder::NotifyError, rv); + NS_DispatchToMainThread(runnable); } if (NS_FAILED(NS_DispatchToMainThread(new EncoderErrorNotifierRunnable(this)))) { MOZ_ASSERT(false, "NS_DispatchToMainThread EncoderErrorNotifierRunnable failed"); diff --git a/dom/media/MediaResource.cpp b/dom/media/MediaResource.cpp index b5b47bc23e71..66cd7a01f580 100644 --- a/dom/media/MediaResource.cpp +++ b/dom/media/MediaResource.cpp @@ -56,8 +56,9 @@ MediaResource::Destroy() delete this; return; } - MOZ_ALWAYS_SUCCEEDS( - NS_DispatchToMainThread(NewNonOwningRunnableMethod(this, &MediaResource::Destroy))); + nsCOMPtr destroyRunnable = + NS_NewNonOwningRunnableMethod(this, &MediaResource::Destroy); + MOZ_ALWAYS_SUCCEEDS(NS_DispatchToMainThread(destroyRunnable)); } NS_IMPL_ADDREF(MediaResource) @@ -870,7 +871,7 @@ ChannelMediaResource::CacheClientNotifyDataReceived() return; mDataReceivedEvent = - NewNonOwningRunnableMethod(this, &ChannelMediaResource::DoNotifyDataReceived); + NS_NewNonOwningRunnableMethod(this, &ChannelMediaResource::DoNotifyDataReceived); NS_DispatchToMainThread(mDataReceivedEvent.get()); } diff --git a/dom/media/MediaStreamTrack.cpp b/dom/media/MediaStreamTrack.cpp index ee5f6028be22..ff364e7fce6f 100644 --- a/dom/media/MediaStreamTrack.cpp +++ b/dom/media/MediaStreamTrack.cpp @@ -89,7 +89,7 @@ public: const PrincipalHandle& aNewPrincipalHandle) override { nsCOMPtr runnable = - NewRunnableMethod>( + NS_NewRunnableMethodWithArgs>( this, &PrincipalHandleListener::DoNotifyPrincipalHandleChanged, aNewPrincipalHandle); aGraph->DispatchToMainThreadAfterStreamStateUpdate(runnable.forget()); } diff --git a/dom/media/MediaTimer.cpp b/dom/media/MediaTimer.cpp index 1420d6aca1bc..89b14e26a845 100644 --- a/dom/media/MediaTimer.cpp +++ b/dom/media/MediaTimer.cpp @@ -38,12 +38,12 @@ MediaTimer::MediaTimer() void MediaTimer::DispatchDestroy() { + nsCOMPtr task = NS_NewNonOwningRunnableMethod(this, &MediaTimer::Destroy); // Hold a strong reference to the thread so that it doesn't get deleted in // Destroy(), which may run completely before the stack if Dispatch() begins // to unwind. nsCOMPtr thread = mThread; - nsresult rv = thread->Dispatch(NewNonOwningRunnableMethod(this, &MediaTimer::Destroy), - NS_DISPATCH_NORMAL); + nsresult rv = thread->Dispatch(task, NS_DISPATCH_NORMAL); MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv)); (void) rv; } @@ -97,8 +97,8 @@ MediaTimer::ScheduleUpdate() } mUpdateScheduled = true; - nsresult rv = mThread->Dispatch(NewRunnableMethod(this, &MediaTimer::Update), - NS_DISPATCH_NORMAL); + nsCOMPtr task = NS_NewRunnableMethod(this, &MediaTimer::Update); + nsresult rv = mThread->Dispatch(task, NS_DISPATCH_NORMAL); MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv)); (void) rv; } diff --git a/dom/media/RtspMediaResource.cpp b/dom/media/RtspMediaResource.cpp index 818857967005..42a8c53bb80d 100644 --- a/dom/media/RtspMediaResource.cpp +++ b/dom/media/RtspMediaResource.cpp @@ -525,8 +525,8 @@ void RtspMediaResource::SetSuspend(bool aIsSuspend) RTSPMLOG("SetSuspend %d",aIsSuspend); nsCOMPtr runnable = - NewRunnableMethod(this, &RtspMediaResource::NotifySuspend, - aIsSuspend); + NS_NewRunnableMethodWithArg(this, &RtspMediaResource::NotifySuspend, + aIsSuspend); NS_DispatchToMainThread(runnable); } diff --git a/dom/media/eme/CDMCallbackProxy.cpp b/dom/media/eme/CDMCallbackProxy.cpp index fb69a8086940..51366299fb12 100644 --- a/dom/media/eme/CDMCallbackProxy.cpp +++ b/dom/media/eme/CDMCallbackProxy.cpp @@ -222,16 +222,16 @@ CDMCallbackProxy::SessionClosed(const nsCString& aSessionId) } if (keyStatusesChange) { nsCOMPtr task; - task = NewRunnableMethod(mProxy, + task = NS_NewRunnableMethodWithArg(mProxy, &CDMProxy::OnKeyStatusesChange, NS_ConvertUTF8toUTF16(aSessionId)); NS_DispatchToMainThread(task); } nsCOMPtr task; - task = NewRunnableMethod(mProxy, - &CDMProxy::OnSessionClosed, - NS_ConvertUTF8toUTF16(aSessionId)); + task = NS_NewRunnableMethodWithArg(mProxy, + &CDMProxy::OnSessionClosed, + NS_ConvertUTF8toUTF16(aSessionId)); NS_DispatchToMainThread(task); } @@ -295,9 +295,9 @@ CDMCallbackProxy::KeyStatusChanged(const nsCString& aSessionId, } if (keyStatusesChange) { nsCOMPtr task; - task = NewRunnableMethod(mProxy, - &CDMProxy::OnKeyStatusesChange, - NS_ConvertUTF8toUTF16(aSessionId)); + task = NS_NewRunnableMethodWithArg(mProxy, + &CDMProxy::OnKeyStatusesChange, + NS_ConvertUTF8toUTF16(aSessionId)); NS_DispatchToMainThread(task); } } @@ -325,7 +325,7 @@ void CDMCallbackProxy::Terminated() { MOZ_ASSERT(mProxy->IsOnGMPThread()); - nsCOMPtr task = NewRunnableMethod(mProxy, &CDMProxy::Terminated); + nsCOMPtr task = NS_NewRunnableMethod(mProxy, &CDMProxy::Terminated); NS_DispatchToMainThread(task); } diff --git a/dom/media/eme/CDMProxy.cpp b/dom/media/eme/CDMProxy.cpp index 9603374eb92f..625aa14df459 100644 --- a/dom/media/eme/CDMProxy.cpp +++ b/dom/media/eme/CDMProxy.cpp @@ -83,9 +83,9 @@ CDMProxy::Init(PromiseId aPromiseId, data->mGMPName = aGMPName; data->mInPrivateBrowsing = aInPrivateBrowsing; nsCOMPtr task( - NewRunnableMethod>(this, - &CDMProxy::gmp_Init, - Move(data))); + NS_NewRunnableMethodWithArg>(this, + &CDMProxy::gmp_Init, + Move(data))); mGMPThread->Dispatch(task, NS_DISPATCH_NORMAL); } @@ -119,9 +119,9 @@ CDMProxy::gmp_InitDone(GMPDecryptorProxy* aCDM, nsAutoPtr&& aData) mCallback = new CDMCallbackProxy(this); mCDM->Init(mCallback); nsCOMPtr task( - NewRunnableMethod(this, - &CDMProxy::OnCDMCreated, - aData->mPromiseId)); + NS_NewRunnableMethodWithArg(this, + &CDMProxy::OnCDMCreated, + aData->mPromiseId)); NS_DispatchToMainThread(task); } @@ -270,7 +270,7 @@ CDMProxy::CreateSession(uint32_t aCreateSessionToken, data->mInitData = Move(aInitData); nsCOMPtr task( - NewRunnableMethod>(this, &CDMProxy::gmp_CreateSession, data)); + NS_NewRunnableMethodWithArg>(this, &CDMProxy::gmp_CreateSession, data)); mGMPThread->Dispatch(task, NS_DISPATCH_NORMAL); } @@ -310,7 +310,7 @@ CDMProxy::LoadSession(PromiseId aPromiseId, data->mPromiseId = aPromiseId; data->mSessionId = NS_ConvertUTF16toUTF8(aSessionId); nsCOMPtr task( - NewRunnableMethod>(this, &CDMProxy::gmp_LoadSession, data)); + NS_NewRunnableMethodWithArg>(this, &CDMProxy::gmp_LoadSession, data)); mGMPThread->Dispatch(task, NS_DISPATCH_NORMAL); } @@ -338,7 +338,7 @@ CDMProxy::SetServerCertificate(PromiseId aPromiseId, data->mPromiseId = aPromiseId; data->mCert = Move(aCert); nsCOMPtr task( - NewRunnableMethod>(this, &CDMProxy::gmp_SetServerCertificate, data)); + NS_NewRunnableMethodWithArg>(this, &CDMProxy::gmp_SetServerCertificate, data)); mGMPThread->Dispatch(task, NS_DISPATCH_NORMAL); } @@ -368,7 +368,7 @@ CDMProxy::UpdateSession(const nsAString& aSessionId, data->mSessionId = NS_ConvertUTF16toUTF8(aSessionId); data->mResponse = Move(aResponse); nsCOMPtr task( - NewRunnableMethod>(this, &CDMProxy::gmp_UpdateSession, data)); + NS_NewRunnableMethodWithArg>(this, &CDMProxy::gmp_UpdateSession, data)); mGMPThread->Dispatch(task, NS_DISPATCH_NORMAL); } @@ -397,7 +397,7 @@ CDMProxy::CloseSession(const nsAString& aSessionId, data->mPromiseId = aPromiseId; data->mSessionId = NS_ConvertUTF16toUTF8(aSessionId); nsCOMPtr task( - NewRunnableMethod>(this, &CDMProxy::gmp_CloseSession, data)); + NS_NewRunnableMethodWithArg>(this, &CDMProxy::gmp_CloseSession, data)); mGMPThread->Dispatch(task, NS_DISPATCH_NORMAL); } @@ -424,7 +424,7 @@ CDMProxy::RemoveSession(const nsAString& aSessionId, data->mPromiseId = aPromiseId; data->mSessionId = NS_ConvertUTF16toUTF8(aSessionId); nsCOMPtr task( - NewRunnableMethod>(this, &CDMProxy::gmp_RemoveSession, data)); + NS_NewRunnableMethodWithArg>(this, &CDMProxy::gmp_RemoveSession, data)); mGMPThread->Dispatch(task, NS_DISPATCH_NORMAL); } @@ -446,7 +446,7 @@ CDMProxy::Shutdown() MOZ_ASSERT(NS_IsMainThread()); mKeys.Clear(); // Note: This may end up being the last owning reference to the CDMProxy. - nsCOMPtr task(NewRunnableMethod(this, &CDMProxy::gmp_Shutdown)); + nsCOMPtr task(NS_NewRunnableMethod(this, &CDMProxy::gmp_Shutdown)); if (mGMPThread) { mGMPThread->Dispatch(task, NS_DISPATCH_NORMAL); } @@ -498,9 +498,9 @@ CDMProxy::ResolvePromise(PromiseId aId) } } else { nsCOMPtr task; - task = NewRunnableMethod(this, - &CDMProxy::ResolvePromise, - aId); + task = NS_NewRunnableMethodWithArg(this, + &CDMProxy::ResolvePromise, + aId); NS_DispatchToMainThread(task); } } @@ -659,7 +659,7 @@ CDMProxy::Decrypt(MediaRawData* aSample) RefPtr promise(job->Ensure()); nsCOMPtr task( - NewRunnableMethod>(this, &CDMProxy::gmp_Decrypt, job)); + NS_NewRunnableMethodWithArg>(this, &CDMProxy::gmp_Decrypt, job)); mGMPThread->Dispatch(task, NS_DISPATCH_NORMAL); return promise; } diff --git a/dom/media/gmp/GMPContentParent.cpp b/dom/media/gmp/GMPContentParent.cpp index 4eea05ae2d3c..83d523c91a3f 100644 --- a/dom/media/gmp/GMPContentParent.cpp +++ b/dom/media/gmp/GMPContentParent.cpp @@ -134,8 +134,8 @@ GMPContentParent::CloseIfUnused() GeckoMediaPluginServiceChild::GetSingleton()); gmp->RemoveGMPContentParent(toClose); } - NS_DispatchToCurrentThread(NewRunnableMethod(toClose, - &GMPContentParent::Close)); + NS_DispatchToCurrentThread(NS_NewRunnableMethod(toClose, + &GMPContentParent::Close)); } } diff --git a/dom/media/gmp/GMPContentParent.h b/dom/media/gmp/GMPContentParent.h index 38fd775f7c8f..0003b5e1afb2 100644 --- a/dom/media/gmp/GMPContentParent.h +++ b/dom/media/gmp/GMPContentParent.h @@ -79,7 +79,7 @@ private: bool DeallocPGMPAudioDecoderParent(PGMPAudioDecoderParent* aActor) override; void CloseIfUnused(); - // Needed because NewRunnableMethod tried to use the class that the method + // Needed because NS_NewRunnableMethod tried to use the class that the method // lives on to store the receiver, but PGMPContentParent isn't refcounted. void Close() { diff --git a/dom/media/gmp/GMPDecryptorChild.cpp b/dom/media/gmp/GMPDecryptorChild.cpp index ebecf239e8a7..1999165d76f4 100644 --- a/dom/media/gmp/GMPDecryptorChild.cpp +++ b/dom/media/gmp/GMPDecryptorChild.cpp @@ -171,10 +171,12 @@ GMPDecryptorChild::Decrypted(GMPBuffer* aBuffer, GMPErr aResult) if (!ON_GMP_THREAD()) { // We should run this whole method on the GMP thread since the buffer needs // to be deleted after the SendDecrypted call. - mPlugin->GMPMessageLoop()->PostTask(NewRunnableMethod - (this, - &GMPDecryptorChild::Decrypted, - aBuffer, aResult)); + RefPtr t = + NS_NewRunnableMethodWithArgs(this, + &GMPDecryptorChild::Decrypted, + aBuffer, aResult); + mPlugin->GMPMessageLoop()->PostTask(t.forget()); return; } diff --git a/dom/media/gmp/GMPParent.cpp b/dom/media/gmp/GMPParent.cpp index 4818fe3c6cf5..9ac0595538d0 100644 --- a/dom/media/gmp/GMPParent.cpp +++ b/dom/media/gmp/GMPParent.cpp @@ -503,7 +503,7 @@ GMPParent::ChildTerminated() // removed so there is no harm in not trying to remove it again. LOGD("%s::%s: GMPThread() returned nullptr.", __CLASS__, __FUNCTION__); } else { - gmpThread->Dispatch(NewRunnableMethod>( + gmpThread->Dispatch(NS_NewRunnableMethodWithArg>( mService, &GeckoMediaPluginServiceParent::PluginTerminated, self), @@ -522,7 +522,7 @@ GMPParent::DeleteProcess() mState = GMPStateClosing; Close(); } - mProcess->Delete(NewRunnableMethod(this, &GMPParent::ChildTerminated)); + mProcess->Delete(NS_NewRunnableMethod(this, &GMPParent::ChildTerminated)); LOGD("%s: Shut down process", __FUNCTION__); mProcess = nullptr; mState = GMPStateNotLoaded; diff --git a/dom/media/gmp/GMPPlatform.cpp b/dom/media/gmp/GMPPlatform.cpp index 4f9a1e534f4f..23d7256671ef 100644 --- a/dom/media/gmp/GMPPlatform.cpp +++ b/dom/media/gmp/GMPPlatform.cpp @@ -73,7 +73,8 @@ public: // main thread tries to do a sync call back to the calling thread. MOZ_ASSERT(!IsOnChildMainThread()); - mMessageLoop->PostTask(NewRunnableMethod(this, &SyncRunnable::Run)); + RefPtr runnable = NS_NewRunnableMethod(this, &SyncRunnable::Run); + mMessageLoop->PostTask(runnable.forget()); MonitorAutoLock lock(mMonitor); while (!mDone) { lock.Wait(); @@ -121,7 +122,8 @@ RunOnMainThread(GMPTask* aTask) } RefPtr r = new Runnable(aTask); - sMainLoop->PostTask(NewRunnableMethod(r, &Runnable::Run)); + RefPtr runnable = NS_NewRunnableMethod(r, &Runnable::Run); + sMainLoop->PostTask(runnable.forget()); return GMPNoErr; } @@ -253,7 +255,8 @@ GMPThreadImpl::Post(GMPTask* aTask) } RefPtr r = new Runnable(aTask); - mThread.message_loop()->PostTask(NewRunnableMethod(r, &Runnable::Run)); + RefPtr runnable = NS_NewRunnableMethod(r, &Runnable::Run); + mThread.message_loop()->PostTask(runnable.forget()); } void diff --git a/dom/media/gmp/GMPProcessParent.cpp b/dom/media/gmp/GMPProcessParent.cpp index ed1903bce46a..9a7a45a792e8 100644 --- a/dom/media/gmp/GMPProcessParent.cpp +++ b/dom/media/gmp/GMPProcessParent.cpp @@ -78,7 +78,8 @@ void GMPProcessParent::Delete(nsCOMPtr aCallback) { mDeletedCallback = aCallback; - XRE_GetIOMessageLoop()->PostTask(NewNonOwningRunnableMethod(this, &GMPProcessParent::DoDelete)); + RefPtr task = NS_NewNonOwningRunnableMethod(this, &GMPProcessParent::DoDelete); + XRE_GetIOMessageLoop()->PostTask(task.forget()); } void diff --git a/dom/media/gmp/GMPService.cpp b/dom/media/gmp/GMPService.cpp index 72ce9deadc8a..683f8aeb7ec5 100644 --- a/dom/media/gmp/GMPService.cpp +++ b/dom/media/gmp/GMPService.cpp @@ -326,16 +326,7 @@ GeckoMediaPluginService::ShutdownGMPThread() } nsresult -GeckoMediaPluginService::GMPDispatch(nsIRunnable* event, - uint32_t flags) -{ - nsCOMPtr r(event); - return GMPDispatch(r.forget()); -} - -nsresult -GeckoMediaPluginService::GMPDispatch(already_AddRefed event, - uint32_t flags) +GeckoMediaPluginService::GMPDispatch(nsIRunnable* event, uint32_t flags) { nsCOMPtr r(event); nsCOMPtr thread; diff --git a/dom/media/gmp/GMPService.h b/dom/media/gmp/GMPService.h index 6b5113621ec5..2bda87777da5 100644 --- a/dom/media/gmp/GMPService.h +++ b/dom/media/gmp/GMPService.h @@ -90,7 +90,6 @@ protected: UniquePtr&& aCallback) = 0; nsresult GMPDispatch(nsIRunnable* event, uint32_t flags = NS_DISPATCH_NORMAL); - nsresult GMPDispatch(already_AddRefed event, uint32_t flags = NS_DISPATCH_NORMAL); void ShutdownGMPThread(); Mutex mMutex; // Protects mGMPThread and mGMPThreadShutdown and some members diff --git a/dom/media/gmp/GMPServiceParent.cpp b/dom/media/gmp/GMPServiceParent.cpp index cd76485c42cf..b9e75fb78fde 100644 --- a/dom/media/gmp/GMPServiceParent.cpp +++ b/dom/media/gmp/GMPServiceParent.cpp @@ -419,8 +419,8 @@ GeckoMediaPluginServiceParent::Observe(nsISupports* aSubject, NS_LITERAL_CSTRING("Dispatching UnloadPlugins")); #endif gmpThread->Dispatch( - NewRunnableMethod(this, - &GeckoMediaPluginServiceParent::UnloadPlugins), + NS_NewRunnableMethod(this, + &GeckoMediaPluginServiceParent::UnloadPlugins), NS_DISPATCH_NORMAL); #ifdef MOZ_CRASHREPORTER @@ -493,7 +493,7 @@ GeckoMediaPluginServiceParent::Observe(nsISupports* aSubject, } else if (!strcmp("browser:purge-session-history", aTopic)) { // Clear everything! if (!aSomeData || nsDependentString(aSomeData).IsEmpty()) { - return GMPDispatch(NewRunnableMethod( + return GMPDispatch(NS_NewRunnableMethod( this, &GeckoMediaPluginServiceParent::ClearStorage)); } @@ -503,7 +503,7 @@ GeckoMediaPluginServiceParent::Observe(nsISupports* aSubject, if (NS_FAILED(rv)) { return rv; } - return GMPDispatch(NewRunnableMethod( + return GMPDispatch(NS_NewRunnableMethodWithArg( this, &GeckoMediaPluginServiceParent::ClearRecentHistoryOnGMPThread, t)); } @@ -605,7 +605,7 @@ GeckoMediaPluginServiceParent::AsyncShutdownComplete(GMPParent* aParent) if (mShuttingDownOnGMPThread) { // The main thread may be waiting for async shutdown of plugins, // one of which has completed. Wake up the main thread by sending a task. - nsCOMPtr task(NewRunnableMethod( + nsCOMPtr task(NS_NewRunnableMethod( this, &GeckoMediaPluginServiceParent::NotifyAsyncShutdownComplete)); NS_DispatchToMainThread(task); } @@ -737,7 +737,7 @@ GeckoMediaPluginServiceParent::UnloadPlugins() SetAsyncShutdownPluginState(nullptr, '3', NS_LITERAL_CSTRING("Dispatching sync-shutdown-complete")); #endif - nsCOMPtr task(NewRunnableMethod( + nsCOMPtr task(NS_NewRunnableMethod( this, &GeckoMediaPluginServiceParent::NotifySyncShutdownComplete)); NS_DispatchToMainThread(task); } @@ -1749,7 +1749,7 @@ NS_IMETHODIMP GeckoMediaPluginServiceParent::ForgetThisSite(const nsAString& aSite) { MOZ_ASSERT(NS_IsMainThread()); - return GMPDispatch(NewRunnableMethod( + return GMPDispatch(NS_NewRunnableMethodWithArg( this, &GeckoMediaPluginServiceParent::ForgetThisSiteOnGMPThread, NS_ConvertUTF16toUTF8(aSite))); } diff --git a/dom/media/gmp/GMPVideoDecoderChild.cpp b/dom/media/gmp/GMPVideoDecoderChild.cpp index 259690628776..1eb3e53df44b 100644 --- a/dom/media/gmp/GMPVideoDecoderChild.cpp +++ b/dom/media/gmp/GMPVideoDecoderChild.cpp @@ -226,8 +226,8 @@ GMPVideoDecoderChild::Alloc(size_t aSize, rv = CallNeedShmem(aSize, aMem); --mNeedShmemIntrCount; if (mPendingDecodeComplete) { - mPlugin->GMPMessageLoop()->PostTask( - NewRunnableMethod(this, &GMPVideoDecoderChild::RecvDecodingComplete)); + RefPtr runnable = NS_NewRunnableMethod(this, &GMPVideoDecoderChild::RecvDecodingComplete); + mPlugin->GMPMessageLoop()->PostTask(runnable.forget()); } #else #ifdef GMP_SAFE_SHMEM diff --git a/dom/media/gmp/GMPVideoEncoderChild.cpp b/dom/media/gmp/GMPVideoEncoderChild.cpp index fa139cef4900..d10a677789da 100644 --- a/dom/media/gmp/GMPVideoEncoderChild.cpp +++ b/dom/media/gmp/GMPVideoEncoderChild.cpp @@ -207,8 +207,8 @@ GMPVideoEncoderChild::Alloc(size_t aSize, rv = CallNeedShmem(aSize, aMem); --mNeedShmemIntrCount; if (mPendingEncodeComplete) { - mPlugin->GMPMessageLoop()->PostTask( - NewRunnableMethod(this, &GMPVideoEncoderChild::RecvEncodingComplete)); + RefPtr runnable = NS_NewRunnableMethod(this, &GMPVideoEncoderChild::RecvEncodingComplete); + mPlugin->GMPMessageLoop()->PostTask(runnable.forget()); } #else #ifdef GMP_SAFE_SHMEM diff --git a/dom/media/gtest/GMPTestMonitor.h b/dom/media/gtest/GMPTestMonitor.h index 8ce6f8ddd83b..d5b6d59c15fb 100644 --- a/dom/media/gtest/GMPTestMonitor.h +++ b/dom/media/gtest/GMPTestMonitor.h @@ -36,8 +36,8 @@ private: public: void SetFinished() { - NS_DispatchToMainThread(mozilla::NewNonOwningRunnableMethod(this, - &GMPTestMonitor::MarkFinished)); + NS_DispatchToMainThread(NS_NewNonOwningRunnableMethod(this, + &GMPTestMonitor::MarkFinished)); } private: diff --git a/dom/media/gtest/TestGMPCrossOrigin.cpp b/dom/media/gtest/TestGMPCrossOrigin.cpp index ead44cf6edbd..16a9f549e2c9 100644 --- a/dom/media/gtest/TestGMPCrossOrigin.cpp +++ b/dom/media/gtest/TestGMPCrossOrigin.cpp @@ -304,8 +304,8 @@ EnumerateGMPStorageDir(const nsACString& aDir, T&& aDirIter) class GMPShutdownObserver : public nsIRunnable , public nsIObserver { public: - GMPShutdownObserver(already_AddRefed aShutdownTask, - already_AddRefed Continuation, + GMPShutdownObserver(nsIRunnable* aShutdownTask, + nsIRunnable* Continuation, const nsACString& aNodeId) : mShutdownTask(aShutdownTask) , mContinuation(Continuation) @@ -371,7 +371,7 @@ public: class ClearGMPStorageTask : public nsIRunnable , public nsIObserver { public: - ClearGMPStorageTask(already_AddRefed Continuation, + ClearGMPStorageTask(nsIRunnable* Continuation, nsIThread* aTarget, PRTime aSince) : mContinuation(Continuation) , mTarget(aTarget) @@ -421,11 +421,11 @@ private: NS_IMPL_ISUPPORTS(ClearGMPStorageTask, nsIRunnable, nsIObserver) static void -ClearGMPStorage(already_AddRefed aContinuation, +ClearGMPStorage(nsIRunnable* aContinuation, nsIThread* aTarget, PRTime aSince = -1) { RefPtr task( - new ClearGMPStorageTask(Move(aContinuation), aTarget, aSince)); + new ClearGMPStorageTask(aContinuation, aTarget, aSince)); NS_DispatchToMainThread(task, NS_DISPATCH_NORMAL); } @@ -516,7 +516,7 @@ class GMPStorageTest : public GMPDecryptorProxyCallback void DoTest(void (GMPStorageTest::*aTestMethod)()) { EnsureNSSInitializedChromeOrContent(); nsCOMPtr thread(GetGMPThread()); - ClearGMPStorage(NewRunnableMethod(this, aTestMethod), thread); + ClearGMPStorage(NS_NewRunnableMethod(this, aTestMethod), thread); AwaitFinished(); } @@ -569,7 +569,7 @@ class GMPStorageTest : public GMPDecryptorProxyCallback EXPECT_TRUE(!PBnodeId2.Equals(nodeId2)); nsCOMPtr thread(GetGMPThread()); - ClearGMPStorage(NewRunnableMethod( + ClearGMPStorage(NS_NewRunnableMethodWithArg( this, &GMPStorageTest::TestGetNodeId_Continuation, nodeId1), thread); } @@ -681,7 +681,7 @@ class GMPStorageTest : public GMPDecryptorProxyCallback // It sends us a "test-storage complete" message when its passed, or // some other message if its tests fail. Expect(NS_LITERAL_CSTRING("test-storage complete"), - NewRunnableMethod(this, &GMPStorageTest::SetFinished)); + NS_NewRunnableMethod(this, &GMPStorageTest::SetFinished)); CreateDecryptor(NS_LITERAL_STRING("http://example1.com"), NS_LITERAL_STRING("http://example2.com"), @@ -700,9 +700,9 @@ class GMPStorageTest : public GMPDecryptorProxyCallback EXPECT_TRUE(IsGMPStorageIsEmpty()); // Generate storage data for some site. - nsCOMPtr r = NewRunnableMethod( + nsCOMPtr r = NS_NewRunnableMethod( this, &GMPStorageTest::TestForgetThisSite_AnotherSite); - Expect(NS_LITERAL_CSTRING("test-storage complete"), r.forget()); + Expect(NS_LITERAL_CSTRING("test-storage complete"), r); CreateDecryptor(NS_LITERAL_STRING("http://example1.com"), NS_LITERAL_STRING("http://example2.com"), @@ -714,9 +714,9 @@ class GMPStorageTest : public GMPDecryptorProxyCallback Shutdown(); // Generate storage data for another site. - nsCOMPtr r = NewRunnableMethod( + nsCOMPtr r = NS_NewRunnableMethod( this, &GMPStorageTest::TestForgetThisSite_CollectSiteInfo); - Expect(NS_LITERAL_CSTRING("test-storage complete"), r.forget()); + Expect(NS_LITERAL_CSTRING("test-storage complete"), r); CreateDecryptor(NS_LITERAL_STRING("http://example3.com"), NS_LITERAL_STRING("http://example4.com"), @@ -751,7 +751,7 @@ class GMPStorageTest : public GMPDecryptorProxyCallback // Collect nodeIds that are expected to remain for later comparison. EnumerateGMPStorageDir(NS_LITERAL_CSTRING("id"), NodeIdCollector(siteInfo)); // Invoke "Forget this site" on the main thread. - NS_DispatchToMainThread(NewRunnableMethod>( + NS_DispatchToMainThread(NS_NewRunnableMethodWithArg>( this, &GMPStorageTest::TestForgetThisSite_Forget, siteInfo)); } @@ -763,11 +763,11 @@ class GMPStorageTest : public GMPDecryptorProxyCallback nsCOMPtr thread; service->GetThread(getter_AddRefs(thread)); - nsCOMPtr r = NewRunnableMethod>( + nsCOMPtr r = NS_NewRunnableMethodWithArg>( this, &GMPStorageTest::TestForgetThisSite_Verify, aSiteInfo); thread->Dispatch(r, NS_DISPATCH_NORMAL); - nsCOMPtr f = NewRunnableMethod( + nsCOMPtr f = NS_NewRunnableMethod( this, &GMPStorageTest::SetFinished); thread->Dispatch(f, NS_DISPATCH_NORMAL); } @@ -833,9 +833,9 @@ class GMPStorageTest : public GMPDecryptorProxyCallback EXPECT_TRUE(IsGMPStorageIsEmpty()); // Generate storage data for some site. - nsCOMPtr r = NewRunnableMethod( + nsCOMPtr r = NS_NewRunnableMethod( this, &GMPStorageTest::TestClearRecentHistory1_Clear); - Expect(NS_LITERAL_CSTRING("test-storage complete"), r.forget()); + Expect(NS_LITERAL_CSTRING("test-storage complete"), r); CreateDecryptor(NS_LITERAL_STRING("http://example1.com"), NS_LITERAL_STRING("http://example2.com"), @@ -855,9 +855,9 @@ class GMPStorageTest : public GMPDecryptorProxyCallback EXPECT_TRUE(IsGMPStorageIsEmpty()); // Generate storage data for some site. - nsCOMPtr r = NewRunnableMethod( + nsCOMPtr r = NS_NewRunnableMethod( this, &GMPStorageTest::TestClearRecentHistory2_Clear); - Expect(NS_LITERAL_CSTRING("test-storage complete"), r.forget()); + Expect(NS_LITERAL_CSTRING("test-storage complete"), r); CreateDecryptor(NS_LITERAL_STRING("http://example1.com"), NS_LITERAL_STRING("http://example2.com"), @@ -877,9 +877,9 @@ class GMPStorageTest : public GMPDecryptorProxyCallback EXPECT_TRUE(IsGMPStorageIsEmpty()); // Generate storage data for some site. - nsCOMPtr r = NewRunnableMethod( + nsCOMPtr r = NS_NewRunnableMethod( this, &GMPStorageTest::TestClearRecentHistory3_Clear); - Expect(NS_LITERAL_CSTRING("test-storage complete"), r.forget()); + Expect(NS_LITERAL_CSTRING("test-storage complete"), r); CreateDecryptor(NS_LITERAL_STRING("http://example1.com"), NS_LITERAL_STRING("http://example2.com"), @@ -908,10 +908,10 @@ class GMPStorageTest : public GMPDecryptorProxyCallback nsresult rv = EnumerateGMPStorageDir(NS_LITERAL_CSTRING("id"), f); EXPECT_TRUE(NS_SUCCEEDED(rv)); - nsCOMPtr r = NewRunnableMethod( + nsCOMPtr r = NS_NewRunnableMethod( this, &GMPStorageTest::TestClearRecentHistory_CheckEmpty); nsCOMPtr t(GetGMPThread()); - ClearGMPStorage(r.forget(), t, f.GetResult()); + ClearGMPStorage(r, t, f.GetResult()); } void TestClearRecentHistory2_Clear() { @@ -919,10 +919,10 @@ class GMPStorageTest : public GMPDecryptorProxyCallback nsresult rv = EnumerateGMPStorageDir(NS_LITERAL_CSTRING("storage"), f); EXPECT_TRUE(NS_SUCCEEDED(rv)); - nsCOMPtr r = NewRunnableMethod( + nsCOMPtr r = NS_NewRunnableMethod( this, &GMPStorageTest::TestClearRecentHistory_CheckEmpty); nsCOMPtr t(GetGMPThread()); - ClearGMPStorage(r.forget(), t, f.GetResult()); + ClearGMPStorage(r, t, f.GetResult()); } void TestClearRecentHistory3_Clear() { @@ -930,10 +930,10 @@ class GMPStorageTest : public GMPDecryptorProxyCallback nsresult rv = EnumerateGMPStorageDir(NS_LITERAL_CSTRING("storage"), f); EXPECT_TRUE(NS_SUCCEEDED(rv)); - nsCOMPtr r = NewRunnableMethod( + nsCOMPtr r = NS_NewRunnableMethod( this, &GMPStorageTest::TestClearRecentHistory_CheckNonEmpty); nsCOMPtr t(GetGMPThread()); - ClearGMPStorage(r.forget(), t, f.GetResult() + 1); + ClearGMPStorage(r, t, f.GetResult() + 1); } class FileCounter { @@ -987,7 +987,7 @@ class GMPStorageTest : public GMPDecryptorProxyCallback auto t = time(0); nsCString response("stored crossOriginTestRecordId "); response.AppendInt((int64_t)t); - Expect(response, NewRunnableMethod(this, + Expect(response, NS_NewRunnableMethod(this, &GMPStorageTest::TestCrossOriginStorage_RecordStoredContinuation)); nsCString update("store crossOriginTestRecordId "); @@ -1007,7 +1007,7 @@ class GMPStorageTest : public GMPDecryptorProxyCallback Shutdown(); Expect(NS_LITERAL_CSTRING("retrieve crossOriginTestRecordId succeeded (length 0 bytes)"), - NewRunnableMethod(this, &GMPStorageTest::SetFinished)); + NS_NewRunnableMethod(this, &GMPStorageTest::SetFinished)); CreateDecryptor(NS_LITERAL_STRING("http://example5.com"), NS_LITERAL_STRING("http://example6.com"), @@ -1019,7 +1019,7 @@ class GMPStorageTest : public GMPDecryptorProxyCallback // Send the decryptor the message "store recordid $time" // Wait for the decrytor to send us "stored recordid $time" nsCString response("stored pbdata test-pb-data"); - Expect(response, NewRunnableMethod(this, + Expect(response, NS_NewRunnableMethod(this, &GMPStorageTest::TestPBStorage_RecordStoredContinuation)); // Open decryptor on one, origin, write a record, close decryptor, @@ -1036,7 +1036,7 @@ class GMPStorageTest : public GMPDecryptorProxyCallback Shutdown(); Expect(NS_LITERAL_CSTRING("retrieve pbdata succeeded (length 12 bytes)"), - NewRunnableMethod(this, + NS_NewRunnableMethod(this, &GMPStorageTest::TestPBStorage_RecordRetrievedContinuation)); CreateDecryptor(NS_LITERAL_STRING("http://pb1.com"), @@ -1050,7 +1050,7 @@ class GMPStorageTest : public GMPDecryptorProxyCallback SimulatePBModeExit(); Expect(NS_LITERAL_CSTRING("retrieve pbdata succeeded (length 0 bytes)"), - NewRunnableMethod(this, + NS_NewRunnableMethod(this, &GMPStorageTest::SetFinished)); CreateDecryptor(NS_LITERAL_STRING("http://pb1.com"), @@ -1073,10 +1073,10 @@ class GMPStorageTest : public GMPDecryptorProxyCallback const nsAString& aOrigin2, void (GMPStorageTest::*aCallback)()) { nsCOMPtr continuation( - NewRunnableMethod>( + NS_NewRunnableMethodWithArg>( this, &GMPStorageTest::NextAsyncShutdownTimeoutTest, - NewRunnableMethod(this, aCallback))); + NS_NewRunnableMethod(this, aCallback))); CreateDecryptor(aOrigin1, aOrigin2, false, continuation); } @@ -1115,7 +1115,7 @@ class GMPStorageTest : public GMPDecryptorProxyCallback // the token. nsCString response("shutdown-token received "); response.Append(token); - Expect(response, NewRunnableMethod(this, + Expect(response, NS_NewRunnableMethodWithArg(this, &GMPStorageTest::TestAsyncShutdownStorage_ReceivedShutdownToken, token)); // Test that a GMP can write to storage during shutdown, and retrieve @@ -1127,7 +1127,7 @@ class GMPStorageTest : public GMPDecryptorProxyCallback } void TestAsyncShutdownStorage_ReceivedShutdownToken(const nsCString& aToken) { - ShutdownThen(NewRunnableMethod(this, + ShutdownThen(NS_NewRunnableMethodWithArg(this, &GMPStorageTest::TestAsyncShutdownStorage_AsyncShutdownComplete, aToken)); } @@ -1137,7 +1137,7 @@ class GMPStorageTest : public GMPDecryptorProxyCallback nsCString response("retrieved shutdown-token "); response.Append(aToken); Expect(response, - NewRunnableMethod(this, &GMPStorageTest::SetFinished)); + NS_NewRunnableMethod(this, &GMPStorageTest::SetFinished)); CreateDecryptor(NS_LITERAL_STRING("http://example13.com"), NS_LITERAL_STRING("http://example14.com"), @@ -1150,7 +1150,7 @@ class GMPStorageTest : public GMPDecryptorProxyCallback Shutdown(); Expect(NS_LITERAL_CSTRING("OP tests completed"), - NewRunnableMethod(this, &GMPStorageTest::SetFinished)); + NS_NewRunnableMethod(this, &GMPStorageTest::SetFinished)); CreateDecryptor(NS_LITERAL_STRING("http://example15.com"), NS_LITERAL_STRING("http://example16.com"), @@ -1161,7 +1161,7 @@ class GMPStorageTest : public GMPDecryptorProxyCallback void TestPluginVoucher() { Expect(NS_LITERAL_CSTRING("retrieved plugin-voucher: gmp-fake placeholder voucher"), - NewRunnableMethod(this, &GMPStorageTest::SetFinished)); + NS_NewRunnableMethod(this, &GMPStorageTest::SetFinished)); CreateDecryptor(NS_LITERAL_STRING("http://example17.com"), NS_LITERAL_STRING("http://example18.com"), @@ -1205,12 +1205,12 @@ class GMPStorageTest : public GMPDecryptorProxyCallback update.AppendLiteral(" test-data"); AppendIntPadded(update, i); - nsCOMPtr continuation; + nsIRunnable* continuation = nullptr; if (i + 1 == num) { continuation = - NewRunnableMethod(this, &GMPStorageTest::TestGetRecordNames_QueryNames); + NS_NewRunnableMethod(this, &GMPStorageTest::TestGetRecordNames_QueryNames); } - Expect(response, continuation.forget()); + Expect(response, continuation); } CreateDecryptor(NS_LITERAL_STRING("http://foo.com"), @@ -1223,7 +1223,7 @@ class GMPStorageTest : public GMPDecryptorProxyCallback nsCString response("record-names "); response.Append(mRecordNames); Expect(response, - NewRunnableMethod(this, &GMPStorageTest::SetFinished)); + NS_NewRunnableMethod(this, &GMPStorageTest::SetFinished)); Update(NS_LITERAL_CSTRING("retrieve-record-names")); } @@ -1260,7 +1260,7 @@ class GMPStorageTest : public GMPDecryptorProxyCallback response.Append(longRecordName); response.AppendLiteral(" "); response.Append(data); - Expect(response, NewRunnableMethod(this, &GMPStorageTest::SetFinished)); + Expect(response, NS_NewRunnableMethod(this, &GMPStorageTest::SetFinished)); nsCString update("store "); update.Append(longRecordName); @@ -1272,8 +1272,8 @@ class GMPStorageTest : public GMPDecryptorProxyCallback update); } - void Expect(const nsCString& aMessage, already_AddRefed aContinuation) { - mExpected.AppendElement(ExpectedMessage(aMessage, Move(aContinuation))); + void Expect(const nsCString& aMessage, nsIRunnable* aContinuation) { + mExpected.AppendElement(ExpectedMessage(aMessage, aContinuation)); } void AwaitFinished() { @@ -1283,15 +1283,15 @@ class GMPStorageTest : public GMPDecryptorProxyCallback mFinished = false; } - void ShutdownThen(already_AddRefed aContinuation) { + void ShutdownThen(nsIRunnable* aContinuation) { EXPECT_TRUE(!!mDecryptor); if (!mDecryptor) { return; } EXPECT_FALSE(mNodeId.IsEmpty()); RefPtr task( - new GMPShutdownObserver(NewRunnableMethod(this, &GMPStorageTest::Shutdown), - Move(aContinuation), mNodeId)); + new GMPShutdownObserver(NS_NewRunnableMethod(this, &GMPStorageTest::Shutdown), + aContinuation, mNodeId)); NS_DispatchToMainThread(task, NS_DISPATCH_NORMAL); } @@ -1309,7 +1309,7 @@ class GMPStorageTest : public GMPDecryptorProxyCallback void SetFinished() { mFinished = true; Shutdown(); - NS_DispatchToMainThread(NewRunnableMethod(this, &GMPStorageTest::Dummy)); + NS_DispatchToMainThread(NS_NewRunnableMethod(this, &GMPStorageTest::Dummy)); } void SessionMessage(const nsCString& aSessionId, @@ -1364,7 +1364,7 @@ private: ~GMPStorageTest() { } struct ExpectedMessage { - ExpectedMessage(const nsCString& aMessage, already_AddRefed aContinuation) + ExpectedMessage(const nsCString& aMessage, nsIRunnable* aContinuation) : mMessage(aMessage) , mContinuation(aContinuation) {} @@ -1386,9 +1386,9 @@ GMPTestRunner::DoTest(void (GMPTestRunner::*aTestMethod)(GMPTestMonitor&)) nsCOMPtr thread(GetGMPThread()); GMPTestMonitor monitor; - thread->Dispatch(NewRunnableMethod(this, - aTestMethod, - monitor), + thread->Dispatch(NS_NewRunnableMethodWithArg(this, + aTestMethod, + monitor), NS_DISPATCH_NORMAL); monitor.AwaitFinished(); } diff --git a/dom/media/gtest/TestGMPRemoveAndDelete.cpp b/dom/media/gtest/TestGMPRemoveAndDelete.cpp index ffedf4d30efe..ef6b8b22d181 100644 --- a/dom/media/gtest/TestGMPRemoveAndDelete.cpp +++ b/dom/media/gtest/TestGMPRemoveAndDelete.cpp @@ -260,7 +260,7 @@ GMPRemoveTest::CreateVideoDecoder(nsCString aNodeId) GMPVideoDecoderProxy* decoder = nullptr; mGMPThread->Dispatch( - NewNonOwningRunnableMethod( + NS_NewNonOwningRunnableMethodWithArgs( this, &GMPRemoveTest::gmp_GetVideoDecoder, aNodeId, &decoder, &host), NS_DISPATCH_NORMAL); @@ -276,7 +276,7 @@ GMPRemoveTest::CreateVideoDecoder(nsCString aNodeId) nsTArray empty; mGMPThread->Dispatch( - NewNonOwningRunnableMethod&, GMPVideoDecoderCallbackProxy*, int32_t>( + NS_NewNonOwningRunnableMethodWithArgs&, GMPVideoDecoderCallbackProxy*, int32_t>( decoder, &GMPVideoDecoderProxy::InitDecode, codec, empty, this, 1 /* core count */), NS_DISPATCH_SYNC); @@ -328,7 +328,7 @@ void GMPRemoveTest::CloseVideoDecoder() { mGMPThread->Dispatch( - NewNonOwningRunnableMethod(mDecoder, &GMPVideoDecoderProxy::Close), + NS_NewNonOwningRunnableMethod(mDecoder, &GMPVideoDecoderProxy::Close), NS_DISPATCH_SYNC); mDecoder = nullptr; @@ -345,7 +345,7 @@ GMPErr GMPRemoveTest::Decode() { mGMPThread->Dispatch( - NewNonOwningRunnableMethod(this, &GMPRemoveTest::gmp_Decode), + NS_NewNonOwningRunnableMethod(this, &GMPRemoveTest::gmp_Decode), NS_DISPATCH_NORMAL); mTestMonitor.AwaitFinished(); diff --git a/dom/media/gtest/TestMP4Reader.cpp b/dom/media/gtest/TestMP4Reader.cpp index f08f7a40da3c..c0120c12a3ea 100644 --- a/dom/media/gtest/TestMP4Reader.cpp +++ b/dom/media/gtest/TestMP4Reader.cpp @@ -43,8 +43,8 @@ public: void Init() { nsCOMPtr thread; - nsCOMPtr r = NewRunnableMethod(this, &TestBinding::ReadMetadata); - nsresult rv = NS_NewThread(getter_AddRefs(thread), r); + nsresult rv = NS_NewThread(getter_AddRefs(thread), + NS_NewRunnableMethod(this, &TestBinding::ReadMetadata)); EXPECT_EQ(NS_OK, rv); thread->Shutdown(); } @@ -54,7 +54,7 @@ private: { { RefPtr queue = reader->OwnerThread(); - nsCOMPtr task = NewRunnableMethod(reader, &MP4Reader::Shutdown); + nsCOMPtr task = NS_NewRunnableMethod(reader, &MP4Reader::Shutdown); // Hackily bypass the tail dispatcher so that we can AwaitShutdownAndIdle. // In production code we'd use BeginShutdown + promises. queue->Dispatch(task.forget(), AbstractThread::AssertDispatchSuccess, diff --git a/dom/media/mediasink/DecodedStream.cpp b/dom/media/mediasink/DecodedStream.cpp index ac82f074f0ae..1acd2779f8c4 100644 --- a/dom/media/mediasink/DecodedStream.cpp +++ b/dom/media/mediasink/DecodedStream.cpp @@ -54,7 +54,7 @@ public: { if (event == EVENT_FINISHED) { nsCOMPtr event = - NewRunnableMethod(this, &DecodedStreamGraphListener::DoNotifyFinished); + NS_NewRunnableMethod(this, &DecodedStreamGraphListener::DoNotifyFinished); aGraph->DispatchToMainThreadAfterStreamStateUpdate(event.forget()); } } @@ -99,9 +99,9 @@ UpdateStreamSuspended(MediaStream* aStream, bool aBlocking) } else { nsCOMPtr r; if (aBlocking) { - r = NewRunnableMethod(aStream, &MediaStream::Suspend); + r = NS_NewRunnableMethod(aStream, &MediaStream::Suspend); } else { - r = NewRunnableMethod(aStream, &MediaStream::Resume); + r = NS_NewRunnableMethod(aStream, &MediaStream::Resume); } AbstractThread::MainThread()->Dispatch(r.forget()); } diff --git a/dom/media/mediasource/MediaSourceDemuxer.cpp b/dom/media/mediasource/MediaSourceDemuxer.cpp index 6ffb65527795..715dc9858eb2 100644 --- a/dom/media/mediasource/MediaSourceDemuxer.cpp +++ b/dom/media/mediasource/MediaSourceDemuxer.cpp @@ -177,7 +177,7 @@ void MediaSourceDemuxer::AttachSourceBuffer(TrackBuffersManager* aSourceBuffer) { nsCOMPtr task = - NewRunnableMethod( + NS_NewRunnableMethodWithArg( this, &MediaSourceDemuxer::DoAttachSourceBuffer, aSourceBuffer); GetTaskQueue()->Dispatch(task.forget()); @@ -195,7 +195,7 @@ void MediaSourceDemuxer::DetachSourceBuffer(TrackBuffersManager* aSourceBuffer) { nsCOMPtr task = - NewRunnableMethod( + NS_NewRunnableMethodWithArg( this, &MediaSourceDemuxer::DoDetachSourceBuffer, aSourceBuffer); GetTaskQueue()->Dispatch(task.forget()); diff --git a/dom/media/mediasource/TrackBuffersManager.cpp b/dom/media/mediasource/TrackBuffersManager.cpp index 0b6a8a7777de..3e21d84da2b3 100644 --- a/dom/media/mediasource/TrackBuffersManager.cpp +++ b/dom/media/mediasource/TrackBuffersManager.cpp @@ -201,7 +201,9 @@ TrackBuffersManager::ProcessTasks() NS_WARNING("Invalid Task"); } } - GetTaskQueue()->Dispatch(NewRunnableMethod(this, &TrackBuffersManager::ProcessTasks)); + nsCOMPtr task = + NS_NewRunnableMethod(this, &TrackBuffersManager::ProcessTasks); + GetTaskQueue()->Dispatch(task.forget()); } // A PromiseHolder will assert upon destruction if it has a pending promise @@ -791,7 +793,9 @@ TrackBuffersManager::ScheduleSegmentParserLoop() if (mDetached) { return; } - GetTaskQueue()->Dispatch(NewRunnableMethod(this, &TrackBuffersManager::SegmentParserLoop)); + nsCOMPtr task = + NS_NewRunnableMethod(this, &TrackBuffersManager::SegmentParserLoop); + GetTaskQueue()->Dispatch(task.forget()); } void @@ -967,10 +971,11 @@ TrackBuffersManager::OnDemuxerInitDone(nsresult) int64_t duration = std::max(videoDuration, audioDuration); // 1. Update the duration attribute if it currently equals NaN. // Those steps are performed by the MediaSourceDecoder::SetInitialDuration - AbstractThread::MainThread()->Dispatch(NewRunnableMethod - (mParentDecoder, - &MediaSourceDecoder::SetInitialDuration, - duration ? duration : -1)); + nsCOMPtr task = + NS_NewRunnableMethodWithArg(mParentDecoder, + &MediaSourceDecoder::SetInitialDuration, + duration ? duration : -1); + AbstractThread::MainThread()->Dispatch(task.forget()); // 2. If the initialization segment has no audio, video, or text tracks, then // run the append error algorithm with the decode error parameter set to true diff --git a/dom/media/omx/AudioOffloadPlayer.cpp b/dom/media/omx/AudioOffloadPlayer.cpp index ccdd82ba846c..05e5a45e67ae 100644 --- a/dom/media/omx/AudioOffloadPlayer.cpp +++ b/dom/media/omx/AudioOffloadPlayer.cpp @@ -354,7 +354,7 @@ status_t AudioOffloadPlayer::DoSeek() if (!mSeekPromise.IsEmpty()) { nsCOMPtr nsEvent = - NewRunnableMethod( + NS_NewRunnableMethodWithArg( mObserver, &MediaDecoder::SeekingStarted, mSeekTarget.mEventVisibility); @@ -425,14 +425,16 @@ void AudioOffloadPlayer::NotifyAudioEOS() MediaDecoder::SeekResolveValue val(mReachedEOS, mSeekTarget.mEventVisibility); mSeekPromise.Resolve(val, __func__); } - NS_DispatchToMainThread(NewRunnableMethod(mObserver, - &MediaDecoder::PlaybackEnded)); + nsCOMPtr nsEvent = NS_NewRunnableMethod(mObserver, + &MediaDecoder::PlaybackEnded); + NS_DispatchToMainThread(nsEvent); } void AudioOffloadPlayer::NotifyPositionChanged() { - NS_DispatchToMainThread(NewRunnableMethod(mObserver, - &MediaOmxCommonDecoder::NotifyOffloadPlayerPositionChanged)); + nsCOMPtr nsEvent = + NS_NewRunnableMethod(mObserver, &MediaOmxCommonDecoder::NotifyOffloadPlayerPositionChanged); + NS_DispatchToMainThread(nsEvent); } void AudioOffloadPlayer::NotifyAudioTearDown() @@ -446,8 +448,9 @@ void AudioOffloadPlayer::NotifyAudioTearDown() MediaDecoder::SeekResolveValue val(mReachedEOS, mSeekTarget.mEventVisibility); mSeekPromise.Resolve(val, __func__); } - NS_DispatchToMainThread(NewRunnableMethod(mObserver, - &MediaOmxCommonDecoder::AudioOffloadTearDown)); + nsCOMPtr nsEvent = NS_NewRunnableMethod(mObserver, + &MediaOmxCommonDecoder::AudioOffloadTearDown); + NS_DispatchToMainThread(nsEvent); } // static diff --git a/dom/media/platforms/agnostic/OpusDecoder.cpp b/dom/media/platforms/agnostic/OpusDecoder.cpp index d5a71e7b6068..e2cbba313921 100644 --- a/dom/media/platforms/agnostic/OpusDecoder.cpp +++ b/dom/media/platforms/agnostic/OpusDecoder.cpp @@ -132,9 +132,11 @@ OpusDataDecoder::DecodeHeader(const unsigned char* aData, size_t aLength) nsresult OpusDataDecoder::Input(MediaRawData* aSample) { - mTaskQueue->Dispatch(NewRunnableMethod>( - this, &OpusDataDecoder::Decode, - RefPtr(aSample))); + nsCOMPtr runnable( + NS_NewRunnableMethodWithArg>( + this, &OpusDataDecoder::Decode, + RefPtr(aSample))); + mTaskQueue->Dispatch(runnable.forget()); return NS_OK; } @@ -307,7 +309,9 @@ OpusDataDecoder::DoDrain() nsresult OpusDataDecoder::Drain() { - mTaskQueue->Dispatch(NewRunnableMethod(this, &OpusDataDecoder::DoDrain)); + RefPtr runnable( + NS_NewRunnableMethod(this, &OpusDataDecoder::DoDrain)); + mTaskQueue->Dispatch(runnable.forget()); return NS_OK; } diff --git a/dom/media/platforms/agnostic/VPXDecoder.cpp b/dom/media/platforms/agnostic/VPXDecoder.cpp index 6b1f5ad2ceed..644361ecaa53 100644 --- a/dom/media/platforms/agnostic/VPXDecoder.cpp +++ b/dom/media/platforms/agnostic/VPXDecoder.cpp @@ -186,9 +186,11 @@ VPXDecoder::DecodeFrame(MediaRawData* aSample) nsresult VPXDecoder::Input(MediaRawData* aSample) { - mTaskQueue->Dispatch(NewRunnableMethod>( - this, &VPXDecoder::DecodeFrame, - RefPtr(aSample))); + nsCOMPtr runnable( + NS_NewRunnableMethodWithArg>( + this, &VPXDecoder::DecodeFrame, + RefPtr(aSample))); + mTaskQueue->Dispatch(runnable.forget()); return NS_OK; } @@ -202,7 +204,9 @@ VPXDecoder::DoDrain() nsresult VPXDecoder::Drain() { - mTaskQueue->Dispatch(NewRunnableMethod(this, &VPXDecoder::DoDrain)); + nsCOMPtr runnable( + NS_NewRunnableMethod(this, &VPXDecoder::DoDrain)); + mTaskQueue->Dispatch(runnable.forget()); return NS_OK; } diff --git a/dom/media/platforms/agnostic/VorbisDecoder.cpp b/dom/media/platforms/agnostic/VorbisDecoder.cpp index ed7217c4573a..259df44d7834 100644 --- a/dom/media/platforms/agnostic/VorbisDecoder.cpp +++ b/dom/media/platforms/agnostic/VorbisDecoder.cpp @@ -129,9 +129,11 @@ VorbisDataDecoder::DecodeHeader(const unsigned char* aData, size_t aLength) nsresult VorbisDataDecoder::Input(MediaRawData* aSample) { - mTaskQueue->Dispatch(NewRunnableMethod>( - this, &VorbisDataDecoder::Decode, - RefPtr(aSample))); + nsCOMPtr runnable( + NS_NewRunnableMethodWithArg>( + this, &VorbisDataDecoder::Decode, + RefPtr(aSample))); + mTaskQueue->Dispatch(runnable.forget()); return NS_OK; } @@ -263,7 +265,9 @@ VorbisDataDecoder::DoDrain() nsresult VorbisDataDecoder::Drain() { - mTaskQueue->Dispatch(NewRunnableMethod(this, &VorbisDataDecoder::DoDrain)); + nsCOMPtr runnable( + NS_NewRunnableMethod(this, &VorbisDataDecoder::DoDrain)); + mTaskQueue->Dispatch(runnable.forget()); return NS_OK; } diff --git a/dom/media/platforms/agnostic/WAVDecoder.cpp b/dom/media/platforms/agnostic/WAVDecoder.cpp index d31d514379c9..677e68b43616 100644 --- a/dom/media/platforms/agnostic/WAVDecoder.cpp +++ b/dom/media/platforms/agnostic/WAVDecoder.cpp @@ -70,9 +70,11 @@ WaveDataDecoder::Init() nsresult WaveDataDecoder::Input(MediaRawData* aSample) { - mTaskQueue->Dispatch(NewRunnableMethod>( - this, &WaveDataDecoder::Decode, - RefPtr(aSample))); + nsCOMPtr runnable( + NS_NewRunnableMethodWithArg>( + this, &WaveDataDecoder::Decode, + RefPtr(aSample))); + mTaskQueue->Dispatch(runnable.forget()); return NS_OK; } @@ -156,7 +158,9 @@ WaveDataDecoder::DoDrain() nsresult WaveDataDecoder::Drain() { - mTaskQueue->Dispatch(NewRunnableMethod(this, &WaveDataDecoder::DoDrain)); + nsCOMPtr runnable( + NS_NewRunnableMethod(this, &WaveDataDecoder::DoDrain)); + mTaskQueue->Dispatch(runnable.forget()); return NS_OK; } @@ -182,4 +186,4 @@ WaveDataDecoder::IsWave(const nsACString& aMimeType) } } // namespace mozilla -#undef LOG +#undef LOG \ No newline at end of file diff --git a/dom/media/platforms/agnostic/eme/SamplesWaitingForKey.cpp b/dom/media/platforms/agnostic/eme/SamplesWaitingForKey.cpp index 1b0fba23b0a0..e15cda20b251 100644 --- a/dom/media/platforms/agnostic/eme/SamplesWaitingForKey.cpp +++ b/dom/media/platforms/agnostic/eme/SamplesWaitingForKey.cpp @@ -52,7 +52,7 @@ SamplesWaitingForKey::NotifyUsable(const CencKeyId& aKeyId) while (i < mSamples.Length()) { if (aKeyId == mSamples[i]->mCrypto.mKeyId) { RefPtr task; - task = NewRunnableMethod>(mDecoder, + task = NS_NewRunnableMethodWithArg>(mDecoder, &MediaDataDecoder::Input, RefPtr(mSamples[i])); mSamples.RemoveElementAt(i); diff --git a/dom/media/platforms/agnostic/gmp/MediaDataDecoderProxy.cpp b/dom/media/platforms/agnostic/gmp/MediaDataDecoderProxy.cpp index 503de5380fbd..8808ff23b993 100644 --- a/dom/media/platforms/agnostic/gmp/MediaDataDecoderProxy.cpp +++ b/dom/media/platforms/agnostic/gmp/MediaDataDecoderProxy.cpp @@ -58,7 +58,9 @@ MediaDataDecoderProxy::Flush() mFlushComplete.Set(false); - mProxyThread->Dispatch(NewRunnableMethod(mProxyDecoder, &MediaDataDecoder::Flush)); + nsCOMPtr task; + task = NS_NewRunnableMethod(mProxyDecoder, &MediaDataDecoder::Flush); + mProxyThread->Dispatch(task.forget()); mFlushComplete.WaitUntil(true); @@ -71,7 +73,9 @@ MediaDataDecoderProxy::Drain() MOZ_ASSERT(!IsOnProxyThread()); MOZ_ASSERT(!mIsShutdown); - mProxyThread->Dispatch(NewRunnableMethod(mProxyDecoder, &MediaDataDecoder::Drain)); + nsCOMPtr task; + task = NS_NewRunnableMethod(mProxyDecoder, &MediaDataDecoder::Drain); + mProxyThread->Dispatch(task.forget()); return NS_OK; } @@ -83,9 +87,9 @@ MediaDataDecoderProxy::Shutdown() #if defined(DEBUG) mIsShutdown = true; #endif - nsresult rv = mProxyThread->AsXPCOMThread()->Dispatch(NewRunnableMethod(mProxyDecoder, - &MediaDataDecoder::Shutdown), - NS_DISPATCH_SYNC); + nsCOMPtr task; + task = NS_NewRunnableMethod(mProxyDecoder, &MediaDataDecoder::Shutdown); + nsresult rv = mProxyThread->AsXPCOMThread()->Dispatch(task, NS_DISPATCH_SYNC); NS_ENSURE_SUCCESS(rv, rv); return NS_OK; } diff --git a/dom/media/platforms/android/AndroidDecoderModule.cpp b/dom/media/platforms/android/AndroidDecoderModule.cpp index f878f493549f..cc09d2c228c1 100644 --- a/dom/media/platforms/android/AndroidDecoderModule.cpp +++ b/dom/media/platforms/android/AndroidDecoderModule.cpp @@ -389,8 +389,9 @@ MediaCodecDataDecoder::InitDecoder(Surface::Param aSurface) NS_ENSURE_SUCCESS(rv = ResetInputBuffers(), rv); NS_ENSURE_SUCCESS(rv = ResetOutputBuffers(), rv); - nsCOMPtr r = NewRunnableMethod(this, &MediaCodecDataDecoder::DecoderLoop); - rv = NS_NewNamedThread("MC Decoder", getter_AddRefs(mThread), r); + rv = NS_NewNamedThread( + "MC Decoder", getter_AddRefs(mThread), + NS_NewRunnableMethod(this, &MediaCodecDataDecoder::DecoderLoop)); return rv; } diff --git a/dom/media/platforms/apple/AppleATDecoder.cpp b/dom/media/platforms/apple/AppleATDecoder.cpp index a5da492aa16a..6d364c25d9ce 100644 --- a/dom/media/platforms/apple/AppleATDecoder.cpp +++ b/dom/media/platforms/apple/AppleATDecoder.cpp @@ -74,7 +74,7 @@ AppleATDecoder::Input(MediaRawData* aSample) // Queue a task to perform the actual decoding on a separate thread. nsCOMPtr runnable = - NewRunnableMethod>( + NS_NewRunnableMethodWithArg>( this, &AppleATDecoder::SubmitSample, RefPtr(aSample)); diff --git a/dom/media/platforms/apple/AppleVDADecoder.cpp b/dom/media/platforms/apple/AppleVDADecoder.cpp index 2c9610040109..89b5e66c8d19 100644 --- a/dom/media/platforms/apple/AppleVDADecoder.cpp +++ b/dom/media/platforms/apple/AppleVDADecoder.cpp @@ -100,7 +100,7 @@ AppleVDADecoder::Shutdown() mIsShutDown = true; if (mTaskQueue) { nsCOMPtr runnable = - NewRunnableMethod(this, &AppleVDADecoder::ProcessShutdown); + NS_NewRunnableMethod(this, &AppleVDADecoder::ProcessShutdown); mTaskQueue->Dispatch(runnable.forget()); } else { ProcessShutdown(); @@ -133,7 +133,7 @@ AppleVDADecoder::Input(MediaRawData* aSample) mInputIncoming++; nsCOMPtr runnable = - NewRunnableMethod>( + NS_NewRunnableMethodWithArg>( this, &AppleVDADecoder::SubmitFrame, RefPtr(aSample)); @@ -148,7 +148,7 @@ AppleVDADecoder::Flush() mIsFlushing = true; mTaskQueue->Flush(); nsCOMPtr runnable = - NewRunnableMethod(this, &AppleVDADecoder::ProcessFlush); + NS_NewRunnableMethod(this, &AppleVDADecoder::ProcessFlush); MonitorAutoLock mon(mMonitor); mTaskQueue->Dispatch(runnable.forget()); while (mIsFlushing) { @@ -163,7 +163,7 @@ AppleVDADecoder::Drain() { MOZ_ASSERT(mCallback->OnReaderTaskQueue()); nsCOMPtr runnable = - NewRunnableMethod(this, &AppleVDADecoder::ProcessDrain); + NS_NewRunnableMethod(this, &AppleVDADecoder::ProcessDrain); mTaskQueue->Dispatch(runnable.forget()); return NS_OK; } diff --git a/dom/media/platforms/apple/AppleVTDecoder.cpp b/dom/media/platforms/apple/AppleVTDecoder.cpp index d3e444688cea..000f95c6389d 100644 --- a/dom/media/platforms/apple/AppleVTDecoder.cpp +++ b/dom/media/platforms/apple/AppleVTDecoder.cpp @@ -107,7 +107,7 @@ AppleVTDecoder::Input(MediaRawData* aSample) mInputIncoming++; nsCOMPtr runnable = - NewRunnableMethod>( + NS_NewRunnableMethodWithArg>( this, &AppleVTDecoder::SubmitFrame, aSample); mTaskQueue->Dispatch(runnable.forget()); return NS_OK; diff --git a/dom/media/platforms/ffmpeg/FFmpegAudioDecoder.cpp b/dom/media/platforms/ffmpeg/FFmpegAudioDecoder.cpp index 8fcacb935008..eb8698b714dc 100644 --- a/dom/media/platforms/ffmpeg/FFmpegAudioDecoder.cpp +++ b/dom/media/platforms/ffmpeg/FFmpegAudioDecoder.cpp @@ -175,7 +175,7 @@ FFmpegAudioDecoder::DecodePacket(MediaRawData* aSample) nsresult FFmpegAudioDecoder::Input(MediaRawData* aSample) { - nsCOMPtr runnable(NewRunnableMethod>( + nsCOMPtr runnable(NS_NewRunnableMethodWithArg>( this, &FFmpegAudioDecoder::DecodePacket, RefPtr(aSample))); mTaskQueue->Dispatch(runnable.forget()); return NS_OK; diff --git a/dom/media/platforms/ffmpeg/FFmpegDataDecoder.cpp b/dom/media/platforms/ffmpeg/FFmpegDataDecoder.cpp index c10ba26d1b54..46c01d719f87 100644 --- a/dom/media/platforms/ffmpeg/FFmpegDataDecoder.cpp +++ b/dom/media/platforms/ffmpeg/FFmpegDataDecoder.cpp @@ -104,7 +104,7 @@ FFmpegDataDecoder::Shutdown() { if (mTaskQueue) { nsCOMPtr runnable = - NewRunnableMethod(this, &FFmpegDataDecoder::ProcessShutdown); + NS_NewRunnableMethod(this, &FFmpegDataDecoder::ProcessShutdown); mTaskQueue->Dispatch(runnable.forget()); } else { ProcessShutdown(); @@ -119,7 +119,7 @@ FFmpegDataDecoder::Flush() mIsFlushing = true; mTaskQueue->Flush(); nsCOMPtr runnable = - NewRunnableMethod(this, &FFmpegDataDecoder::ProcessFlush); + NS_NewRunnableMethod(this, &FFmpegDataDecoder::ProcessFlush); MonitorAutoLock mon(mMonitor); mTaskQueue->Dispatch(runnable.forget()); while (mIsFlushing) { @@ -133,7 +133,7 @@ FFmpegDataDecoder::Drain() { MOZ_ASSERT(mCallback->OnReaderTaskQueue()); nsCOMPtr runnable = - NewRunnableMethod(this, &FFmpegDataDecoder::ProcessDrain); + NS_NewRunnableMethod(this, &FFmpegDataDecoder::ProcessDrain); mTaskQueue->Dispatch(runnable.forget()); return NS_OK; } diff --git a/dom/media/platforms/ffmpeg/FFmpegVideoDecoder.cpp b/dom/media/platforms/ffmpeg/FFmpegVideoDecoder.cpp index 203457386545..3c0cd0850f06 100644 --- a/dom/media/platforms/ffmpeg/FFmpegVideoDecoder.cpp +++ b/dom/media/platforms/ffmpeg/FFmpegVideoDecoder.cpp @@ -331,7 +331,7 @@ nsresult FFmpegVideoDecoder::Input(MediaRawData* aSample) { nsCOMPtr runnable( - NewRunnableMethod>( + NS_NewRunnableMethodWithArg>( this, &FFmpegVideoDecoder::DecodeFrame, RefPtr(aSample))); mTaskQueue->Dispatch(runnable.forget()); diff --git a/dom/media/platforms/omx/OmxDataDecoder.cpp b/dom/media/platforms/omx/OmxDataDecoder.cpp index 59768b00ac65..2f90ff5fd2b6 100644 --- a/dom/media/platforms/omx/OmxDataDecoder.cpp +++ b/dom/media/platforms/omx/OmxDataDecoder.cpp @@ -114,7 +114,9 @@ OmxDataDecoder::OmxDataDecoder(const TrackInfo& aTrackInfo, LOG(""); mOmxLayer = new OmxPromiseLayer(mOmxTaskQueue, this, aImageContainer); - mOmxTaskQueue->Dispatch(NewRunnableMethod(this, &OmxDataDecoder::InitializationTask)); + nsCOMPtr r = + NS_NewRunnableMethod(this, &OmxDataDecoder::InitializationTask); + mOmxTaskQueue->Dispatch(r.forget()); } OmxDataDecoder::~OmxDataDecoder() @@ -207,7 +209,9 @@ OmxDataDecoder::Flush() mFlushing = true; - mOmxTaskQueue->Dispatch(NewRunnableMethod(this, &OmxDataDecoder::DoFlush)); + nsCOMPtr r = + NS_NewRunnableMethod(this, &OmxDataDecoder::DoFlush); + mOmxTaskQueue->Dispatch(r.forget()); // According to the definition of Flush() in PDM: // "the decoder must be ready to accept new input for decoding". @@ -225,7 +229,9 @@ OmxDataDecoder::Drain() { LOG(""); - mOmxTaskQueue->Dispatch(NewRunnableMethod(this, &OmxDataDecoder::SendEosBuffer)); + nsCOMPtr r = + NS_NewRunnableMethod(this, &OmxDataDecoder::SendEosBuffer); + mOmxTaskQueue->Dispatch(r.forget()); return NS_OK; } @@ -237,7 +243,9 @@ OmxDataDecoder::Shutdown() mShuttingDown = true; - mOmxTaskQueue->Dispatch(NewRunnableMethod(this, &OmxDataDecoder::DoAsyncShutdown)); + nsCOMPtr r = + NS_NewRunnableMethod(this, &OmxDataDecoder::DoAsyncShutdown); + mOmxTaskQueue->Dispatch(r.forget()); { // DoAsyncShutdown() will be running for a while, it could be still running diff --git a/dom/media/platforms/wmf/WMFMediaDataDecoder.cpp b/dom/media/platforms/wmf/WMFMediaDataDecoder.cpp index 3fd48f7a8592..48cc4f6e535b 100644 --- a/dom/media/platforms/wmf/WMFMediaDataDecoder.cpp +++ b/dom/media/platforms/wmf/WMFMediaDataDecoder.cpp @@ -79,7 +79,9 @@ WMFMediaDataDecoder::Shutdown() MOZ_DIAGNOSTIC_ASSERT(!mIsShutDown); if (mTaskQueue) { - mTaskQueue->Dispatch(NewRunnableMethod(this, &WMFMediaDataDecoder::ProcessShutdown)); + nsCOMPtr runnable = + NS_NewRunnableMethod(this, &WMFMediaDataDecoder::ProcessShutdown); + mTaskQueue->Dispatch(runnable.forget()); } else { ProcessShutdown(); } @@ -107,7 +109,7 @@ WMFMediaDataDecoder::Input(MediaRawData* aSample) MOZ_DIAGNOSTIC_ASSERT(!mIsShutDown); nsCOMPtr runnable = - NewRunnableMethod>( + NS_NewRunnableMethodWithArg>( this, &WMFMediaDataDecoder::ProcessDecode, RefPtr(aSample)); @@ -183,9 +185,11 @@ WMFMediaDataDecoder::Flush() MOZ_ASSERT(mCallback->OnReaderTaskQueue()); MOZ_DIAGNOSTIC_ASSERT(!mIsShutDown); + nsCOMPtr runnable = + NS_NewRunnableMethod(this, &WMFMediaDataDecoder::ProcessFlush); MonitorAutoLock mon(mMonitor); mIsFlushing = true; - mTaskQueue->Dispatch(NewRunnableMethod(this, &WMFMediaDataDecoder::ProcessFlush)); + mTaskQueue->Dispatch(runnable.forget()); while (mIsFlushing) { mon.Wait(); } @@ -215,7 +219,9 @@ WMFMediaDataDecoder::Drain() MOZ_ASSERT(mCallback->OnReaderTaskQueue()); MOZ_DIAGNOSTIC_ASSERT(!mIsShutDown); - mTaskQueue->Dispatch(NewRunnableMethod(this, &WMFMediaDataDecoder::ProcessDrain)); + nsCOMPtr runnable = + NS_NewRunnableMethod(this, &WMFMediaDataDecoder::ProcessDrain); + mTaskQueue->Dispatch(runnable.forget()); return NS_OK; } @@ -232,7 +238,7 @@ WMFMediaDataDecoder::ConfigurationChanged(const TrackInfo& aConfig) MOZ_ASSERT(mCallback->OnReaderTaskQueue()); nsCOMPtr runnable = - NewRunnableMethod&&>( + NS_NewRunnableMethodWithArg&&>( this, &WMFMediaDataDecoder::ProcessConfigurationChanged, aConfig.Clone()); diff --git a/dom/media/platforms/wrappers/FuzzingWrapper.cpp b/dom/media/platforms/wrappers/FuzzingWrapper.cpp index 3e4081f19d39..0cb776c582ea 100644 --- a/dom/media/platforms/wrappers/FuzzingWrapper.cpp +++ b/dom/media/platforms/wrappers/FuzzingWrapper.cpp @@ -136,7 +136,7 @@ DecoderCallbackFuzzingWrapper::Output(MediaData* aData) { if (!mTaskQueue->IsCurrentThreadIn()) { nsCOMPtr task = - NewRunnableMethod>( + NS_NewRunnableMethodWithArg>( this, &DecoderCallbackFuzzingWrapper::Output, aData); mTaskQueue->Dispatch(task.forget()); return; @@ -176,7 +176,9 @@ void DecoderCallbackFuzzingWrapper::Error() { if (!mTaskQueue->IsCurrentThreadIn()) { - mTaskQueue->Dispatch(NewRunnableMethod(this, &DecoderCallbackFuzzingWrapper::Error)); + nsCOMPtr task = + NS_NewRunnableMethod(this, &DecoderCallbackFuzzingWrapper::Error); + mTaskQueue->Dispatch(task.forget()); return; } CFW_LOGV(""); @@ -189,7 +191,9 @@ void DecoderCallbackFuzzingWrapper::InputExhausted() { if (!mTaskQueue->IsCurrentThreadIn()) { - mTaskQueue->Dispatch(NewRunnableMethod(this, &DecoderCallbackFuzzingWrapper::InputExhausted)); + nsCOMPtr task = + NS_NewRunnableMethod(this, &DecoderCallbackFuzzingWrapper::InputExhausted); + mTaskQueue->Dispatch(task.forget()); return; } if (!mDontDelayInputExhausted && !mDelayedOutput.empty()) { @@ -208,7 +212,9 @@ void DecoderCallbackFuzzingWrapper::DrainComplete() { if (!mTaskQueue->IsCurrentThreadIn()) { - mTaskQueue->Dispatch(NewRunnableMethod(this, &DecoderCallbackFuzzingWrapper::DrainComplete)); + nsCOMPtr task = + NS_NewRunnableMethod(this, &DecoderCallbackFuzzingWrapper::DrainComplete); + mTaskQueue->Dispatch(task.forget()); return; } MOZ_ASSERT(mCallback); @@ -227,7 +233,9 @@ void DecoderCallbackFuzzingWrapper::ReleaseMediaResources() { if (!mTaskQueue->IsCurrentThreadIn()) { - mTaskQueue->Dispatch(NewRunnableMethod(this, &DecoderCallbackFuzzingWrapper::ReleaseMediaResources)); + nsCOMPtr task = + NS_NewRunnableMethod(this, &DecoderCallbackFuzzingWrapper::ReleaseMediaResources); + mTaskQueue->Dispatch(task.forget()); return; } CFW_LOGV(""); @@ -309,7 +317,9 @@ DecoderCallbackFuzzingWrapper::ClearDelayedOutput() { if (!mTaskQueue->IsCurrentThreadIn()) { DFW_LOGV("(dispatching self)"); - mTaskQueue->Dispatch(NewRunnableMethod(this, &DecoderCallbackFuzzingWrapper::ClearDelayedOutput)); + nsCOMPtr task = + NS_NewRunnableMethod(this, &DecoderCallbackFuzzingWrapper::ClearDelayedOutput); + mTaskQueue->Dispatch(task.forget()); return; } DFW_LOGV(""); diff --git a/dom/media/systemservices/MediaSystemResourceManager.cpp b/dom/media/systemservices/MediaSystemResourceManager.cpp index 88dcc7080e12..2da48288f37a 100644 --- a/dom/media/systemservices/MediaSystemResourceManager.cpp +++ b/dom/media/systemservices/MediaSystemResourceManager.cpp @@ -198,11 +198,12 @@ MediaSystemResourceManager::Acquire(MediaSystemResourceClient* aClient) return; } aClient->mResourceState = MediaSystemResourceClient::RESOURCE_STATE_WAITING; - ImageBridgeChild::GetSingleton()->GetMessageLoop()->PostTask( - NewRunnableMethod( + RefPtr runnable = + NS_NewRunnableMethodWithArgs( this, &MediaSystemResourceManager::DoAcquire, - aClient->mId)); + aClient->mId); + ImageBridgeChild::GetSingleton()->GetMessageLoop()->PostTask(runnable.forget()); } bool @@ -241,11 +242,12 @@ MediaSystemResourceManager::AcquireSyncNoWait(MediaSystemResourceClient* aClient aClient->mResourceState = MediaSystemResourceClient::RESOURCE_STATE_WAITING; } - ImageBridgeChild::GetSingleton()->GetMessageLoop()->PostTask( - NewRunnableMethod( + RefPtr runnable = + NS_NewRunnableMethodWithArgs( this, &MediaSystemResourceManager::DoAcquire, - aClient->mId)); + aClient->mId); + ImageBridgeChild::GetSingleton()->GetMessageLoop()->PostTask(runnable.forget()); // should stop the thread until done. while (!done) { @@ -308,11 +310,12 @@ MediaSystemResourceManager::ReleaseResource(MediaSystemResourceClient* aClient) aClient->mResourceState = MediaSystemResourceClient::RESOURCE_STATE_END; - ImageBridgeChild::GetSingleton()->GetMessageLoop()->PostTask( - NewRunnableMethod( + RefPtr runnable = + NS_NewRunnableMethodWithArgs( this, &MediaSystemResourceManager::DoRelease, - aClient->mId)); + aClient->mId); + ImageBridgeChild::GetSingleton()->GetMessageLoop()->PostTask(runnable.forget()); } } @@ -336,12 +339,13 @@ void MediaSystemResourceManager::HandleAcquireResult(uint32_t aId, bool aSuccess) { if (!InImageBridgeChildThread()) { - ImageBridgeChild::GetSingleton()->GetMessageLoop()->PostTask( - NewRunnableMethod( + RefPtr runnable = + NS_NewRunnableMethodWithArgs( this, &MediaSystemResourceManager::HandleAcquireResult, aId, - aSuccess)); + aSuccess); + ImageBridgeChild::GetSingleton()->GetMessageLoop()->PostTask(runnable.forget()); return; } diff --git a/dom/media/webaudio/AudioDestinationNode.cpp b/dom/media/webaudio/AudioDestinationNode.cpp index 7da9c5dd901b..a4708489c46a 100644 --- a/dom/media/webaudio/AudioDestinationNode.cpp +++ b/dom/media/webaudio/AudioDestinationNode.cpp @@ -412,8 +412,9 @@ AudioDestinationNode::NotifyMainThreadStreamFinished() MOZ_ASSERT(mStream->IsFinished()); if (mIsOffline) { - NS_DispatchToCurrentThread(NewRunnableMethod(this, - &AudioDestinationNode::FireOfflineCompletionEvent)); + nsCOMPtr runnable = + NS_NewRunnableMethod(this, &AudioDestinationNode::FireOfflineCompletionEvent); + NS_DispatchToCurrentThread(runnable); } } @@ -657,10 +658,11 @@ AudioDestinationNode::NotifyStableState() void AudioDestinationNode::ScheduleStableStateNotification() { + nsCOMPtr event = + NS_NewRunnableMethod(this, &AudioDestinationNode::NotifyStableState); // Dispatch will fail if this is called on AudioNode destruction during // shutdown, in which case failure can be ignored. - nsContentUtils::RunInStableState(NewRunnableMethod(this, - &AudioDestinationNode::NotifyStableState)); + nsContentUtils::RunInStableState(event.forget()); } StreamTime diff --git a/dom/media/webaudio/MediaBufferDecoder.cpp b/dom/media/webaudio/MediaBufferDecoder.cpp index 97fcbd70f6f8..262395bb9e0d 100644 --- a/dom/media/webaudio/MediaBufferDecoder.cpp +++ b/dom/media/webaudio/MediaBufferDecoder.cpp @@ -122,7 +122,7 @@ private: mDecodeJob.OnFailure(aErrorCode); } else { // Take extra care to cleanup on the main thread - NS_DispatchToMainThread(NewRunnableMethod(this, &MediaDecodeTask::Cleanup)); + NS_DispatchToMainThread(NS_NewRunnableMethod(this, &MediaDecodeTask::Cleanup)); nsCOMPtr event = new ReportResultTask(mDecodeJob, &WebAudioDecodeJob::OnFailure, aErrorCode); diff --git a/dom/media/webaudio/blink/ReverbConvolver.cpp b/dom/media/webaudio/blink/ReverbConvolver.cpp index e739400aee35..7167394030af 100644 --- a/dom/media/webaudio/blink/ReverbConvolver.cpp +++ b/dom/media/webaudio/blink/ReverbConvolver.cpp @@ -151,8 +151,8 @@ ReverbConvolver::ReverbConvolver(const float* impulseResponseData, NS_WARNING("Cannot start convolver thread."); return; } - m_backgroundThread.message_loop()->PostTask(NewNonOwningRunnableMethod(this, - &ReverbConvolver::backgroundThreadEntry)); + RefPtr runnable = NS_NewNonOwningRunnableMethod(this, &ReverbConvolver::backgroundThreadEntry); + m_backgroundThread.message_loop()->PostTask(runnable.forget()); } } diff --git a/dom/media/webspeech/synth/nsSpeechTask.cpp b/dom/media/webspeech/synth/nsSpeechTask.cpp index bfc4670cae8f..2e918570f266 100644 --- a/dom/media/webspeech/synth/nsSpeechTask.cpp +++ b/dom/media/webspeech/synth/nsSpeechTask.cpp @@ -61,12 +61,12 @@ public: if (!mStarted) { mStarted = true; nsCOMPtr startRunnable = - NewRunnableMethod(this, &SynthStreamListener::DoNotifyStarted); + NS_NewRunnableMethod(this, &SynthStreamListener::DoNotifyStarted); aGraph->DispatchToMainThreadAfterStreamStateUpdate(startRunnable.forget()); } nsCOMPtr endRunnable = - NewRunnableMethod(this, &SynthStreamListener::DoNotifyFinished); + NS_NewRunnableMethod(this, &SynthStreamListener::DoNotifyFinished); aGraph->DispatchToMainThreadAfterStreamStateUpdate(endRunnable.forget()); } break; @@ -85,7 +85,7 @@ public: if (aBlocked == MediaStreamListener::UNBLOCKED && !mStarted) { mStarted = true; nsCOMPtr event = - NewRunnableMethod(this, &SynthStreamListener::DoNotifyStarted); + NS_NewRunnableMethod(this, &SynthStreamListener::DoNotifyStarted); aGraph->DispatchToMainThreadAfterStreamStateUpdate(event.forget()); } } diff --git a/dom/media/webspeech/synth/pico/nsPicoService.cpp b/dom/media/webspeech/synth/pico/nsPicoService.cpp index 6f31509b6c63..b52c4181ae9a 100644 --- a/dom/media/webspeech/synth/pico/nsPicoService.cpp +++ b/dom/media/webspeech/synth/pico/nsPicoService.cpp @@ -469,7 +469,7 @@ nsPicoService::Observe(nsISupports* aSubject, const char* aTopic, DebugOnly rv = NS_NewNamedThread("Pico Worker", getter_AddRefs(mThread)); MOZ_ASSERT(NS_SUCCEEDED(rv)); return mThread->Dispatch( - NewRunnableMethod(this, &nsPicoService::Init), NS_DISPATCH_NORMAL); + NS_NewRunnableMethod(this, &nsPicoService::Init), NS_DISPATCH_NORMAL); } // nsISpeechService @@ -579,7 +579,7 @@ nsPicoService::Init() rv = dirIterator->HasMoreElements(&hasMoreElements); } - NS_DispatchToMainThread(NewRunnableMethod(this, &nsPicoService::RegisterVoices)); + NS_DispatchToMainThread(NS_NewRunnableMethod(this, &nsPicoService::RegisterVoices)); } void diff --git a/dom/media/webspeech/synth/speechd/SpeechDispatcherService.cpp b/dom/media/webspeech/synth/speechd/SpeechDispatcherService.cpp index 47154df34677..7b54e01e2fb7 100644 --- a/dom/media/webspeech/synth/speechd/SpeechDispatcherService.cpp +++ b/dom/media/webspeech/synth/speechd/SpeechDispatcherService.cpp @@ -274,7 +274,7 @@ speechd_cb(size_t msg_id, size_t client_id, SPDNotificationType state) if (service) { NS_DispatchToMainThread( - NewRunnableMethod( + NS_NewRunnableMethodWithArgs( service, &SpeechDispatcherService::EventNotify, static_cast(msg_id), state)); } @@ -311,7 +311,7 @@ SpeechDispatcherService::Init() getter_AddRefs(mInitThread)); MOZ_ASSERT(NS_SUCCEEDED(rv)); rv = mInitThread->Dispatch( - NewRunnableMethod(this, &SpeechDispatcherService::Setup), NS_DISPATCH_NORMAL); + NS_NewRunnableMethod(this, &SpeechDispatcherService::Setup), NS_DISPATCH_NORMAL); MOZ_ASSERT(NS_SUCCEEDED(rv)); } @@ -412,7 +412,7 @@ SpeechDispatcherService::Setup() } } - NS_DispatchToMainThread(NewRunnableMethod(this, &SpeechDispatcherService::RegisterVoices)); + NS_DispatchToMainThread(NS_NewRunnableMethod(this, &SpeechDispatcherService::RegisterVoices)); //mInitialized = true; } @@ -518,10 +518,10 @@ SpeechDispatcherService::Speak(const nsAString& aText, const nsAString& aUri, // Speech dispatcher does not work well with empty strings. // In that case, don't send empty string to speechd, // and just emulate a speechd start and end event. - NS_DispatchToMainThread(NewRunnableMethod( + NS_DispatchToMainThread(NS_NewRunnableMethodWithArgs( callback, &SpeechDispatcherCallback::OnSpeechEvent, SPD_EVENT_BEGIN)); - NS_DispatchToMainThread(NewRunnableMethod( + NS_DispatchToMainThread(NS_NewRunnableMethodWithArgs( callback, &SpeechDispatcherCallback::OnSpeechEvent, SPD_EVENT_END)); } diff --git a/dom/media/webspeech/synth/test/nsFakeSynthServices.cpp b/dom/media/webspeech/synth/test/nsFakeSynthServices.cpp index 582ff35510af..4e34e7200809 100644 --- a/dom/media/webspeech/synth/test/nsFakeSynthServices.cpp +++ b/dom/media/webspeech/synth/test/nsFakeSynthServices.cpp @@ -356,7 +356,7 @@ nsFakeSynthServices::Observe(nsISupports* aSubject, const char* aTopic, } if (Preferences::GetBool("media.webspeech.synth.test")) { - NS_DispatchToMainThread(NewRunnableMethod(this, &nsFakeSynthServices::Init)); + NS_DispatchToMainThread(NS_NewRunnableMethod(this, &nsFakeSynthServices::Init)); } return NS_OK; diff --git a/dom/notification/Notification.cpp b/dom/notification/Notification.cpp index d4211c70b356..f12ae3bafb5b 100644 --- a/dom/notification/Notification.cpp +++ b/dom/notification/Notification.cpp @@ -46,7 +46,6 @@ #include "nsProxyRelease.h" #include "nsServiceManagerUtils.h" #include "nsStructuredCloneContainer.h" -#include "nsThreadUtils.h" #include "nsToolkitCompsCID.h" #include "nsXULAppAPI.h" #include "ServiceWorkerManager.h" @@ -646,8 +645,9 @@ NotificationPermissionRequest::GetRequester(nsIContentPermissionRequester** aReq inline nsresult NotificationPermissionRequest::DispatchResolvePromise() { - return NS_DispatchToMainThread(NewRunnableMethod(this, - &NotificationPermissionRequest::ResolvePromise)); + nsCOMPtr resolveRunnable = NS_NewRunnableMethod(this, + &NotificationPermissionRequest::ResolvePromise); + return NS_DispatchToMainThread(resolveRunnable); } nsresult diff --git a/dom/plugins/base/nsNPAPIPluginInstance.cpp b/dom/plugins/base/nsNPAPIPluginInstance.cpp index b953c71d8a48..28b5256a35db 100644 --- a/dom/plugins/base/nsNPAPIPluginInstance.cpp +++ b/dom/plugins/base/nsNPAPIPluginInstance.cpp @@ -891,7 +891,7 @@ already_AddRefed nsNPAPIPluginInstance::CreateSurfaceText return nullptr; } - nsCOMPtr frameCallback = NewRunnableMethod(this, &nsNPAPIPluginInstance::OnSurfaceTextureFrameAvailable); + nsCOMPtr frameCallback = NS_NewRunnableMethod(this, &nsNPAPIPluginInstance::OnSurfaceTextureFrameAvailable); surface->SetFrameAvailableCallback(frameCallback); return surface.forget(); } diff --git a/dom/plugins/ipc/PluginInstanceChild.cpp b/dom/plugins/ipc/PluginInstanceChild.cpp index a6ed968bde2b..a35fe3dc1ffe 100644 --- a/dom/plugins/ipc/PluginInstanceChild.cpp +++ b/dom/plugins/ipc/PluginInstanceChild.cpp @@ -3292,7 +3292,7 @@ PluginInstanceChild::RecvAsyncSetWindow(const gfxSurfaceType& aSurfaceType, // RPC call, and both Flash and Java don't expect to receive setwindow calls // at arbitrary times. mCurrentAsyncSetWindowTask = - NewNonOwningCancelableRunnableMethod + NS_NewNonOwningCancelableRunnableMethodWithArgs (this, &PluginInstanceChild::DoAsyncSetWindow, aSurfaceType, aWindow, true); RefPtr addrefedTask = mCurrentAsyncSetWindowTask; MessageLoop::current()->PostTask(addrefedTask.forget()); @@ -4213,7 +4213,7 @@ PluginInstanceChild::AsyncShowPluginFrame(void) } mCurrentInvalidateTask = - NewNonOwningCancelableRunnableMethod(this, &PluginInstanceChild::InvalidateRectDelayed); + NS_NewNonOwningCancelableRunnableMethod(this, &PluginInstanceChild::InvalidateRectDelayed); RefPtr addrefedTask = mCurrentInvalidateTask; MessageLoop::current()->PostTask(addrefedTask.forget()); } diff --git a/dom/plugins/ipc/PluginInstanceParent.cpp b/dom/plugins/ipc/PluginInstanceParent.cpp index ddfcd31cb968..81302170198e 100644 --- a/dom/plugins/ipc/PluginInstanceParent.cpp +++ b/dom/plugins/ipc/PluginInstanceParent.cpp @@ -1216,7 +1216,7 @@ PluginInstanceParent::ScheduleScrollCapture(int aTimeout) } CAPTURE_LOG("delayed scroll capture requested."); mCaptureRefreshTask = - NewNonOwningCancelableRunnableMethod(this, &PluginInstanceParent::ScheduledUpdateScrollCaptureCallback); + NS_NewNonOwningRunnableMethod(this, &PluginInstanceParent::ScheduledUpdateScrollCaptureCallback); RefPtr addrefedTask = mCaptureRefreshTask; MessageLoop::current()->PostDelayedTask(addrefedTask.forget(), kScrollCaptureDelayMs); diff --git a/dom/plugins/ipc/PluginProcessParent.cpp b/dom/plugins/ipc/PluginProcessParent.cpp index 6331470325cb..3b99f3a606b0 100644 --- a/dom/plugins/ipc/PluginProcessParent.cpp +++ b/dom/plugins/ipc/PluginProcessParent.cpp @@ -195,7 +195,8 @@ PluginProcessParent::Delete() return; } - ioLoop->PostTask(NewNonOwningRunnableMethod(this, &PluginProcessParent::Delete)); + RefPtr runnable = NS_NewNonOwningRunnableMethod(this, &PluginProcessParent::Delete); + ioLoop->PostTask(runnable.forget()); } void diff --git a/dom/presentation/PresentationAvailability.cpp b/dom/presentation/PresentationAvailability.cpp index 4195b450397a..f599d9195775 100644 --- a/dom/presentation/PresentationAvailability.cpp +++ b/dom/presentation/PresentationAvailability.cpp @@ -107,10 +107,11 @@ PresentationAvailability::Value() const NS_IMETHODIMP PresentationAvailability::NotifyAvailableChange(bool aIsAvailable) { - return NS_DispatchToCurrentThread(NewRunnableMethod - (this, - &PresentationAvailability::UpdateAvailabilityAndDispatchEvent, - aIsAvailable)); + nsCOMPtr runnable = + NS_NewRunnableMethodWithArg(this, + &PresentationAvailability::UpdateAvailabilityAndDispatchEvent, + aIsAvailable); + return NS_DispatchToCurrentThread(runnable); } void diff --git a/dom/presentation/PresentationDeviceManager.cpp b/dom/presentation/PresentationDeviceManager.cpp index ce8c6fde9cd8..474c83b73ff3 100644 --- a/dom/presentation/PresentationDeviceManager.cpp +++ b/dom/presentation/PresentationDeviceManager.cpp @@ -155,7 +155,7 @@ PresentationDeviceManager::GetAvailableDevices(nsIArray** aRetVal) // Bug 1194049: some providers may discontinue discovery after timeout. // Call |ForceDiscovery()| here to make sure device lists are updated. NS_DispatchToMainThread( - NewRunnableMethod(this, &PresentationDeviceManager::ForceDiscovery)); + NS_NewRunnableMethod(this, &PresentationDeviceManager::ForceDiscovery)); nsCOMPtr devices = do_CreateInstance(NS_ARRAY_CONTRACTID); for (uint32_t i = 0; i < mDevices.Length(); ++i) { diff --git a/dom/presentation/PresentationSessionInfo.cpp b/dom/presentation/PresentationSessionInfo.cpp index 8d1a6678be68..030dd2a95004 100644 --- a/dom/presentation/PresentationSessionInfo.cpp +++ b/dom/presentation/PresentationSessionInfo.cpp @@ -112,9 +112,9 @@ PresentationNetworkHelper::OnGetWifiIPAddress(const nsACString& aIPAddress) MOZ_ASSERT(mFunc); NS_DispatchToMainThread( - NewRunnableMethod(mInfo, - mFunc, - aIPAddress)); + NS_NewRunnableMethodWithArg(mInfo, + mFunc, + aIPAddress)); return NS_OK; } @@ -550,7 +550,7 @@ PresentationControllingInfo::GetAddress() // To make consistent code sequence, following function call is dispatched // into main thread instead of calling it directly. NS_DispatchToMainThread( - NewRunnableMethod( + NS_NewRunnableMethodWithArg( this, &PresentationControllingInfo::OnGetAddress, NS_ConvertUTF16toUTF8(ip))); @@ -570,7 +570,7 @@ PresentationControllingInfo::GetAddress() #elif defined(MOZ_MULET) // In simulator,we need to use the "127.0.0.1" as target address. NS_DispatchToMainThread( - NewRunnableMethod( + NS_NewRunnableMethodWithArg( this, &PresentationControllingInfo::OnGetAddress, "127.0.0.1")); @@ -579,7 +579,7 @@ PresentationControllingInfo::GetAddress() // TODO Get host IP via other platforms. NS_DispatchToMainThread( - NewRunnableMethod( + NS_NewRunnableMethodWithArg( this, &PresentationControllingInfo::OnGetAddress, EmptyCString())); diff --git a/dom/presentation/PresentationTCPSessionTransport.cpp b/dom/presentation/PresentationTCPSessionTransport.cpp index 111242f4d7c4..a2cd9b3a0b61 100644 --- a/dom/presentation/PresentationTCPSessionTransport.cpp +++ b/dom/presentation/PresentationTCPSessionTransport.cpp @@ -111,18 +111,18 @@ PresentationTCPSessionTransport::BuildTCPSenderTransport(nsISocketTransport* aTr nsCOMPtr sessionTransport = do_QueryObject(this); nsCOMPtr onSessionTransportRunnable = - NewRunnableMethod + NS_NewRunnableMethodWithArgs (mListener, &nsIPresentationSessionTransportBuilderListener::OnSessionTransport, sessionTransport); - NS_DispatchToCurrentThread(onSessionTransportRunnable.forget()); + NS_DispatchToCurrentThread(onSessionTransportRunnable); nsCOMPtr setReadyStateRunnable = - NewRunnableMethod(this, - &PresentationTCPSessionTransport::SetReadyState, - ReadyState::OPEN); - return NS_DispatchToCurrentThread(setReadyStateRunnable.forget()); + NS_NewRunnableMethodWithArgs(this, + &PresentationTCPSessionTransport::SetReadyState, + ReadyState::OPEN); + return NS_DispatchToCurrentThread(setReadyStateRunnable); } NS_IMETHODIMP @@ -193,11 +193,11 @@ PresentationTCPSessionTransport::BuildTCPReceiverTransport(nsIPresentationChanne nsCOMPtr sessionTransport = do_QueryObject(this); nsCOMPtr runnable = - NewRunnableMethod + NS_NewRunnableMethodWithArgs (mListener, &nsIPresentationSessionTransportBuilderListener::OnSessionTransport, sessionTransport); - return NS_DispatchToCurrentThread(runnable.forget()); + return NS_DispatchToCurrentThread(runnable); } nsresult diff --git a/dom/presentation/provider/MulticastDNSDeviceProvider.cpp b/dom/presentation/provider/MulticastDNSDeviceProvider.cpp index 07f6710fc810..0880c83b3811 100644 --- a/dom/presentation/provider/MulticastDNSDeviceProvider.cpp +++ b/dom/presentation/provider/MulticastDNSDeviceProvider.cpp @@ -721,7 +721,7 @@ MulticastDNSDeviceProvider::OnRegistrationFailed(nsIDNSServiceInfo* aServiceInfo if (aErrorCode == nsIDNSRegistrationListener::ERROR_SERVICE_NOT_RUNNING) { return NS_DispatchToMainThread( - NewRunnableMethod(this, &MulticastDNSDeviceProvider::RegisterService)); + NS_NewRunnableMethod(this, &MulticastDNSDeviceProvider::RegisterService)); } return NS_OK; diff --git a/dom/quota/ActorsParent.cpp b/dom/quota/ActorsParent.cpp index 4e02495d13f3..15ba4c243322 100644 --- a/dom/quota/ActorsParent.cpp +++ b/dom/quota/ActorsParent.cpp @@ -3084,15 +3084,13 @@ QuotaManager::Shutdown() NS_WARNING("Failed to cancel shutdown timer!"); } - // NB: It's very important that runnable is destroyed on this thread - // (i.e. after we join the IO thread) because we can't release the - // QuotaManager on the IO thread. This should probably use - // NewNonOwningRunnableMethod ... - RefPtr runnable = - NewRunnableMethod(this, &QuotaManager::ReleaseIOThreadObjects); - MOZ_ASSERT(runnable); - // Give clients a chance to cleanup IO thread only objects. + nsCOMPtr runnable = + NS_NewRunnableMethod(this, &QuotaManager::ReleaseIOThreadObjects); + if (!runnable) { + NS_WARNING("Failed to create runnable!"); + } + if (NS_FAILED(mIOThread->Dispatch(runnable, NS_DISPATCH_NORMAL))) { NS_WARNING("Failed to dispatch runnable!"); } @@ -5315,7 +5313,7 @@ Quota::RecvStartIdleMaintenance() QuotaManager* quotaManager = QuotaManager::Get(); if (!quotaManager) { nsCOMPtr callback = - NewRunnableMethod(this, &Quota::StartIdleMaintenance); + NS_NewRunnableMethod(this, &Quota::StartIdleMaintenance); QuotaManager::GetOrCreate(callback); return true; diff --git a/dom/storage/DOMStorageCache.cpp b/dom/storage/DOMStorageCache.cpp index 6c7aed5b3258..82c6ddcae924 100644 --- a/dom/storage/DOMStorageCache.cpp +++ b/dom/storage/DOMStorageCache.cpp @@ -110,8 +110,8 @@ DOMStorageCache::Release(void) } RefPtr > event = - NewNonOwningRunnableMethod(static_cast(this), - &DOMStorageCacheBridge::Release); + NS_NewNonOwningRunnableMethod(static_cast(this), + &DOMStorageCacheBridge::Release); nsresult rv = NS_DispatchToMainThread(event); if (NS_FAILED(rv)) { @@ -281,7 +281,10 @@ DOMStorageCache::KeepAlive() if (!NS_IsMainThread()) { // Timer and the holder must be initialized on the main thread. - NS_DispatchToMainThread(NewRunnableMethod(this, &DOMStorageCache::KeepAlive)); + RefPtr > event = + NS_NewRunnableMethod(this, &DOMStorageCache::KeepAlive); + + NS_DispatchToMainThread(event); return; } diff --git a/dom/storage/DOMStorageDBThread.cpp b/dom/storage/DOMStorageDBThread.cpp index 95e461c9f6fe..945b4407b229 100644 --- a/dom/storage/DOMStorageDBThread.cpp +++ b/dom/storage/DOMStorageDBThread.cpp @@ -721,7 +721,7 @@ DOMStorageDBThread::NotifyFlushCompletion() #ifdef DOM_STORAGE_TESTS if (!NS_IsMainThread()) { RefPtr > event = - NewNonOwningRunnableMethod(this, &DOMStorageDBThread::NotifyFlushCompletion); + NS_NewNonOwningRunnableMethod(this, &DOMStorageDBThread::NotifyFlushCompletion); NS_DispatchToMainThread(event); return; } diff --git a/dom/svg/SVGFEImageElement.cpp b/dom/svg/SVGFEImageElement.cpp index b2ebfbe0fd56..e085f00895ed 100644 --- a/dom/svg/SVGFEImageElement.cpp +++ b/dom/svg/SVGFEImageElement.cpp @@ -155,7 +155,7 @@ SVGFEImageElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent, ClearBrokenState(); RemoveStatesSilently(NS_EVENT_STATE_BROKEN); nsContentUtils::AddScriptRunner( - NewRunnableMethod(this, &SVGFEImageElement::MaybeLoadSVGImage)); + NS_NewRunnableMethod(this, &SVGFEImageElement::MaybeLoadSVGImage)); } return rv; diff --git a/dom/svg/SVGImageElement.cpp b/dom/svg/SVGImageElement.cpp index 6d5af4128ee4..144e375f2dc8 100644 --- a/dom/svg/SVGImageElement.cpp +++ b/dom/svg/SVGImageElement.cpp @@ -183,7 +183,7 @@ SVGImageElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent, ClearBrokenState(); RemoveStatesSilently(NS_EVENT_STATE_BROKEN); nsContentUtils::AddScriptRunner( - NewRunnableMethod(this, &SVGImageElement::MaybeLoadSVGImage)); + NS_NewRunnableMethod(this, &SVGImageElement::MaybeLoadSVGImage)); } return rv; diff --git a/dom/svg/SVGStyleElement.cpp b/dom/svg/SVGStyleElement.cpp index 22fb204dff95..33437f7ba712 100644 --- a/dom/svg/SVGStyleElement.cpp +++ b/dom/svg/SVGStyleElement.cpp @@ -78,7 +78,7 @@ SVGStyleElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent, NS_ENSURE_SUCCESS(rv, rv); void (SVGStyleElement::*update)() = &SVGStyleElement::UpdateStyleSheetInternal; - nsContentUtils::AddScriptRunner(NewRunnableMethod(this, update)); + nsContentUtils::AddScriptRunner(NS_NewRunnableMethod(this, update)); return rv; } diff --git a/dom/tv/TVSource.cpp b/dom/tv/TVSource.cpp index 1b78fdf0b66d..869315e650ed 100644 --- a/dom/tv/TVSource.cpp +++ b/dom/tv/TVSource.cpp @@ -372,9 +372,9 @@ TVSource::DispatchCurrentChannelChangedEvent(TVChannel* aChannel) NS_LITERAL_STRING("currentchannelchanged"), init); nsCOMPtr runnable = - NewRunnableMethod>(this, - &TVSource::DispatchTVEvent, - event); + NS_NewRunnableMethodWithArg>(this, + &TVSource::DispatchTVEvent, + event); return NS_DispatchToCurrentThread(runnable); } @@ -390,9 +390,9 @@ TVSource::DispatchScanningStateChangedEvent(TVScanningState aState, NS_LITERAL_STRING("scanningstatechanged"), init); nsCOMPtr runnable = - NewRunnableMethod>(this, - &TVSource::DispatchTVEvent, - event); + NS_NewRunnableMethodWithArg>(this, + &TVSource::DispatchTVEvent, + event); return NS_DispatchToCurrentThread(runnable); } @@ -406,9 +406,9 @@ TVSource::DispatchEITBroadcastedEvent(const Sequence>& NS_LITERAL_STRING("eitbroadcasted"), init); nsCOMPtr runnable = - NewRunnableMethod>(this, - &TVSource::DispatchTVEvent, - event); + NS_NewRunnableMethodWithArg>(this, + &TVSource::DispatchTVEvent, + event); return NS_DispatchToCurrentThread(runnable); } diff --git a/dom/tv/TVTuner.cpp b/dom/tv/TVTuner.cpp index 35f53eb9ac5c..e1e4412ddca8 100644 --- a/dom/tv/TVTuner.cpp +++ b/dom/tv/TVTuner.cpp @@ -315,9 +315,9 @@ TVTuner::DispatchCurrentSourceChangedEvent(TVSource* aSource) NS_LITERAL_STRING("currentsourcechanged"), init); nsCOMPtr runnable = - NewRunnableMethod>(this, - &TVTuner::DispatchTVEvent, - event); + NS_NewRunnableMethodWithArg>(this, + &TVTuner::DispatchTVEvent, + event); return NS_DispatchToCurrentThread(runnable); } diff --git a/dom/workers/ScriptLoader.cpp b/dom/workers/ScriptLoader.cpp index 00d68750d176..09f599004bb6 100644 --- a/dom/workers/ScriptLoader.cpp +++ b/dom/workers/ScriptLoader.cpp @@ -716,9 +716,11 @@ private: if (aStatus >= Terminating && !mCanceled) { mCanceled = true; - MOZ_ALWAYS_SUCCEEDS( - NS_DispatchToMainThread(NewRunnableMethod(this, - &ScriptLoaderRunnable::CancelMainThreadWithBindingAborted))); + nsCOMPtr runnable = + NS_NewRunnableMethod(this, + &ScriptLoaderRunnable::CancelMainThreadWithBindingAborted); + NS_ASSERTION(runnable, "This should never fail!"); + MOZ_ALWAYS_SUCCEEDS(NS_DispatchToMainThread(runnable)); } return true; diff --git a/dom/workers/ServiceWorkerEvents.cpp b/dom/workers/ServiceWorkerEvents.cpp index 5d86cd1f3019..f79105c00a89 100644 --- a/dom/workers/ServiceWorkerEvents.cpp +++ b/dom/workers/ServiceWorkerEvents.cpp @@ -853,8 +853,9 @@ public: mColumn = column; } - MOZ_ALWAYS_SUCCEEDS( - NS_DispatchToMainThread(NewRunnableMethod(this, &WaitUntilHandler::ReportOnMainThread))); + nsCOMPtr runnable = + NS_NewRunnableMethod(this, &WaitUntilHandler::ReportOnMainThread); + MOZ_ALWAYS_SUCCEEDS(NS_DispatchToMainThread(runnable.forget())); } void diff --git a/dom/workers/ServiceWorkerJob.cpp b/dom/workers/ServiceWorkerJob.cpp index 73716fab615b..c634fb915480 100644 --- a/dom/workers/ServiceWorkerJob.cpp +++ b/dom/workers/ServiceWorkerJob.cpp @@ -95,7 +95,7 @@ ServiceWorkerJob::Start(Callback* aFinalCallback) mState = State::Started; nsCOMPtr runnable = - NewRunnableMethod(this, &ServiceWorkerJob::AsyncExecute); + NS_NewRunnableMethod(this, &ServiceWorkerJob::AsyncExecute); // We may have to wait for the PBackground actor to be initialized // before proceeding. We should always be able to get a ServiceWorkerManager, diff --git a/dom/workers/ServiceWorkerPrivate.cpp b/dom/workers/ServiceWorkerPrivate.cpp index ba13cf17ef1d..3ada307db781 100644 --- a/dom/workers/ServiceWorkerPrivate.cpp +++ b/dom/workers/ServiceWorkerPrivate.cpp @@ -622,7 +622,7 @@ public: return; } nsCOMPtr runnable = - NewRunnableMethod(this, + NS_NewRunnableMethodWithArg(this, &PushErrorReporter::ReportOnMainThread, aReason); MOZ_ALWAYS_TRUE(NS_SUCCEEDED( NS_DispatchToMainThread(runnable.forget()))); @@ -1457,7 +1457,7 @@ ServiceWorkerPrivate::SendFetchEvent(nsIInterceptedChannel* aChannel, // if the ServiceWorker script fails to load for some reason, just resume // the original channel. nsCOMPtr failRunnable = - NewRunnableMethod(aChannel, &nsIInterceptedChannel::ResetInterception); + NS_NewRunnableMethod(aChannel, &nsIInterceptedChannel::ResetInterception); nsresult rv = SpawnWorkerIfNeeded(FetchEvent, failRunnable, aLoadGroup); NS_ENSURE_SUCCESS(rv, rv); diff --git a/dom/workers/ServiceWorkerRegistrar.cpp b/dom/workers/ServiceWorkerRegistrar.cpp index 54ab9b4d586a..a9609aae3d31 100644 --- a/dom/workers/ServiceWorkerRegistrar.cpp +++ b/dom/workers/ServiceWorkerRegistrar.cpp @@ -540,7 +540,7 @@ public: service->SaveData(); RefPtr runnable = - NewRunnableMethod(service, &ServiceWorkerRegistrar::DataSaved); + NS_NewRunnableMethod(service, &ServiceWorkerRegistrar::DataSaved); nsresult rv = mThread->Dispatch(runnable, NS_DISPATCH_NORMAL); if (NS_WARN_IF(NS_FAILED(rv))) { return rv; @@ -614,7 +614,7 @@ ServiceWorkerRegistrar::MaybeScheduleShutdownCompleted() } RefPtr runnable = - NewRunnableMethod(this, &ServiceWorkerRegistrar::ShutdownCompleted); + NS_NewRunnableMethod(this, &ServiceWorkerRegistrar::ShutdownCompleted); nsresult rv = NS_DispatchToMainThread(runnable); if (NS_WARN_IF(NS_FAILED(rv))) { return; @@ -744,7 +744,7 @@ ServiceWorkerRegistrar::ProfileStarted() MOZ_ASSERT(target, "Must have stream transport service"); nsCOMPtr runnable = - NewRunnableMethod(this, &ServiceWorkerRegistrar::LoadData); + NS_NewRunnableMethod(this, &ServiceWorkerRegistrar::LoadData); rv = target->Dispatch(runnable, NS_DISPATCH_NORMAL); if (NS_FAILED(rv)) { NS_WARNING("Failed to dispatch the LoadDataRunnable."); diff --git a/dom/workers/ServiceWorkerRegistrationInfo.cpp b/dom/workers/ServiceWorkerRegistrationInfo.cpp index 3bf6348e6219..aeb96a44780b 100644 --- a/dom/workers/ServiceWorkerRegistrationInfo.cpp +++ b/dom/workers/ServiceWorkerRegistrationInfo.cpp @@ -201,9 +201,10 @@ ServiceWorkerRegistrationInfo::GetServiceWorkerInfoById(uint64_t aId) void ServiceWorkerRegistrationInfo::TryToActivateAsync() { - MOZ_ALWAYS_SUCCEEDS( - NS_DispatchToMainThread(NewRunnableMethod(this, - &ServiceWorkerRegistrationInfo::TryToActivate))); + nsCOMPtr r = + NS_NewRunnableMethod(this, + &ServiceWorkerRegistrationInfo::TryToActivate); + MOZ_ALWAYS_SUCCEEDS(NS_DispatchToMainThread(r)); } /* @@ -235,14 +236,14 @@ ServiceWorkerRegistrationInfo::Activate() // "Queue a task to fire a simple event named controllerchange..." nsCOMPtr controllerChangeRunnable = - NewRunnableMethod>( + NS_NewRunnableMethodWithArg>( swm, &ServiceWorkerManager::FireControllerChange, this); NS_DispatchToMainThread(controllerChangeRunnable); nsCOMPtr failRunnable = - NewRunnableMethod(this, - &ServiceWorkerRegistrationInfo::FinishActivate, - false /* success */); + NS_NewRunnableMethodWithArg(this, + &ServiceWorkerRegistrationInfo::FinishActivate, + false /* success */); nsMainThreadPtrHandle handle( new nsMainThreadPtrHolder(this)); diff --git a/dom/workers/ServiceWorkerUpdateJob.cpp b/dom/workers/ServiceWorkerUpdateJob.cpp index 337c3dca365e..d1f20a3452d9 100644 --- a/dom/workers/ServiceWorkerUpdateJob.cpp +++ b/dom/workers/ServiceWorkerUpdateJob.cpp @@ -489,7 +489,7 @@ ServiceWorkerUpdateJob::Install() // fire the updatefound event nsCOMPtr upr = - NewRunnableMethod>( + NS_NewRunnableMethodWithArg>( swm, &ServiceWorkerManager::FireUpdateFoundOnServiceWorkerRegistrations, mRegistration); @@ -497,7 +497,7 @@ ServiceWorkerUpdateJob::Install() // Call ContinueAfterInstallEvent(false) on main thread if the SW // script fails to load. - nsCOMPtr failRunnable = NewRunnableMethod + nsCOMPtr failRunnable = NS_NewRunnableMethodWithArgs (this, &ServiceWorkerUpdateJob::ContinueAfterInstallEvent, false); nsMainThreadPtrHandle handle( diff --git a/dom/xbl/nsBindingManager.cpp b/dom/xbl/nsBindingManager.cpp index b3ee9b121af4..9e2bb527713a 100644 --- a/dom/xbl/nsBindingManager.cpp +++ b/dom/xbl/nsBindingManager.cpp @@ -347,7 +347,7 @@ void nsBindingManager::PostProcessAttachedQueueEvent() { mProcessAttachedQueueEvent = - NewRunnableMethod(this, &nsBindingManager::DoProcessAttachedQueue); + NS_NewRunnableMethod(this, &nsBindingManager::DoProcessAttachedQueue); nsresult rv = NS_DispatchToCurrentThread(mProcessAttachedQueueEvent); if (NS_SUCCEEDED(rv) && mDocument) { mDocument->BlockOnload(); diff --git a/dom/xml/XMLStylesheetProcessingInstruction.cpp b/dom/xml/XMLStylesheetProcessingInstruction.cpp index 3d94e179b48a..cc5734c6a490 100644 --- a/dom/xml/XMLStylesheetProcessingInstruction.cpp +++ b/dom/xml/XMLStylesheetProcessingInstruction.cpp @@ -63,7 +63,7 @@ XMLStylesheetProcessingInstruction::BindToTree(nsIDocument* aDocument, void (XMLStylesheetProcessingInstruction::*update)() = &XMLStylesheetProcessingInstruction::UpdateStyleSheetInternal; - nsContentUtils::AddScriptRunner(NewRunnableMethod(this, update)); + nsContentUtils::AddScriptRunner(NS_NewRunnableMethod(this, update)); return rv; } diff --git a/dom/xml/nsXMLContentSink.cpp b/dom/xml/nsXMLContentSink.cpp index e33c48d0360d..1bc56506c46d 100644 --- a/dom/xml/nsXMLContentSink.cpp +++ b/dom/xml/nsXMLContentSink.cpp @@ -1553,7 +1553,7 @@ nsXMLContentSink::ContinueInterruptedParsingIfEnabled() void nsXMLContentSink::ContinueInterruptedParsingAsync() { - nsCOMPtr ev = NewRunnableMethod(this, + nsCOMPtr ev = NS_NewRunnableMethod(this, &nsXMLContentSink::ContinueInterruptedParsingIfEnabled); NS_DispatchToCurrentThread(ev); diff --git a/dom/xml/nsXMLPrettyPrinter.cpp b/dom/xml/nsXMLPrettyPrinter.cpp index 2e086dde0bee..ee50cd0ac3cb 100644 --- a/dom/xml/nsXMLPrettyPrinter.cpp +++ b/dom/xml/nsXMLPrettyPrinter.cpp @@ -194,7 +194,7 @@ nsXMLPrettyPrinter::MaybeUnhook(nsIContent* aContent) // synchronously mUnhookPending = true; nsContentUtils::AddScriptRunner( - NewRunnableMethod(this, &nsXMLPrettyPrinter::Unhook)); + NS_NewRunnableMethod(this, &nsXMLPrettyPrinter::Unhook)); } } diff --git a/dom/xul/XULDocument.cpp b/dom/xul/XULDocument.cpp index 50ba10c233a8..6e6262d91216 100644 --- a/dom/xul/XULDocument.cpp +++ b/dom/xul/XULDocument.cpp @@ -1015,7 +1015,7 @@ XULDocument::AttributeChanged(nsIDocument* aDocument, if (ShouldPersistAttribute(aElement, aAttribute) && !persist.IsEmpty() && // XXXldb This should check that it's a token, not just a substring. persist.Find(nsDependentAtomString(aAttribute)) >= 0) { - nsContentUtils::AddScriptRunner(NewRunnableMethod + nsContentUtils::AddScriptRunner(NS_NewRunnableMethodWithArgs (this, &XULDocument::DoPersist, aElement, kNameSpaceID_None, aAttribute)); @@ -3135,7 +3135,7 @@ XULDocument::MaybeBroadcast() if (!nsContentUtils::IsSafeToRunScript()) { if (!mInDestructor) { nsContentUtils::AddScriptRunner( - NewRunnableMethod(this, &XULDocument::MaybeBroadcast)); + NS_NewRunnableMethod(this, &XULDocument::MaybeBroadcast)); } return; } diff --git a/dom/xul/templates/nsXULTemplateBuilder.cpp b/dom/xul/templates/nsXULTemplateBuilder.cpp index 2ae794944cad..632afcd06400 100644 --- a/dom/xul/templates/nsXULTemplateBuilder.cpp +++ b/dom/xul/templates/nsXULTemplateBuilder.cpp @@ -1096,13 +1096,13 @@ nsXULTemplateBuilder::AttributeChanged(nsIDocument* aDocument, // beneath the element. if (aAttribute == nsGkAtoms::ref) nsContentUtils::AddScriptRunner( - NewRunnableMethod(this, &nsXULTemplateBuilder::RunnableRebuild)); + NS_NewRunnableMethod(this, &nsXULTemplateBuilder::RunnableRebuild)); // Check for a change to the 'datasources' attribute. If so, setup // mDB by parsing the new value and rebuild. else if (aAttribute == nsGkAtoms::datasources) { nsContentUtils::AddScriptRunner( - NewRunnableMethod(this, &nsXULTemplateBuilder::RunnableLoadAndRebuild)); + NS_NewRunnableMethod(this, &nsXULTemplateBuilder::RunnableLoadAndRebuild)); } } } @@ -1122,7 +1122,7 @@ nsXULTemplateBuilder::ContentRemoved(nsIDocument* aDocument, // Pass false to Uninit since content is going away anyway nsContentUtils::AddScriptRunner( - NewRunnableMethod(this, &nsXULTemplateBuilder::UninitFalse)); + NS_NewRunnableMethod(this, &nsXULTemplateBuilder::UninitFalse)); MOZ_ASSERT(aDocument == mObservedDocument); StopObserving(); @@ -1161,7 +1161,7 @@ nsXULTemplateBuilder::NodeWillBeDestroyed(const nsINode* aNode) mCompDB = nullptr; nsContentUtils::AddScriptRunner( - NewRunnableMethod(this, &nsXULTemplateBuilder::UninitTrue)); + NS_NewRunnableMethod(this, &nsXULTemplateBuilder::UninitTrue)); } diff --git a/editor/libeditor/nsHTMLEditRules.cpp b/editor/libeditor/nsHTMLEditRules.cpp index 63aac4ea5dae..9ec1864f54c8 100644 --- a/editor/libeditor/nsHTMLEditRules.cpp +++ b/editor/libeditor/nsHTMLEditRules.cpp @@ -9037,7 +9037,7 @@ nsHTMLEditRules::WillRelativeChangeZIndex(Selection* aSelection, NS_IMETHODIMP nsHTMLEditRules::DocumentModified() { - nsContentUtils::AddScriptRunner(NewRunnableMethod(this, &nsHTMLEditRules::DocumentModifiedWorker)); + nsContentUtils::AddScriptRunner(NS_NewRunnableMethod(this, &nsHTMLEditRules::DocumentModifiedWorker)); return NS_OK; } diff --git a/editor/libeditor/nsHTMLEditor.cpp b/editor/libeditor/nsHTMLEditor.cpp index 14e1e6d25038..daa845a4881f 100644 --- a/editor/libeditor/nsHTMLEditor.cpp +++ b/editor/libeditor/nsHTMLEditor.cpp @@ -3206,7 +3206,7 @@ nsHTMLEditor::DoContentInserted(nsIDocument* aDocument, nsIContent* aContainer, nsCOMPtr kungFuDeathGrip(this); if (ShouldReplaceRootElement()) { - nsContentUtils::AddScriptRunner(NewRunnableMethod( + nsContentUtils::AddScriptRunner(NS_NewRunnableMethod( this, &nsHTMLEditor::ResetRootElementAndEventTarget)); } // We don't need to handle our own modifications @@ -3248,7 +3248,7 @@ nsHTMLEditor::ContentRemoved(nsIDocument *aDocument, nsIContent* aContainer, nsCOMPtr kungFuDeathGrip(this); if (SameCOMIdentity(aChild, mRootElement)) { - nsContentUtils::AddScriptRunner(NewRunnableMethod( + nsContentUtils::AddScriptRunner(NS_NewRunnableMethod( this, &nsHTMLEditor::ResetRootElementAndEventTarget)); } // We don't need to handle our own modifications diff --git a/embedding/components/webbrowserpersist/WebBrowserPersistDocumentParent.cpp b/embedding/components/webbrowserpersist/WebBrowserPersistDocumentParent.cpp index 248b05b9b0cc..35a62918755d 100644 --- a/embedding/components/webbrowserpersist/WebBrowserPersistDocumentParent.cpp +++ b/embedding/components/webbrowserpersist/WebBrowserPersistDocumentParent.cpp @@ -43,7 +43,7 @@ WebBrowserPersistDocumentParent::ActorDestroy(ActorDestroyReason aWhy) // dropping the last reference to another document's // WebBrowserPersistRemoteDocument. To avoid that, defer the // callback until after the entire subtree is destroyed. - nsCOMPtr errorLater = NewRunnableMethod + nsCOMPtr errorLater = NS_NewRunnableMethodWithArg (mOnReady, &nsIWebBrowserPersistDocumentReceiver::OnError, NS_ERROR_FAILURE); NS_DispatchToCurrentThread(errorLater); diff --git a/embedding/components/webbrowserpersist/WebBrowserPersistResourcesParent.cpp b/embedding/components/webbrowserpersist/WebBrowserPersistResourcesParent.cpp index 195cabb58b9d..13c1f7f65e6f 100644 --- a/embedding/components/webbrowserpersist/WebBrowserPersistResourcesParent.cpp +++ b/embedding/components/webbrowserpersist/WebBrowserPersistResourcesParent.cpp @@ -33,7 +33,7 @@ WebBrowserPersistResourcesParent::ActorDestroy(ActorDestroyReason aWhy) if (aWhy != Deletion && mVisitor) { // See comment in WebBrowserPersistDocumentParent::ActorDestroy // (or bug 1202887) for why this is deferred. - nsCOMPtr errorLater = NewRunnableMethod + nsCOMPtr errorLater = NS_NewRunnableMethodWithArgs , nsresult> (mVisitor, &nsIWebBrowserPersistResourceVisitor::EndVisit, mDocument, NS_ERROR_FAILURE); diff --git a/embedding/components/webbrowserpersist/WebBrowserPersistSerializeParent.cpp b/embedding/components/webbrowserpersist/WebBrowserPersistSerializeParent.cpp index 2f76ffb332a8..348ba3418ae1 100644 --- a/embedding/components/webbrowserpersist/WebBrowserPersistSerializeParent.cpp +++ b/embedding/components/webbrowserpersist/WebBrowserPersistSerializeParent.cpp @@ -77,7 +77,7 @@ WebBrowserPersistSerializeParent::ActorDestroy(ActorDestroyReason aWhy) MOZ_ASSERT(aWhy != Deletion); // See comment in WebBrowserPersistDocumentParent::ActorDestroy // (or bug 1202887) for why this is deferred. - nsCOMPtr errorLater = NewRunnableMethod + nsCOMPtr errorLater = NS_NewRunnableMethodWithArgs , nsCOMPtr, nsCString, nsresult> (mFinish, &nsIWebBrowserPersistWriteCompletion::OnFinish, diff --git a/embedding/components/webbrowserpersist/nsWebBrowserPersist.cpp b/embedding/components/webbrowserpersist/nsWebBrowserPersist.cpp index 6cf3e7751861..0b1ae126a924 100644 --- a/embedding/components/webbrowserpersist/nsWebBrowserPersist.cpp +++ b/embedding/components/webbrowserpersist/nsWebBrowserPersist.cpp @@ -672,7 +672,7 @@ nsWebBrowserPersist::SerializeNextFile() // Finish and clean things up. Defer this because the caller // may have been expecting to use the listeners that that // method will clear. - NS_DispatchToCurrentThread(NewRunnableMethod(this, + NS_DispatchToCurrentThread(NS_NewRunnableMethod(this, &nsWebBrowserPersist::FinishDownload)); return; } @@ -784,7 +784,7 @@ nsWebBrowserPersist::OnWrite::OnFinish(nsIWebBrowserPersistDocument* aDoc, return NS_OK; } } - NS_DispatchToCurrentThread(NewRunnableMethod(mParent, + NS_DispatchToCurrentThread(NS_NewRunnableMethod(mParent, &nsWebBrowserPersist::SerializeNextFile)); return NS_OK; } @@ -1794,8 +1794,8 @@ nsWebBrowserPersist::FinishSaveDocumentInternal(nsIURI* aFile, typedef StoreCopyPassByRRef WalkStorage; auto saveMethod = &nsWebBrowserPersist::SaveDocumentDeferred; nsCOMPtr saveLater = - NewRunnableMethod(this, saveMethod, - mozilla::Move(toWalk)); + NS_NewRunnableMethodWithArg(this, saveMethod, + mozilla::Move(toWalk)); NS_DispatchToCurrentThread(saveLater); } else { // Done walking DOMs; on to the serialization phase. diff --git a/gfx/gl/AndroidSurfaceTexture.cpp b/gfx/gl/AndroidSurfaceTexture.cpp index 02aa2fc9577f..08d880c7ca14 100644 --- a/gfx/gl/AndroidSurfaceTexture.cpp +++ b/gfx/gl/AndroidSurfaceTexture.cpp @@ -293,7 +293,8 @@ AndroidSurfaceTexture::NotifyFrameAvailable() // Proxy to main thread if we aren't on it if (!NS_IsMainThread()) { // Proxy to main thread - NS_DispatchToCurrentThread(NewRunnableMethod(this, &AndroidSurfaceTexture::NotifyFrameAvailable)); + nsCOMPtr event = NS_NewRunnableMethod(this, &AndroidSurfaceTexture::NotifyFrameAvailable); + NS_DispatchToCurrentThread(event); } else { mFrameAvailableCallback->Run(); } diff --git a/gfx/layers/apz/src/APZCTreeManager.cpp b/gfx/layers/apz/src/APZCTreeManager.cpp index 9716aba0c327..fd66eaea20fa 100644 --- a/gfx/layers/apz/src/APZCTreeManager.cpp +++ b/gfx/layers/apz/src/APZCTreeManager.cpp @@ -649,8 +649,8 @@ APZCTreeManager::FlushApzRepaints(uint64_t aLayersId) const CompositorBridgeParent::LayerTreeState* state = CompositorBridgeParent::GetIndirectShadowTree(aLayersId); MOZ_ASSERT(state && state->mController); - NS_DispatchToMainThread(NewRunnableMethod( - state->mController, &GeckoContentController::NotifyFlushComplete)); + NS_DispatchToMainThread(NS_NewRunnableMethod( + state->mController.get(), &GeckoContentController::NotifyFlushComplete)); } nsEventStatus @@ -1335,7 +1335,8 @@ APZCTreeManager::ClearTree() // Ensure that no references to APZCs are alive in any lingering input // blocks. This breaks cycles from InputBlockState::mTargetApzc back to // the InputQueue. - APZThreadUtils::RunOnControllerThread(NewRunnableMethod(mInputQueue, &InputQueue::Clear)); + RefPtr runnable = NS_NewRunnableMethod(mInputQueue.get(), &InputQueue::Clear); + APZThreadUtils::RunOnControllerThread(runnable.forget()); MutexAutoLock lock(mTreeLock); diff --git a/gfx/layers/apz/src/AsyncPanZoomController.cpp b/gfx/layers/apz/src/AsyncPanZoomController.cpp index 5534ec2c4706..d74536e38015 100644 --- a/gfx/layers/apz/src/AsyncPanZoomController.cpp +++ b/gfx/layers/apz/src/AsyncPanZoomController.cpp @@ -516,9 +516,9 @@ public: // is this one, then the SetState(NOTHING) in UpdateAnimation will // stomp on the SetState(SNAP_BACK) it does. mDeferredTasks.AppendElement( - NewRunnableMethod(mOverscrollHandoffChain.get(), - &OverscrollHandoffChain::SnapBackOverscrolledApzc, - &mApzc)); + NS_NewRunnableMethodWithArg(mOverscrollHandoffChain.get(), + &OverscrollHandoffChain::SnapBackOverscrolledApzc, + &mApzc)); return false; } @@ -568,13 +568,13 @@ public: // called after mMonitor is released. APZC_LOG("%p fling went into overscroll, handing off with velocity %s\n", &mApzc, Stringify(velocity).c_str()); mDeferredTasks.AppendElement( - NewRunnableMethod, - RefPtr>(&mApzc, - &AsyncPanZoomController::HandleFlingOverscroll, - velocity, - mOverscrollHandoffChain, - mScrolledApzc)); + NS_NewRunnableMethodWithArgs, + RefPtr>(&mApzc, + &AsyncPanZoomController::HandleFlingOverscroll, + velocity, + mOverscrollHandoffChain, + mScrolledApzc)); // If there is a remaining velocity on this APZC, continue this fling // as well. (This fling and the handed-off fling will run concurrently.) @@ -702,7 +702,7 @@ public: // The scroll snapping is done in a deferred task, otherwise the state // change to NOTHING caused by the overscroll animation ending would // clobber a possible state change to SMOOTH_SCROLL in ScrollSnap(). - mDeferredTasks.AppendElement(NewRunnableMethod(&mApzc, &AsyncPanZoomController::ScrollSnap)); + mDeferredTasks.AppendElement(NS_NewRunnableMethod(&mApzc, &AsyncPanZoomController::ScrollSnap)); return false; } return true; @@ -819,9 +819,9 @@ public: // the lock ordering. Instead we schedule HandleSmoothScrollOverscroll() to be // called after mMonitor is released. mDeferredTasks.AppendElement( - NewRunnableMethod(&mApzc, - &AsyncPanZoomController::HandleSmoothScrollOverscroll, - velocity)); + NS_NewRunnableMethodWithArgs(&mApzc, + &AsyncPanZoomController::HandleSmoothScrollOverscroll, + velocity)); return false; } @@ -2173,11 +2173,11 @@ nsEventStatus AsyncPanZoomController::GenerateSingleTap(const ScreenIntPoint& aP // schedule the singletap message to run on the next spin of the event loop. // See bug 965381 for the issue this was causing. RefPtr runnable = - NewRunnableMethod(controller, &GeckoContentController::HandleSingleTap, - geckoScreenPoint, aModifiers, - GetGuid()); + NS_NewRunnableMethodWithArgs(controller, &GeckoContentController::HandleSingleTap, + geckoScreenPoint, aModifiers, + GetGuid()); controller->PostDelayedTask(runnable.forget(), 0); return nsEventStatus_eConsumeNoDefault; @@ -2987,7 +2987,7 @@ void AsyncPanZoomController::RequestContentRepaint() { // use the local variable to resolve the function overload. auto func = static_cast (&AsyncPanZoomController::RequestContentRepaint); - NS_DispatchToMainThread(NewRunnableMethod(this, func)); + NS_DispatchToMainThread(NS_NewRunnableMethod(this, func)); return; } @@ -3720,7 +3720,7 @@ void AsyncPanZoomController::ZoomToRect(CSSRect aRect, const uint32_t aFlags) { auto func = static_cast (&AsyncPanZoomController::RequestContentRepaint); NS_DispatchToMainThread( - NewRunnableMethod( + NS_NewRunnableMethodWithArgs( this, func, endZoomToMetrics, velocity)); } } diff --git a/gfx/layers/apz/src/GestureEventListener.cpp b/gfx/layers/apz/src/GestureEventListener.cpp index b81ddc10efe1..c3c6f8b0d73f 100644 --- a/gfx/layers/apz/src/GestureEventListener.cpp +++ b/gfx/layers/apz/src/GestureEventListener.cpp @@ -498,7 +498,7 @@ void GestureEventListener::CancelLongTapTimeoutTask() void GestureEventListener::CreateLongTapTimeoutTask() { RefPtr task = - NewCancelableRunnableMethod(this, &GestureEventListener::HandleInputTimeoutLongTap); + NS_NewCancelableRunnableMethod(this, &GestureEventListener::HandleInputTimeoutLongTap); mLongTapTimeoutTask = task; mAsyncPanZoomController->PostDelayedTask( @@ -525,9 +525,9 @@ void GestureEventListener::CreateMaxTapTimeoutTask() TouchBlockState* block = mAsyncPanZoomController->GetInputQueue()->CurrentTouchBlock(); RefPtr task = - NewCancelableRunnableMethod(this, - &GestureEventListener::HandleInputTimeoutMaxTap, - block->IsDuringFastFling()); + NS_NewCancelableRunnableMethodWithArgs(this, + &GestureEventListener::HandleInputTimeoutMaxTap, + block->IsDuringFastFling()); mMaxTapTimeoutTask = task; mAsyncPanZoomController->PostDelayedTask( diff --git a/gfx/layers/apz/src/InputQueue.cpp b/gfx/layers/apz/src/InputQueue.cpp index c267b097b26e..1fe5606da344 100644 --- a/gfx/layers/apz/src/InputQueue.cpp +++ b/gfx/layers/apz/src/InputQueue.cpp @@ -570,10 +570,10 @@ InputQueue::ScheduleMainThreadTimeout(const RefPtr& aTar CancelableBlockState* aBlock) { INPQ_LOG("scheduling main thread timeout for target %p\n", aTarget.get()); aBlock->StartContentResponseTimer(); - aTarget->PostDelayedTask(NewRunnableMethod(this, - &InputQueue::MainThreadTimeout, - aBlock->GetBlockId()), - gfxPrefs::APZContentResponseTimeout()); + RefPtr runnable = + NS_NewRunnableMethodWithArgs(this, &InputQueue::MainThreadTimeout, aBlock->GetBlockId()); + aTarget->PostDelayedTask(runnable.forget(), + gfxPrefs::APZContentResponseTimeout()); } void diff --git a/gfx/layers/apz/util/ActiveElementManager.cpp b/gfx/layers/apz/util/ActiveElementManager.cpp index 95e0a7079cd6..3403bb877d5c 100644 --- a/gfx/layers/apz/util/ActiveElementManager.cpp +++ b/gfx/layers/apz/util/ActiveElementManager.cpp @@ -95,9 +95,9 @@ ActiveElementManager::TriggerElementActivation() MOZ_ASSERT(mSetActiveTask == nullptr); RefPtr task = - NewCancelableRunnableMethod>(this, - &ActiveElementManager::SetActiveTask, - mTarget); + NS_NewCancelableRunnableMethodWithArgs>(this, + &ActiveElementManager::SetActiveTask, + mTarget); mSetActiveTask = task; MessageLoop::current()->PostDelayedTask(task.forget(), sActivationDelayMs); AEM_LOG("Scheduling mSetActiveTask %p\n", mSetActiveTask); diff --git a/gfx/layers/apz/util/ChromeProcessController.cpp b/gfx/layers/apz/util/ChromeProcessController.cpp index 19ec6ac26973..54950bd04d43 100644 --- a/gfx/layers/apz/util/ChromeProcessController.cpp +++ b/gfx/layers/apz/util/ChromeProcessController.cpp @@ -36,7 +36,8 @@ ChromeProcessController::ChromeProcessController(nsIWidget* aWidget, MOZ_ASSERT(aAPZEventState); MOZ_ASSERT(aAPZCTreeManager); - mUILoop->PostTask(NewRunnableMethod(this, &ChromeProcessController::InitializeRoot)); + RefPtr runnable = NS_NewRunnableMethod(this, &ChromeProcessController::InitializeRoot); + mUILoop->PostTask(runnable.forget()); } ChromeProcessController::~ChromeProcessController() {} @@ -70,7 +71,8 @@ void ChromeProcessController::Destroy() { if (MessageLoop::current() != mUILoop) { - mUILoop->PostTask(NewRunnableMethod(this, &ChromeProcessController::Destroy)); + RefPtr runnable = NS_NewRunnableMethod(this, &ChromeProcessController::Destroy); + mUILoop->PostTask(runnable.forget()); return; } @@ -119,12 +121,12 @@ ChromeProcessController::HandleDoubleTap(const mozilla::CSSPoint& aPoint, const ScrollableLayerGuid& aGuid) { if (MessageLoop::current() != mUILoop) { - mUILoop->PostTask(NewRunnableMethod - (this, - &ChromeProcessController::HandleDoubleTap, - aPoint, aModifiers, aGuid)); + RefPtr runnable = + NS_NewRunnableMethodWithArgs(this, &ChromeProcessController::HandleDoubleTap, + aPoint, aModifiers, aGuid); + mUILoop->PostTask(runnable.forget()); return; } @@ -159,12 +161,12 @@ ChromeProcessController::HandleSingleTap(const CSSPoint& aPoint, const ScrollableLayerGuid& aGuid) { if (MessageLoop::current() != mUILoop) { - mUILoop->PostTask(NewRunnableMethod - (this, - &ChromeProcessController::HandleSingleTap, - aPoint, aModifiers, aGuid)); + RefPtr runnable = + NS_NewRunnableMethodWithArgs(this, &ChromeProcessController::HandleSingleTap, + aPoint, aModifiers, aGuid); + mUILoop->PostTask(runnable.forget()); return; } @@ -177,12 +179,13 @@ ChromeProcessController::HandleLongTap(const mozilla::CSSPoint& aPoint, Modifier uint64_t aInputBlockId) { if (MessageLoop::current() != mUILoop) { - mUILoop->PostTask(NewRunnableMethod - (this, &ChromeProcessController::HandleLongTap, - aPoint, aModifiers, aGuid, aInputBlockId)); + RefPtr runnable = + NS_NewRunnableMethodWithArgs(this, &ChromeProcessController::HandleLongTap, + aPoint, aModifiers, aGuid, aInputBlockId); + mUILoop->PostTask(runnable.forget()); return; } @@ -196,11 +199,12 @@ ChromeProcessController::NotifyAPZStateChange(const ScrollableLayerGuid& aGuid, int aArg) { if (MessageLoop::current() != mUILoop) { - mUILoop->PostTask(NewRunnableMethod - (this, &ChromeProcessController::NotifyAPZStateChange, - aGuid, aChange, aArg)); + RefPtr runnable = + NS_NewRunnableMethodWithArgs(this, &ChromeProcessController::NotifyAPZStateChange, + aGuid, aChange, aArg); + mUILoop->PostTask(runnable.forget()); return; } @@ -211,10 +215,11 @@ void ChromeProcessController::NotifyMozMouseScrollEvent(const FrameMetrics::ViewID& aScrollId, const nsString& aEvent) { if (MessageLoop::current() != mUILoop) { - mUILoop->PostTask(NewRunnableMethod - (this, &ChromeProcessController::NotifyMozMouseScrollEvent, - aScrollId, aEvent)); + RefPtr runnable = + NS_NewRunnableMethodWithArgs(this, &ChromeProcessController::NotifyMozMouseScrollEvent, + aScrollId, aEvent); + mUILoop->PostTask(runnable.forget()); return; } diff --git a/gfx/layers/ipc/CompositorBridgeParent.cpp b/gfx/layers/ipc/CompositorBridgeParent.cpp index 5c2ae8c02ea8..00e6d032e47d 100644 --- a/gfx/layers/ipc/CompositorBridgeParent.cpp +++ b/gfx/layers/ipc/CompositorBridgeParent.cpp @@ -362,7 +362,7 @@ CompositorVsyncScheduler::SetDisplay(bool aDisplayEnable) MOZ_ASSERT(NS_IsMainThread()); MonitorAutoLock lock(mSetDisplayMonitor); RefPtr task = - NewCancelableRunnableMethod(this, &CompositorVsyncScheduler::SetDisplay, aDisplayEnable); + NS_NewCancelableRunnableMethodWithArgs(this, &CompositorVsyncScheduler::SetDisplay, aDisplayEnable); mSetDisplayTask = task; ScheduleTask(task.forget(), 0); return; @@ -427,8 +427,8 @@ CompositorVsyncScheduler::PostCompositeTask(TimeStamp aCompositeTimestamp) MonitorAutoLock lock(mCurrentCompositeTaskMonitor); if (mCurrentCompositeTask == nullptr) { RefPtr task = - NewCancelableRunnableMethod(this, &CompositorVsyncScheduler::Composite, - aCompositeTimestamp); + NS_NewCancelableRunnableMethodWithArgs(this, &CompositorVsyncScheduler::Composite, + aCompositeTimestamp); mCurrentCompositeTask = task; ScheduleTask(task.forget(), 0); } @@ -481,7 +481,7 @@ CompositorVsyncScheduler::SetNeedsComposite() if (!CompositorBridgeParent::IsInCompositorThread()) { MonitorAutoLock lock(mSetNeedsCompositeMonitor); RefPtr task = - NewCancelableRunnableMethod(this, &CompositorVsyncScheduler::SetNeedsComposite); + NS_NewCancelableRunnableMethod(this, &CompositorVsyncScheduler::SetNeedsComposite); mSetNeedsCompositeTask = task; ScheduleTask(task.forget(), 0); return; @@ -982,7 +982,8 @@ CompositorBridgeParent::ActorDestroy(ActorDestroyReason why) // We must keep the compositor parent alive untill the code handling message // reception is finished on this thread. mSelfRef = this; - MessageLoop::current()->PostTask(NewRunnableMethod(this, &CompositorBridgeParent::DeferredDestroy)); + RefPtr runnable = NS_NewRunnableMethod(this, &CompositorBridgeParent::DeferredDestroy); + MessageLoop::current()->PostTask(runnable.forget()); } @@ -990,14 +991,16 @@ void CompositorBridgeParent::ScheduleRenderOnCompositorThread() { MOZ_ASSERT(CompositorLoop()); - CompositorLoop()->PostTask(NewRunnableMethod(this, &CompositorBridgeParent::ScheduleComposition)); + RefPtr runnable = NS_NewRunnableMethod(this, &CompositorBridgeParent::ScheduleComposition); + CompositorLoop()->PostTask(runnable.forget()); } void CompositorBridgeParent::InvalidateOnCompositorThread() { MOZ_ASSERT(CompositorLoop()); - CompositorLoop()->PostTask(NewRunnableMethod(this, &CompositorBridgeParent::Invalidate)); + RefPtr runnable = NS_NewRunnableMethod(this, &CompositorBridgeParent::Invalidate); + CompositorLoop()->PostTask(runnable.forget()); } void @@ -1088,7 +1091,8 @@ CompositorBridgeParent::SchedulePauseOnCompositorThread() MonitorAutoLock lock(mPauseCompositionMonitor); MOZ_ASSERT(CompositorLoop()); - CompositorLoop()->PostTask(NewRunnableMethod(this, &CompositorBridgeParent::PauseComposition)); + RefPtr runnable = NS_NewRunnableMethod(this, &CompositorBridgeParent::PauseComposition); + CompositorLoop()->PostTask(runnable.forget()); // Wait until the pause has actually been processed by the compositor thread lock.Wait(); @@ -1100,7 +1104,8 @@ CompositorBridgeParent::ScheduleResumeOnCompositorThread() MonitorAutoLock lock(mResumeCompositionMonitor); MOZ_ASSERT(CompositorLoop()); - CompositorLoop()->PostTask(NewRunnableMethod(this, &CompositorBridgeParent::ResumeComposition)); + RefPtr runnable = NS_NewRunnableMethod(this, &CompositorBridgeParent::ResumeComposition); + CompositorLoop()->PostTask(runnable.forget()); // Wait until the resume has actually been processed by the compositor thread lock.Wait(); @@ -1114,10 +1119,10 @@ CompositorBridgeParent::ScheduleResumeOnCompositorThread(int width, int height) MonitorAutoLock lock(mResumeCompositionMonitor); MOZ_ASSERT(CompositorLoop()); - CompositorLoop()->PostTask(NewRunnableMethod - (this, - &CompositorBridgeParent::ResumeCompositionAndResize, - width, height)); + RefPtr runnable = + NS_NewRunnableMethodWithArgs(this, &CompositorBridgeParent::ResumeCompositionAndResize, + width, height); + CompositorLoop()->PostTask(runnable.forget()); // Wait until the resume has actually been processed by the compositor thread lock.Wait(); @@ -1369,7 +1374,7 @@ CompositorBridgeParent::ScheduleRotationOnCompositorThread(const TargetConfig& a mForceCompositionTask->Cancel(); } RefPtr task = - NewCancelableRunnableMethod(this, &CompositorBridgeParent::ForceComposition); + NS_NewCancelableRunnableMethod(this, &CompositorBridgeParent::ForceComposition); mForceCompositionTask = task; ScheduleTask(task.forget(), gfxPrefs::OrientationSyncMillis()); } @@ -2110,12 +2115,13 @@ CompositorBridgeParent::ResetCompositor(const nsTArray& aBackendH { MonitorAutoLock lock(mResetCompositorMonitor); - CompositorLoop()->PostTask(NewRunnableMethod - >, - Maybe*>(this, - &CompositorBridgeParent::ResetCompositorTask, - aBackendHints, - &newIdentifier)); + RefPtr runnable = + NS_NewRunnableMethodWithArgs>, + Maybe*>(this, + &CompositorBridgeParent::ResetCompositorTask, + aBackendHints, + &newIdentifier); + CompositorLoop()->PostTask(runnable.forget()); mResetCompositorMonitor.Wait(); } @@ -2283,7 +2289,8 @@ CrossProcessCompositorBridgeParent::ActorDestroy(ActorDestroyReason aWhy) // We must keep this object alive untill the code handling message // reception is finished on this thread. - MessageLoop::current()->PostTask(NewRunnableMethod(this, &CrossProcessCompositorBridgeParent::DeferredDestroy)); + RefPtr runnable = NS_NewRunnableMethod(this, &CrossProcessCompositorBridgeParent::DeferredDestroy); + MessageLoop::current()->PostTask(runnable.forget()); } PLayerTransactionParent* @@ -2528,7 +2535,8 @@ void CompositorBridgeParent::ScheduleShowAllPluginWindows() { MOZ_ASSERT(CompositorLoop()); - CompositorLoop()->PostTask(NewRunnableMethod(this, &CompositorBridgeParent::ShowAllPluginWindows)); + RefPtr runnable = NS_NewRunnableMethod(this, &CompositorBridgeParent::ShowAllPluginWindows); + CompositorLoop()->PostTask(runnable.forget()); } void @@ -2543,7 +2551,8 @@ void CompositorBridgeParent::ScheduleHideAllPluginWindows() { MOZ_ASSERT(CompositorLoop()); - CompositorLoop()->PostTask(NewRunnableMethod(this, &CompositorBridgeParent::HideAllPluginWindows)); + RefPtr runnable = NS_NewRunnableMethod(this, &CompositorBridgeParent::HideAllPluginWindows); + CompositorLoop()->PostTask(runnable.forget()); } void diff --git a/gfx/layers/ipc/ImageBridgeParent.cpp b/gfx/layers/ipc/ImageBridgeParent.cpp index 72353dca8269..1dff5588a843 100644 --- a/gfx/layers/ipc/ImageBridgeParent.cpp +++ b/gfx/layers/ipc/ImageBridgeParent.cpp @@ -106,7 +106,8 @@ ImageBridgeParent::ActorDestroy(ActorDestroyReason aWhy) mSubprocess = nullptr; } - MessageLoop::current()->PostTask(NewRunnableMethod(this, &ImageBridgeParent::DeferredDestroy)); + RefPtr runnable = NS_NewRunnableMethod(this, &ImageBridgeParent::DeferredDestroy); + MessageLoop::current()->PostTask(runnable.forget()); // It is very important that this method gets called at shutdown (be it a clean // or an abnormal shutdown), because DeferredDestroy is what clears mSelfRef. diff --git a/gfx/layers/ipc/RemoteContentController.cpp b/gfx/layers/ipc/RemoteContentController.cpp index 7756c6b7412d..d86593476154 100644 --- a/gfx/layers/ipc/RemoteContentController.cpp +++ b/gfx/layers/ipc/RemoteContentController.cpp @@ -58,11 +58,12 @@ RemoteContentController::HandleDoubleTap(const CSSPoint& aPoint, if (MessageLoop::current() != mUILoop) { // We have to send this message from the "UI thread" (main // thread). - mUILoop->PostTask(NewRunnableMethod(this, - &RemoteContentController::HandleDoubleTap, - aPoint, aModifiers, aGuid)); + RefPtr runnable = + NS_NewRunnableMethodWithArgs(this, &RemoteContentController::HandleDoubleTap, + aPoint, aModifiers, aGuid); + mUILoop->PostTask(runnable.forget()); return; } if (CanSend()) { @@ -79,11 +80,12 @@ RemoteContentController::HandleSingleTap(const CSSPoint& aPoint, if (MessageLoop::current() != mUILoop) { // We have to send this message from the "UI thread" (main // thread). - mUILoop->PostTask(NewRunnableMethod(this, - &RemoteContentController::HandleSingleTap, - aPoint, aModifiers, aGuid)); + RefPtr runnable = + NS_NewRunnableMethodWithArgs(this, &RemoteContentController::HandleSingleTap, + aPoint, aModifiers, aGuid); + mUILoop->PostTask(runnable.forget()); return; } @@ -114,12 +116,13 @@ RemoteContentController::HandleLongTap(const CSSPoint& aPoint, if (MessageLoop::current() != mUILoop) { // We have to send this message from the "UI thread" (main // thread). - mUILoop->PostTask(NewRunnableMethod(this, - &RemoteContentController::HandleLongTap, - aPoint, aModifiers, aGuid, aInputBlockId)); + RefPtr runnable = + NS_NewRunnableMethodWithArgs(this, &RemoteContentController::HandleLongTap, + aPoint, aModifiers, aGuid, aInputBlockId); + mUILoop->PostTask(runnable.forget()); return; } if (CanSend()) { @@ -157,11 +160,12 @@ RemoteContentController::NotifyAPZStateChange(const ScrollableLayerGuid& aGuid, int aArg) { if (MessageLoop::current() != mUILoop) { - mUILoop->PostTask(NewRunnableMethod(this, - &RemoteContentController::NotifyAPZStateChange, - aGuid, aChange, aArg)); + RefPtr runnable = + NS_NewRunnableMethodWithArgs(this, &RemoteContentController::NotifyAPZStateChange, + aGuid, aChange, aArg); + mUILoop->PostTask(runnable.forget()); return; } if (CanSend()) { @@ -174,10 +178,11 @@ RemoteContentController::NotifyMozMouseScrollEvent(const FrameMetrics::ViewID& a const nsString& aEvent) { if (MessageLoop::current() != mUILoop) { - mUILoop->PostTask(NewRunnableMethod(this, - &RemoteContentController::NotifyMozMouseScrollEvent, - aScrollId, aEvent)); + RefPtr runnable = + NS_NewRunnableMethodWithArgs(this, &RemoteContentController::NotifyMozMouseScrollEvent, + aScrollId, aEvent); + mUILoop->PostTask(runnable.forget()); return; } @@ -227,10 +232,12 @@ RemoteContentController::RecvContentReceivedInputBlock(const ScrollableLayerGuid return false; } if (RefPtr apzcTreeManager = GetApzcTreeManager()) { - APZThreadUtils::RunOnControllerThread(NewRunnableMethod(apzcTreeManager, - &APZCTreeManager::ContentReceivedInputBlock, - aInputBlockId, aPreventDefault)); + RefPtr runnable = + NS_NewRunnableMethodWithArgs(apzcTreeManager, + &APZCTreeManager::ContentReceivedInputBlock, + aInputBlockId, aPreventDefault); + APZThreadUtils::RunOnControllerThread(runnable.forget()); } return true; @@ -243,11 +250,12 @@ RemoteContentController::RecvStartScrollbarDrag(const AsyncDragMetrics& aDragMet ScrollableLayerGuid guid(mLayersId, aDragMetrics.mPresShellId, aDragMetrics.mViewId); - APZThreadUtils::RunOnControllerThread(NewRunnableMethod - (apzcTreeManager, - &APZCTreeManager::StartScrollbarDrag, - guid, aDragMetrics)); + RefPtr runnable = + NS_NewRunnableMethodWithArgs(apzcTreeManager, + &APZCTreeManager::StartScrollbarDrag, + guid, aDragMetrics); + APZThreadUtils::RunOnControllerThread(runnable.forget()); } return true; } @@ -267,10 +275,11 @@ RemoteContentController::RecvSetTargetAPZC(const uint64_t& aInputBlockId, // need a local var to disambiguate between the SetTargetAPZC overloads. void (APZCTreeManager::*setTargetApzcFunc)(uint64_t, const nsTArray&) = &APZCTreeManager::SetTargetAPZC; - APZThreadUtils::RunOnControllerThread(NewRunnableMethod - >> - (apzcTreeManager, setTargetApzcFunc, aInputBlockId, aTargets)); + RefPtr runnable = + NS_NewRunnableMethodWithArgs>>(apzcTreeManager, setTargetApzcFunc, + aInputBlockId, aTargets); + APZThreadUtils::RunOnControllerThread(runnable.forget()); } return true; @@ -281,12 +290,12 @@ RemoteContentController::RecvSetAllowedTouchBehavior(const uint64_t& aInputBlock nsTArray&& aFlags) { if (RefPtr apzcTreeManager = GetApzcTreeManager()) { - APZThreadUtils::RunOnControllerThread(NewRunnableMethod - >> - (apzcTreeManager, - &APZCTreeManager::SetAllowedTouchBehavior, - aInputBlockId, Move(aFlags))); + RefPtr runnable = + NS_NewRunnableMethodWithArgs>>(apzcTreeManager, + &APZCTreeManager::SetAllowedTouchBehavior, + aInputBlockId, Move(aFlags)); + APZThreadUtils::RunOnControllerThread(runnable.forget()); } return true; } diff --git a/gfx/thebes/SoftwareVsyncSource.cpp b/gfx/thebes/SoftwareVsyncSource.cpp index d86ff9bbd2b9..aa01013dc0fb 100644 --- a/gfx/thebes/SoftwareVsyncSource.cpp +++ b/gfx/thebes/SoftwareVsyncSource.cpp @@ -9,8 +9,6 @@ #include "gfxPlatform.h" #include "nsThreadUtils.h" -using namespace mozilla; - SoftwareVsyncSource::SoftwareVsyncSource() { MOZ_ASSERT(NS_IsMainThread()); @@ -47,8 +45,8 @@ SoftwareDisplay::EnableVsync() } mVsyncEnabled = true; - mVsyncThread->message_loop()->PostTask( - NewRunnableMethod(this, &SoftwareDisplay::EnableVsync)); + RefPtr runnable = NS_NewRunnableMethod(this, &SoftwareDisplay::EnableVsync); + mVsyncThread->message_loop()->PostTask(runnable.forget()); return; } @@ -66,8 +64,8 @@ SoftwareDisplay::DisableVsync() } mVsyncEnabled = false; - mVsyncThread->message_loop()->PostTask( - NewRunnableMethod(this, &SoftwareDisplay::DisableVsync)); + RefPtr runnable = NS_NewRunnableMethod(this, &SoftwareDisplay::DisableVsync); + mVsyncThread->message_loop()->PostTask(runnable.forget()); return; } @@ -131,11 +129,11 @@ SoftwareDisplay::ScheduleNextVsync(mozilla::TimeStamp aVsyncTimestamp) } mCurrentVsyncTask = - NewCancelableRunnableMethod(this, - &SoftwareDisplay::NotifyVsync, - nextVsync); + NS_NewCancelableRunnableMethodWithArgs(this, + &SoftwareDisplay::NotifyVsync, + nextVsync); - RefPtr addrefedTask = mCurrentVsyncTask; + RefPtr addrefedTask = mCurrentVsyncTask; mVsyncThread->message_loop()->PostDelayedTask( addrefedTask.forget(), delay.ToMilliseconds()); diff --git a/gfx/vr/ipc/VRManagerParent.cpp b/gfx/vr/ipc/VRManagerParent.cpp index 352fe020977b..f64119066bf8 100644 --- a/gfx/vr/ipc/VRManagerParent.cpp +++ b/gfx/vr/ipc/VRManagerParent.cpp @@ -112,7 +112,8 @@ void VRManagerParent::ActorDestroy(ActorDestroyReason why) { UnregisterFromManager(); - MessageLoop::current()->PostTask(NewRunnableMethod(this, &VRManagerParent::DeferredDestroy)); + RefPtr runnable = NS_NewRunnableMethod(this, &VRManagerParent::DeferredDestroy); + MessageLoop::current()->PostTask(runnable.forget()); } mozilla::ipc::IToplevelProtocol* diff --git a/image/DecodePool.cpp b/image/DecodePool.cpp index b99550965e8f..259ad06642b9 100644 --- a/image/DecodePool.cpp +++ b/image/DecodePool.cpp @@ -173,7 +173,9 @@ public: { // Threads have to be shut down from another thread, so we'll ask the // main thread to do it for us. - NS_DispatchToMainThread(NewRunnableMethod(aThisThread, &nsIThread::Shutdown)); + nsCOMPtr runnable = + NS_NewRunnableMethod(aThisThread, &nsIThread::Shutdown); + NS_DispatchToMainThread(runnable); } /** diff --git a/image/RasterImage.cpp b/image/RasterImage.cpp index 99d6886385ef..d27adf76b340 100644 --- a/image/RasterImage.cpp +++ b/image/RasterImage.cpp @@ -430,7 +430,9 @@ RasterImage::OnSurfaceDiscarded() { MOZ_ASSERT(mProgressTracker); - NS_DispatchToMainThread(NewRunnableMethod(mProgressTracker, &ProgressTracker::OnDiscard)); + nsCOMPtr runnable = + NS_NewRunnableMethod(mProgressTracker, &ProgressTracker::OnDiscard); + NS_DispatchToMainThread(runnable); } //****************************************************************************** diff --git a/image/VectorImage.cpp b/image/VectorImage.cpp index b8d8950433c3..3f08dd4310d4 100644 --- a/image/VectorImage.cpp +++ b/image/VectorImage.cpp @@ -1063,7 +1063,9 @@ VectorImage::OnSurfaceDiscarded() { MOZ_ASSERT(mProgressTracker); - NS_DispatchToMainThread(NewRunnableMethod(mProgressTracker, &ProgressTracker::OnDiscard)); + nsCOMPtr runnable = + NS_NewRunnableMethod(mProgressTracker, &ProgressTracker::OnDiscard); + NS_DispatchToMainThread(runnable); } //****************************************************************************** diff --git a/image/imgRequestProxy.cpp b/image/imgRequestProxy.cpp index 923d7a2ccfc2..d8750cd563df 100644 --- a/image/imgRequestProxy.cpp +++ b/image/imgRequestProxy.cpp @@ -349,7 +349,9 @@ imgRequestProxy::CancelAndForgetObserver(nsresult aStatus) mIsInLoadGroup = oldIsInLoadGroup; if (mIsInLoadGroup) { - NS_DispatchToCurrentThread(NewRunnableMethod(this, &imgRequestProxy::DoRemoveFromLoadGroup)); + nsCOMPtr ev = + NS_NewRunnableMethod(this, &imgRequestProxy::DoRemoveFromLoadGroup); + NS_DispatchToCurrentThread(ev); } NullOutListener(); diff --git a/ipc/glue/BackgroundImpl.cpp b/ipc/glue/BackgroundImpl.cpp index 5a77e436dc61..3b7235613f3d 100644 --- a/ipc/glue/BackgroundImpl.cpp +++ b/ipc/glue/BackgroundImpl.cpp @@ -433,8 +433,9 @@ private: ChildImpl* actor; threadLocalInfo->mActor.forget(&actor); - MOZ_ALWAYS_SUCCEEDS( - NS_DispatchToMainThread(NewNonOwningRunnableMethod(actor, &ChildImpl::Release))); + nsCOMPtr releaser = + NS_NewNonOwningRunnableMethod(actor, &ChildImpl::Release); + MOZ_ALWAYS_SUCCEEDS(NS_DispatchToMainThread(releaser)); } } delete threadLocalInfo; @@ -1002,8 +1003,11 @@ ParentImpl::GetContentParent(PBackgroundParent* aBackgroundActor) // it for us. This is safe since we are guaranteed that our AddRef runnable // will run before the reference we hand out can be released, and the // ContentParent can't die as long as the existing reference is maintained. - MOZ_ALWAYS_SUCCEEDS( - NS_DispatchToMainThread(NewNonOwningRunnableMethod(actor->mContent, &ContentParent::AddRef))); + nsCOMPtr runnable = + NS_NewNonOwningRunnableMethod(actor->mContent, &ContentParent::AddRef); + MOZ_ASSERT(runnable); + + MOZ_ALWAYS_SUCCEEDS(NS_DispatchToMainThread(runnable)); } return already_AddRefed(actor->mContent.get()); @@ -1267,8 +1271,11 @@ ParentImpl::Destroy() AssertIsInMainProcess(); - MOZ_ALWAYS_SUCCEEDS( - NS_DispatchToMainThread(NewNonOwningRunnableMethod(this, &ParentImpl::MainThreadActorDestroy))); + nsCOMPtr destroyRunnable = + NS_NewNonOwningRunnableMethod(this, &ParentImpl::MainThreadActorDestroy); + MOZ_ASSERT(destroyRunnable); + + MOZ_ALWAYS_SUCCEEDS(NS_DispatchToMainThread(destroyRunnable)); } void @@ -1356,9 +1363,11 @@ ParentImpl::ActorDestroy(ActorDestroyReason aWhy) // IPDL is about to call MessageChannel::Clear() on this thread! To avoid // racing with the main thread we must ensure that the MessageChannel lives // long enough to be cleared in this call stack. + nsCOMPtr destroyRunnable = + NS_NewNonOwningRunnableMethod(this, &ParentImpl::Destroy); + MOZ_ASSERT(destroyRunnable); - MOZ_ALWAYS_SUCCEEDS( - NS_DispatchToCurrentThread(NewNonOwningRunnableMethod(this, &ParentImpl::Destroy))); + MOZ_ALWAYS_SUCCEEDS(NS_DispatchToCurrentThread(destroyRunnable)); } NS_IMPL_ISUPPORTS(ParentImpl::ShutdownObserver, nsIObserver) diff --git a/ipc/glue/GeckoChildProcessHost.cpp b/ipc/glue/GeckoChildProcessHost.cpp index 0a2296c41d6a..d1777f878b7c 100644 --- a/ipc/glue/GeckoChildProcessHost.cpp +++ b/ipc/glue/GeckoChildProcessHost.cpp @@ -344,10 +344,12 @@ GeckoChildProcessHost::SyncLaunch(std::vector aExtraOpts, int aTime MessageLoop* ioLoop = XRE_GetIOMessageLoop(); NS_ASSERTION(MessageLoop::current() != ioLoop, "sync launch from the IO thread NYI"); - ioLoop->PostTask(NewNonOwningRunnableMethod - , base::ProcessArchitecture> - (this, &GeckoChildProcessHost::RunPerformAsyncLaunch, - aExtraOpts, arch)); + RefPtr runnable = + NS_NewNonOwningRunnableMethodWithArgs, + base::ProcessArchitecture>(this, + &GeckoChildProcessHost::RunPerformAsyncLaunch, + aExtraOpts, arch); + ioLoop->PostTask(runnable.forget()); return WaitUntilConnected(aTimeoutMs); } @@ -360,10 +362,12 @@ GeckoChildProcessHost::AsyncLaunch(std::vector aExtraOpts, MessageLoop* ioLoop = XRE_GetIOMessageLoop(); - ioLoop->PostTask(NewNonOwningRunnableMethod - , base::ProcessArchitecture> - (this, &GeckoChildProcessHost::RunPerformAsyncLaunch, - aExtraOpts, arch)); + RefPtr runnable = + NS_NewNonOwningRunnableMethodWithArgs, + base::ProcessArchitecture>(this, + &GeckoChildProcessHost::RunPerformAsyncLaunch, + aExtraOpts, arch); + ioLoop->PostTask(runnable.forget()); // This may look like the sync launch wait, but we only delay as // long as it takes to create the channel. @@ -419,10 +423,13 @@ GeckoChildProcessHost::LaunchAndWaitForProcessHandle(StringVector aExtraOpts) PrepareLaunch(); MessageLoop* ioLoop = XRE_GetIOMessageLoop(); - ioLoop->PostTask(NewNonOwningRunnableMethod - , base::ProcessArchitecture> - (this, &GeckoChildProcessHost::RunPerformAsyncLaunch, - aExtraOpts, base::GetCurrentProcessArchitecture())); + RefPtr runnable = + NS_NewNonOwningRunnableMethodWithArgs, + base::ProcessArchitecture>(this, + &GeckoChildProcessHost::RunPerformAsyncLaunch, + aExtraOpts, + base::GetCurrentProcessArchitecture()); + ioLoop->PostTask(runnable.forget()); MonitorAutoLock lock(mMonitor); while (mProcessState < PROCESS_CREATED) { diff --git a/ipc/glue/MessageChannel.cpp b/ipc/glue/MessageChannel.cpp index c6dda27ecedd..90bb4f865007 100644 --- a/ipc/glue/MessageChannel.cpp +++ b/ipc/glue/MessageChannel.cpp @@ -496,10 +496,11 @@ MessageChannel::MessageChannel(MessageListener *aListener) #endif RefPtr runnable = - NewNonOwningCancelableRunnableMethod(this, &MessageChannel::OnMaybeDequeueOne); + NS_NewNonOwningCancelableRunnableMethod(this, &MessageChannel::OnMaybeDequeueOne); mDequeueOneTask = new RefCountedTask(runnable.forget()); - runnable = NewNonOwningCancelableRunnableMethod(this, &MessageChannel::DispatchOnChannelConnected); + runnable = NS_NewNonOwningCancelableRunnableMethod(this, &MessageChannel::DispatchOnChannelConnected); + mOnChannelConnectedTask = new RefCountedTask(runnable.forget()); #ifdef OS_WIN @@ -685,10 +686,11 @@ MessageChannel::Open(MessageChannel *aTargetChan, MessageLoop *aTargetLoop, Side MonitorAutoLock lock(*mMonitor); mChannelState = ChannelOpening; - aTargetLoop->PostTask(NewNonOwningRunnableMethod - (aTargetChan, - &MessageChannel::OnOpenAsSlave, - this, oppSide)); + RefPtr runnable = + NS_NewNonOwningRunnableMethodWithArgs(aTargetChan, + &MessageChannel::OnOpenAsSlave, + this, oppSide); + aTargetLoop->PostTask(runnable.forget()); while (ChannelOpening == mChannelState) mMonitor->Wait(); @@ -2085,7 +2087,7 @@ MessageChannel::OnNotifyMaybeChannelError() if (IsOnCxxStack()) { mChannelErrorTask = - NewNonOwningCancelableRunnableMethod(this, &MessageChannel::OnNotifyMaybeChannelError); + NS_NewNonOwningCancelableRunnableMethod(this, &MessageChannel::OnNotifyMaybeChannelError); RefPtr task = mChannelErrorTask; // 10 ms delay is completely arbitrary mWorkerLoop->PostDelayedTask(task.forget(), 10); @@ -2105,7 +2107,7 @@ MessageChannel::PostErrorNotifyTask() // This must be the last code that runs on this thread! mChannelErrorTask = - NewNonOwningCancelableRunnableMethod(this, &MessageChannel::OnNotifyMaybeChannelError); + NS_NewNonOwningCancelableRunnableMethod(this, &MessageChannel::OnNotifyMaybeChannelError); RefPtr task = mChannelErrorTask; mWorkerLoop->PostTask(task.forget()); } diff --git a/ipc/glue/MessageLink.cpp b/ipc/glue/MessageLink.cpp index 1dc56687c912..c3b20b347a97 100644 --- a/ipc/glue/MessageLink.cpp +++ b/ipc/glue/MessageLink.cpp @@ -118,12 +118,14 @@ ProcessLink::Open(mozilla::ipc::Transport* aTransport, MessageLoop *aIOLoop, Sid // Transport::Connect() has not been called. Call it so // we start polling our pipe and processing outgoing // messages. - mIOLoop->PostTask(NewNonOwningRunnableMethod(this, &ProcessLink::OnChannelOpened)); + RefPtr runnable = NS_NewNonOwningRunnableMethod(this, &ProcessLink::OnChannelOpened); + mIOLoop->PostTask(runnable.forget()); } else { // Transport::Connect() has already been called. Take // over the channel from the previous listener and process // any queued messages. - mIOLoop->PostTask(NewNonOwningRunnableMethod(this, &ProcessLink::OnTakeConnectedChannel)); + RefPtr runnable = NS_NewNonOwningRunnableMethod(this, &ProcessLink::OnTakeConnectedChannel); + mIOLoop->PostTask(runnable.forget()); } #ifdef MOZ_NUWA_PROCESS @@ -150,7 +152,9 @@ ProcessLink::EchoMessage(Message *msg) mChan->AssertWorkerThread(); mChan->mMonitor->AssertCurrentThreadOwns(); - mIOLoop->PostTask(NewNonOwningRunnableMethod(this, &ProcessLink::OnEchoMessage, msg)); + RefPtr runnable = + NS_NewNonOwningRunnableMethodWithArgs(this, &ProcessLink::OnEchoMessage, msg); + mIOLoop->PostTask(runnable.forget()); // OnEchoMessage takes ownership of |msg| } @@ -196,7 +200,9 @@ ProcessLink::SendMessage(Message *msg) #endif #endif - mIOLoop->PostTask(NewNonOwningRunnableMethod(mTransport, &Transport::Send, msg)); + RefPtr runnable = + NS_NewNonOwningRunnableMethodWithArgs(mTransport, &Transport::Send, msg); + mIOLoop->PostTask(runnable.forget()); } void @@ -205,7 +211,8 @@ ProcessLink::SendClose() mChan->AssertWorkerThread(); mChan->mMonitor->AssertCurrentThreadOwns(); - mIOLoop->PostTask(NewNonOwningRunnableMethod(this, &ProcessLink::OnCloseChannel)); + RefPtr runnable = NS_NewNonOwningRunnableMethod(this, &ProcessLink::OnCloseChannel); + mIOLoop->PostTask(runnable.forget()); } ThreadLink::ThreadLink(MessageChannel *aChan, MessageChannel *aTargetChan) diff --git a/layout/base/ZoomConstraintsClient.cpp b/layout/base/ZoomConstraintsClient.cpp index c76f971c39ac..ef1db18081ce 100644 --- a/layout/base/ZoomConstraintsClient.cpp +++ b/layout/base/ZoomConstraintsClient.cpp @@ -152,7 +152,7 @@ ZoomConstraintsClient::Observe(nsISupports* aSubject, const char* aTopic, const // We need to run this later because all the pref change listeners need // to execute before we can be guaranteed that gfxPrefs::ForceUserScalable() // returns the updated value. - NS_DispatchToMainThread(NewRunnableMethod( + NS_DispatchToMainThread(NS_NewRunnableMethod( this, &ZoomConstraintsClient::RefreshZoomConstraints)); } return NS_OK; diff --git a/layout/base/nsPresContext.cpp b/layout/base/nsPresContext.cpp index 0a8ac6cfae54..f11c4dda2490 100644 --- a/layout/base/nsPresContext.cpp +++ b/layout/base/nsPresContext.cpp @@ -1590,7 +1590,7 @@ nsPresContext::ThemeChanged() sThemeChanged = true; nsCOMPtr ev = - NewRunnableMethod(this, &nsPresContext::ThemeChangedInternal); + NS_NewRunnableMethod(this, &nsPresContext::ThemeChangedInternal); if (NS_SUCCEEDED(NS_DispatchToCurrentThread(ev))) { mPendingThemeChanged = true; } @@ -1649,7 +1649,7 @@ nsPresContext::SysColorChanged() if (!mPendingSysColorChanged) { sLookAndFeelChanged = true; nsCOMPtr ev = - NewRunnableMethod(this, &nsPresContext::SysColorChangedInternal); + NS_NewRunnableMethod(this, &nsPresContext::SysColorChangedInternal); if (NS_SUCCEEDED(NS_DispatchToCurrentThread(ev))) { mPendingSysColorChanged = true; } @@ -1681,7 +1681,7 @@ nsPresContext::UIResolutionChanged() { if (!mPendingUIResolutionChanged) { nsCOMPtr ev = - NewRunnableMethod(this, &nsPresContext::UIResolutionChangedInternal); + NS_NewRunnableMethod(this, &nsPresContext::UIResolutionChangedInternal); if (NS_SUCCEEDED(NS_DispatchToCurrentThread(ev))) { mPendingUIResolutionChanged = true; } @@ -1932,7 +1932,7 @@ nsPresContext::PostMediaFeatureValuesChangedEvent() // need to track whether it's been added). if (!mPendingMediaFeatureValuesChanged) { nsCOMPtr ev = - NewRunnableMethod(this, &nsPresContext::HandleMediaFeatureValuesChangedEvent); + NS_NewRunnableMethod(this, &nsPresContext::HandleMediaFeatureValuesChangedEvent); if (NS_SUCCEEDED(NS_DispatchToCurrentThread(ev))) { mPendingMediaFeatureValuesChanged = true; mDocument->SetNeedStyleFlush(); @@ -2123,7 +2123,7 @@ nsPresContext::RebuildCounterStyles() mDocument->SetNeedStyleFlush(); if (!mPostedFlushCounterStyles) { nsCOMPtr ev = - NewRunnableMethod(this, &nsPresContext::HandleRebuildCounterStyles); + NS_NewRunnableMethod(this, &nsPresContext::HandleRebuildCounterStyles); if (NS_SUCCEEDED(NS_DispatchToCurrentThread(ev))) { mPostedFlushCounterStyles = true; } diff --git a/layout/base/nsPresShell.cpp b/layout/base/nsPresShell.cpp index fac704b99285..82d8e02b6f3c 100644 --- a/layout/base/nsPresShell.cpp +++ b/layout/base/nsPresShell.cpp @@ -1904,7 +1904,7 @@ PresShell::ResizeReflowIgnoreOverride(nscoord aWidth, nscoord aHeight) } } else { RefPtr > resizeEvent = - NewRunnableMethod(this, &PresShell::FireResizeEvent); + NS_NewRunnableMethod(this, &PresShell::FireResizeEvent); if (NS_SUCCEEDED(NS_DispatchToCurrentThread(resizeEvent))) { mResizeEvent = resizeEvent; mDocument->SetNeedStyleFlush(); @@ -6085,7 +6085,7 @@ PresShell::ScheduleApproximateFrameVisibilityUpdateNow() } RefPtr > ev = - NewRunnableMethod(this, &PresShell::UpdateApproximateFrameVisibility); + NS_NewRunnableMethod(this, &PresShell::UpdateApproximateFrameVisibility); if (NS_SUCCEEDED(NS_DispatchToCurrentThread(ev))) { mUpdateApproximateFrameVisibilityEvent = ev; } @@ -6368,7 +6368,7 @@ PresShell::Paint(nsView* aViewToPaint, // since this is happening during a paint and updating the visible // regions triggers a recomposite. RefPtr> event = - NewRunnableMethod(this, &PresShell::NotifyCompositorOfVisibleRegionsChange); + NS_NewRunnableMethod(this, &PresShell::NotifyCompositorOfVisibleRegionsChange); if (NS_SUCCEEDED(NS_DispatchToMainThread(event))) { mNotifyCompositorOfVisibleRegionsChangeEvent = event; } diff --git a/layout/base/nsRefreshDriver.cpp b/layout/base/nsRefreshDriver.cpp index 0f5ecc8fbb25..9c800495fa30 100644 --- a/layout/base/nsRefreshDriver.cpp +++ b/layout/base/nsRefreshDriver.cpp @@ -417,9 +417,9 @@ private: } nsCOMPtr vsyncEvent = - NewRunnableMethod(this, - &RefreshDriverVsyncObserver::TickRefreshDriver, - aVsyncTimestamp); + NS_NewRunnableMethodWithArg(this, + &RefreshDriverVsyncObserver::TickRefreshDriver, + aVsyncTimestamp); NS_DispatchToMainThread(vsyncEvent); } else { TickRefreshDriver(aVsyncTimestamp); @@ -1972,7 +1972,7 @@ nsRefreshDriver::Thaw() // updates our mMostRecentRefresh, but the DoRefresh call won't run // and notify our observers until we get back to the event loop. // Thus MostRecentRefresh() will lie between now and the DoRefresh. - NS_DispatchToCurrentThread(NewRunnableMethod(this, &nsRefreshDriver::DoRefresh)); + NS_DispatchToCurrentThread(NS_NewRunnableMethod(this, &nsRefreshDriver::DoRefresh)); EnsureTimerStarted(); } } diff --git a/layout/ipc/VsyncParent.cpp b/layout/ipc/VsyncParent.cpp index 6de114f60357..9fdb8511d610 100644 --- a/layout/ipc/VsyncParent.cpp +++ b/layout/ipc/VsyncParent.cpp @@ -50,9 +50,9 @@ VsyncParent::NotifyVsync(TimeStamp aTimeStamp) // Called on hardware vsync thread. We should post to current ipc thread. MOZ_ASSERT(!IsOnBackgroundThread()); nsCOMPtr vsyncEvent = - NewRunnableMethod(this, - &VsyncParent::DispatchVsyncEvent, - aTimeStamp); + NS_NewRunnableMethodWithArg(this, + &VsyncParent::DispatchVsyncEvent, + aTimeStamp); MOZ_ALWAYS_SUCCEEDS(mBackgroundThread->Dispatch(vsyncEvent, NS_DISPATCH_NORMAL)); return true; } diff --git a/layout/style/FontFaceSet.cpp b/layout/style/FontFaceSet.cpp index bf4ad3b24442..942f9648f7c3 100644 --- a/layout/style/FontFaceSet.cpp +++ b/layout/style/FontFaceSet.cpp @@ -1471,7 +1471,7 @@ FontFaceSet::OnFontFaceStatusChanged(FontFace* aFontFace) if (!mDelayedLoadCheck) { mDelayedLoadCheck = true; nsCOMPtr checkTask = - NewRunnableMethod(this, &FontFaceSet::CheckLoadingFinishedAfterDelay); + NS_NewRunnableMethod(this, &FontFaceSet::CheckLoadingFinishedAfterDelay); NS_DispatchToMainThread(checkTask); } } diff --git a/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp b/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp index 618858ae46ea..c262fab71407 100644 --- a/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp +++ b/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp @@ -192,7 +192,7 @@ public: ++mLength; // Atomic nsCOMPtr runnable = - NewRunnableMethod, bool>( + NS_NewRunnableMethodWithArgs, bool>( this, &VideoFrameConverter::ProcessVideoFrame, aChunk.mFrame.GetImage(), forceBlack); mTaskQueue->Dispatch(runnable.forget()); diff --git a/modules/libjar/nsJARChannel.cpp b/modules/libjar/nsJARChannel.cpp index 34cb1fc140db..bdc1c7f32584 100644 --- a/modules/libjar/nsJARChannel.cpp +++ b/modules/libjar/nsJARChannel.cpp @@ -1204,10 +1204,11 @@ nsJARChannel::OnDataAvailable(nsIRequest *req, nsISupports *ctx, if (NS_IsMainThread()) { FireOnProgress(offset + count); } else { - NS_DispatchToMainThread(NewRunnableMethod - (this, - &nsJARChannel::FireOnProgress, - offset + count)); + nsCOMPtr runnable = + NS_NewRunnableMethodWithArg(this, + &nsJARChannel::FireOnProgress, + offset + count); + NS_DispatchToMainThread(runnable); } } diff --git a/netwerk/base/BackgroundFileSaver.cpp b/netwerk/base/BackgroundFileSaver.cpp index c6690661c6d9..6c5745e3c354 100644 --- a/netwerk/base/BackgroundFileSaver.cpp +++ b/netwerk/base/BackgroundFileSaver.cpp @@ -327,9 +327,11 @@ BackgroundFileSaver::GetWorkerThreadAttention(bool aShouldInterruptCopy) if (!mAsyncCopyContext) { // Copy is not in progress, post an event to handle the change manually. - rv = mWorkerThread->Dispatch(NewRunnableMethod(this, - &BackgroundFileSaver::ProcessAttention), - NS_DISPATCH_NORMAL); + nsCOMPtr event = + NS_NewRunnableMethod(this, &BackgroundFileSaver::ProcessAttention); + NS_ENSURE_TRUE(event, NS_ERROR_FAILURE); + + rv = mWorkerThread->Dispatch(event, NS_DISPATCH_NORMAL); NS_ENSURE_SUCCESS(rv, rv); } else if (aShouldInterruptCopy) { // Interrupt the copy. The copy will be resumed, if needed, by the @@ -747,9 +749,10 @@ BackgroundFileSaver::CheckCompletion() } // Post an event to notify that the operation completed. - if (NS_FAILED(mControlThread->Dispatch(NewRunnableMethod(this, - &BackgroundFileSaver::NotifySaveComplete), - NS_DISPATCH_NORMAL))) { + nsCOMPtr event = + NS_NewRunnableMethod(this, &BackgroundFileSaver::NotifySaveComplete); + if (!event || + NS_FAILED(mControlThread->Dispatch(event, NS_DISPATCH_NORMAL))) { NS_WARNING("Unable to post completion event to the control thread."); } @@ -1153,9 +1156,10 @@ BackgroundFileSaverStreamListener::AsyncCopyProgressCallback(void *aClosure, self->mReceivedTooMuchData = false; // Post an event to verify if the request should be resumed. - if (NS_FAILED(self->mControlThread->Dispatch(NewRunnableMethod(self, - &BackgroundFileSaverStreamListener::NotifySuspendOrResume), - NS_DISPATCH_NORMAL))) { + nsCOMPtr event = NS_NewRunnableMethod(self, + &BackgroundFileSaverStreamListener::NotifySuspendOrResume); + if (!event || NS_FAILED(self->mControlThread->Dispatch(event, + NS_DISPATCH_NORMAL))) { NS_WARNING("Unable to post resume event to the control thread."); } } diff --git a/netwerk/base/Dashboard.cpp b/netwerk/base/Dashboard.cpp index 9fbc7b44a6e9..398758aef326 100644 --- a/netwerk/base/Dashboard.cpp +++ b/netwerk/base/Dashboard.cpp @@ -175,9 +175,10 @@ ConnectionData::OnTransportStatus(nsITransport *aTransport, nsresult aStatus, } GetErrorString(aStatus, mStatus); - mThread->Dispatch(NewRunnableMethod> - (mDashboard, &Dashboard::GetConnectionStatus, this), - NS_DISPATCH_NORMAL); + nsCOMPtr event = + NS_NewRunnableMethodWithArg > + (mDashboard, &Dashboard::GetConnectionStatus, this); + mThread->Dispatch(event, NS_DISPATCH_NORMAL); return NS_OK; } @@ -196,9 +197,10 @@ ConnectionData::Notify(nsITimer *aTimer) mTimer = nullptr; mStatus.AssignLiteral(MOZ_UTF16("NS_ERROR_NET_TIMEOUT")); - mThread->Dispatch(NewRunnableMethod> - (mDashboard, &Dashboard::GetConnectionStatus, this), - NS_DISPATCH_NORMAL); + nsCOMPtr event = + NS_NewRunnableMethodWithArg > + (mDashboard, &Dashboard::GetConnectionStatus, this); + mThread->Dispatch(event, NS_DISPATCH_NORMAL); return NS_OK; } @@ -285,9 +287,10 @@ LookupHelper::OnLookupComplete(nsICancelable *aRequest, mStatus = aStatus; RefPtr arg = new LookupArgument(aRecord, this); - mThread->Dispatch(NewRunnableMethod> - (this, &LookupHelper::ConstructAnswer, arg), - NS_DISPATCH_NORMAL); + nsCOMPtr event = + NS_NewRunnableMethodWithArg >( + this, &LookupHelper::ConstructAnswer, arg); + mThread->Dispatch(event, NS_DISPATCH_NORMAL); return NS_OK; } @@ -351,9 +354,10 @@ Dashboard::RequestSockets(NetDashboardCallback *aCallback) socketData->mCallback = new nsMainThreadPtrHolder(aCallback, true); socketData->mThread = NS_GetCurrentThread(); - gSocketTransportService->Dispatch(NewRunnableMethod> - (this, &Dashboard::GetSocketsDispatch, socketData), - NS_DISPATCH_NORMAL); + nsCOMPtr event = + NS_NewRunnableMethodWithArg > + (this, &Dashboard::GetSocketsDispatch, socketData); + gSocketTransportService->Dispatch(event, NS_DISPATCH_NORMAL); return NS_OK; } @@ -366,9 +370,10 @@ Dashboard::GetSocketsDispatch(SocketData *aSocketData) socketData->mTotalSent = gSocketTransportService->GetSentBytes(); socketData->mTotalRecv = gSocketTransportService->GetReceivedBytes(); } - socketData->mThread->Dispatch(NewRunnableMethod> - (this, &Dashboard::GetSockets, socketData), - NS_DISPATCH_NORMAL); + nsCOMPtr event = + NS_NewRunnableMethodWithArg > + (this, &Dashboard::GetSockets, socketData); + socketData->mThread->Dispatch(event, NS_DISPATCH_NORMAL); return NS_OK; } @@ -421,9 +426,10 @@ Dashboard::RequestHttpConnections(NetDashboardCallback *aCallback) new nsMainThreadPtrHolder(aCallback, true); httpData->mThread = NS_GetCurrentThread(); - gSocketTransportService->Dispatch(NewRunnableMethod> - (this, &Dashboard::GetHttpDispatch, httpData), - NS_DISPATCH_NORMAL); + nsCOMPtr event = + NS_NewRunnableMethodWithArg > + (this, &Dashboard::GetHttpDispatch, httpData); + gSocketTransportService->Dispatch(event, NS_DISPATCH_NORMAL); return NS_OK; } @@ -432,9 +438,10 @@ Dashboard::GetHttpDispatch(HttpData *aHttpData) { RefPtr httpData = aHttpData; HttpInfo::GetHttpConnectionData(&httpData->mData); - httpData->mThread->Dispatch(NewRunnableMethod> - (this, &Dashboard::GetHttpConnections, httpData), - NS_DISPATCH_NORMAL); + nsCOMPtr event = + NS_NewRunnableMethodWithArg > + (this, &Dashboard::GetHttpConnections, httpData); + httpData->mThread->Dispatch(event, NS_DISPATCH_NORMAL); return NS_OK; } @@ -597,9 +604,10 @@ Dashboard::RequestWebsocketConnections(NetDashboardCallback *aCallback) new nsMainThreadPtrHolder(aCallback, true); wsRequest->mThread = NS_GetCurrentThread(); - wsRequest->mThread->Dispatch(NewRunnableMethod> - (this, &Dashboard::GetWebSocketConnections, wsRequest), - NS_DISPATCH_NORMAL); + nsCOMPtr event = + NS_NewRunnableMethodWithArg > + (this, &Dashboard::GetWebSocketConnections, wsRequest); + wsRequest->mThread->Dispatch(event, NS_DISPATCH_NORMAL); return NS_OK; } @@ -658,9 +666,10 @@ Dashboard::RequestDNSInfo(NetDashboardCallback *aCallback) } } - gSocketTransportService->Dispatch(NewRunnableMethod> - (this, &Dashboard::GetDnsInfoDispatch, dnsData), - NS_DISPATCH_NORMAL); + nsCOMPtr event = + NS_NewRunnableMethodWithArg > + (this, &Dashboard::GetDnsInfoDispatch, dnsData); + gSocketTransportService->Dispatch(event, NS_DISPATCH_NORMAL); return NS_OK; } @@ -671,9 +680,10 @@ Dashboard::GetDnsInfoDispatch(DnsData *aDnsData) if (mDnsService) { mDnsService->GetDNSCacheEntries(&dnsData->mData); } - dnsData->mThread->Dispatch(NewRunnableMethod> - (this, &Dashboard::GetDNSCacheEntries, dnsData), - NS_DISPATCH_NORMAL); + nsCOMPtr event = + NS_NewRunnableMethodWithArg > + (this, &Dashboard::GetDNSCacheEntries, dnsData); + dnsData->mThread->Dispatch(event, NS_DISPATCH_NORMAL); return NS_OK; } @@ -800,9 +810,10 @@ Dashboard::RequestConnection(const nsACString& aHost, uint32_t aPort, rv = TestNewConnection(connectionData); if (NS_FAILED(rv)) { mozilla::net::GetErrorString(rv, connectionData->mStatus); - connectionData->mThread->Dispatch(NewRunnableMethod> - (this, &Dashboard::GetConnectionStatus, connectionData), - NS_DISPATCH_NORMAL); + nsCOMPtr event = + NS_NewRunnableMethodWithArg > + (this, &Dashboard::GetConnectionStatus, connectionData); + connectionData->mThread->Dispatch(event, NS_DISPATCH_NORMAL); return rv; } diff --git a/netwerk/base/OfflineObserver.cpp b/netwerk/base/OfflineObserver.cpp index 286173e98e12..1cdc838ea758 100644 --- a/netwerk/base/OfflineObserver.cpp +++ b/netwerk/base/OfflineObserver.cpp @@ -21,8 +21,9 @@ OfflineObserver::RegisterOfflineObserver() if (NS_IsMainThread()) { RegisterOfflineObserverMainThread(); } else { - NS_DispatchToMainThread(NewRunnableMethod(this, - &OfflineObserver::RegisterOfflineObserverMainThread)); + nsCOMPtr event = + NS_NewRunnableMethod(this, &OfflineObserver::RegisterOfflineObserverMainThread); + NS_DispatchToMainThread(event); } } @@ -32,8 +33,9 @@ OfflineObserver::RemoveOfflineObserver() if (NS_IsMainThread()) { RemoveOfflineObserverMainThread(); } else { - NS_DispatchToMainThread(NewRunnableMethod(this, - &OfflineObserver::RemoveOfflineObserverMainThread)); + nsCOMPtr event = + NS_NewRunnableMethod(this, &OfflineObserver::RemoveOfflineObserverMainThread); + NS_DispatchToMainThread(event); } } diff --git a/netwerk/base/Tickler.cpp b/netwerk/base/Tickler.cpp index a705104ba3cf..5d42440dcaef 100644 --- a/netwerk/base/Tickler.cpp +++ b/netwerk/base/Tickler.cpp @@ -130,7 +130,7 @@ void Tickler::Tickle() void Tickler::PostCheckTickler() { mLock.AssertCurrentThreadOwns(); - mThread->Dispatch(NewRunnableMethod(this, &Tickler::CheckTickler), + mThread->Dispatch(NS_NewRunnableMethod(this, &Tickler::CheckTickler), NS_DISPATCH_NORMAL); return; } @@ -146,7 +146,7 @@ void Tickler::MaybeStartTickler() mLock.AssertCurrentThreadOwns(); if (!NS_IsMainThread()) { NS_DispatchToMainThread( - NewRunnableMethod(this, &Tickler::MaybeStartTicklerUnlocked)); + NS_NewRunnableMethod(this, &Tickler::MaybeStartTicklerUnlocked)); return; } diff --git a/netwerk/base/nsAsyncStreamCopier.cpp b/netwerk/base/nsAsyncStreamCopier.cpp index 0a1473a9fe5e..331dcc65a9e0 100644 --- a/netwerk/base/nsAsyncStreamCopier.cpp +++ b/netwerk/base/nsAsyncStreamCopier.cpp @@ -44,9 +44,8 @@ public: return NS_OK; } - rv = mTarget->Dispatch(NewRunnableMethod(mCopier, - &nsAsyncStreamCopier::AsyncCopyInternal), - NS_DISPATCH_NORMAL); + nsCOMPtr event = NS_NewRunnableMethod(mCopier, &nsAsyncStreamCopier::AsyncCopyInternal); + rv = mTarget->Dispatch(event, NS_DISPATCH_NORMAL); MOZ_ASSERT(NS_SUCCEEDED(rv)); if (NS_FAILED(rv)) { diff --git a/netwerk/base/nsInputStreamPump.cpp b/netwerk/base/nsInputStreamPump.cpp index 998961c1e74f..1096c10f012d 100644 --- a/netwerk/base/nsInputStreamPump.cpp +++ b/netwerk/base/nsInputStreamPump.cpp @@ -679,7 +679,7 @@ nsInputStreamPump::OnStateStop() MOZ_ASSERT(NS_IsMainThread(), "OnStateStop should only be called on the main thread."); nsresult rv = NS_DispatchToMainThread( - NewRunnableMethod(this, &nsInputStreamPump::CallOnStateStop)); + NS_NewRunnableMethod(this, &nsInputStreamPump::CallOnStateStop)); NS_ENSURE_SUCCESS(rv, STATE_IDLE); return STATE_IDLE; } diff --git a/netwerk/base/nsPACMan.cpp b/netwerk/base/nsPACMan.cpp index c52854cf5bd4..169c3b51fad8 100644 --- a/netwerk/base/nsPACMan.cpp +++ b/netwerk/base/nsPACMan.cpp @@ -415,8 +415,10 @@ nsPACMan::LoadPACFromURI(const nsCString &spec) // queries the enter between now and when we actually load the PAC file. if (!mLoadPending) { + nsCOMPtr event = + NS_NewRunnableMethod(this, &nsPACMan::StartLoading); nsresult rv; - if (NS_FAILED(rv = NS_DispatchToCurrentThread(NewRunnableMethod(this, &nsPACMan::StartLoading)))) + if (NS_FAILED(rv = NS_DispatchToCurrentThread(event))) return rv; mLoadPending = true; } @@ -782,9 +784,9 @@ nsPACMan::Init(nsISystemProxySettings *systemProxySettings) if (NS_FAILED(rv)) return rv; + nsCOMPtr event = NS_NewRunnableMethod(this, &nsPACMan::NamePACThread); // don't check return value as it is not a big deal for this to fail. - mPACThread->Dispatch(NewRunnableMethod(this, &nsPACMan::NamePACThread), - nsIEventTarget::DISPATCH_NORMAL); + mPACThread->Dispatch(event, nsIEventTarget::DISPATCH_NORMAL); return NS_OK; } diff --git a/netwerk/base/nsServerSocket.cpp b/netwerk/base/nsServerSocket.cpp index a074bc7e0ec7..3822448263e1 100644 --- a/netwerk/base/nsServerSocket.cpp +++ b/netwerk/base/nsServerSocket.cpp @@ -30,7 +30,10 @@ typedef void (nsServerSocket:: *nsServerSocketFunc)(void); static nsresult PostEvent(nsServerSocket *s, nsServerSocketFunc func) { - nsCOMPtr ev = NewRunnableMethod(s, func); + nsCOMPtr ev = NS_NewRunnableMethod(s, func); + if (!ev) + return NS_ERROR_OUT_OF_MEMORY; + if (!gSocketTransportService) return NS_ERROR_FAILURE; @@ -126,7 +129,7 @@ nsServerSocket::TryAttach() if (!gSocketTransportService->CanAttachSocket()) { nsCOMPtr event = - NewRunnableMethod(this, &nsServerSocket::OnMsgAttach); + NS_NewRunnableMethod(this, &nsServerSocket::OnMsgAttach); if (!event) return NS_ERROR_OUT_OF_MEMORY; diff --git a/netwerk/base/nsSocketTransportService2.cpp b/netwerk/base/nsSocketTransportService2.cpp index 1544fd441bb8..08f3ffe03b5d 100644 --- a/netwerk/base/nsSocketTransportService2.cpp +++ b/netwerk/base/nsSocketTransportService2.cpp @@ -919,7 +919,7 @@ nsSocketTransportService::Run() mRawThread->HasPendingEvents(&pendingEvents); if (pendingEvents) { if (!mServingPendingQueue) { - nsresult rv = Dispatch(NewRunnableMethod(this, + nsresult rv = Dispatch(NS_NewRunnableMethod(this, &nsSocketTransportService::MarkTheLastElementOfPendingQueue), nsIEventTarget::DISPATCH_NORMAL); if (NS_FAILED(rv)) { @@ -1261,7 +1261,7 @@ nsSocketTransportService::OnKeepaliveEnabledPrefChange() // Dispatch to socket thread if we're not executing there. if (PR_GetCurrentThread() != gSocketThread) { gSocketTransportService->Dispatch( - NewRunnableMethod( + NS_NewRunnableMethod( this, &nsSocketTransportService::OnKeepaliveEnabledPrefChange), NS_DISPATCH_NORMAL); return; @@ -1313,8 +1313,8 @@ nsSocketTransportService::Observe(nsISupports *subject, if (!strcmp(topic, "last-pb-context-exited")) { nsCOMPtr ev = - NewRunnableMethod(this, - &nsSocketTransportService::ClosePrivateConnections); + NS_NewRunnableMethod(this, + &nsSocketTransportService::ClosePrivateConnections); nsresult rv = Dispatch(ev, nsIEventTarget::DISPATCH_NORMAL); NS_ENSURE_SUCCESS(rv, rv); } diff --git a/netwerk/base/nsUDPSocket.cpp b/netwerk/base/nsUDPSocket.cpp index 1002d28ddf34..26e3d10f900f 100644 --- a/netwerk/base/nsUDPSocket.cpp +++ b/netwerk/base/nsUDPSocket.cpp @@ -48,10 +48,12 @@ typedef void (nsUDPSocket:: *nsUDPSocketFunc)(void); static nsresult PostEvent(nsUDPSocket *s, nsUDPSocketFunc func) { + nsCOMPtr ev = NS_NewRunnableMethod(s, func); + if (!gSocketTransportService) return NS_ERROR_FAILURE; - return gSocketTransportService->Dispatch(NewRunnableMethod(s, func), NS_DISPATCH_NORMAL); + return gSocketTransportService->Dispatch(ev, NS_DISPATCH_NORMAL); } static nsresult @@ -345,7 +347,7 @@ nsUDPSocket::TryAttach() if (!gSocketTransportService->CanAttachSocket()) { nsCOMPtr event = - NewRunnableMethod(this, &nsUDPSocket::OnMsgAttach); + NS_NewRunnableMethod(this, &nsUDPSocket::OnMsgAttach); nsresult rv = gSocketTransportService->NotifyWhenCanAttachSocket(event); if (NS_FAILED(rv)) diff --git a/netwerk/cache/nsCacheService.cpp b/netwerk/cache/nsCacheService.cpp index 70cd4bd9e306..c1a27baed12c 100644 --- a/netwerk/cache/nsCacheService.cpp +++ b/netwerk/cache/nsCacheService.cpp @@ -1525,8 +1525,8 @@ nsresult nsCacheService::EvictEntriesInternal(nsCacheStoragePolicy storagePolicy if (storagePolicy == nsICache::STORE_ANYWHERE) { // if not called on main thread, dispatch the notification to the main thread to notify observers if (!NS_IsMainThread()) { - nsCOMPtr event = NewRunnableMethod(this, - &nsCacheService::FireClearNetworkCacheStoredAnywhereNotification); + nsCOMPtr event = NS_NewRunnableMethod(this, + &nsCacheService::FireClearNetworkCacheStoredAnywhereNotification); NS_DispatchToMainThread(event); } else { // else you're already on main thread - notify observers diff --git a/netwerk/cache2/CacheEntry.cpp b/netwerk/cache2/CacheEntry.cpp index b1441ae9ff56..6a312e073dc0 100644 --- a/netwerk/cache2/CacheEntry.cpp +++ b/netwerk/cache2/CacheEntry.cpp @@ -668,9 +668,10 @@ bool CacheEntry::InvokeCallbacks(bool aReadOnly) if (NS_SUCCEEDED(rv) && !onCheckThread) { // Redispatch to the target thread - rv = mCallbacks[i].mTargetThread->Dispatch(NewRunnableMethod(this, - &CacheEntry::InvokeCallbacksLock), - nsIEventTarget::DISPATCH_NORMAL); + RefPtr > event = + NS_NewRunnableMethod(this, &CacheEntry::InvokeCallbacksLock); + + rv = mCallbacks[i].mTargetThread->Dispatch(event, nsIEventTarget::DISPATCH_NORMAL); if (NS_SUCCEEDED(rv)) { LOG((" re-dispatching to target thread")); return false; @@ -1738,7 +1739,9 @@ void CacheEntry::BackgroundOp(uint32_t aOperations, bool aForceAsync) // Because CacheFile::Set*() are not thread-safe to use (uses WeakReference that // is not thread-safe) we must post to the main thread... - NS_DispatchToMainThread(NewRunnableMethod(this, &CacheEntry::StoreFrecency, mFrecency)); + RefPtr > event = + NS_NewRunnableMethodWithArg(this, &CacheEntry::StoreFrecency, mFrecency); + NS_DispatchToMainThread(event); } if (aOperations & Ops::REGISTER) { diff --git a/netwerk/cache2/CacheFileChunk.cpp b/netwerk/cache2/CacheFileChunk.cpp index da3770f7e0f6..d0bda85604d2 100644 --- a/netwerk/cache2/CacheFileChunk.cpp +++ b/netwerk/cache2/CacheFileChunk.cpp @@ -54,7 +54,9 @@ CacheFileChunk::DispatchRelease() return false; } - NS_DispatchToMainThread(NewNonOwningRunnableMethod(this, &CacheFileChunk::Release)); + RefPtr > event = + NS_NewNonOwningRunnableMethod(this, &CacheFileChunk::Release); + NS_DispatchToMainThread(event); return true; } diff --git a/netwerk/cache2/CacheFileContextEvictor.cpp b/netwerk/cache2/CacheFileContextEvictor.cpp index 79966927c373..b92dcacf7d9c 100644 --- a/netwerk/cache2/CacheFileContextEvictor.cpp +++ b/netwerk/cache2/CacheFileContextEvictor.cpp @@ -522,7 +522,7 @@ CacheFileContextEvictor::StartEvicting() } nsCOMPtr ev; - ev = NewRunnableMethod(this, &CacheFileContextEvictor::EvictEntries); + ev = NS_NewRunnableMethod(this, &CacheFileContextEvictor::EvictEntries); RefPtr ioThread = CacheFileIOManager::IOThread(); diff --git a/netwerk/cache2/CacheFileIOManager.cpp b/netwerk/cache2/CacheFileIOManager.cpp index 4415b449c609..0e78f7205ea5 100644 --- a/netwerk/cache2/CacheFileIOManager.cpp +++ b/netwerk/cache2/CacheFileIOManager.cpp @@ -68,10 +68,9 @@ CacheFileHandle::DispatchRelease() return false; } - nsresult rv = - ioTarget->Dispatch(NewNonOwningRunnableMethod(this, - &CacheFileHandle::Release), - nsIEventTarget::DISPATCH_NORMAL); + RefPtr > event = + NS_NewNonOwningRunnableMethod(this, &CacheFileHandle::Release); + nsresult rv = ioTarget->Dispatch(event, nsIEventTarget::DISPATCH_NORMAL); if (NS_FAILED(rv)) { return false; } @@ -2640,8 +2639,8 @@ CacheFileIOManager::EvictIfOverLimit() } nsCOMPtr ev; - ev = NewRunnableMethod(ioMan, - &CacheFileIOManager::EvictIfOverLimitInternal); + ev = NS_NewRunnableMethod(ioMan, + &CacheFileIOManager::EvictIfOverLimitInternal); rv = ioMan->mIOThread->Dispatch(ev, CacheIOThread::EVICT); NS_ENSURE_SUCCESS(rv, rv); @@ -2701,8 +2700,8 @@ CacheFileIOManager::EvictIfOverLimitInternal() cacheUsage, cacheLimit)); nsCOMPtr ev; - ev = NewRunnableMethod(this, - &CacheFileIOManager::OverLimitEvictionInternal); + ev = NS_NewRunnableMethod(this, + &CacheFileIOManager::OverLimitEvictionInternal); rv = mIOThread->Dispatch(ev, CacheIOThread::EVICT); NS_ENSURE_SUCCESS(rv, rv); @@ -2841,7 +2840,7 @@ CacheFileIOManager::EvictAll() } nsCOMPtr ev; - ev = NewRunnableMethod(ioMan, &CacheFileIOManager::EvictAllInternal); + ev = NS_NewRunnableMethod(ioMan, &CacheFileIOManager::EvictAllInternal); rv = ioMan->mIOThread->DispatchAfterPendingOpens(ev); if (NS_WARN_IF(NS_FAILED(rv))) { @@ -2959,7 +2958,7 @@ CacheFileIOManager::EvictByContext(nsILoadContextInfo *aLoadContextInfo, bool aP } nsCOMPtr ev; - ev = NewRunnableMethod, bool> + ev = NS_NewRunnableMethodWithArgs, bool> (ioMan, &CacheFileIOManager::EvictByContextInternal, aLoadContextInfo, aPinned); rv = ioMan->mIOThread->DispatchAfterPendingOpens(ev); @@ -3078,7 +3077,7 @@ CacheFileIOManager::CacheIndexStateChanged() // We have to re-distatch even if we are on IO thread to prevent reentering // the lock in CacheIndex nsCOMPtr ev; - ev = NewRunnableMethod( + ev = NS_NewRunnableMethod( gInstance, &CacheFileIOManager::CacheIndexStateChangedInternal); nsCOMPtr ioTarget = IOTarget(); @@ -3243,8 +3242,8 @@ CacheFileIOManager::StartRemovingTrash() } nsCOMPtr ev; - ev = NewRunnableMethod(this, - &CacheFileIOManager::RemoveTrashInternal); + ev = NS_NewRunnableMethod(this, + &CacheFileIOManager::RemoveTrashInternal); rv = mIOThread->Dispatch(ev, CacheIOThread::EVICT); NS_ENSURE_SUCCESS(rv, rv); diff --git a/netwerk/cache2/CacheIndex.cpp b/netwerk/cache2/CacheIndex.cpp index 3ea6beed985c..3e5114303657 100644 --- a/netwerk/cache2/CacheIndex.cpp +++ b/netwerk/cache2/CacheIndex.cpp @@ -346,7 +346,7 @@ CacheIndex::PreShutdown() } nsCOMPtr event; - event = NewRunnableMethod(index, &CacheIndex::PreShutdownInternal); + event = NS_NewRunnableMethod(index, &CacheIndex::PreShutdownInternal); RefPtr ioThread = CacheFileIOManager::IOThread(); MOZ_ASSERT(ioThread); diff --git a/netwerk/cache2/CacheObserver.cpp b/netwerk/cache2/CacheObserver.cpp index 5b3d59a8cb3a..e20bb942a144 100644 --- a/netwerk/cache2/CacheObserver.cpp +++ b/netwerk/cache2/CacheObserver.cpp @@ -323,7 +323,7 @@ CacheObserver::SetDiskCacheCapacity(uint32_t aCapacity) sSelf->StoreDiskCacheCapacity(); } else { nsCOMPtr event = - NewRunnableMethod(sSelf, &CacheObserver::StoreDiskCacheCapacity); + NS_NewRunnableMethod(sSelf, &CacheObserver::StoreDiskCacheCapacity); NS_DispatchToMainThread(event); } } @@ -349,7 +349,7 @@ CacheObserver::SetCacheFSReported() sSelf->StoreCacheFSReported(); } else { nsCOMPtr event = - NewRunnableMethod(sSelf, &CacheObserver::StoreCacheFSReported); + NS_NewRunnableMethod(sSelf, &CacheObserver::StoreCacheFSReported); NS_DispatchToMainThread(event); } } @@ -375,7 +375,7 @@ CacheObserver::SetHashStatsReported() sSelf->StoreHashStatsReported(); } else { nsCOMPtr event = - NewRunnableMethod(sSelf, &CacheObserver::StoreHashStatsReported); + NS_NewRunnableMethod(sSelf, &CacheObserver::StoreHashStatsReported); NS_DispatchToMainThread(event); } } diff --git a/netwerk/cache2/CacheStorageService.cpp b/netwerk/cache2/CacheStorageService.cpp index 03292b2e282f..bb9e45687991 100644 --- a/netwerk/cache2/CacheStorageService.cpp +++ b/netwerk/cache2/CacheStorageService.cpp @@ -143,7 +143,7 @@ void CacheStorageService::Shutdown() mShutdown = true; nsCOMPtr event = - NewRunnableMethod(this, &CacheStorageService::ShutdownBackground); + NS_NewRunnableMethod(this, &CacheStorageService::ShutdownBackground); Dispatch(event); mozilla::MutexAutoLock lock(mLock); @@ -1212,7 +1212,7 @@ CacheStorageService::OnMemoryConsumptionChange(CacheMemoryConsumer* aConsumer, // Dispatch as a priority task, we want to set the purge timer // ASAP to prevent vain redispatch of this event. nsCOMPtr event = - NewRunnableMethod(this, &CacheStorageService::SchedulePurgeOverMemoryLimit); + NS_NewRunnableMethod(this, &CacheStorageService::SchedulePurgeOverMemoryLimit); cacheIOTarget->Dispatch(event, nsIEventTarget::DISPATCH_NORMAL); } @@ -1252,7 +1252,7 @@ CacheStorageService::Notify(nsITimer* aTimer) mPurgeTimer = nullptr; nsCOMPtr event = - NewRunnableMethod(this, &CacheStorageService::PurgeOverMemoryLimit); + NS_NewRunnableMethod(this, &CacheStorageService::PurgeOverMemoryLimit); Dispatch(event); } diff --git a/netwerk/dns/DNSRequestChild.cpp b/netwerk/dns/DNSRequestChild.cpp index 431fc8fbe67c..44b27eb8fefe 100644 --- a/netwerk/dns/DNSRequestChild.cpp +++ b/netwerk/dns/DNSRequestChild.cpp @@ -207,7 +207,7 @@ DNSRequestChild::StartRequest() // we can only do IPDL on the main thread if (!NS_IsMainThread()) { NS_DispatchToMainThread( - NewRunnableMethod(this, &DNSRequestChild::StartRequest)); + NS_NewRunnableMethod(this, &DNSRequestChild::StartRequest)); return; } @@ -260,7 +260,7 @@ DNSRequestChild::RecvLookupCompleted(const DNSRequestResponse& reply) CallOnLookupComplete(); } else { nsCOMPtr event = - NewRunnableMethod(this, &DNSRequestChild::CallOnLookupComplete); + NS_NewRunnableMethod(this, &DNSRequestChild::CallOnLookupComplete); mTarget->Dispatch(event, NS_DISPATCH_NORMAL); } diff --git a/netwerk/dns/mdns/libmdns/MDNSResponderOperator.cpp b/netwerk/dns/mdns/libmdns/MDNSResponderOperator.cpp index d66c3f571d98..5b205f925ba6 100644 --- a/netwerk/dns/mdns/libmdns/MDNSResponderOperator.cpp +++ b/netwerk/dns/mdns/libmdns/MDNSResponderOperator.cpp @@ -74,8 +74,9 @@ public: PR_Close(mFD); mFD = nullptr; - mThread->Dispatch(NewRunnableMethod(this, &ServiceWatcher::Deallocate), - NS_DISPATCH_NORMAL); + nsCOMPtr ev = + NS_NewRunnableMethod(this, &ServiceWatcher::Deallocate); + mThread->Dispatch(ev, NS_DISPATCH_NORMAL); } virtual void IsLocal(bool *aIsLocal) override { *aIsLocal = true; } @@ -153,8 +154,8 @@ private: nsresult PostEvent(void(ServiceWatcher::*func)(void)) { - return gSocketTransportService->Dispatch(NewRunnableMethod(this, func), - NS_DISPATCH_NORMAL); + nsCOMPtr ev = NS_NewRunnableMethod(this, func); + return gSocketTransportService->Dispatch(ev, NS_DISPATCH_NORMAL); } void OnMsgClose() @@ -218,7 +219,7 @@ private: // if (!gSocketTransportService->CanAttachSocket()) { nsCOMPtr event = - NewRunnableMethod(this, &ServiceWatcher::OnMsgAttach); + NS_NewRunnableMethod(this, &ServiceWatcher::OnMsgAttach); nsresult rv = gSocketTransportService->NotifyWhenCanAttachSocket(event); if (NS_FAILED(rv)) { diff --git a/netwerk/ipc/ChannelEventQueue.cpp b/netwerk/ipc/ChannelEventQueue.cpp index ae55ebd032bf..d0511e2d61e8 100644 --- a/netwerk/ipc/ChannelEventQueue.cpp +++ b/netwerk/ipc/ChannelEventQueue.cpp @@ -67,13 +67,13 @@ ChannelEventQueue::Resume() } if (!--mSuspendCount) { - RefPtr event = - NewRunnableMethod(this, &ChannelEventQueue::CompleteResume); + RefPtr > event = + NS_NewRunnableMethod(this, &ChannelEventQueue::CompleteResume); if (mTargetThread) { - mTargetThread->Dispatch(event.forget(), NS_DISPATCH_NORMAL); + mTargetThread->Dispatch(event, NS_DISPATCH_NORMAL); } else { MOZ_RELEASE_ASSERT(NS_IsMainThread()); - NS_WARN_IF(NS_FAILED(NS_DispatchToCurrentThread(event.forget()))); + NS_WARN_IF(NS_FAILED(NS_DispatchToCurrentThread(event))); } } } diff --git a/netwerk/protocol/about/nsAboutCache.cpp b/netwerk/protocol/about/nsAboutCache.cpp index 2ab2e719d52f..31f4a02c82fe 100644 --- a/netwerk/protocol/about/nsAboutCache.cpp +++ b/netwerk/protocol/about/nsAboutCache.cpp @@ -179,7 +179,9 @@ nsAboutCache::VisitNextStorage() // from visitor callback. The cache v1 service doesn't like it. // TODO - mayhemer, bug 913828, remove this dispatch and call // directly. - return NS_DispatchToMainThread(mozilla::NewRunnableMethod(this, &nsAboutCache::FireVisitStorage)); + nsCOMPtr event = + NS_NewRunnableMethod(this, &nsAboutCache::FireVisitStorage); + return NS_DispatchToMainThread(event); } void diff --git a/netwerk/protocol/file/nsFileChannel.cpp b/netwerk/protocol/file/nsFileChannel.cpp index 38b59af4b608..8368161a0140 100644 --- a/netwerk/protocol/file/nsFileChannel.cpp +++ b/netwerk/protocol/file/nsFileChannel.cpp @@ -232,7 +232,7 @@ nsFileUploadContentStream::AsyncWait(nsIInputStreamCallback *callback, if (IsNonBlocking()) { nsCOMPtr callback = - NewRunnableMethod(this, &nsFileUploadContentStream::OnCopyComplete); + NS_NewRunnableMethod(this, &nsFileUploadContentStream::OnCopyComplete); mCopyEvent->Dispatch(callback, mSink, target); } diff --git a/netwerk/protocol/ftp/FTPChannelParent.cpp b/netwerk/protocol/ftp/FTPChannelParent.cpp index fbe3addde21b..cd2013c6024e 100644 --- a/netwerk/protocol/ftp/FTPChannelParent.cpp +++ b/netwerk/protocol/ftp/FTPChannelParent.cpp @@ -740,7 +740,7 @@ FTPChannelParent::DivertTo(nsIStreamListener *aListener) // Call OnStartRequest and SendDivertMessages asynchronously to avoid // reentering client context. NS_DispatchToCurrentThread( - NewRunnableMethod(this, &FTPChannelParent::StartDiversion)); + NS_NewRunnableMethod(this, &FTPChannelParent::StartDiversion)); return; } diff --git a/netwerk/protocol/http/HttpBaseChannel.cpp b/netwerk/protocol/http/HttpBaseChannel.cpp index ebba1f804814..e5d652272302 100644 --- a/netwerk/protocol/http/HttpBaseChannel.cpp +++ b/netwerk/protocol/http/HttpBaseChannel.cpp @@ -665,7 +665,7 @@ void CopyComplete(void* aClosure, nsresult aStatus) { // Called on the STS thread by NS_AsyncCopy auto channel = static_cast(aClosure); - nsCOMPtr runnable = NewRunnableMethod( + nsCOMPtr runnable = NS_NewRunnableMethodWithArg( channel, &HttpBaseChannel::EnsureUploadStreamIsCloneableComplete, aStatus); NS_DispatchToMainThread(runnable.forget()); } diff --git a/netwerk/protocol/http/HttpBaseChannel.h b/netwerk/protocol/http/HttpBaseChannel.h index 0bd97a9686ce..20083217cf68 100644 --- a/netwerk/protocol/http/HttpBaseChannel.h +++ b/netwerk/protocol/http/HttpBaseChannel.h @@ -582,11 +582,11 @@ inline void HttpAsyncAborter::HandleAsyncAbort() template nsresult HttpAsyncAborter::AsyncCall(void (T::*funcPtr)(), - nsRunnableMethod **retval) + nsRunnableMethod **retval) { nsresult rv; - RefPtr> event = NewRunnableMethod(mThis, funcPtr); + RefPtr > event = NS_NewRunnableMethod(mThis, funcPtr); rv = NS_DispatchToCurrentThread(event); if (NS_SUCCEEDED(rv) && retval) { *retval = event; diff --git a/netwerk/protocol/http/HttpChannelParent.cpp b/netwerk/protocol/http/HttpChannelParent.cpp index 89d3d9526e33..a8c14c1ebf66 100644 --- a/netwerk/protocol/http/HttpChannelParent.cpp +++ b/netwerk/protocol/http/HttpChannelParent.cpp @@ -1433,7 +1433,7 @@ HttpChannelParent::DivertTo(nsIStreamListener *aListener) // Call OnStartRequest and SendDivertMessages asynchronously to avoid // reentering client context. NS_DispatchToCurrentThread( - NewRunnableMethod(this, &HttpChannelParent::StartDiversion)); + NS_NewRunnableMethod(this, &HttpChannelParent::StartDiversion)); return; } diff --git a/netwerk/protocol/http/PackagedAppVerifier.cpp b/netwerk/protocol/http/PackagedAppVerifier.cpp index c0dac5f42843..b520eab3fcb1 100644 --- a/netwerk/protocol/http/PackagedAppVerifier.cpp +++ b/netwerk/protocol/http/PackagedAppVerifier.cpp @@ -248,13 +248,13 @@ PackagedAppVerifier::FireVerifiedEvent(bool aForManifest, bool aSuccess) nsCOMPtr r; if (aForManifest) { - r = NewRunnableMethod(this, - &PackagedAppVerifier::OnManifestVerified, - aSuccess); + r = NS_NewRunnableMethodWithArgs(this, + &PackagedAppVerifier::OnManifestVerified, + aSuccess); } else { - r = NewRunnableMethod(this, - &PackagedAppVerifier::OnResourceVerified, - aSuccess); + r = NS_NewRunnableMethodWithArgs(this, + &PackagedAppVerifier::OnResourceVerified, + aSuccess); } NS_DispatchToMainThread(r); diff --git a/netwerk/protocol/http/nsHttpHandler.cpp b/netwerk/protocol/http/nsHttpHandler.cpp index be8a008d825a..1565a591baba 100644 --- a/netwerk/protocol/http/nsHttpHandler.cpp +++ b/netwerk/protocol/http/nsHttpHandler.cpp @@ -2165,8 +2165,8 @@ nsHttpHandler::Observe(nsISupports *subject, if (mConnMgr) { if (gSocketTransportService) { nsCOMPtr event = - NewRunnableMethod(mConnMgr, - &nsHttpConnectionMgr::ClearConnectionHistory); + NS_NewRunnableMethod(mConnMgr, + &nsHttpConnectionMgr::ClearConnectionHistory); gSocketTransportService->Dispatch(event, NS_DISPATCH_NORMAL); } mConnMgr->ClearAltServiceMappings(); diff --git a/netwerk/protocol/websocket/WebSocketChannel.cpp b/netwerk/protocol/websocket/WebSocketChannel.cpp index c081035cda73..5465426388ea 100644 --- a/netwerk/protocol/websocket/WebSocketChannel.cpp +++ b/netwerk/protocol/websocket/WebSocketChannel.cpp @@ -1248,7 +1248,7 @@ WebSocketChannel::Observe(nsISupports *subject, // Next we check mDataStarted, which we need to do on mTargetThread. if (!IsOnTargetThread()) { mTargetThread->Dispatch( - NewRunnableMethod(this, &WebSocketChannel::OnNetworkChanged), + NS_NewRunnableMethod(this, &WebSocketChannel::OnNetworkChanged), NS_DISPATCH_NORMAL); } else { OnNetworkChanged(); @@ -1272,7 +1272,7 @@ WebSocketChannel::OnNetworkChanged() } return mSocketThread->Dispatch( - NewRunnableMethod(this, &WebSocketChannel::OnNetworkChanged), + NS_NewRunnableMethod(this, &WebSocketChannel::OnNetworkChanged), NS_DISPATCH_NORMAL); } @@ -1359,7 +1359,7 @@ WebSocketChannel::BeginOpen(bool aCalledFromAdmissionManager) // When called from nsWSAdmissionManager post an event to avoid potential // re-entering of nsWSAdmissionManager and its lock. NS_DispatchToMainThread( - NewRunnableMethod(this, &WebSocketChannel::BeginOpenInternal), + NS_NewRunnableMethod(this, &WebSocketChannel::BeginOpenInternal), NS_DISPATCH_NORMAL); } else { BeginOpenInternal(); @@ -2795,7 +2795,7 @@ WebSocketChannel::StartWebsocketData() if (!IsOnTargetThread()) { return mTargetThread->Dispatch( - NewRunnableMethod(this, &WebSocketChannel::StartWebsocketData), + NS_NewRunnableMethod(this, &WebSocketChannel::StartWebsocketData), NS_DISPATCH_NORMAL); } @@ -2808,15 +2808,15 @@ WebSocketChannel::StartWebsocketData() LOG(("WebSocketChannel::StartWebsocketData mSocketIn->AsyncWait() failed " "with error 0x%08x", rv)); return mSocketThread->Dispatch( - NewRunnableMethod(this, - &WebSocketChannel::AbortSession, - rv), + NS_NewRunnableMethodWithArgs(this, + &WebSocketChannel::AbortSession, + rv), NS_DISPATCH_NORMAL); } if (mPingInterval) { rv = mSocketThread->Dispatch( - NewRunnableMethod(this, &WebSocketChannel::StartPinging), + NS_NewRunnableMethod(this, &WebSocketChannel::StartPinging), NS_DISPATCH_NORMAL); if (NS_FAILED(rv)) { LOG(("WebSocketChannel::StartWebsocketData Could not start pinging, " diff --git a/netwerk/protocol/websocket/WebSocketChannelChild.cpp b/netwerk/protocol/websocket/WebSocketChannelChild.cpp index b88a4698aa29..d98167db75ab 100644 --- a/netwerk/protocol/websocket/WebSocketChannelChild.cpp +++ b/netwerk/protocol/websocket/WebSocketChannelChild.cpp @@ -107,9 +107,9 @@ WebSocketChannelChild::MaybeReleaseIPCObject() } if (!NS_IsMainThread()) { - MOZ_ALWAYS_SUCCEEDS( - NS_DispatchToMainThread(NewRunnableMethod(this, - &WebSocketChannelChild::MaybeReleaseIPCObject))); + nsCOMPtr runnable = + NS_NewRunnableMethod(this, &WebSocketChannelChild::MaybeReleaseIPCObject); + MOZ_ALWAYS_SUCCEEDS(NS_DispatchToMainThread(runnable)); return; } diff --git a/netwerk/protocol/wyciwyg/nsWyciwygChannel.cpp b/netwerk/protocol/wyciwyg/nsWyciwygChannel.cpp index 7f1a4313173f..c73bf4287d69 100644 --- a/netwerk/protocol/wyciwyg/nsWyciwygChannel.cpp +++ b/netwerk/protocol/wyciwyg/nsWyciwygChannel.cpp @@ -700,7 +700,7 @@ nsWyciwygChannel::OnCacheEntryAvailable(nsICacheEntry *aCacheEntry, if (!aNew) { // Since OnCacheEntryAvailable can be called directly from AsyncOpen // we must dispatch. - NS_DispatchToCurrentThread(mozilla::NewRunnableMethod( + NS_DispatchToCurrentThread(NS_NewRunnableMethod( this, &nsWyciwygChannel::NotifyListener)); } } diff --git a/parser/html/nsHtml5TreeOpExecutor.cpp b/parser/html/nsHtml5TreeOpExecutor.cpp index 3a260e6ebb78..d3d8c8e34a4c 100644 --- a/parser/html/nsHtml5TreeOpExecutor.cpp +++ b/parser/html/nsHtml5TreeOpExecutor.cpp @@ -233,8 +233,11 @@ nsHtml5TreeOpExecutor::MarkAsBroken(nsresult aReason) // works out so that we get to terminate and clean up the parser from // a safer point. if (mParser) { // can mParser ever be null here? - MOZ_ALWAYS_SUCCEEDS( - NS_DispatchToMainThread(NewRunnableMethod(GetParser(), &nsHtml5Parser::Terminate))); + nsCOMPtr terminator = + NS_NewRunnableMethod(GetParser(), &nsHtml5Parser::Terminate); + if (NS_FAILED(NS_DispatchToMainThread(terminator))) { + NS_WARNING("failed to dispatch executor flush event"); + } } return aReason; } diff --git a/security/manager/ssl/DataStorage.cpp b/security/manager/ssl/DataStorage.cpp index 2059bb5f8d72..72c9717a85ac 100644 --- a/security/manager/ssl/DataStorage.cpp +++ b/security/manager/ssl/DataStorage.cpp @@ -193,9 +193,9 @@ DataStorage::Reader::~Reader() // This is for tests. nsCOMPtr job = - NewRunnableMethod(mDataStorage, - &DataStorage::NotifyObservers, - "data-storage-ready"); + NS_NewRunnableMethodWithArg(mDataStorage, + &DataStorage::NotifyObservers, + "data-storage-ready"); nsresult rv = NS_DispatchToMainThread(job, NS_DISPATCH_NORMAL); Unused << NS_WARN_IF(NS_FAILED(rv)); } @@ -686,9 +686,9 @@ DataStorage::Writer::Run() // Observed by tests. nsCOMPtr job = - NewRunnableMethod(mDataStorage, - &DataStorage::NotifyObservers, - "data-storage-written"); + NS_NewRunnableMethodWithArg(mDataStorage, + &DataStorage::NotifyObservers, + "data-storage-written"); rv = NS_DispatchToMainThread(job, NS_DISPATCH_NORMAL); if (NS_WARN_IF(NS_FAILED(rv))) { return rv; @@ -777,7 +777,7 @@ DataStorage::AsyncSetTimer(const MutexAutoLock& /*aProofOfLock*/) mPendingWrite = true; nsCOMPtr job = - NewRunnableMethod(this, &DataStorage::SetTimer); + NS_NewRunnableMethod(this, &DataStorage::SetTimer); nsresult rv = mWorkerThread->Dispatch(job, NS_DISPATCH_NORMAL); if (NS_WARN_IF(NS_FAILED(rv))) { return rv; @@ -827,7 +827,7 @@ DataStorage::DispatchShutdownTimer(const MutexAutoLock& /*aProofOfLock*/) MOZ_ASSERT(XRE_IsParentProcess()); nsCOMPtr job = - NewRunnableMethod(this, &DataStorage::ShutdownTimer); + NS_NewRunnableMethod(this, &DataStorage::ShutdownTimer); nsresult rv = mWorkerThread->Dispatch(job, NS_DISPATCH_NORMAL); if (NS_WARN_IF(NS_FAILED(rv))) { return rv; diff --git a/security/manager/ssl/PSMContentListener.cpp b/security/manager/ssl/PSMContentListener.cpp index 295264c53916..bc6c4c98ecd6 100644 --- a/security/manager/ssl/PSMContentListener.cpp +++ b/security/manager/ssl/PSMContentListener.cpp @@ -152,7 +152,7 @@ PSMContentStreamListener::OnStopRequest(nsIRequest* request, // Because importing the cert can spin the event loop (via alerts), we can't // do it here. Do it off the event loop instead. nsCOMPtr r = - NewRunnableMethod(this, &PSMContentStreamListener::ImportCertificate); + NS_NewRunnableMethod(this, &PSMContentStreamListener::ImportCertificate); MOZ_ALWAYS_SUCCEEDS(NS_DispatchToMainThread(r)); return NS_OK; diff --git a/storage/mozStorageConnection.cpp b/storage/mozStorageConnection.cpp index ef7bba350db4..b7a16c6697da 100644 --- a/storage/mozStorageConnection.cpp +++ b/storage/mozStorageConnection.cpp @@ -367,7 +367,7 @@ public: MOZ_ASSERT(onAsyncThread); #endif // DEBUG - nsCOMPtr event = NewRunnableMethod> + nsCOMPtr event = NS_NewRunnableMethodWithArg> (mConnection, &Connection::shutdownAsyncThread, mAsyncExecutionThread); (void)NS_DispatchToMainThread(event); diff --git a/storage/mozStorageService.cpp b/storage/mozStorageService.cpp index 2d175f7f421e..9283cf9b0f68 100644 --- a/storage/mozStorageService.cpp +++ b/storage/mozStorageService.cpp @@ -383,7 +383,7 @@ Service::minimizeMemory() // We are on the wrong thread, the query should be executed on the // opener thread, so we must dispatch to it. nsCOMPtr event = - NewRunnableMethod( + NS_NewRunnableMethodWithArg( conn, &Connection::ExecuteSimpleSQL, shrinkPragma); conn->threadOpenedOn->Dispatch(event, NS_DISPATCH_NORMAL); } @@ -702,7 +702,7 @@ public: : mConnection->initialize(); if (NS_FAILED(rv)) { nsCOMPtr closeRunnable = - NewRunnableMethod( + NS_NewRunnableMethodWithArg( mConnection.get(), &Connection::AsyncClose, nullptr); diff --git a/toolkit/components/filewatcher/NativeFileWatcherWin.cpp b/toolkit/components/filewatcher/NativeFileWatcherWin.cpp index 21385b03bf9a..ac9a7654d08d 100644 --- a/toolkit/components/filewatcher/NativeFileWatcherWin.cpp +++ b/toolkit/components/filewatcher/NativeFileWatcherWin.cpp @@ -1311,7 +1311,7 @@ NativeFileWatcherService::AddPath(const nsAString& aPathToWatch, nsMainThreadPtrHandle successCallbackHandle( new nsMainThreadPtrHolder(aOnSuccess)); - // Wrap the path and the callbacks in order to pass them using NewRunnableMethod. + // Wrap the path and the callbacks in order to pass them using NS_NewRunnableMethodWithArg. UniquePtr wrappedCallbacks( new PathRunnablesParametersWrapper( aPathToWatch, @@ -1322,7 +1322,7 @@ NativeFileWatcherService::AddPath(const nsAString& aPathToWatch, // Since this function does a bit of I/O stuff , run it in the IO thread. nsresult rv = mIOThread->Dispatch( - NewRunnableMethod( + NS_NewRunnableMethodWithArg( static_cast(mWorkerIORunnable.get()), &NativeFileWatcherIOTask::AddPathRunnableMethod, wrappedCallbacks.get()), @@ -1381,7 +1381,7 @@ NativeFileWatcherService::RemovePath(const nsAString& aPathToRemove, nsMainThreadPtrHandle successCallbackHandle( new nsMainThreadPtrHolder(aOnSuccess)); - // Wrap the path and the callbacks in order to pass them using NewRunnableMethod. + // Wrap the path and the callbacks in order to pass them using NS_NewRunnableMethodWithArg. UniquePtr wrappedCallbacks( new PathRunnablesParametersWrapper( aPathToRemove, @@ -1392,7 +1392,7 @@ NativeFileWatcherService::RemovePath(const nsAString& aPathToRemove, // Since this function does a bit of I/O stuff, run it in the IO thread. nsresult rv = mIOThread->Dispatch( - NewRunnableMethod( + NS_NewRunnableMethodWithArg( static_cast(mWorkerIORunnable.get()), &NativeFileWatcherIOTask::RemovePathRunnableMethod, wrappedCallbacks.get()), @@ -1441,7 +1441,7 @@ NativeFileWatcherService::Uninit() // in the IO thread. nsresult rv = ioThread->Dispatch( - NewRunnableMethod( + NS_NewRunnableMethod( static_cast(mWorkerIORunnable.get()), &NativeFileWatcherIOTask::DeactivateRunnableMethod), nsIEventTarget::DISPATCH_NORMAL); diff --git a/toolkit/components/places/History.cpp b/toolkit/components/places/History.cpp index 73c330972122..a3c2f77acfeb 100644 --- a/toolkit/components/places/History.cpp +++ b/toolkit/components/places/History.cpp @@ -504,7 +504,9 @@ public: RefPtr cb = new VisitedQuery(aURI, callback, true); NS_ENSURE_TRUE(cb, NS_ERROR_OUT_OF_MEMORY); // As per IHistory contract, we must notify asynchronously. - NS_DispatchToMainThread(NewRunnableMethod(cb, &VisitedQuery::NotifyVisitedStatus)); + nsCOMPtr event = + NS_NewRunnableMethod(cb, &VisitedQuery::NotifyVisitedStatus); + NS_DispatchToMainThread(event); return NS_OK; } diff --git a/toolkit/components/satchel/nsFormFillController.cpp b/toolkit/components/satchel/nsFormFillController.cpp index 73c79cd9dc8b..775386fab5bd 100644 --- a/toolkit/components/satchel/nsFormFillController.cpp +++ b/toolkit/components/satchel/nsFormFillController.cpp @@ -119,7 +119,7 @@ nsFormFillController::AttributeChanged(nsIDocument* aDocument, // to avoid ending up in an endless loop due to re-registering our // mutation observer (which would notify us again for *this* event). nsCOMPtr event = - mozilla::NewRunnableMethod> + NS_NewRunnableMethodWithArg> (this, &nsFormFillController::MaybeStartControllingInput, focusedInput); NS_DispatchToCurrentThread(event); } diff --git a/toolkit/components/telemetry/Telemetry.cpp b/toolkit/components/telemetry/Telemetry.cpp index e26f36dcc8af..a3d255277f59 100644 --- a/toolkit/components/telemetry/Telemetry.cpp +++ b/toolkit/components/telemetry/Telemetry.cpp @@ -1748,7 +1748,7 @@ public: ReadLastShutdownDuration(mShutdownTimeFilename); mTelemetry->ReadLateWritesStacks(mProfileDir); nsCOMPtr e = - NewRunnableMethod(this, &nsFetchTelemetryData::MainThread); + NS_NewRunnableMethod(this, &nsFetchTelemetryData::MainThread); NS_ENSURE_STATE(e); NS_DispatchToMainThread(e); return NS_OK; diff --git a/toolkit/components/url-classifier/nsUrlClassifierProxies.cpp b/toolkit/components/url-classifier/nsUrlClassifierProxies.cpp index f0be4f2000c0..96fdfea720ee 100644 --- a/toolkit/components/url-classifier/nsUrlClassifierProxies.cpp +++ b/toolkit/components/url-classifier/nsUrlClassifierProxies.cpp @@ -9,7 +9,6 @@ #include "mozilla/SyncRunnable.h" using namespace mozilla::safebrowsing; -using mozilla::NewRunnableMethod; static nsresult DispatchToWorkerThread(nsIRunnable* r) @@ -114,8 +113,8 @@ NS_IMETHODIMP UrlClassifierDBServiceWorkerProxy::FinishStream() { nsCOMPtr r = - NewRunnableMethod(mTarget, - &nsIUrlClassifierDBServiceWorker::FinishStream); + NS_NewRunnableMethod(mTarget, + &nsIUrlClassifierDBServiceWorker::FinishStream); return DispatchToWorkerThread(r); } @@ -148,8 +147,8 @@ NS_IMETHODIMP UrlClassifierDBServiceWorkerProxy::FinishUpdate() { nsCOMPtr r = - NewRunnableMethod(mTarget, - &nsIUrlClassifierDBServiceWorker::FinishUpdate); + NS_NewRunnableMethod(mTarget, + &nsIUrlClassifierDBServiceWorker::FinishUpdate); return DispatchToWorkerThread(r); } @@ -157,8 +156,8 @@ NS_IMETHODIMP UrlClassifierDBServiceWorkerProxy::CancelUpdate() { nsCOMPtr r = - NewRunnableMethod(mTarget, - &nsIUrlClassifierDBServiceWorker::CancelUpdate); + NS_NewRunnableMethod(mTarget, + &nsIUrlClassifierDBServiceWorker::CancelUpdate); return DispatchToWorkerThread(r); } @@ -166,8 +165,8 @@ NS_IMETHODIMP UrlClassifierDBServiceWorkerProxy::ResetDatabase() { nsCOMPtr r = - NewRunnableMethod(mTarget, - &nsIUrlClassifierDBServiceWorker::ResetDatabase); + NS_NewRunnableMethod(mTarget, + &nsIUrlClassifierDBServiceWorker::ResetDatabase); return DispatchToWorkerThread(r); } @@ -175,8 +174,8 @@ NS_IMETHODIMP UrlClassifierDBServiceWorkerProxy::OpenDb() { nsCOMPtr r = - NewRunnableMethod(mTarget, - &nsIUrlClassifierDBServiceWorker::OpenDb); + NS_NewRunnableMethod(mTarget, + &nsIUrlClassifierDBServiceWorker::OpenDb); return DispatchToWorkerThread(r); } @@ -184,8 +183,8 @@ NS_IMETHODIMP UrlClassifierDBServiceWorkerProxy::CloseDb() { nsCOMPtr r = - NewRunnableMethod(mTarget, - &nsIUrlClassifierDBServiceWorker::CloseDb); + NS_NewRunnableMethod(mTarget, + &nsIUrlClassifierDBServiceWorker::CloseDb); return DispatchToWorkerThread(r); } diff --git a/toolkit/xre/nsUpdateDriver.cpp b/toolkit/xre/nsUpdateDriver.cpp index cc8b87ef6377..83002ca02243 100644 --- a/toolkit/xre/nsUpdateDriver.cpp +++ b/toolkit/xre/nsUpdateDriver.cpp @@ -1204,8 +1204,8 @@ nsUpdateProcessor::ProcessUpdate(nsIUpdate* aUpdate) #endif MOZ_ASSERT(NS_IsMainThread(), "not main thread"); - nsCOMPtr r = NewRunnableMethod(this, &nsUpdateProcessor::StartStagedUpdate); - return NS_NewThread(getter_AddRefs(mProcessWatcher), r); + return NS_NewThread(getter_AddRefs(mProcessWatcher), + NS_NewRunnableMethod(this, &nsUpdateProcessor::StartStagedUpdate)); } @@ -1229,13 +1229,13 @@ nsUpdateProcessor::StartStagedUpdate() if (mUpdaterPID) { // Track the state of the updater process while it is staging an update. - rv = NS_DispatchToCurrentThread(NewRunnableMethod(this, &nsUpdateProcessor::WaitForProcess)); + rv = NS_DispatchToCurrentThread(NS_NewRunnableMethod(this, &nsUpdateProcessor::WaitForProcess)); NS_ENSURE_SUCCESS_VOID(rv); } else { // Failed to launch the updater process for some reason. // We need to shutdown the current thread as there isn't anything more for // us to do... - rv = NS_DispatchToMainThread(NewRunnableMethod(this, &nsUpdateProcessor::ShutdownWatcherThread)); + rv = NS_DispatchToMainThread(NS_NewRunnableMethod(this, &nsUpdateProcessor::ShutdownWatcherThread)); NS_ENSURE_SUCCESS_VOID(rv); } } @@ -1253,7 +1253,7 @@ nsUpdateProcessor::WaitForProcess() { MOZ_ASSERT(!NS_IsMainThread(), "main thread"); ::WaitForProcess(mUpdaterPID); - NS_DispatchToMainThread(NewRunnableMethod(this, &nsUpdateProcessor::UpdateDone)); + NS_DispatchToMainThread(NS_NewRunnableMethod(this, &nsUpdateProcessor::UpdateDone)); } void diff --git a/uriloader/prefetch/nsOfflineCacheUpdate.cpp b/uriloader/prefetch/nsOfflineCacheUpdate.cpp index 746a447499c8..96d960842a6e 100644 --- a/uriloader/prefetch/nsOfflineCacheUpdate.cpp +++ b/uriloader/prefetch/nsOfflineCacheUpdate.cpp @@ -1733,8 +1733,10 @@ nsOfflineCacheUpdate::Begin() mItemsInProgress = 0; if (mState == STATE_CANCELLED) { - nsresult rv = NS_DispatchToMainThread(NewRunnableMethod(this, - &nsOfflineCacheUpdate::AsyncFinishWithError)); + RefPtr > errorNotification = + NS_NewRunnableMethod(this, + &nsOfflineCacheUpdate::AsyncFinishWithError); + nsresult rv = NS_DispatchToMainThread(errorNotification); NS_ENSURE_SUCCESS(rv, rv); return NS_OK; diff --git a/widget/ScreenProxy.cpp b/widget/ScreenProxy.cpp index 5257eb68ab23..cf774a6e9a50 100644 --- a/widget/ScreenProxy.cpp +++ b/widget/ScreenProxy.cpp @@ -174,7 +174,9 @@ ScreenProxy::InvalidateCacheOnNextTick() mCacheWillInvalidate = true; - nsContentUtils::RunInStableState(NewRunnableMethod(this, &ScreenProxy::InvalidateCache)); + nsCOMPtr r = + NS_NewRunnableMethod(this, &ScreenProxy::InvalidateCache); + nsContentUtils::RunInStableState(r.forget()); } void diff --git a/widget/VsyncDispatcher.cpp b/widget/VsyncDispatcher.cpp index 04ad7410b124..b57c71136d72 100644 --- a/widget/VsyncDispatcher.cpp +++ b/widget/VsyncDispatcher.cpp @@ -89,7 +89,7 @@ CompositorVsyncDispatcher::SetCompositorVsyncObserver(VsyncObserver* aVsyncObser } bool observeVsync = aVsyncObserver != nullptr; - nsCOMPtr vsyncControl = NewRunnableMethod(this, + nsCOMPtr vsyncControl = NS_NewRunnableMethodWithArg(this, &CompositorVsyncDispatcher::ObserveVsync, observeVsync); NS_DispatchToMainThread(vsyncControl); @@ -180,8 +180,9 @@ void RefreshTimerVsyncDispatcher::UpdateVsyncStatus() { if (!NS_IsMainThread()) { - NS_DispatchToMainThread(NewRunnableMethod(this, - &RefreshTimerVsyncDispatcher::UpdateVsyncStatus)); + nsCOMPtr vsyncControl = NS_NewRunnableMethod(this, + &RefreshTimerVsyncDispatcher::UpdateVsyncStatus); + NS_DispatchToMainThread(vsyncControl); return; } diff --git a/widget/android/AndroidContentController.cpp b/widget/android/AndroidContentController.cpp index 655cec69dad1..0090396a8b50 100644 --- a/widget/android/AndroidContentController.cpp +++ b/widget/android/AndroidContentController.cpp @@ -34,7 +34,7 @@ AndroidContentController::NotifyDefaultPrevented(APZCTreeManager* aManager, // The notification must reach the APZ on the Java UI thread (aka the // APZ "controller" thread) but we get it from the Gecko thread, so we // have to throw it onto the other thread. - AndroidBridge::Bridge()->PostTaskToUiThread(NewRunnableMethod( + AndroidBridge::Bridge()->PostTaskToUiThread(NewRunnableMethod( aManager, &APZCTreeManager::ContentReceivedInputBlock, aInputBlockId, aDefaultPrevented), 0); return; diff --git a/widget/gtk/nsDeviceContextSpecG.cpp b/widget/gtk/nsDeviceContextSpecG.cpp index dbbddebb132f..0c69a907af79 100644 --- a/widget/gtk/nsDeviceContextSpecG.cpp +++ b/widget/gtk/nsDeviceContextSpecG.cpp @@ -269,7 +269,9 @@ gboolean nsDeviceContextSpecGTK::PrinterEnumerator(GtkPrinter *aPrinter, // misunderstanding what the capabilities of the printer are due to a // GTK bug (https://bugzilla.gnome.org/show_bug.cgi?id=753041). We // sidestep this by deferring the print to the next tick. - NS_DispatchToCurrentThread(NewRunnableMethod(spec, &nsDeviceContextSpecGTK::StartPrintJob)); + nsCOMPtr event = + NS_NewRunnableMethod(spec, &nsDeviceContextSpecGTK::StartPrintJob); + NS_DispatchToCurrentThread(event); return TRUE; } } @@ -327,7 +329,9 @@ NS_IMETHODIMP nsDeviceContextSpecGTK::EndDocument() } else { // We don't have a printer. We have to enumerate the printers and find // one with a matching name. - NS_DispatchToCurrentThread(NewRunnableMethod(this, &nsDeviceContextSpecGTK::EnumeratePrinters)); + nsCOMPtr event = + NS_NewRunnableMethod(this, &nsDeviceContextSpecGTK::EnumeratePrinters); + NS_DispatchToCurrentThread(event); } } else { // Handle print-to-file ourselves for the benefit of embedders diff --git a/widget/gtk/nsWindow.cpp b/widget/gtk/nsWindow.cpp index 5e87cee87e09..9b0c062f2db2 100644 --- a/widget/gtk/nsWindow.cpp +++ b/widget/gtk/nsWindow.cpp @@ -2484,7 +2484,9 @@ nsWindow::OnSizeAllocate(GtkAllocation *aAllocation) // GtkWindow callers of gtk_widget_size_allocate expect the signal // handlers to return sometime in the near future. mNeedsDispatchResized = true; - NS_DispatchToCurrentThread(NewRunnableMethod(this, &nsWindow::MaybeDispatchResized)); + nsCOMPtr r = + NS_NewRunnableMethod(this, &nsWindow::MaybeDispatchResized); + NS_DispatchToCurrentThread(r.forget()); } void diff --git a/widget/nsBaseWidget.cpp b/widget/nsBaseWidget.cpp index 18e3543fcea7..dcb041f3444a 100644 --- a/widget/nsBaseWidget.cpp +++ b/widget/nsBaseWidget.cpp @@ -966,11 +966,10 @@ void nsBaseWidget::ConfigureAPZCTreeManager() bool aPreventDefault) { MOZ_ASSERT(NS_IsMainThread()); - APZThreadUtils::RunOnControllerThread(NewRunnableMethod - (treeManager, - &APZCTreeManager::ContentReceivedInputBlock, - aInputBlockId, - aPreventDefault)); + RefPtr runnable = + NS_NewRunnableMethodWithArgs(treeManager, &APZCTreeManager::ContentReceivedInputBlock, + aInputBlockId, aPreventDefault); + APZThreadUtils::RunOnControllerThread(runnable.forget()); }); mAPZEventState = new APZEventState(this, mozilla::Move(callback)); @@ -978,11 +977,12 @@ void nsBaseWidget::ConfigureAPZCTreeManager() const nsTArray& aFlags) { MOZ_ASSERT(NS_IsMainThread()); - APZThreadUtils::RunOnControllerThread(NewRunnableMethod - >>(treeManager, - &APZCTreeManager::SetAllowedTouchBehavior, - aInputBlockId, aFlags)); + RefPtr runnable = + NS_NewRunnableMethodWithArgs>>(treeManager, + &APZCTreeManager::SetAllowedTouchBehavior, + aInputBlockId, aFlags); + APZThreadUtils::RunOnControllerThread(runnable.forget()); }; mRootContentController = CreateRootContentController(); @@ -1013,10 +1013,12 @@ nsBaseWidget::SetConfirmedTargetAPZC(uint64_t aInputBlockId, // Need to specifically bind this since it's overloaded. void (APZCTreeManager::*setTargetApzcFunc)(uint64_t, const nsTArray&) = &APZCTreeManager::SetTargetAPZC; - APZThreadUtils::RunOnControllerThread(NewRunnableMethod - >>(mAPZC, - setTargetApzcFunc, - aInputBlockId, aTargets)); + RefPtr runnable = + NS_NewRunnableMethodWithArgs>>(mAPZC, + setTargetApzcFunc, + aInputBlockId, aTargets); + APZThreadUtils::RunOnControllerThread(runnable.forget()); } void @@ -1934,10 +1936,11 @@ nsBaseWidget::StartAsyncScrollbarDrag(const AsyncDragMetrics& aDragMetrics) int layersId = mCompositorBridgeParent->RootLayerTreeId();; ScrollableLayerGuid guid(layersId, aDragMetrics.mPresShellId, aDragMetrics.mViewId); - APZThreadUtils::RunOnControllerThread(NewRunnableMethod - (mAPZC, - &APZCTreeManager::StartScrollbarDrag, - guid, aDragMetrics)); + RefPtr runnable = + NS_NewRunnableMethodWithArgs(mAPZC, &APZCTreeManager::StartScrollbarDrag, + guid, aDragMetrics); + APZThreadUtils::RunOnControllerThread(runnable.forget()); } already_AddRefed diff --git a/widget/nsScreenManagerProxy.cpp b/widget/nsScreenManagerProxy.cpp index a4448b25667e..18661451b40d 100644 --- a/widget/nsScreenManagerProxy.cpp +++ b/widget/nsScreenManagerProxy.cpp @@ -199,7 +199,9 @@ nsScreenManagerProxy::InvalidateCacheOnNextTick() mCacheWillInvalidate = true; - nsContentUtils::RunInStableState(NewRunnableMethod(this, &nsScreenManagerProxy::InvalidateCache)); + nsCOMPtr r = + NS_NewRunnableMethod(this, &nsScreenManagerProxy::InvalidateCache); + nsContentUtils::RunInStableState(r.forget()); } void diff --git a/widget/qt/nsWindow.h b/widget/qt/nsWindow.h index 53a7b20ff5e9..3943018b28b2 100644 --- a/widget/qt/nsWindow.h +++ b/widget/qt/nsWindow.h @@ -312,7 +312,7 @@ private: void DispatchMotionToMainThread() { if (!mTimerStarted) { nsCOMPtr event = - mozilla::NewRunnableMethod(this, &nsWindow::ProcessMotionEvent); + NS_NewRunnableMethod(this, &nsWindow::ProcessMotionEvent); NS_DispatchToMainThread(event); mTimerStarted = true; } diff --git a/widget/windows/AudioSession.cpp b/widget/windows/AudioSession.cpp index f0288da3fe7e..f75cfa49e01f 100644 --- a/widget/windows/AudioSession.cpp +++ b/widget/windows/AudioSession.cpp @@ -409,7 +409,7 @@ AudioSession::OnSessionDisconnected(AudioSessionDisconnectReason aReason) // Run our code asynchronously. Per MSDN we can't do anything interesting // in this callback. nsCOMPtr runnable = - NewRunnableMethod(this, &AudioSession::OnSessionDisconnectedInternal); + NS_NewRunnableMethod(this, &AudioSession::OnSessionDisconnectedInternal); NS_DispatchToMainThread(runnable); return S_OK; } diff --git a/widget/windows/LSPAnnotator.cpp b/widget/windows/LSPAnnotator.cpp index de4a40d2ac83..bbe55563e5a0 100644 --- a/widget/windows/LSPAnnotator.cpp +++ b/widget/windows/LSPAnnotator.cpp @@ -145,7 +145,7 @@ LSPAnnotationGatherer::Run() } mString = str; - NS_DispatchToMainThread(NewRunnableMethod(this, &LSPAnnotationGatherer::Annotate)); + NS_DispatchToMainThread(NS_NewRunnableMethod(this, &LSPAnnotationGatherer::Annotate)); return NS_OK; } diff --git a/widget/windows/nsWindow.cpp b/widget/windows/nsWindow.cpp index 332dc07a2195..df291ec92bfd 100644 --- a/widget/windows/nsWindow.cpp +++ b/widget/windows/nsWindow.cpp @@ -4988,7 +4988,9 @@ nsWindow::ProcessMessage(UINT msg, WPARAM& wParam, LPARAM& lParam, if (wParam == TRUE && !gfxEnv::DisableForcePresent() && gfxWindowsPlatform::GetPlatform()->DwmCompositionEnabled()) { - NS_DispatchToMainThread(NewRunnableMethod(this, &nsWindow::ForcePresent)); + nsCOMPtr event = + NS_NewRunnableMethod(this, &nsWindow::ForcePresent); + NS_DispatchToMainThread(event); } // let the dwm handle nc painting on glass diff --git a/widget/windows/nsWindowGfx.cpp b/widget/windows/nsWindowGfx.cpp index 07621f1a9e82..e226ff1857a2 100644 --- a/widget/windows/nsWindowGfx.cpp +++ b/widget/windows/nsWindowGfx.cpp @@ -391,7 +391,7 @@ bool nsWindow::OnPaint(HDC aDC, uint32_t aNestingLevel) this, LayoutDeviceIntRegion::FromUnknownRegion(region)); if (!gfxEnv::DisableForcePresent() && gfxWindowsPlatform::GetPlatform()->DwmCompositionEnabled()) { nsCOMPtr event = - NewRunnableMethod(this, &nsWindow::ForcePresent); + NS_NewRunnableMethod(this, &nsWindow::ForcePresent); NS_DispatchToMainThread(event); } } diff --git a/xpcom/base/nsDumpUtils.cpp b/xpcom/base/nsDumpUtils.cpp index 33dceb47c66a..d2c33d5ccdb3 100644 --- a/xpcom/base/nsDumpUtils.cpp +++ b/xpcom/base/nsDumpUtils.cpp @@ -74,7 +74,8 @@ FdWatcher::Init() nsCOMPtr os = services::GetObserverService(); os->AddObserver(this, "xpcom-shutdown", /* ownsWeak = */ false); - XRE_GetIOMessageLoop()->PostTask(NewRunnableMethod(this, &FdWatcher::StartWatching)); + RefPtr runnable = NS_NewRunnableMethod(this, &FdWatcher::StartWatching); + XRE_GetIOMessageLoop()->PostTask(runnable.forget()); } // Implementations may call this function multiple times if they ensure that diff --git a/xpcom/base/nsDumpUtils.h b/xpcom/base/nsDumpUtils.h index 12a99da18dc9..1d9c8cfb90f2 100644 --- a/xpcom/base/nsDumpUtils.h +++ b/xpcom/base/nsDumpUtils.h @@ -89,7 +89,9 @@ public: MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(!strcmp(aTopic, "xpcom-shutdown")); - XRE_GetIOMessageLoop()->PostTask(mozilla::NewRunnableMethod(this, &FdWatcher::StopWatching)); + RefPtr runnable = + NS_NewRunnableMethod(this, &FdWatcher::StopWatching); + XRE_GetIOMessageLoop()->PostTask(runnable.forget()); return NS_OK; } diff --git a/xpcom/base/nsMemoryReporterManager.cpp b/xpcom/base/nsMemoryReporterManager.cpp index 054060cd2ecd..7c319e667678 100644 --- a/xpcom/base/nsMemoryReporterManager.cpp +++ b/xpcom/base/nsMemoryReporterManager.cpp @@ -1693,9 +1693,8 @@ nsMemoryReporterManager::GetReportsExtended( aDMDDumpIdent); if (aMinimize) { - nsCOMPtr callback = - NewRunnableMethod(this, &nsMemoryReporterManager::StartGettingReports); - rv = MinimizeMemoryUsage(callback); + rv = MinimizeMemoryUsage(NS_NewRunnableMethod( + this, &nsMemoryReporterManager::StartGettingReports)); } else { rv = StartGettingReports(); } diff --git a/xpcom/ds/nsObserverService.cpp b/xpcom/ds/nsObserverService.cpp index 7e17ca5f4f05..e40aa27fbfbf 100644 --- a/xpcom/ds/nsObserverService.cpp +++ b/xpcom/ds/nsObserverService.cpp @@ -200,7 +200,9 @@ nsObserverService::Create(nsISupports* aOuter, const nsIID& aIID, // The memory reporter can not be immediately registered here because // the nsMemoryReporterManager may attempt to get the nsObserverService // during initialization, causing a recursive GetService. - NS_DispatchToCurrentThread(NewRunnableMethod(os, &nsObserverService::RegisterReporter)); + RefPtr> registerRunnable = + NS_NewRunnableMethod(os, &nsObserverService::RegisterReporter); + NS_DispatchToCurrentThread(registerRunnable); return os->QueryInterface(aIID, aInstancePtr); } diff --git a/xpcom/glue/nsThreadUtils.h b/xpcom/glue/nsThreadUtils.h index 0cf96b621913..c5b1cbf0773c 100644 --- a/xpcom/glue/nsThreadUtils.h +++ b/xpcom/glue/nsThreadUtils.h @@ -753,91 +753,99 @@ public: // Use this template function like so: // // nsCOMPtr event = -// mozilla::NewRunnableMethod(myObject, &MyClass::HandleEvent); +// NS_NewRunnableMethod(myObject, &MyClass::HandleEvent); // NS_DispatchToCurrentThread(event); // // Statically enforced constraints: // - myObject must be of (or implicitly convertible to) type MyClass // - MyClass must defined AddRef and Release methods // - -namespace mozilla { - template -already_AddRefed::base_type> -NewRunnableMethod(PtrType aPtr, Method aMethod) +typename nsRunnableMethodTraits::base_type* +NS_NewRunnableMethod(PtrType aPtr, Method aMethod) { - return do_AddRef(new nsRunnableMethodImpl(aPtr, aMethod)); + return new nsRunnableMethodImpl(aPtr, aMethod); } template -already_AddRefed::base_type> -NewCancelableRunnableMethod(PtrType aPtr, Method aMethod) +typename nsRunnableMethodTraits::base_type* +NS_NewCancelableRunnableMethod(PtrType aPtr, Method aMethod) { - return do_AddRef(new nsRunnableMethodImpl(aPtr, aMethod)); + return new nsRunnableMethodImpl(aPtr, aMethod); } template -already_AddRefed::base_type> -NewNonOwningRunnableMethod(PtrType&& aPtr, Method aMethod) +typename nsRunnableMethodTraits::base_type* +NS_NewNonOwningRunnableMethod(PtrType&& aPtr, Method aMethod) { - return do_AddRef(new nsRunnableMethodImpl(aPtr, aMethod)); + return new nsRunnableMethodImpl(aPtr, aMethod); } template -already_AddRefed::base_type> -NewNonOwningCancelableRunnableMethod(PtrType&& aPtr, Method aMethod) +typename nsRunnableMethodTraits::base_type* +NS_NewNonOwningCancelableRunnableMethod(PtrType&& aPtr, Method aMethod) { - return do_AddRef(new nsRunnableMethodImpl(aPtr, aMethod)); + return new nsRunnableMethodImpl(aPtr, aMethod); } -// Similar to NewRunnableMethod. Call like so: +// Similar to NS_NewRunnableMethod. Call like so: // nsCOMPtr event = -// NewRunnableMethod(myObject, &MyClass::HandleEvent, myArg1,...); +// NS_NewRunnableMethodWithArg(myObject, &MyClass::HandleEvent, myArg); +// 'Type' is the stored type for the argument, see ParameterStorage for details. +template +typename nsRunnableMethodTraits::base_type* +NS_NewRunnableMethodWithArg(PtrType&& aPtr, Method aMethod, Arg&& aArg) +{ + return new nsRunnableMethodImpl( + aPtr, aMethod, mozilla::Forward(aArg)); +} + +// Similar to NS_NewRunnableMethod. Call like so: +// nsCOMPtr event = +// NS_NewRunnableMethodWithArg(myObject, &MyClass::HandleEvent, myArg1,...); // 'Types' are the stored type for each argument, see ParameterStorage for details. template -already_AddRefed::base_type> -NewRunnableMethod(PtrType&& aPtr, Method aMethod, Args&&... aArgs) +typename nsRunnableMethodTraits::base_type* +NS_NewRunnableMethodWithArgs(PtrType&& aPtr, Method aMethod, Args&&... aArgs) { static_assert(sizeof...(Storages) == sizeof...(Args), " size should be equal to number of arguments"); - return do_AddRef(new nsRunnableMethodImpl( - aPtr, aMethod, mozilla::Forward(aArgs)...)); + return new nsRunnableMethodImpl( + aPtr, aMethod, mozilla::Forward(aArgs)...); } template -already_AddRefed::base_type> -NewNonOwningRunnableMethod(PtrType&& aPtr, Method aMethod, Args&&... aArgs) +typename nsRunnableMethodTraits::base_type* +NS_NewNonOwningRunnableMethodWithArgs(PtrType&& aPtr, Method aMethod, + Args&&... aArgs) { static_assert(sizeof...(Storages) == sizeof...(Args), " size should be equal to number of arguments"); - return do_AddRef(new nsRunnableMethodImpl( - aPtr, aMethod, mozilla::Forward(aArgs)...)); + return new nsRunnableMethodImpl( + aPtr, aMethod, mozilla::Forward(aArgs)...); } template -already_AddRefed::base_type> -NewCancelableRunnableMethod(PtrType&& aPtr, Method aMethod, Args&&... aArgs) +typename nsRunnableMethodTraits::base_type* +NS_NewCancelableRunnableMethodWithArgs(PtrType&& aPtr, Method aMethod, Args&&... aArgs) { static_assert(sizeof...(Storages) == sizeof...(Args), " size should be equal to number of arguments"); - return do_AddRef(new nsRunnableMethodImpl( - aPtr, aMethod, mozilla::Forward(aArgs)...)); + return new nsRunnableMethodImpl( + aPtr, aMethod, mozilla::Forward(aArgs)...); } template -already_AddRefed::base_type> -NewNonOwningCancelableRunnableMethod(PtrType&& aPtr, Method aMethod, +typename nsRunnableMethodTraits::base_type* +NS_NewNonOwningCancelableRunnableMethodWithArgs(PtrType&& aPtr, Method aMethod, Args&&... aArgs) { static_assert(sizeof...(Storages) == sizeof...(Args), " size should be equal to number of arguments"); - return do_AddRef(new nsRunnableMethodImpl( - aPtr, aMethod, mozilla::Forward(aArgs)...)); + return new nsRunnableMethodImpl( + aPtr, aMethod, mozilla::Forward(aArgs)...); } -} // namespace mozilla - #endif // XPCOM_GLUE_AVOID_NSPR // This class is designed to be used when you have an event class E that has a @@ -901,16 +909,6 @@ public: return *this; } - const nsRevocableEventPtr& operator=(already_AddRefed aEvent) - { - RefPtr event = aEvent; - if (mEvent != event) { - Revoke(); - mEvent = event.forget(); - } - return *this; - } - void Revoke() { if (mEvent) { diff --git a/xpcom/glue/tests/gtest/TestThreadUtils.cpp b/xpcom/glue/tests/gtest/TestThreadUtils.cpp index 728bae612a5c..ac4b9ef0d831 100644 --- a/xpcom/glue/tests/gtest/TestThreadUtils.cpp +++ b/xpcom/glue/tests/gtest/TestThreadUtils.cpp @@ -290,18 +290,18 @@ TEST(ThreadUtils, main) // Test legacy functions. nsCOMPtr r1 = - NewRunnableMethod(rpt, &ThreadUtilsObject::Test0); + NS_NewRunnableMethod(rpt, &ThreadUtilsObject::Test0); r1->Run(); EXPECT_EQ(count += 1, rpt->mCount); - r1 = NewRunnableMethod(rpt, &ThreadUtilsObject::Test1i, 11); + r1 = NS_NewRunnableMethodWithArg(rpt, &ThreadUtilsObject::Test1i, 11); r1->Run(); EXPECT_EQ(count += 2, rpt->mCount); EXPECT_EQ(11, rpt->mA0); // Test variadic function with simple POD arguments. - r1 = NewRunnableMethod(rpt, &ThreadUtilsObject::Test0); + r1 = NS_NewRunnableMethodWithArgs(rpt, &ThreadUtilsObject::Test0); r1->Run(); EXPECT_EQ(count += 1, rpt->mCount); @@ -314,19 +314,19 @@ TEST(ThreadUtils, main) StoreCopyPassByValue>::value, "detail::ParameterStorage>::Type should be StoreCopyPassByValue"); - r1 = NewRunnableMethod(rpt, &ThreadUtilsObject::Test1i, 12); + r1 = NS_NewRunnableMethodWithArgs(rpt, &ThreadUtilsObject::Test1i, 12); r1->Run(); EXPECT_EQ(count += 2, rpt->mCount); EXPECT_EQ(12, rpt->mA0); - r1 = NewRunnableMethod( + r1 = NS_NewRunnableMethodWithArgs( rpt, &ThreadUtilsObject::Test2i, 21, 22); r1->Run(); EXPECT_EQ(count += 3, rpt->mCount); EXPECT_EQ(21, rpt->mA0); EXPECT_EQ(22, rpt->mA1); - r1 = NewRunnableMethod( + r1 = NS_NewRunnableMethodWithArgs( rpt, &ThreadUtilsObject::Test3i, 31, 32, 33); r1->Run(); EXPECT_EQ(count += 4, rpt->mCount); @@ -334,7 +334,7 @@ TEST(ThreadUtils, main) EXPECT_EQ(32, rpt->mA1); EXPECT_EQ(33, rpt->mA2); - r1 = NewRunnableMethod( + r1 = NS_NewRunnableMethodWithArgs( rpt, &ThreadUtilsObject::Test4i, 41, 42, 43, 44); r1->Run(); EXPECT_EQ(count += 5, rpt->mCount); @@ -347,7 +347,7 @@ TEST(ThreadUtils, main) // Passing a short to make sure forwarding works with an inexact type match. short int si = 11; - r1 = NewRunnableMethod(rpt, &ThreadUtilsObject::Test1i, si); + r1 = NS_NewRunnableMethodWithArgs(rpt, &ThreadUtilsObject::Test1i, si); r1->Run(); EXPECT_EQ(count += 2, rpt->mCount); EXPECT_EQ(si, rpt->mA0); @@ -373,7 +373,7 @@ TEST(ThreadUtils, main) "detail::ParameterStorage::Type::passed_type should be int*"); { int i = 12; - r1 = NewRunnableMethod(rpt, &ThreadUtilsObject::Test1pi, &i); + r1 = NS_NewRunnableMethodWithArgs(rpt, &ThreadUtilsObject::Test1pi, &i); r1->Run(); EXPECT_EQ(count += 2, rpt->mCount); EXPECT_EQ(i, rpt->mA0); @@ -400,7 +400,7 @@ TEST(ThreadUtils, main) "detail::ParameterStorage::Type::passed_type should be const int*"); { int i = 1201; - r1 = NewRunnableMethod(rpt, &ThreadUtilsObject::Test1pci, &i); + r1 = NS_NewRunnableMethodWithArgs(rpt, &ThreadUtilsObject::Test1pci, &i); r1->Run(); EXPECT_EQ(count += 2, rpt->mCount); EXPECT_EQ(i, rpt->mA0); @@ -415,7 +415,7 @@ TEST(ThreadUtils, main) "StoreCopyPassByPtr::passed_type should be int*"); { int i = 1202; - r1 = NewRunnableMethod>( + r1 = NS_NewRunnableMethodWithArgs>( rpt, &ThreadUtilsObject::Test1pi, i); r1->Run(); EXPECT_EQ(count += 2, rpt->mCount); @@ -431,7 +431,7 @@ TEST(ThreadUtils, main) "StoreCopyPassByConstPtr::passed_type should be const int*"); { int i = 1203; - r1 = NewRunnableMethod>( + r1 = NS_NewRunnableMethodWithArgs>( rpt, &ThreadUtilsObject::Test1pci, i); r1->Run(); EXPECT_EQ(count += 2, rpt->mCount); @@ -491,7 +491,7 @@ TEST(ThreadUtils, main) "ParameterStorage::Type::passed_type should be int&"); { int i = 13; - r1 = NewRunnableMethod(rpt, &ThreadUtilsObject::Test1ri, i); + r1 = NS_NewRunnableMethodWithArgs(rpt, &ThreadUtilsObject::Test1ri, i); r1->Run(); EXPECT_EQ(count += 2, rpt->mCount); EXPECT_EQ(i, rpt->mA0); @@ -512,7 +512,7 @@ TEST(ThreadUtils, main) "ParameterStorage::Type::passed_type should be int&&"); { int i = 14; - r1 = NewRunnableMethod( + r1 = NS_NewRunnableMethodWithArgs( rpt, &ThreadUtilsObject::Test1rri, mozilla::Move(i)); } r1->Run(); @@ -534,7 +534,7 @@ TEST(ThreadUtils, main) "ParameterStorage&&>::Type::passed_type should be UniquePtr&&"); { mozilla::UniquePtr upi; - r1 = NewRunnableMethod&&>( + r1 = NS_NewRunnableMethodWithArgs&&>( rpt, &ThreadUtilsObject::Test1upi, mozilla::Move(upi)); } r1->Run(); @@ -557,7 +557,7 @@ TEST(ThreadUtils, main) "ParameterStorage>>::Type::passed_type should be UniquePtr&&"); { mozilla::UniquePtr upi; - r1 = NewRunnableMethod + r1 = NS_NewRunnableMethodWithArgs >>( rpt, &ThreadUtilsObject::Test1upi, mozilla::Move(upi)); } @@ -568,7 +568,7 @@ TEST(ThreadUtils, main) // Unique pointer as xvalue. { mozilla::UniquePtr upi = mozilla::MakeUnique(1); - r1 = NewRunnableMethod&&>( + r1 = NS_NewRunnableMethodWithArgs&&>( rpt, &ThreadUtilsObject::Test1upi, mozilla::Move(upi)); } r1->Run(); @@ -577,7 +577,7 @@ TEST(ThreadUtils, main) { mozilla::UniquePtr upi = mozilla::MakeUnique(1); - r1 = NewRunnableMethod + r1 = NS_NewRunnableMethodWithArgs >> (rpt, &ThreadUtilsObject::Test1upi, mozilla::Move(upi)); } @@ -586,7 +586,7 @@ TEST(ThreadUtils, main) EXPECT_EQ(1, rpt->mA0); // Unique pointer as prvalue. - r1 = NewRunnableMethod&&>( + r1 = NS_NewRunnableMethodWithArgs&&>( rpt, &ThreadUtilsObject::Test1upi, mozilla::MakeUnique(2)); r1->Run(); EXPECT_EQ(count += 2, rpt->mCount); @@ -595,7 +595,7 @@ TEST(ThreadUtils, main) // Unique pointer as lvalue to lref. { mozilla::UniquePtr upi; - r1 = NewRunnableMethod&>( + r1 = NS_NewRunnableMethodWithArgs&>( rpt, &ThreadUtilsObject::Test1rupi, upi); // Passed as lref, so Run() must be called while local upi is still alive! r1->Run(); @@ -614,8 +614,8 @@ TEST(ThreadUtils, main) Spy s(10); EXPECT_EQ(1, gConstructions); EXPECT_EQ(1, gAlive); - if (gDebug) { printf("%d - r2 = NewRunnableMethod>(&TestByValue, s)\n", __LINE__); } - r2 = NewRunnableMethod>( + if (gDebug) { printf("%d - r2 = NS_NewRunnableMethodWithArgs>(&TestByValue, s)\n", __LINE__); } + r2 = NS_NewRunnableMethodWithArgs>( rpt, &ThreadUtilsObject::TestByValue, s); EXPECT_EQ(2, gAlive); EXPECT_LE(1, gCopyConstructions); // At least 1 copy-construction. @@ -641,9 +641,9 @@ TEST(ThreadUtils, main) Spy::ClearAll(); if (gDebug) { printf("%d - Test: Store copy from prvalue, pass by value\n", __LINE__); } { - if (gDebug) { printf("%d - r3 = NewRunnableMethod>(&TestByValue, Spy(11))\n", __LINE__); } + if (gDebug) { printf("%d - r3 = NS_NewRunnableMethodWithArgs>(&TestByValue, Spy(11))\n", __LINE__); } nsCOMPtr r3 = - NewRunnableMethod>( + NS_NewRunnableMethodWithArgs>( rpt, &ThreadUtilsObject::TestByValue, Spy(11)); EXPECT_EQ(1, gAlive); EXPECT_EQ(1, gConstructions); @@ -670,7 +670,7 @@ TEST(ThreadUtils, main) EXPECT_EQ(1, gConstructions); EXPECT_EQ(1, gAlive); Spy::ClearActions(); - r4 = NewRunnableMethod>( + r4 = NS_NewRunnableMethodWithArgs>( rpt, &ThreadUtilsObject::TestByValue, mozilla::Move(s)); EXPECT_LE(1, gMoveConstructions); EXPECT_EQ(1, gAlive); @@ -701,8 +701,8 @@ TEST(ThreadUtils, main) Spy s(20); EXPECT_EQ(1, gConstructions); EXPECT_EQ(1, gAlive); - if (gDebug) { printf("%d - r5 = NewRunnableMethod>(&TestByConstLRef, s)\n", __LINE__); } - r5 = NewRunnableMethod>( + if (gDebug) { printf("%d - r5 = NS_NewRunnableMethodWithArgs>(&TestByConstLRef, s)\n", __LINE__); } + r5 = NS_NewRunnableMethodWithArgs>( rpt, &ThreadUtilsObject::TestByConstLRef, s); EXPECT_EQ(2, gAlive); EXPECT_LE(1, gCopyConstructions); // At least 1 copy-construction. @@ -728,9 +728,9 @@ TEST(ThreadUtils, main) Spy::ClearAll(); if (gDebug) { printf("%d - Test: Store copy from prvalue, pass by const lvalue ref\n", __LINE__); } { - if (gDebug) { printf("%d - r6 = NewRunnableMethod>(&TestByConstLRef, Spy(21))\n", __LINE__); } + if (gDebug) { printf("%d - r6 = NS_NewRunnableMethodWithArgs>(&TestByConstLRef, Spy(21))\n", __LINE__); } nsCOMPtr r6 = - NewRunnableMethod>( + NS_NewRunnableMethodWithArgs>( rpt, &ThreadUtilsObject::TestByConstLRef, Spy(21)); EXPECT_EQ(1, gAlive); EXPECT_EQ(1, gConstructions); @@ -758,8 +758,8 @@ TEST(ThreadUtils, main) Spy s(30); EXPECT_EQ(1, gConstructions); EXPECT_EQ(1, gAlive); - if (gDebug) { printf("%d - r7 = NewRunnableMethod>(&TestByRRef, s)\n", __LINE__); } - r7 = NewRunnableMethod>( + if (gDebug) { printf("%d - r7 = NS_NewRunnableMethodWithArgs>(&TestByRRef, s)\n", __LINE__); } + r7 = NS_NewRunnableMethodWithArgs>( rpt, &ThreadUtilsObject::TestByRRef, s); EXPECT_EQ(2, gAlive); EXPECT_LE(1, gCopyConstructions); // At least 1 copy-construction. @@ -786,9 +786,9 @@ TEST(ThreadUtils, main) Spy::ClearAll(); if (gDebug) { printf("%d - Test: Store copy from prvalue, pass by rvalue ref\n", __LINE__); } { - if (gDebug) { printf("%d - r8 = NewRunnableMethod>(&TestByRRef, Spy(31))\n", __LINE__); } + if (gDebug) { printf("%d - r8 = NS_NewRunnableMethodWithArgs>(&TestByRRef, Spy(31))\n", __LINE__); } nsCOMPtr r8 = - NewRunnableMethod>( + NS_NewRunnableMethodWithArgs>( rpt, &ThreadUtilsObject::TestByRRef, Spy(31)); EXPECT_EQ(1, gAlive); EXPECT_EQ(1, gConstructions); @@ -816,9 +816,9 @@ TEST(ThreadUtils, main) EXPECT_EQ(1, gConstructions); EXPECT_EQ(1, gAlive); Spy::ClearActions(); - if (gDebug) { printf("%d - r9 = NewRunnableMethod(&TestByLRef, s)\n", __LINE__); } + if (gDebug) { printf("%d - r9 = NS_NewRunnableMethodWithArgs(&TestByLRef, s)\n", __LINE__); } nsCOMPtr r9 = - NewRunnableMethod( + NS_NewRunnableMethodWithArgs( rpt, &ThreadUtilsObject::TestByLRef, s); EXPECT_EQ(0, gAllConstructions); EXPECT_EQ(0, gDestructions); @@ -849,8 +849,8 @@ TEST(ThreadUtils, main) ptr = s.get(); EXPECT_EQ(1, gConstructions); EXPECT_EQ(1, gAlive); - if (gDebug) { printf("%d - r10 = NewRunnableMethod>(&TestByRRef, s.get())\n", __LINE__); } - r10 = NewRunnableMethod>( + if (gDebug) { printf("%d - r10 = NS_NewRunnableMethodWithArgs>(&TestByRRef, s.get())\n", __LINE__); } + r10 = NS_NewRunnableMethodWithArgs>( rpt, &ThreadUtilsObject::TestByPointer, s.get()); EXPECT_LE(0, gAllConstructions); EXPECT_EQ(1, gAlive); @@ -882,9 +882,9 @@ TEST(ThreadUtils, main) EXPECT_EQ(1, gConstructions); EXPECT_EQ(1, gAlive); Spy::ClearActions(); - if (gDebug) { printf("%d - r11 = NewRunnableMethod(&TestByPointer, s)\n", __LINE__); } + if (gDebug) { printf("%d - r11 = NS_NewRunnableMethodWithArgs(&TestByPointer, s)\n", __LINE__); } nsCOMPtr r11 = - NewRunnableMethod( + NS_NewRunnableMethodWithArgs( rpt, &ThreadUtilsObject::TestByPointer, &s); EXPECT_EQ(0, gAllConstructions); EXPECT_EQ(0, gDestructions); @@ -912,9 +912,9 @@ TEST(ThreadUtils, main) EXPECT_EQ(1, gConstructions); EXPECT_EQ(1, gAlive); Spy::ClearActions(); - if (gDebug) { printf("%d - r12 = NewRunnableMethod(&TestByPointer, s)\n", __LINE__); } + if (gDebug) { printf("%d - r12 = NS_NewRunnableMethodWithArgs(&TestByPointer, s)\n", __LINE__); } nsCOMPtr r12 = - NewRunnableMethod( + NS_NewRunnableMethodWithArgs( rpt, &ThreadUtilsObject::TestByPointerToConst, &s); EXPECT_EQ(0, gAllConstructions); EXPECT_EQ(0, gDestructions); diff --git a/xpcom/tests/TestThreadUtils.cpp b/xpcom/tests/TestThreadUtils.cpp index 521933827555..494aa4c3e980 100644 --- a/xpcom/tests/TestThreadUtils.cpp +++ b/xpcom/tests/TestThreadUtils.cpp @@ -5,8 +5,6 @@ #include "TestHarness.h" #include "nsThreadUtils.h" -using namespace mozilla; - enum { TEST_CALL_VOID_ARG_VOID_RETURN, TEST_CALL_VOID_ARG_VOID_RETURN_CONST, @@ -135,24 +133,24 @@ int main(int argc, char** argv) // Read only string. Dereferencing in runnable method to check this works. char* message = (char*)"Test message"; - NS_DispatchToMainThread(NewRunnableMethod(bar, &nsBar::DoBar1)); - NS_DispatchToMainThread(NewRunnableMethod(constBar, &nsBar::DoBar1Const)); - NS_DispatchToMainThread(NewRunnableMethod(bar, &nsBar::DoBar2)); - NS_DispatchToMainThread(NewRunnableMethod> + NS_DispatchToMainThread(NS_NewRunnableMethod(bar, &nsBar::DoBar1)); + NS_DispatchToMainThread(NS_NewRunnableMethod(constBar, &nsBar::DoBar1Const)); + NS_DispatchToMainThread(NS_NewRunnableMethod(bar, &nsBar::DoBar2)); + NS_DispatchToMainThread(NS_NewRunnableMethodWithArg< RefPtr > (bar, &nsBar::DoBar3, foo)); - NS_DispatchToMainThread(NewRunnableMethod> + NS_DispatchToMainThread(NS_NewRunnableMethodWithArg< RefPtr > (bar, &nsBar::DoBar4, foo)); - NS_DispatchToMainThread(NewRunnableMethod(bar, &nsBar::DoBar5, rawFoo)); - NS_DispatchToMainThread(NewRunnableMethod(bar, &nsBar::DoBar6, message)); + NS_DispatchToMainThread(NS_NewRunnableMethodWithArg(bar, &nsBar::DoBar5, rawFoo)); + NS_DispatchToMainThread(NS_NewRunnableMethodWithArg(bar, &nsBar::DoBar6, message)); #ifdef HAVE_STDCALL - NS_DispatchToMainThread(NewRunnableMethod(bar, &nsBar::DoBar1std)); - NS_DispatchToMainThread(NewRunnableMethod(bar, &nsBar::DoBar2std)); - NS_DispatchToMainThread(NewRunnableMethod> + NS_DispatchToMainThread(NS_NewRunnableMethod(bar, &nsBar::DoBar1std)); + NS_DispatchToMainThread(NS_NewRunnableMethod(bar, &nsBar::DoBar2std)); + NS_DispatchToMainThread(NS_NewRunnableMethodWithArg< RefPtr > (bar, &nsBar::DoBar3std, foo)); - NS_DispatchToMainThread(NewRunnableMethod> + NS_DispatchToMainThread(NS_NewRunnableMethodWithArg< RefPtr > (bar, &nsBar::DoBar4std, foo)); - NS_DispatchToMainThread(NewRunnableMethod(bar, &nsBar::DoBar5std, rawFoo)); - NS_DispatchToMainThread(NewRunnableMethod(bar, &nsBar::DoBar6std, message)); + NS_DispatchToMainThread(NS_NewRunnableMethodWithArg(bar, &nsBar::DoBar5std, rawFoo)); + NS_DispatchToMainThread(NS_NewRunnableMethodWithArg(bar, &nsBar::DoBar6std, message)); #endif } diff --git a/xpcom/threads/AbstractThread.cpp b/xpcom/threads/AbstractThread.cpp index 4a78a742f57c..1aa8b4bd4dc1 100644 --- a/xpcom/threads/AbstractThread.cpp +++ b/xpcom/threads/AbstractThread.cpp @@ -88,7 +88,7 @@ public: if (!mTailDispatcher.isSome()) { mTailDispatcher.emplace(/* aIsTailDispatcher = */ true); - nsCOMPtr event = NewRunnableMethod(this, &XPCOMThreadWrapper::FireTailDispatcher); + nsCOMPtr event = NS_NewRunnableMethod(this, &XPCOMThreadWrapper::FireTailDispatcher); nsContentUtils::RunInStableState(event.forget()); } diff --git a/xpcom/threads/LazyIdleThread.cpp b/xpcom/threads/LazyIdleThread.cpp index 535a48a8e4aa..43d8857aa190 100644 --- a/xpcom/threads/LazyIdleThread.cpp +++ b/xpcom/threads/LazyIdleThread.cpp @@ -163,7 +163,7 @@ LazyIdleThread::EnsureThread() } nsCOMPtr runnable = - NewRunnableMethod(this, &LazyIdleThread::InitThread); + NS_NewRunnableMethod(this, &LazyIdleThread::InitThread); if (NS_WARN_IF(!runnable)) { return NS_ERROR_UNEXPECTED; } @@ -291,7 +291,7 @@ LazyIdleThread::ShutdownThread() #endif nsCOMPtr runnable = - NewRunnableMethod(this, &LazyIdleThread::CleanupThread); + NS_NewRunnableMethod(this, &LazyIdleThread::CleanupThread); if (NS_WARN_IF(!runnable)) { return NS_ERROR_UNEXPECTED; } @@ -368,7 +368,7 @@ LazyIdleThread::Release() mRefCnt = 1; nsCOMPtr runnable = - NewNonOwningRunnableMethod(this, &LazyIdleThread::SelfDestruct); + NS_NewNonOwningRunnableMethod(this, &LazyIdleThread::SelfDestruct); NS_WARN_IF_FALSE(runnable, "Couldn't make runnable!"); if (NS_FAILED(NS_DispatchToCurrentThread(runnable))) { @@ -561,7 +561,7 @@ LazyIdleThread::AfterProcessNextEvent(nsIThreadInternal* /* aThread */, if (shouldNotifyIdle) { nsCOMPtr runnable = - NewRunnableMethod(this, &LazyIdleThread::ScheduleTimer); + NS_NewRunnableMethod(this, &LazyIdleThread::ScheduleTimer); if (NS_WARN_IF(!runnable)) { return NS_ERROR_UNEXPECTED; } diff --git a/xpcom/threads/SharedThreadPool.cpp b/xpcom/threads/SharedThreadPool.cpp index 004a352135a3..4944e6fc684c 100644 --- a/xpcom/threads/SharedThreadPool.cpp +++ b/xpcom/threads/SharedThreadPool.cpp @@ -141,9 +141,10 @@ NS_IMETHODIMP_(MozExternalRefCountType) SharedThreadPool::Release(void) MOZ_ASSERT(!sPools->Get(mName)); // Dispatch an event to the main thread to call Shutdown() on - // the nsIThreadPool. The Runnable here will add a refcount to the pool, + // the nsIThreadPool. The Runnable here will add a refcount to the pool, // and when the Runnable releases the nsIThreadPool it will be deleted. - NS_DispatchToMainThread(NewRunnableMethod(mPool, &nsIThreadPool::Shutdown)); + nsCOMPtr r = NS_NewRunnableMethod(mPool, &nsIThreadPool::Shutdown); + NS_DispatchToMainThread(r); // Stabilize refcount, so that if something in the dtor QIs, it won't explode. mRefCnt = 1; diff --git a/xpcom/threads/StateMirroring.h b/xpcom/threads/StateMirroring.h index d004b6983ad0..bcb65fea381d 100644 --- a/xpcom/threads/StateMirroring.h +++ b/xpcom/threads/StateMirroring.h @@ -152,9 +152,9 @@ private: { MIRROR_LOG("%s [%p] Disconnecting all mirrors", mName, this); for (size_t i = 0; i < mMirrors.Length(); ++i) { - mMirrors[i]->OwnerThread()->Dispatch(NewRunnableMethod(mMirrors[i], - &AbstractMirror::NotifyDisconnected), - AbstractThread::DontAssertDispatchSuccess); + nsCOMPtr r = + NS_NewRunnableMethod(mMirrors[i], &AbstractMirror::NotifyDisconnected); + mMirrors[i]->OwnerThread()->Dispatch(r.forget(), AbstractThread::DontAssertDispatchSuccess); } mMirrors.Clear(); } @@ -191,7 +191,8 @@ private: // we can avoid sending multiple updates, and possibly avoid sending any // updates at all if the value ends up where it started. if (!alreadyNotifying) { - AbstractThread::DispatchDirectTask(NewRunnableMethod(this, &Impl::DoNotify)); + nsCOMPtr r = NS_NewRunnableMethod(this, &Impl::DoNotify); + AbstractThread::DispatchDirectTask(r.forget()); } } @@ -222,7 +223,9 @@ private: already_AddRefed MakeNotifier(AbstractMirror* aMirror) { - return NewRunnableMethod(aMirror, &AbstractMirror::UpdateValue, mValue);; + nsCOMPtr r = + NS_NewRunnableMethodWithArg(aMirror, &AbstractMirror::UpdateValue, mValue); + return r.forget(); } T mValue; @@ -325,7 +328,7 @@ private: MOZ_ASSERT(!IsConnected()); MOZ_ASSERT(OwnerThread()->RequiresTailDispatch(aCanonical->OwnerThread()), "Can't get coherency without tail dispatch"); - nsCOMPtr r = NewRunnableMethod>> + nsCOMPtr r = NS_NewRunnableMethodWithArg>> (aCanonical, &AbstractCanonical::AddMirror, this); aCanonical->OwnerThread()->Dispatch(r.forget(), AbstractThread::DontAssertDispatchSuccess); mCanonical = aCanonical; @@ -340,7 +343,7 @@ private: } MIRROR_LOG("%s [%p] Disconnecting from %p", mName, this, mCanonical.get()); - nsCOMPtr r = NewRunnableMethod>> + nsCOMPtr r = NS_NewRunnableMethodWithArg>> (mCanonical, &AbstractCanonical::RemoveMirror, this); mCanonical->OwnerThread()->Dispatch(r.forget(), AbstractThread::DontAssertDispatchSuccess); mCanonical = nullptr; diff --git a/xpcom/threads/StateWatching.h b/xpcom/threads/StateWatching.h index a5543120b610..3ad8c2184051 100644 --- a/xpcom/threads/StateWatching.h +++ b/xpcom/threads/StateWatching.h @@ -255,7 +255,8 @@ private: mStrongRef = mOwner; // Hold the owner alive while notifying. // Queue up our notification jobs to run in a stable state. - mOwnerThread->TailDispatcher().AddDirectTask(NewRunnableMethod(this, &PerCallbackWatcher::DoNotify)); + nsCOMPtr r = NS_NewRunnableMethod(this, &PerCallbackWatcher::DoNotify); + mOwnerThread->TailDispatcher().AddDirectTask(r.forget()); } bool CallbackMethodIs(CallbackMethod aMethod) const diff --git a/xpcom/threads/nsProcessCommon.cpp b/xpcom/threads/nsProcessCommon.cpp index 9e714b40a794..efb5d4a138fd 100644 --- a/xpcom/threads/nsProcessCommon.cpp +++ b/xpcom/threads/nsProcessCommon.cpp @@ -301,7 +301,9 @@ nsProcess::Monitor(void* aArg) if (NS_IsMainThread()) { process->ProcessComplete(); } else { - NS_DispatchToMainThread(NewRunnableMethod(process, &nsProcess::ProcessComplete)); + nsCOMPtr event = + NS_NewRunnableMethod(process, &nsProcess::ProcessComplete); + NS_DispatchToMainThread(event); } } diff --git a/xpcom/threads/nsThreadPool.cpp b/xpcom/threads/nsThreadPool.cpp index 0b4ac6047aac..8be613d57823 100644 --- a/xpcom/threads/nsThreadPool.cpp +++ b/xpcom/threads/nsThreadPool.cpp @@ -146,8 +146,9 @@ nsThreadPool::ShutdownThread(nsIThread* aThread) // shutdown requires this thread have an event loop (and it may not, see bug // 10204784). The simplest way to cover all cases is to asynchronously // shutdown aThread from the main thread. - NS_DispatchToMainThread(NewRunnableMethod(aThread, - &nsIThread::AsyncShutdown)); + nsCOMPtr r = NS_NewRunnableMethod(aThread, + &nsIThread::AsyncShutdown); + NS_DispatchToMainThread(r); } NS_IMETHODIMP