Bug 1350787 - DocGroup labeling runnables in dom/xhr, r=baku, f=bevistseng

This patch is to label the runnables dispatched to main thread of the
content process.
The major changes in xhr are to replace DispatchTo{Current,Main}Thread and
replace NS_DispatchToCurrentThread with |mWorkerPrivate->DispatchToMainThread|
in which a DocGroup-specific EventTarget on main thread for worker.
This commit is contained in:
Shawn Huang 2017-05-09 16:14:51 +08:00
parent 517b0f8cbf
commit 001b63cc33
3 changed files with 23 additions and 7 deletions

View File

@ -2827,6 +2827,7 @@ XMLHttpRequestMainThread::Send(nsIVariant* aVariant)
void
XMLHttpRequestMainThread::UnsuppressEventHandlingAndResume()
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(mFlagSynchronous);
if (mSuspendedDoc) {
@ -2835,7 +2836,7 @@ XMLHttpRequestMainThread::UnsuppressEventHandlingAndResume()
}
if (mResumeTimeoutRunnable) {
NS_DispatchToCurrentThread(mResumeTimeoutRunnable);
DispatchToMainThread(mResumeTimeoutRunnable.forget());
mResumeTimeoutRunnable = nullptr;
}
}
@ -2843,6 +2844,8 @@ XMLHttpRequestMainThread::UnsuppressEventHandlingAndResume()
nsresult
XMLHttpRequestMainThread::SendInternal(const BodyExtractorBase* aBody)
{
MOZ_ASSERT(NS_IsMainThread());
NS_ENSURE_TRUE(mPrincipal, NS_ERROR_NOT_INITIALIZED);
// Step 1
@ -3026,11 +3029,9 @@ XMLHttpRequestMainThread::SendInternal(const BodyExtractorBase* aBody)
} else {
// Defer the actual sending of async events just in case listeners
// are attached after the send() method is called.
NS_DispatchToCurrentThread(
NewRunnableMethod<ProgressEventType>(this,
&XMLHttpRequestMainThread::CloseRequestWithError,
ProgressEventType::error));
return NS_OK;
return DispatchToMainThread(NewRunnableMethod<ProgressEventType>(this,
&XMLHttpRequestMainThread::CloseRequestWithError,
ProgressEventType::error));
}
}
@ -3127,6 +3128,19 @@ XMLHttpRequestMainThread::SetTimerEventTarget(nsITimer* aTimer)
}
}
nsresult
XMLHttpRequestMainThread::DispatchToMainThread(already_AddRefed<nsIRunnable> aRunnable)
{
if (nsCOMPtr<nsIGlobalObject> global = GetOwnerGlobal()) {
nsCOMPtr<nsIEventTarget> target = global->EventTargetFor(TaskCategory::Other);
MOZ_ASSERT(target);
return target->Dispatch(Move(aRunnable), NS_DISPATCH_NORMAL);
}
return NS_DispatchToMainThread(Move(aRunnable));
}
void
XMLHttpRequestMainThread::StartTimeoutTimer()
{

View File

@ -580,6 +580,8 @@ protected:
void SetTimerEventTarget(nsITimer* aTimer);
nsresult DispatchToMainThread(already_AddRefed<nsIRunnable> aRunnable);
already_AddRefed<nsXMLHttpRequestXPCOMifier> EnsureXPCOMifier();
nsCOMPtr<nsISupports> mContext;

View File

@ -460,7 +460,7 @@ public:
return false;
}
return NS_SUCCEEDED(NS_DispatchToCurrentThread(this));
return NS_SUCCEEDED(mWorkerPrivate->DispatchToMainThread(this));
}
private: