Bug 1362444 P2 Allow idle worker shutdown while Cache/CacheStorage DOM objects exist, but block it during Cache operation. r=baku

This commit is contained in:
Ben Kelly 2017-05-10 09:27:10 -07:00
Родитель 93100c8123
Коммит 62239d1de6
4 изменённых файлов: 46 добавлений и 9 удалений

13
dom/cache/CacheOpChild.cpp поставляемый
Просмотреть файл

@ -75,7 +75,12 @@ CacheOpChild::CacheOpChild(CacheWorkerHolder* aWorkerHolder,
MOZ_DIAGNOSTIC_ASSERT(mPromise);
MOZ_ASSERT_IF(!NS_IsMainThread(), aWorkerHolder);
SetWorkerHolder(aWorkerHolder);
RefPtr<CacheWorkerHolder> workerHolder =
CacheWorkerHolder::PreferBehavior(aWorkerHolder,
CacheWorkerHolder::PreventIdleShutdownStart);
SetWorkerHolder(workerHolder);
}
CacheOpChild::~CacheOpChild()
@ -166,7 +171,11 @@ CacheOpChild::Recv__delete__(const ErrorResult& aRv,
break;
}
actor->SetWorkerHolder(GetWorkerHolder());
RefPtr<CacheWorkerHolder> workerHolder =
CacheWorkerHolder::PreferBehavior(GetWorkerHolder(),
CacheWorkerHolder::AllowIdleShutdownStart);
actor->SetWorkerHolder(workerHolder);
RefPtr<Cache> cache = new Cache(mGlobal, actor);
mPromise->MaybeResolve(cache);
break;

3
dom/cache/CacheStorage.cpp поставляемый
Просмотреть файл

@ -195,7 +195,8 @@ CacheStorage::CreateOnWorker(Namespace aNamespace, nsIGlobalObject* aGlobal,
}
RefPtr<CacheWorkerHolder> workerHolder =
CacheWorkerHolder::Create(aWorkerPrivate);
CacheWorkerHolder::Create(aWorkerPrivate,
CacheWorkerHolder::AllowIdleShutdownStart);
if (!workerHolder) {
NS_WARNING("Worker thread is shutting down.");
aRv.Throw(NS_ERROR_FAILURE);

31
dom/cache/CacheWorkerHolder.cpp поставляемый
Просмотреть файл

@ -19,11 +19,11 @@ using mozilla::dom::workers::WorkerPrivate;
// static
already_AddRefed<CacheWorkerHolder>
CacheWorkerHolder::Create(WorkerPrivate* aWorkerPrivate)
CacheWorkerHolder::Create(WorkerPrivate* aWorkerPrivate, Behavior aBehavior)
{
MOZ_DIAGNOSTIC_ASSERT(aWorkerPrivate);
RefPtr<CacheWorkerHolder> workerHolder = new CacheWorkerHolder();
RefPtr<CacheWorkerHolder> workerHolder = new CacheWorkerHolder(aBehavior);
if (NS_WARN_IF(!workerHolder->HoldWorker(aWorkerPrivate, Terminating))) {
return nullptr;
}
@ -31,6 +31,28 @@ CacheWorkerHolder::Create(WorkerPrivate* aWorkerPrivate)
return workerHolder.forget();
}
// static
already_AddRefed<CacheWorkerHolder>
CacheWorkerHolder::PreferBehavior(CacheWorkerHolder* aCurrentHolder,
Behavior aBehavior)
{
if (!aCurrentHolder) {
return nullptr;
}
RefPtr<CacheWorkerHolder> orig = aCurrentHolder;
if (orig->GetBehavior() == aBehavior) {
return orig.forget();
}
RefPtr<CacheWorkerHolder> replace = Create(orig->mWorkerPrivate, aBehavior);
if (!replace) {
return orig.forget();
}
return replace.forget();
}
void
CacheWorkerHolder::AddActor(ActorChild* aActor)
{
@ -93,8 +115,9 @@ CacheWorkerHolder::Notify(Status aStatus)
return true;
}
CacheWorkerHolder::CacheWorkerHolder()
: mNotified(false)
CacheWorkerHolder::CacheWorkerHolder(Behavior aBehavior)
: WorkerHolder(aBehavior)
, mNotified(false)
{
}

8
dom/cache/CacheWorkerHolder.h поставляемый
Просмотреть файл

@ -26,7 +26,11 @@ class CacheWorkerHolder final : public workers::WorkerHolder
{
public:
static already_AddRefed<CacheWorkerHolder>
Create(workers::WorkerPrivate* aWorkerPrivate);
Create(workers::WorkerPrivate* aWorkerPrivate,
Behavior aBehavior);
static already_AddRefed<CacheWorkerHolder>
PreferBehavior(CacheWorkerHolder* aCurrentHolder, Behavior aBehavior);
void AddActor(ActorChild* aActor);
void RemoveActor(ActorChild* aActor);
@ -37,7 +41,7 @@ public:
virtual bool Notify(workers::Status aStatus) override;
private:
CacheWorkerHolder();
explicit CacheWorkerHolder(Behavior aBehavior);
~CacheWorkerHolder();
nsTArray<ActorChild*> mActorList;