Bug 1318506 - Label some common runnables with a DocGroup (r?ehsan)
MozReview-Commit-ID: 19gyZRfbzXP
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -11898,17 +11898,17 @@ nsDocument::GetVisibilityState() const
return dom::VisibilityState::Visible;
}
/* virtual */ void
nsDocument::PostVisibilityUpdateEvent()
{
nsCOMPtr<nsIRunnable> event =
NewRunnableMethod(this, &nsDocument::UpdateVisibilityState);
- NS_DispatchToMainThread(event);
+ Dispatch("UpdateVisibility", TaskCategory::Other, event.forget());
}
void
nsDocument::MaybeActiveMediaComponents()
{
if (mEverInForeground) {
return;
}
--- a/dom/base/nsGlobalWindow.cpp
+++ b/dom/base/nsGlobalWindow.cpp
@@ -8591,17 +8591,17 @@ nsGlobalWindow::PostMessageMozOuter(JSCo
JS::Rooted<JS::Value> message(aCx, aMessage);
JS::Rooted<JS::Value> transfer(aCx, aTransfer);
event->Write(aCx, message, transfer, JS::CloneDataPolicy(), aError);
if (NS_WARN_IF(aError.Failed())) {
return;
}
- aError = NS_DispatchToCurrentThread(event);
+ aError = Dispatch("PostMessage", TaskCategory::Other, event.forget());
}
void
nsGlobalWindow::PostMessageMoz(JSContext* aCx, JS::Handle<JS::Value> aMessage,
const nsAString& aTargetOrigin,
JS::Handle<JS::Value> aTransfer,
nsIPrincipal& aSubjectPrincipal,
ErrorResult& aError)
--- a/dom/base/nsScriptLoader.cpp
+++ b/dom/base/nsScriptLoader.cpp
@@ -12,18 +12,19 @@
#include "prsystem.h"
#include "jsapi.h"
#include "jsfriendapi.h"
#include "xpcpublic.h"
#include "nsCycleCollectionParticipant.h"
#include "nsIContent.h"
#include "nsJSUtils.h"
+#include "mozilla/dom/DocGroup.h"
+#include "mozilla/dom/Element.h"
#include "mozilla/dom/ScriptSettings.h"
-#include "mozilla/dom/Element.h"
#include "mozilla/dom/SRILogHelper.h"
#include "nsGkAtoms.h"
#include "nsNetUtil.h"
#include "nsIScriptGlobalObject.h"
#include "nsIScriptContext.h"
#include "nsIScriptSecurityManager.h"
#include "nsIPrincipal.h"
#include "nsJSPrincipals.h"
@@ -1713,31 +1714,42 @@ nsScriptLoader::ProcessScriptElement(nsI
}
namespace {
class NotifyOffThreadScriptLoadCompletedRunnable : public Runnable
{
RefPtr<nsScriptLoadRequest> mRequest;
RefPtr<nsScriptLoader> mLoader;
+ RefPtr<DocGroup> mDocGroup;
void *mToken;
public:
NotifyOffThreadScriptLoadCompletedRunnable(nsScriptLoadRequest* aRequest,
nsScriptLoader* aLoader)
: mRequest(aRequest), mLoader(aLoader), mToken(nullptr)
- {}
+ {
+ MOZ_ASSERT(NS_IsMainThread());
+ nsCOMPtr<nsINode> scriptElem = do_QueryInterface(aRequest->mElement);
+ mDocGroup = scriptElem->OwnerDoc()->GetDocGroup();
+ }
virtual ~NotifyOffThreadScriptLoadCompletedRunnable();
void SetToken(void* aToken) {
MOZ_ASSERT(aToken && !mToken);
mToken = aToken;
}
+ static void Dispatch(already_AddRefed<NotifyOffThreadScriptLoadCompletedRunnable>&& aSelf) {
+ RefPtr<NotifyOffThreadScriptLoadCompletedRunnable> self = aSelf;
+ RefPtr<DocGroup> docGroup = self->mDocGroup;
+ docGroup->Dispatch("OffThreadScriptLoader", TaskCategory::Other, self.forget());
+ }
+
NS_DECL_NSIRUNNABLE
};
} /* anonymous namespace */
nsresult
nsScriptLoader::ProcessOffThreadRequest(nsScriptLoadRequest* aRequest)
{
@@ -1805,17 +1817,17 @@ NotifyOffThreadScriptLoadCompletedRunnab
}
static void
OffThreadScriptLoaderCallback(void *aToken, void *aCallbackData)
{
RefPtr<NotifyOffThreadScriptLoadCompletedRunnable> aRunnable =
dont_AddRef(static_cast<NotifyOffThreadScriptLoadCompletedRunnable*>(aCallbackData));
aRunnable->SetToken(aToken);
- NS_DispatchToMainThread(aRunnable);
+ NotifyOffThreadScriptLoadCompletedRunnable::Dispatch(aRunnable.forget());
}
nsresult
nsScriptLoader::AttemptAsyncScriptCompile(nsScriptLoadRequest* aRequest)
{
MOZ_ASSERT_IF(!aRequest->IsModuleRequest(), aRequest->IsReadyToRun());
MOZ_ASSERT(!aRequest->mWasCompiledOMT);
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -5145,17 +5145,19 @@ nsresult HTMLMediaElement::DispatchAsync
// Save events that occur while in the bfcache. These will be dispatched
// if the page comes out of the bfcache.
if (mEventDeliveryPaused) {
mPendingEvents.AppendElement(aName);
return NS_OK;
}
nsCOMPtr<nsIRunnable> event = new nsAsyncEventRunner(aName, this);
- NS_DispatchToMainThread(event);
+ OwnerDoc()->Dispatch("HTMLMediaElement::DispatchEvent",
+ TaskCategory::Other,
+ event.forget());
if ((aName.EqualsLiteral("play") || aName.EqualsLiteral("playing"))) {
mPlayTime.Start();
if (IsHidden()) {
HiddenVideoStart();
}
} else if (aName.EqualsLiteral("waiting")) {
mPlayTime.Pause();
--- a/dom/media/mediasource/SourceBuffer.cpp
+++ b/dom/media/mediasource/SourceBuffer.cpp
@@ -352,17 +352,19 @@ SourceBuffer::DispatchSimpleEvent(const
DispatchTrustedEvent(NS_ConvertUTF8toUTF16(aName));
}
void
SourceBuffer::QueueAsyncSimpleEvent(const char* aName)
{
MSE_DEBUG("Queuing event '%s'", aName);
nsCOMPtr<nsIRunnable> event = new AsyncEventRunner<SourceBuffer>(this, aName);
- NS_DispatchToMainThread(event, NS_DISPATCH_NORMAL);
+ GetOwnerGlobal()->Dispatch(aName,
+ TaskCategory::Other,
+ event.forget());
}
void
SourceBuffer::StartUpdating()
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(!mUpdating);
mUpdating = true;
--- a/parser/html/nsHtml5StreamParser.cpp
+++ b/parser/html/nsHtml5StreamParser.cpp
@@ -1314,17 +1314,20 @@ nsHtml5StreamParser::FlushTreeOpsAndDisa
// a mutex
mFlushTimer->Cancel();
mFlushTimerArmed = false;
}
if (mMode == VIEW_SOURCE_HTML || mMode == VIEW_SOURCE_XML) {
mTokenizer->FlushViewSource();
}
mTreeBuilder->Flush();
- if (NS_FAILED(NS_DispatchToMainThread(mExecutorFlusher))) {
+ nsCOMPtr<nsIRunnable> runnable(mExecutorFlusher);
+ if (NS_FAILED(mExecutor->GetDocument()->Dispatch("FlushTreeOpsAndDisarmTimer",
+ dom::TaskCategory::Other,
+ runnable.forget()))) {
NS_WARNING("failed to dispatch executor flush event");
}
}
void
nsHtml5StreamParser::ParseAvailableData()
{
NS_ASSERTION(IsParserThread(), "Wrong thread!");
--- a/parser/html/nsHtml5TreeOpExecutor.cpp
+++ b/parser/html/nsHtml5TreeOpExecutor.cpp
@@ -254,17 +254,19 @@ FlushTimerCallback(nsITimer* aTimer, voi
}
}
void
nsHtml5TreeOpExecutor::ContinueInterruptedParsingAsync()
{
if (!mDocument || !mDocument->IsInBackgroundWindow()) {
nsCOMPtr<nsIRunnable> flusher = new nsHtml5ExecutorReflusher(this);
- if (NS_FAILED(NS_DispatchToMainThread(flusher))) {
+ if (NS_FAILED(mDocument->Dispatch("ContinueInterruptedParsingAsync",
+ dom::TaskCategory::Other,
+ flusher.forget()))) {
NS_WARNING("failed to dispatch executor flush event");
}
} else {
if (!gBackgroundFlushList) {
gBackgroundFlushList = new mozilla::LinkedList<nsHtml5TreeOpExecutor>();
}
if (!isInList()) {
gBackgroundFlushList->insertBack(this);