Bug 1338446 Part 4 - Label StyleImageRequestCleanupTask. r=heycam

If nsStyleImageRequest::Resolve() has been called, we cache the DocGroup and
use it for dispatching events for the clean up task. Otherwise, it's safe to
do clean up task on non-main thread.

MozReview-Commit-ID: BXalEkc6dBm

--HG--
extra : rebase_source : ccc7c43a385f3149b53763030419561fc64efbfa
This commit is contained in:
Ting-Yu Lin 2017-03-14 21:29:55 +08:00
Родитель f087300185
Коммит dd4484225f
3 изменённых файлов: 26 добавлений и 6 удалений

Просмотреть файл

@ -3057,7 +3057,9 @@ css::ImageValue::Initialize(nsIDocument* aDocument)
css::ImageValue::~ImageValue()
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(NS_IsMainThread() || mRequests.Count() == 0,
"Destructor should run on main thread, or on non-main thread "
"when mRequest is empty!");
for (auto iter = mRequests.Iter(); !iter.Done(); iter.Next()) {
nsIDocument* doc = iter.Key();

Просмотреть файл

@ -33,6 +33,7 @@
#include "CounterStyleManager.h"
#include "mozilla/dom/AnimationEffectReadOnlyBinding.h" // for PlaybackDirection
#include "mozilla/dom/DocGroup.h"
#include "mozilla/dom/ImageTracker.h"
#include "mozilla/Likely.h"
#include "nsIURI.h"
@ -1890,7 +1891,7 @@ nsStyleGradient::HasCalc()
/**
* Runnable to release the nsStyleImageRequest's mRequestProxy,
* mImageValue and mImageValue on the main thread, and to perform
* mImageValue and mImageTracker on the main thread, and to perform
* any necessary unlocking and untracking of the image.
*/
class StyleImageRequestCleanupTask : public mozilla::Runnable
@ -1911,7 +1912,8 @@ public:
NS_IMETHOD Run() final
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(!mRequestProxy || NS_IsMainThread(),
"If mRequestProxy is non-null, we need to run on main thread!");
if (!mRequestProxy) {
return NS_OK;
@ -1932,7 +1934,15 @@ public:
}
protected:
virtual ~StyleImageRequestCleanupTask() { MOZ_ASSERT(NS_IsMainThread()); }
virtual ~StyleImageRequestCleanupTask()
{
MOZ_ASSERT(mImageValue->mRequests.Count() == 0 || NS_IsMainThread(),
"If mImageValue has any mRequests, we need to run on main "
"thread to release ImageValues!");
MOZ_ASSERT((!mRequestProxy && !mImageTracker) || NS_IsMainThread(),
"mRequestProxy and mImageTracker's destructor need to run "
"on the main thread!");
}
private:
Mode mModeFlags;
@ -1986,10 +1996,13 @@ nsStyleImageRequest::~nsStyleImageRequest()
mRequestProxy.forget(),
mImageValue.forget(),
mImageTracker.forget());
if (NS_IsMainThread()) {
if (NS_IsMainThread() || !IsResolved()) {
task->Run();
} else {
NS_DispatchToMainThread(task.forget());
MOZ_ASSERT(IsResolved() == bool(mDocGroup),
"We forgot to cache mDocGroup in Resolve()?");
mDocGroup->Dispatch("StyleImageRequestCleanupTask",
TaskCategory::Other, task.forget());
}
}
@ -2003,8 +2016,10 @@ nsStyleImageRequest::Resolve(nsPresContext* aPresContext)
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(!IsResolved(), "already resolved");
MOZ_ASSERT(aPresContext);
mResolved = true;
mDocGroup = aPresContext->Document()->GetDocGroup();
// For now, just have unique nsCSSValue/ImageValue objects. We should
// really store the ImageValue on the Servo specified value, so that we can

Просмотреть файл

@ -385,6 +385,9 @@ private:
RefPtr<mozilla::css::ImageValue> mImageValue;
RefPtr<mozilla::dom::ImageTracker> mImageTracker;
// Cache DocGroup for dispatching events in the destructor.
RefPtr<mozilla::dom::DocGroup> mDocGroup;
Mode mModeFlags;
bool mResolved;
};