mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 05:11:16 +00:00
Bug 924967 - Dispatch nsIRequest::Cancel to main thread in imgRequest::Cancel r=seth
This commit is contained in:
parent
134858c6de
commit
000699ecd8
@ -245,6 +245,28 @@ void imgRequest::CancelAndAbort(nsresult aStatus)
|
||||
}
|
||||
}
|
||||
|
||||
class imgRequestMainThreadCancel : public nsRunnable
|
||||
{
|
||||
public:
|
||||
imgRequestMainThreadCancel(imgRequest *aImgRequest, nsresult aStatus)
|
||||
: mImgRequest(aImgRequest)
|
||||
, mStatus(aStatus)
|
||||
{
|
||||
MOZ_ASSERT(!NS_IsMainThread(), "Create me off main thread only!");
|
||||
MOZ_ASSERT(aImgRequest);
|
||||
}
|
||||
|
||||
NS_IMETHOD Run()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread(), "I should be running on the main thread!");
|
||||
mImgRequest->ContinueCancel(mStatus);
|
||||
return NS_OK;
|
||||
}
|
||||
private:
|
||||
nsRefPtr<imgRequest> mImgRequest;
|
||||
nsresult mStatus;
|
||||
};
|
||||
|
||||
void imgRequest::Cancel(nsresult aStatus)
|
||||
{
|
||||
/* The Cancel() method here should only be called by this class. */
|
||||
@ -258,14 +280,22 @@ void imgRequest::Cancel(nsresult aStatus)
|
||||
statusTracker->RecordCancel();
|
||||
|
||||
if (NS_IsMainThread()) {
|
||||
RemoveFromCache();
|
||||
ContinueCancel(aStatus);
|
||||
} else {
|
||||
NS_DispatchToMainThread(
|
||||
NS_NewRunnableMethod(this, &imgRequest::RemoveFromCache));
|
||||
NS_DispatchToMainThread(new imgRequestMainThreadCancel(this, aStatus));
|
||||
}
|
||||
}
|
||||
|
||||
if (mRequest && statusTracker->IsLoading())
|
||||
mRequest->Cancel(aStatus);
|
||||
void imgRequest::ContinueCancel(nsresult aStatus)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
RemoveFromCache();
|
||||
|
||||
nsRefPtr<imgStatusTracker> statusTracker = GetStatusTracker();
|
||||
if (mRequest && statusTracker->IsLoading()) {
|
||||
mRequest->Cancel(aStatus);
|
||||
}
|
||||
}
|
||||
|
||||
nsresult imgRequest::GetURI(ImageURL **aURI)
|
||||
|
@ -72,6 +72,9 @@ public:
|
||||
// won't be sufficient.
|
||||
void CancelAndAbort(nsresult aStatus);
|
||||
|
||||
// Called or dispatched by cancel for main thread only execution.
|
||||
void ContinueCancel(nsresult aStatus);
|
||||
|
||||
// Methods that get forwarded to the Image, or deferred until it's
|
||||
// instantiated.
|
||||
nsresult LockImage();
|
||||
|
Loading…
Reference in New Issue
Block a user