зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1269154 - Get rid of WorkerFeature: WorkerHolder, r=khuey
--HG-- rename : dom/cache/Feature.cpp => dom/cache/CacheWorkerHolder.cpp rename : dom/cache/Feature.h => dom/cache/CacheWorkerHolder.h rename : dom/workers/WorkerFeature.h => dom/workers/WorkerHolder.h
This commit is contained in:
Родитель
6f2998f958
Коммит
45087a7970
|
@ -604,7 +604,7 @@ FileReader::OnInputStreamReady(nsIAsyncInputStream* aStream)
|
|||
|
||||
// We use this class to decrease the busy counter at the end of this method.
|
||||
// In theory we can do it immediatelly but, for debugging reasons, we want to
|
||||
// be 100% sure we have a feature when OnLoadEnd() is called.
|
||||
// be 100% sure we have a workerHolder when OnLoadEnd() is called.
|
||||
FileReaderDecreaseBusyCounter RAII(this);
|
||||
|
||||
uint64_t aCount;
|
||||
|
@ -701,7 +701,7 @@ nsresult
|
|||
FileReader::IncreaseBusyCounter()
|
||||
{
|
||||
if (mWorkerPrivate && mBusyCount++ == 0 &&
|
||||
!mWorkerPrivate->AddFeature(this)) {
|
||||
!HoldWorker(mWorkerPrivate)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
|
@ -713,7 +713,7 @@ FileReader::DecreaseBusyCounter()
|
|||
{
|
||||
MOZ_ASSERT_IF(mWorkerPrivate, mBusyCount);
|
||||
if (mWorkerPrivate && --mBusyCount == 0) {
|
||||
mWorkerPrivate->RemoveFeature(this);
|
||||
ReleaseWorker();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -742,7 +742,7 @@ FileReader::Shutdown()
|
|||
}
|
||||
|
||||
if (mWorkerPrivate && mBusyCount != 0) {
|
||||
mWorkerPrivate->RemoveFeature(this);
|
||||
ReleaseWorker();
|
||||
mWorkerPrivate = nullptr;
|
||||
mBusyCount = 0;
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
#include "nsCOMPtr.h"
|
||||
#include "nsString.h"
|
||||
#include "nsWeakReference.h"
|
||||
#include "WorkerFeature.h"
|
||||
#include "WorkerHolder.h"
|
||||
|
||||
#define NS_PROGRESS_EVENT_INTERVAL 50
|
||||
|
||||
|
@ -41,7 +41,7 @@ class FileReader final : public DOMEventTargetHelper,
|
|||
public nsSupportsWeakReference,
|
||||
public nsIInputStreamCallback,
|
||||
public nsITimerCallback,
|
||||
public workers::WorkerFeature
|
||||
public workers::WorkerHolder
|
||||
{
|
||||
friend class FileReaderDecreaseBusyCounter;
|
||||
|
||||
|
@ -106,7 +106,7 @@ public:
|
|||
ReadFileContent(aBlob, EmptyString(), FILE_AS_BINARY, aRv);
|
||||
}
|
||||
|
||||
// WorkerFeature
|
||||
// WorkerHolder
|
||||
bool Notify(workers::Status) override;
|
||||
|
||||
private:
|
||||
|
@ -190,7 +190,7 @@ private:
|
|||
|
||||
uint64_t mBusyCount;
|
||||
|
||||
// Kept alive with a WorkerFeature.
|
||||
// Kept alive with a WorkerHolder.
|
||||
workers::WorkerPrivate* mWorkerPrivate;
|
||||
};
|
||||
|
||||
|
|
|
@ -99,7 +99,7 @@ public:
|
|||
, mInnerWindowID(0)
|
||||
, mWorkerPrivate(nullptr)
|
||||
#ifdef DEBUG
|
||||
, mHasFeatureRegistered(false)
|
||||
, mHasWorkerHolderRegistered(false)
|
||||
#endif
|
||||
, mIsMainThread(true)
|
||||
, mMutex("WebSocketImpl::mMutex")
|
||||
|
@ -166,8 +166,8 @@ public:
|
|||
void AddRefObject();
|
||||
void ReleaseObject();
|
||||
|
||||
bool RegisterFeature();
|
||||
void UnregisterFeature();
|
||||
bool RegisterWorkerHolder();
|
||||
void UnregisterWorkerHolder();
|
||||
|
||||
nsresult CancelInternal();
|
||||
|
||||
|
@ -213,24 +213,24 @@ public:
|
|||
uint64_t mInnerWindowID;
|
||||
|
||||
WorkerPrivate* mWorkerPrivate;
|
||||
nsAutoPtr<WorkerFeature> mWorkerFeature;
|
||||
nsAutoPtr<WorkerHolder> mWorkerHolder;
|
||||
|
||||
#ifdef DEBUG
|
||||
// This is protected by mutex.
|
||||
bool mHasFeatureRegistered;
|
||||
bool mHasWorkerHolderRegistered;
|
||||
|
||||
bool HasFeatureRegistered()
|
||||
bool HasWorkerHolderRegistered()
|
||||
{
|
||||
MOZ_ASSERT(mWebSocket);
|
||||
MutexAutoLock lock(mWebSocket->mMutex);
|
||||
return mHasFeatureRegistered;
|
||||
return mHasWorkerHolderRegistered;
|
||||
}
|
||||
|
||||
void SetHasFeatureRegistered(bool aValue)
|
||||
void SetHasWorkerHolderRegistered(bool aValue)
|
||||
{
|
||||
MOZ_ASSERT(mWebSocket);
|
||||
MutexAutoLock lock(mWebSocket->mMutex);
|
||||
mHasFeatureRegistered = aValue;
|
||||
mHasWorkerHolderRegistered = aValue;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -489,7 +489,7 @@ WebSocketImpl::CloseConnection(uint16_t aReasonCode,
|
|||
|
||||
// If this method is called because the worker is going away, we will not
|
||||
// receive the OnStop() method and we have to disconnect the WebSocket and
|
||||
// release the WorkerFeature.
|
||||
// release the WorkerHolder.
|
||||
MaybeDisconnect md(this);
|
||||
|
||||
uint16_t readyState = mWebSocket->ReadyState();
|
||||
|
@ -610,7 +610,7 @@ WebSocketImpl::Disconnect()
|
|||
AssertIsOnTargetThread();
|
||||
|
||||
// Disconnect can be called from some control event (such as Notify() of
|
||||
// WorkerFeature). This will be schedulated before any other sync/async
|
||||
// WorkerHolder). This will be schedulated before any other sync/async
|
||||
// runnable. In order to prevent some double Disconnect() calls, we use this
|
||||
// boolean.
|
||||
mDisconnectingOrDisconnected = true;
|
||||
|
@ -640,8 +640,8 @@ WebSocketImpl::Disconnect()
|
|||
mWebSocket->DontKeepAliveAnyMore();
|
||||
mWebSocket->mImpl = nullptr;
|
||||
|
||||
if (mWorkerPrivate && mWorkerFeature) {
|
||||
UnregisterFeature();
|
||||
if (mWorkerPrivate && mWorkerHolder) {
|
||||
UnregisterWorkerHolder();
|
||||
}
|
||||
|
||||
// We want to release the WebSocket in the correct thread.
|
||||
|
@ -1262,9 +1262,9 @@ WebSocket::ConstructorCommon(const GlobalObject& aGlobal,
|
|||
aUrl, protocolArray, EmptyCString(),
|
||||
0, 0, aRv, &connectionFailed);
|
||||
} else {
|
||||
// In workers we have to keep the worker alive using a feature in order to
|
||||
// dispatch messages correctly.
|
||||
if (!webSocket->mImpl->RegisterFeature()) {
|
||||
// In workers we have to keep the worker alive using a workerHolder in order
|
||||
// to dispatch messages correctly.
|
||||
if (!webSocket->mImpl->RegisterWorkerHolder()) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -2204,10 +2204,10 @@ WebSocket::DontKeepAliveAnyMore()
|
|||
|
||||
namespace {
|
||||
|
||||
class WebSocketWorkerFeature final : public WorkerFeature
|
||||
class WebSocketWorkerHolder final : public WorkerHolder
|
||||
{
|
||||
public:
|
||||
explicit WebSocketWorkerFeature(WebSocketImpl* aWebSocketImpl)
|
||||
explicit WebSocketWorkerHolder(WebSocketImpl* aWebSocketImpl)
|
||||
: mWebSocketImpl(aWebSocketImpl)
|
||||
{
|
||||
}
|
||||
|
@ -2250,39 +2250,39 @@ WebSocketImpl::ReleaseObject()
|
|||
}
|
||||
|
||||
bool
|
||||
WebSocketImpl::RegisterFeature()
|
||||
WebSocketImpl::RegisterWorkerHolder()
|
||||
{
|
||||
mWorkerPrivate->AssertIsOnWorkerThread();
|
||||
MOZ_ASSERT(!mWorkerFeature);
|
||||
mWorkerFeature = new WebSocketWorkerFeature(this);
|
||||
MOZ_ASSERT(!mWorkerHolder);
|
||||
mWorkerHolder = new WebSocketWorkerHolder(this);
|
||||
|
||||
if (!mWorkerPrivate->AddFeature(mWorkerFeature)) {
|
||||
NS_WARNING("Failed to register a feature.");
|
||||
mWorkerFeature = nullptr;
|
||||
if (NS_WARN_IF(!mWorkerHolder->HoldWorker(mWorkerPrivate))) {
|
||||
mWorkerHolder = nullptr;
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
SetHasFeatureRegistered(true);
|
||||
SetHasWorkerHolderRegistered(true);
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
WebSocketImpl::UnregisterFeature()
|
||||
WebSocketImpl::UnregisterWorkerHolder()
|
||||
{
|
||||
MOZ_ASSERT(mDisconnectingOrDisconnected);
|
||||
MOZ_ASSERT(mWorkerPrivate);
|
||||
mWorkerPrivate->AssertIsOnWorkerThread();
|
||||
MOZ_ASSERT(mWorkerFeature);
|
||||
MOZ_ASSERT(mWorkerHolder);
|
||||
|
||||
// The DTOR of this WorkerHolder will release the worker for us.
|
||||
mWorkerHolder = nullptr;
|
||||
|
||||
mWorkerPrivate->RemoveFeature(mWorkerFeature);
|
||||
mWorkerFeature = nullptr;
|
||||
mWorkerPrivate = nullptr;
|
||||
|
||||
#ifdef DEBUG
|
||||
SetHasFeatureRegistered(false);
|
||||
SetHasWorkerHolderRegistered(false);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -2842,7 +2842,7 @@ WebSocketImpl::Dispatch(already_AddRefed<nsIRunnable> aEvent, uint32_t aFlags)
|
|||
MOZ_ASSERT(mWorkerPrivate);
|
||||
|
||||
#ifdef DEBUG
|
||||
MOZ_ASSERT(HasFeatureRegistered());
|
||||
MOZ_ASSERT(HasWorkerHolderRegistered());
|
||||
#endif
|
||||
|
||||
// If the target is a worker, we have to use a custom WorkerRunnableDispatcher
|
||||
|
|
|
@ -3298,7 +3298,7 @@ namespace {
|
|||
// This runnable is used to write a deprecation message from a worker to the
|
||||
// console running on the main-thread.
|
||||
class DeprecationWarningRunnable final : public Runnable
|
||||
, public WorkerFeature
|
||||
, public WorkerHolder
|
||||
{
|
||||
WorkerPrivate* mWorkerPrivate;
|
||||
nsIDocument::DeprecatedOperations mOperation;
|
||||
|
@ -3315,12 +3315,12 @@ public:
|
|||
void
|
||||
Dispatch()
|
||||
{
|
||||
if (NS_WARN_IF(!mWorkerPrivate->AddFeature(this))) {
|
||||
if (NS_WARN_IF(!HoldWorker(mWorkerPrivate))) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (NS_WARN_IF(NS_FAILED(NS_DispatchToMainThread(this)))) {
|
||||
mWorkerPrivate->RemoveFeature(this);
|
||||
ReleaseWorker();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -3351,12 +3351,12 @@ private:
|
|||
window->GetExtantDoc()->WarnOnceAbout(mOperation);
|
||||
}
|
||||
|
||||
ReleaseWorker();
|
||||
ReleaseWorkerHolder();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
ReleaseWorker()
|
||||
ReleaseWorkerHolder()
|
||||
{
|
||||
class ReleaseRunnable final : public MainThreadWorkerRunnable
|
||||
{
|
||||
|
@ -3375,7 +3375,7 @@ private:
|
|||
MOZ_ASSERT(aWorkerPrivate);
|
||||
aWorkerPrivate->AssertIsOnWorkerThread();
|
||||
|
||||
aWorkerPrivate->RemoveFeature(mRunnable);
|
||||
mRunnable->ReleaseWorker();
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -266,15 +266,15 @@ private:
|
|||
|
||||
NS_IMPL_ISUPPORTS(TeardownRunnable, nsICancelableRunnable, nsIRunnable)
|
||||
|
||||
class BroadcastChannelFeature final : public workers::WorkerFeature
|
||||
class BroadcastChannelWorkerHolder final : public workers::WorkerHolder
|
||||
{
|
||||
BroadcastChannel* mChannel;
|
||||
|
||||
public:
|
||||
explicit BroadcastChannelFeature(BroadcastChannel* aChannel)
|
||||
explicit BroadcastChannelWorkerHolder(BroadcastChannel* aChannel)
|
||||
: mChannel(aChannel)
|
||||
{
|
||||
MOZ_COUNT_CTOR(BroadcastChannelFeature);
|
||||
MOZ_COUNT_CTOR(BroadcastChannelWorkerHolder);
|
||||
}
|
||||
|
||||
virtual bool Notify(workers::Status aStatus) override
|
||||
|
@ -287,9 +287,9 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
~BroadcastChannelFeature()
|
||||
~BroadcastChannelWorkerHolder()
|
||||
{
|
||||
MOZ_COUNT_DTOR(BroadcastChannelFeature);
|
||||
MOZ_COUNT_DTOR(BroadcastChannelWorkerHolder);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -300,7 +300,7 @@ BroadcastChannel::BroadcastChannel(nsPIDOMWindowInner* aWindow,
|
|||
const nsACString& aOrigin,
|
||||
const nsAString& aChannel)
|
||||
: DOMEventTargetHelper(aWindow)
|
||||
, mWorkerFeature(nullptr)
|
||||
, mWorkerHolder(nullptr)
|
||||
, mPrincipalInfo(new PrincipalInfo(aPrincipalInfo))
|
||||
, mOrigin(aOrigin)
|
||||
, mChannel(aChannel)
|
||||
|
@ -314,7 +314,7 @@ BroadcastChannel::BroadcastChannel(nsPIDOMWindowInner* aWindow,
|
|||
BroadcastChannel::~BroadcastChannel()
|
||||
{
|
||||
Shutdown();
|
||||
MOZ_ASSERT(!mWorkerFeature);
|
||||
MOZ_ASSERT(!mWorkerHolder);
|
||||
}
|
||||
|
||||
JSObject*
|
||||
|
@ -406,10 +406,9 @@ BroadcastChannel::Constructor(const GlobalObject& aGlobal,
|
|||
obs->AddObserver(bc, "inner-window-destroyed", false);
|
||||
}
|
||||
} else {
|
||||
bc->mWorkerFeature = new BroadcastChannelFeature(bc);
|
||||
if (NS_WARN_IF(!workerPrivate->AddFeature(bc->mWorkerFeature))) {
|
||||
NS_WARNING("Failed to register the BroadcastChannel worker feature.");
|
||||
bc->mWorkerFeature = nullptr;
|
||||
bc->mWorkerHolder = new BroadcastChannelWorkerHolder(bc);
|
||||
if (NS_WARN_IF(!bc->mWorkerHolder->HoldWorker(workerPrivate))) {
|
||||
bc->mWorkerHolder = nullptr;
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -528,11 +527,8 @@ BroadcastChannel::Shutdown()
|
|||
{
|
||||
mState = StateClosed;
|
||||
|
||||
if (mWorkerFeature) {
|
||||
WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
|
||||
workerPrivate->RemoveFeature(mWorkerFeature);
|
||||
mWorkerFeature = nullptr;
|
||||
}
|
||||
// The DTOR of this WorkerHolder will release the worker for us.
|
||||
mWorkerHolder = nullptr;
|
||||
|
||||
if (mActor) {
|
||||
mActor->SetParent(nullptr);
|
||||
|
|
|
@ -26,7 +26,7 @@ class PrincipalInfo;
|
|||
namespace dom {
|
||||
|
||||
namespace workers {
|
||||
class WorkerFeature;
|
||||
class WorkerHolder;
|
||||
} // namespace workers
|
||||
|
||||
class BroadcastChannelChild;
|
||||
|
@ -110,7 +110,7 @@ private:
|
|||
RefPtr<BroadcastChannelChild> mActor;
|
||||
nsTArray<RefPtr<BroadcastChannelMessage>> mPendingMessages;
|
||||
|
||||
nsAutoPtr<workers::WorkerFeature> mWorkerFeature;
|
||||
nsAutoPtr<workers::WorkerHolder> mWorkerHolder;
|
||||
|
||||
nsAutoPtr<PrincipalInfo> mPrincipalInfo;
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
#include "mozilla/dom/cache/ActorChild.h"
|
||||
|
||||
#include "mozilla/dom/cache/Feature.h"
|
||||
#include "mozilla/dom/cache/CacheWorkerHolder.h"
|
||||
#include "nsThreadUtils.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
@ -14,42 +14,42 @@ namespace dom {
|
|||
namespace cache {
|
||||
|
||||
void
|
||||
ActorChild::SetFeature(Feature* aFeature)
|
||||
ActorChild::SetWorkerHolder(CacheWorkerHolder* aWorkerHolder)
|
||||
{
|
||||
// Some of the Cache actors can have multiple DOM objects associated with
|
||||
// them. In this case the feature will be added multiple times. This is
|
||||
// permitted, but the feature should be the same each time.
|
||||
if (mFeature) {
|
||||
MOZ_ASSERT(mFeature == aFeature);
|
||||
// them. In this case the workerHolder will be added multiple times. This is
|
||||
// permitted, but the workerHolder should be the same each time.
|
||||
if (mWorkerHolder) {
|
||||
MOZ_ASSERT(mWorkerHolder == aWorkerHolder);
|
||||
return;
|
||||
}
|
||||
|
||||
mFeature = aFeature;
|
||||
if (mFeature) {
|
||||
mFeature->AddActor(this);
|
||||
mWorkerHolder = aWorkerHolder;
|
||||
if (mWorkerHolder) {
|
||||
mWorkerHolder->AddActor(this);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ActorChild::RemoveFeature()
|
||||
ActorChild::RemoveWorkerHolder()
|
||||
{
|
||||
MOZ_ASSERT_IF(!NS_IsMainThread(), mFeature);
|
||||
if (mFeature) {
|
||||
mFeature->RemoveActor(this);
|
||||
mFeature = nullptr;
|
||||
MOZ_ASSERT_IF(!NS_IsMainThread(), mWorkerHolder);
|
||||
if (mWorkerHolder) {
|
||||
mWorkerHolder->RemoveActor(this);
|
||||
mWorkerHolder = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
Feature*
|
||||
ActorChild::GetFeature() const
|
||||
CacheWorkerHolder*
|
||||
ActorChild::GetWorkerHolder() const
|
||||
{
|
||||
return mFeature;
|
||||
return mWorkerHolder;
|
||||
}
|
||||
|
||||
bool
|
||||
ActorChild::FeatureNotified() const
|
||||
ActorChild::WorkerHolderNotified() const
|
||||
{
|
||||
return mFeature && mFeature->Notified();
|
||||
return mWorkerHolder && mWorkerHolder->Notified();
|
||||
}
|
||||
|
||||
ActorChild::ActorChild()
|
||||
|
@ -58,7 +58,7 @@ ActorChild::ActorChild()
|
|||
|
||||
ActorChild::~ActorChild()
|
||||
{
|
||||
MOZ_ASSERT(!mFeature);
|
||||
MOZ_ASSERT(!mWorkerHolder);
|
||||
}
|
||||
|
||||
} // namespace cache
|
||||
|
|
|
@ -13,7 +13,7 @@ namespace mozilla {
|
|||
namespace dom {
|
||||
namespace cache {
|
||||
|
||||
class Feature;
|
||||
class CacheWorkerHolder;
|
||||
|
||||
class ActorChild
|
||||
{
|
||||
|
@ -22,23 +22,23 @@ public:
|
|||
StartDestroy() = 0;
|
||||
|
||||
void
|
||||
SetFeature(Feature* aFeature);
|
||||
SetWorkerHolder(CacheWorkerHolder* aWorkerHolder);
|
||||
|
||||
void
|
||||
RemoveFeature();
|
||||
RemoveWorkerHolder();
|
||||
|
||||
Feature*
|
||||
GetFeature() const;
|
||||
CacheWorkerHolder*
|
||||
GetWorkerHolder() const;
|
||||
|
||||
bool
|
||||
FeatureNotified() const;
|
||||
WorkerHolderNotified() const;
|
||||
|
||||
protected:
|
||||
ActorChild();
|
||||
~ActorChild();
|
||||
|
||||
private:
|
||||
RefPtr<Feature> mFeature;
|
||||
RefPtr<CacheWorkerHolder> mWorkerHolder;
|
||||
};
|
||||
|
||||
} // namespace cache
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
#include "mozilla/dom/CacheBinding.h"
|
||||
#include "mozilla/dom/cache/AutoUtils.h"
|
||||
#include "mozilla/dom/cache/CacheChild.h"
|
||||
#include "mozilla/dom/cache/Feature.h"
|
||||
#include "mozilla/dom/cache/CacheWorkerHolder.h"
|
||||
#include "mozilla/dom/cache/ReadStream.h"
|
||||
#include "mozilla/ErrorResult.h"
|
||||
#include "mozilla/Preferences.h"
|
||||
|
@ -82,21 +82,21 @@ IsValidPutRequestMethod(const RequestOrUSVString& aRequest, ErrorResult& aRv)
|
|||
} // namespace
|
||||
|
||||
// Helper class to wait for Add()/AddAll() fetch requests to complete and
|
||||
// then perform a PutAll() with the responses. This class holds a Feature
|
||||
// then perform a PutAll() with the responses. This class holds a WorkerHolder
|
||||
// to keep the Worker thread alive. This is mainly to ensure that Add/AddAll
|
||||
// act the same as other Cache operations that directly create a CacheOpChild
|
||||
// actor.
|
||||
class Cache::FetchHandler final : public PromiseNativeHandler
|
||||
{
|
||||
public:
|
||||
FetchHandler(Feature* aFeature, Cache* aCache,
|
||||
FetchHandler(CacheWorkerHolder* aWorkerHolder, Cache* aCache,
|
||||
nsTArray<RefPtr<Request>>&& aRequestList, Promise* aPromise)
|
||||
: mFeature(aFeature)
|
||||
: mWorkerHolder(aWorkerHolder)
|
||||
, mCache(aCache)
|
||||
, mRequestList(Move(aRequestList))
|
||||
, mPromise(aPromise)
|
||||
{
|
||||
MOZ_ASSERT_IF(!NS_IsMainThread(), mFeature);
|
||||
MOZ_ASSERT_IF(!NS_IsMainThread(), mWorkerHolder);
|
||||
MOZ_ASSERT(mCache);
|
||||
MOZ_ASSERT(mPromise);
|
||||
}
|
||||
|
@ -107,8 +107,8 @@ public:
|
|||
NS_ASSERT_OWNINGTHREAD(FetchHandler);
|
||||
|
||||
// Stop holding the worker alive when we leave this method.
|
||||
RefPtr<Feature> feature;
|
||||
feature.swap(mFeature);
|
||||
RefPtr<CacheWorkerHolder> workerHolder;
|
||||
workerHolder.swap(mWorkerHolder);
|
||||
|
||||
// Promise::All() passed an array of fetch() Promises should give us
|
||||
// an Array of Response objects. The following code unwraps these
|
||||
|
@ -217,7 +217,7 @@ private:
|
|||
mPromise->MaybeReject(rv);
|
||||
}
|
||||
|
||||
RefPtr<Feature> mFeature;
|
||||
RefPtr<CacheWorkerHolder> mWorkerHolder;
|
||||
RefPtr<Cache> mCache;
|
||||
nsTArray<RefPtr<Request>> mRequestList;
|
||||
RefPtr<Promise> mPromise;
|
||||
|
@ -614,8 +614,9 @@ Cache::AddAll(const GlobalObject& aGlobal,
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
RefPtr<FetchHandler> handler = new FetchHandler(mActor->GetFeature(), this,
|
||||
Move(aRequestList), promise);
|
||||
RefPtr<FetchHandler> handler =
|
||||
new FetchHandler(mActor->GetWorkerHolder(), this,
|
||||
Move(aRequestList), promise);
|
||||
|
||||
RefPtr<Promise> fetchPromise = Promise::All(aGlobal, fetchList, aRv);
|
||||
if (NS_WARN_IF(aRv.Failed())) {
|
||||
|
|
|
@ -70,7 +70,7 @@ CacheChild::ExecuteOp(nsIGlobalObject* aGlobal, Promise* aPromise,
|
|||
{
|
||||
mNumChildActors += 1;
|
||||
MOZ_ALWAYS_TRUE(SendPCacheOpConstructor(
|
||||
new CacheOpChild(GetFeature(), aGlobal, aParent, aPromise), aArgs));
|
||||
new CacheOpChild(GetWorkerHolder(), aGlobal, aParent, aPromise), aArgs));
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -103,7 +103,7 @@ CacheChild::StartDestroy()
|
|||
|
||||
RefPtr<Cache> listener = mListener;
|
||||
|
||||
// StartDestroy() can get called from either Cache or the Feature.
|
||||
// StartDestroy() can get called from either Cache or the WorkerHolder.
|
||||
// Theoretically we can get double called if the right race happens. Handle
|
||||
// that by just ignoring the second StartDestroy() call.
|
||||
if (!listener) {
|
||||
|
@ -130,7 +130,7 @@ CacheChild::ActorDestroy(ActorDestroyReason aReason)
|
|||
MOZ_ASSERT(!mListener);
|
||||
}
|
||||
|
||||
RemoveFeature();
|
||||
RemoveWorkerHolder();
|
||||
}
|
||||
|
||||
PCacheOpChild*
|
||||
|
|
|
@ -65,7 +65,7 @@ public:
|
|||
private:
|
||||
// ActorChild methods
|
||||
|
||||
// Feature is trying to destroy due to worker shutdown.
|
||||
// WorkerHolder is trying to destroy due to worker shutdown.
|
||||
virtual void StartDestroy() override;
|
||||
|
||||
// PCacheChild methods
|
||||
|
|
|
@ -22,43 +22,49 @@ using mozilla::ipc::PBackgroundChild;
|
|||
namespace {
|
||||
|
||||
void
|
||||
AddFeatureToStreamChild(const CacheReadStream& aReadStream, Feature* aFeature)
|
||||
AddWorkerHolderToStreamChild(const CacheReadStream& aReadStream,
|
||||
CacheWorkerHolder* aWorkerHolder)
|
||||
{
|
||||
MOZ_ASSERT_IF(!NS_IsMainThread(), aFeature);
|
||||
MOZ_ASSERT_IF(!NS_IsMainThread(), aWorkerHolder);
|
||||
CacheStreamControlChild* cacheControl =
|
||||
static_cast<CacheStreamControlChild*>(aReadStream.controlChild());
|
||||
if (cacheControl) {
|
||||
cacheControl->SetFeature(aFeature);
|
||||
cacheControl->SetWorkerHolder(aWorkerHolder);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
AddFeatureToStreamChild(const CacheResponse& aResponse, Feature* aFeature)
|
||||
AddWorkerHolderToStreamChild(const CacheResponse& aResponse,
|
||||
CacheWorkerHolder* aWorkerHolder)
|
||||
{
|
||||
MOZ_ASSERT_IF(!NS_IsMainThread(), aFeature);
|
||||
MOZ_ASSERT_IF(!NS_IsMainThread(), aWorkerHolder);
|
||||
|
||||
if (aResponse.body().type() == CacheReadStreamOrVoid::Tvoid_t) {
|
||||
return;
|
||||
}
|
||||
|
||||
AddFeatureToStreamChild(aResponse.body().get_CacheReadStream(), aFeature);
|
||||
AddWorkerHolderToStreamChild(aResponse.body().get_CacheReadStream(),
|
||||
aWorkerHolder);
|
||||
}
|
||||
|
||||
void
|
||||
AddFeatureToStreamChild(const CacheRequest& aRequest, Feature* aFeature)
|
||||
AddWorkerHolderToStreamChild(const CacheRequest& aRequest,
|
||||
CacheWorkerHolder* aWorkerHolder)
|
||||
{
|
||||
MOZ_ASSERT_IF(!NS_IsMainThread(), aFeature);
|
||||
MOZ_ASSERT_IF(!NS_IsMainThread(), aWorkerHolder);
|
||||
|
||||
if (aRequest.body().type() == CacheReadStreamOrVoid::Tvoid_t) {
|
||||
return;
|
||||
}
|
||||
|
||||
AddFeatureToStreamChild(aRequest.body().get_CacheReadStream(), aFeature);
|
||||
AddWorkerHolderToStreamChild(aRequest.body().get_CacheReadStream(),
|
||||
aWorkerHolder);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
CacheOpChild::CacheOpChild(Feature* aFeature, nsIGlobalObject* aGlobal,
|
||||
CacheOpChild::CacheOpChild(CacheWorkerHolder* aWorkerHolder,
|
||||
nsIGlobalObject* aGlobal,
|
||||
nsISupports* aParent, Promise* aPromise)
|
||||
: mGlobal(aGlobal)
|
||||
, mParent(aParent)
|
||||
|
@ -68,8 +74,8 @@ CacheOpChild::CacheOpChild(Feature* aFeature, nsIGlobalObject* aGlobal,
|
|||
MOZ_ASSERT(mParent);
|
||||
MOZ_ASSERT(mPromise);
|
||||
|
||||
MOZ_ASSERT_IF(!NS_IsMainThread(), aFeature);
|
||||
SetFeature(aFeature);
|
||||
MOZ_ASSERT_IF(!NS_IsMainThread(), aWorkerHolder);
|
||||
SetWorkerHolder(aWorkerHolder);
|
||||
}
|
||||
|
||||
CacheOpChild::~CacheOpChild()
|
||||
|
@ -90,7 +96,7 @@ CacheOpChild::ActorDestroy(ActorDestroyReason aReason)
|
|||
mPromise = nullptr;
|
||||
}
|
||||
|
||||
RemoveFeature();
|
||||
RemoveWorkerHolder();
|
||||
}
|
||||
|
||||
bool
|
||||
|
@ -149,7 +155,7 @@ CacheOpChild::Recv__delete__(const ErrorResult& aRv,
|
|||
{
|
||||
auto actor = static_cast<CacheChild*>(
|
||||
aResult.get_StorageOpenResult().actorChild());
|
||||
actor->SetFeature(GetFeature());
|
||||
actor->SetWorkerHolder(GetWorkerHolder());
|
||||
RefPtr<Cache> cache = new Cache(mGlobal, actor);
|
||||
mPromise->MaybeResolve(cache);
|
||||
break;
|
||||
|
@ -178,8 +184,8 @@ CacheOpChild::StartDestroy()
|
|||
{
|
||||
NS_ASSERT_OWNINGTHREAD(CacheOpChild);
|
||||
|
||||
// Do not cancel on-going operations when Feature calls this. Instead, keep
|
||||
// the Worker alive until we are done.
|
||||
// Do not cancel on-going operations when WorkerHolder calls this. Instead,
|
||||
// keep the Worker alive until we are done.
|
||||
}
|
||||
|
||||
nsIGlobalObject*
|
||||
|
@ -212,7 +218,7 @@ CacheOpChild::HandleResponse(const CacheResponseOrVoid& aResponseOrVoid)
|
|||
|
||||
const CacheResponse& cacheResponse = aResponseOrVoid.get_CacheResponse();
|
||||
|
||||
AddFeatureToStreamChild(cacheResponse, GetFeature());
|
||||
AddWorkerHolderToStreamChild(cacheResponse, GetWorkerHolder());
|
||||
RefPtr<Response> response = ToResponse(cacheResponse);
|
||||
|
||||
mPromise->MaybeResolve(response);
|
||||
|
@ -225,7 +231,7 @@ CacheOpChild::HandleResponseList(const nsTArray<CacheResponse>& aResponseList)
|
|||
responses.SetCapacity(aResponseList.Length());
|
||||
|
||||
for (uint32_t i = 0; i < aResponseList.Length(); ++i) {
|
||||
AddFeatureToStreamChild(aResponseList[i], GetFeature());
|
||||
AddWorkerHolderToStreamChild(aResponseList[i], GetWorkerHolder());
|
||||
responses.AppendElement(ToResponse(aResponseList[i]));
|
||||
}
|
||||
|
||||
|
@ -239,7 +245,7 @@ CacheOpChild::HandleRequestList(const nsTArray<CacheRequest>& aRequestList)
|
|||
requests.SetCapacity(aRequestList.Length());
|
||||
|
||||
for (uint32_t i = 0; i < aRequestList.Length(); ++i) {
|
||||
AddFeatureToStreamChild(aRequestList[i], GetFeature());
|
||||
AddWorkerHolderToStreamChild(aRequestList[i], GetWorkerHolder());
|
||||
requests.AppendElement(ToRequest(aRequestList[i]));
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ class CacheOpChild final : public PCacheOpChild
|
|||
private:
|
||||
// This class must be constructed by CacheChild or CacheStorageChild using
|
||||
// their ExecuteOp() factory method.
|
||||
CacheOpChild(Feature* aFeature, nsIGlobalObject* aGlobal,
|
||||
CacheOpChild(CacheWorkerHolder* aWorkerHolder, nsIGlobalObject* aGlobal,
|
||||
nsISupports* aParent, Promise* aPromise);
|
||||
~CacheOpChild();
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
#include "mozilla/dom/cache/Cache.h"
|
||||
#include "mozilla/dom/cache/CacheChild.h"
|
||||
#include "mozilla/dom/cache/CacheStorageChild.h"
|
||||
#include "mozilla/dom/cache/Feature.h"
|
||||
#include "mozilla/dom/cache/CacheWorkerHolder.h"
|
||||
#include "mozilla/dom/cache/PCacheChild.h"
|
||||
#include "mozilla/dom/cache/ReadStream.h"
|
||||
#include "mozilla/dom/cache/TypeUtils.h"
|
||||
|
@ -202,8 +202,9 @@ CacheStorage::CreateOnWorker(Namespace aNamespace, nsIGlobalObject* aGlobal,
|
|||
return ref.forget();
|
||||
}
|
||||
|
||||
RefPtr<Feature> feature = Feature::Create(aWorkerPrivate);
|
||||
if (!feature) {
|
||||
RefPtr<CacheWorkerHolder> workerHolder =
|
||||
CacheWorkerHolder::Create(aWorkerPrivate);
|
||||
if (!workerHolder) {
|
||||
NS_WARNING("Worker thread is shutting down.");
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
|
@ -236,7 +237,7 @@ CacheStorage::CreateOnWorker(Namespace aNamespace, nsIGlobalObject* aGlobal,
|
|||
}
|
||||
|
||||
RefPtr<CacheStorage> ref = new CacheStorage(aNamespace, aGlobal,
|
||||
principalInfo, feature);
|
||||
principalInfo, workerHolder);
|
||||
return ref.forget();
|
||||
}
|
||||
|
||||
|
@ -276,11 +277,12 @@ CacheStorage::DefineCaches(JSContext* aCx, JS::Handle<JSObject*> aGlobal)
|
|||
}
|
||||
|
||||
CacheStorage::CacheStorage(Namespace aNamespace, nsIGlobalObject* aGlobal,
|
||||
const PrincipalInfo& aPrincipalInfo, Feature* aFeature)
|
||||
const PrincipalInfo& aPrincipalInfo,
|
||||
CacheWorkerHolder* aWorkerHolder)
|
||||
: mNamespace(aNamespace)
|
||||
, mGlobal(aGlobal)
|
||||
, mPrincipalInfo(MakeUnique<PrincipalInfo>(aPrincipalInfo))
|
||||
, mFeature(aFeature)
|
||||
, mWorkerHolder(aWorkerHolder)
|
||||
, mActor(nullptr)
|
||||
, mStatus(NS_OK)
|
||||
{
|
||||
|
@ -509,15 +511,15 @@ CacheStorage::ActorCreated(PBackgroundChild* aActor)
|
|||
NS_ASSERT_OWNINGTHREAD(CacheStorage);
|
||||
MOZ_ASSERT(aActor);
|
||||
|
||||
if (NS_WARN_IF(mFeature && mFeature->Notified())) {
|
||||
if (NS_WARN_IF(mWorkerHolder && mWorkerHolder->Notified())) {
|
||||
ActorFailed();
|
||||
return;
|
||||
}
|
||||
|
||||
// Feature ownership is passed to the CacheStorageChild actor and any actors
|
||||
// it may create. The Feature will keep the worker thread alive until the
|
||||
// actors can gracefully shutdown.
|
||||
CacheStorageChild* newActor = new CacheStorageChild(this, mFeature);
|
||||
// WorkerHolder ownership is passed to the CacheStorageChild actor and any
|
||||
// actors it may create. The WorkerHolder will keep the worker thread alive
|
||||
// until the actors can gracefully shutdown.
|
||||
CacheStorageChild* newActor = new CacheStorageChild(this, mWorkerHolder);
|
||||
PCacheStorageChild* constructedActor =
|
||||
aActor->SendPCacheStorageConstructor(newActor, mNamespace, *mPrincipalInfo);
|
||||
|
||||
|
@ -526,7 +528,7 @@ CacheStorage::ActorCreated(PBackgroundChild* aActor)
|
|||
return;
|
||||
}
|
||||
|
||||
mFeature = nullptr;
|
||||
mWorkerHolder = nullptr;
|
||||
|
||||
MOZ_ASSERT(constructedActor == newActor);
|
||||
mActor = newActor;
|
||||
|
@ -542,7 +544,7 @@ CacheStorage::ActorFailed()
|
|||
MOZ_ASSERT(!NS_FAILED(mStatus));
|
||||
|
||||
mStatus = NS_ERROR_UNEXPECTED;
|
||||
mFeature = nullptr;
|
||||
mWorkerHolder = nullptr;
|
||||
|
||||
for (uint32_t i = 0; i < mPendingRequests.Length(); ++i) {
|
||||
nsAutoPtr<Entry> entry(mPendingRequests[i].forget());
|
||||
|
|
|
@ -38,7 +38,7 @@ namespace workers {
|
|||
namespace cache {
|
||||
|
||||
class CacheStorageChild;
|
||||
class Feature;
|
||||
class CacheWorkerHolder;
|
||||
|
||||
class CacheStorage final : public nsIIPCBackgroundChildCreateCallback
|
||||
, public nsWrapperCache
|
||||
|
@ -97,7 +97,8 @@ public:
|
|||
|
||||
private:
|
||||
CacheStorage(Namespace aNamespace, nsIGlobalObject* aGlobal,
|
||||
const mozilla::ipc::PrincipalInfo& aPrincipalInfo, Feature* aFeature);
|
||||
const mozilla::ipc::PrincipalInfo& aPrincipalInfo,
|
||||
CacheWorkerHolder* aWorkerHolder);
|
||||
explicit CacheStorage(nsresult aFailureResult);
|
||||
~CacheStorage();
|
||||
|
||||
|
@ -106,7 +107,7 @@ private:
|
|||
const Namespace mNamespace;
|
||||
nsCOMPtr<nsIGlobalObject> mGlobal;
|
||||
UniquePtr<mozilla::ipc::PrincipalInfo> mPrincipalInfo;
|
||||
RefPtr<Feature> mFeature;
|
||||
RefPtr<CacheWorkerHolder> mWorkerHolder;
|
||||
|
||||
// weak ref cleared in DestroyInternal
|
||||
CacheStorageChild* mActor;
|
||||
|
|
|
@ -22,7 +22,8 @@ DeallocPCacheStorageChild(PCacheStorageChild* aActor)
|
|||
delete aActor;
|
||||
}
|
||||
|
||||
CacheStorageChild::CacheStorageChild(CacheStorage* aListener, Feature* aFeature)
|
||||
CacheStorageChild::CacheStorageChild(CacheStorage* aListener,
|
||||
CacheWorkerHolder* aWorkerHolder)
|
||||
: mListener(aListener)
|
||||
, mNumChildActors(0)
|
||||
, mDelayedDestroy(false)
|
||||
|
@ -30,7 +31,7 @@ CacheStorageChild::CacheStorageChild(CacheStorage* aListener, Feature* aFeature)
|
|||
MOZ_COUNT_CTOR(cache::CacheStorageChild);
|
||||
MOZ_ASSERT(mListener);
|
||||
|
||||
SetFeature(aFeature);
|
||||
SetWorkerHolder(aWorkerHolder);
|
||||
}
|
||||
|
||||
CacheStorageChild::~CacheStorageChild()
|
||||
|
@ -54,7 +55,7 @@ CacheStorageChild::ExecuteOp(nsIGlobalObject* aGlobal, Promise* aPromise,
|
|||
{
|
||||
mNumChildActors += 1;
|
||||
Unused << SendPCacheOpConstructor(
|
||||
new CacheOpChild(GetFeature(), aGlobal, aParent, aPromise), aArgs);
|
||||
new CacheOpChild(GetWorkerHolder(), aGlobal, aParent, aPromise), aArgs);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -86,7 +87,8 @@ CacheStorageChild::StartDestroy()
|
|||
|
||||
RefPtr<CacheStorage> listener = mListener;
|
||||
|
||||
// StartDestroy() can get called from either CacheStorage or the Feature.
|
||||
// StartDestroy() can get called from either CacheStorage or the
|
||||
// CacheWorkerHolder.
|
||||
// Theoretically we can get double called if the right race happens. Handle
|
||||
// that by just ignoring the second StartDestroy() call.
|
||||
if (!listener) {
|
||||
|
@ -113,7 +115,7 @@ CacheStorageChild::ActorDestroy(ActorDestroyReason aReason)
|
|||
MOZ_ASSERT(!mListener);
|
||||
}
|
||||
|
||||
RemoveFeature();
|
||||
RemoveWorkerHolder();
|
||||
}
|
||||
|
||||
PCacheOpChild*
|
||||
|
|
|
@ -22,14 +22,14 @@ namespace cache {
|
|||
|
||||
class CacheOpArgs;
|
||||
class CacheStorage;
|
||||
class CacheWorkerHolder;
|
||||
class PCacheChild;
|
||||
class Feature;
|
||||
|
||||
class CacheStorageChild final : public PCacheStorageChild
|
||||
, public ActorChild
|
||||
{
|
||||
public:
|
||||
CacheStorageChild(CacheStorage* aListener, Feature* aFeature);
|
||||
CacheStorageChild(CacheStorage* aListener, CacheWorkerHolder* aWorkerHolder);
|
||||
~CacheStorageChild();
|
||||
|
||||
// Must be called by the associated CacheStorage listener in its
|
||||
|
@ -48,7 +48,7 @@ public:
|
|||
private:
|
||||
// ActorChild methods
|
||||
|
||||
// Feature is trying to destroy due to worker shutdown.
|
||||
// CacheWorkerHolder is trying to destroy due to worker shutdown.
|
||||
virtual void StartDestroy() override;
|
||||
|
||||
// PCacheStorageChild methods
|
||||
|
|
|
@ -58,8 +58,8 @@ CacheStreamControlChild::StartDestroy()
|
|||
{
|
||||
NS_ASSERT_OWNINGTHREAD(CacheStreamControlChild);
|
||||
// This can get called twice under some circumstances. For example, if the
|
||||
// actor is added to a Feature that has already been notified and the Cache
|
||||
// actor has no mListener.
|
||||
// actor is added to a CacheWorkerHolder that has already been notified and
|
||||
// the Cache actor has no mListener.
|
||||
if (mDestroyStarted) {
|
||||
return;
|
||||
}
|
||||
|
@ -135,7 +135,7 @@ CacheStreamControlChild::ActorDestroy(ActorDestroyReason aReason)
|
|||
{
|
||||
NS_ASSERT_OWNINGTHREAD(CacheStreamControlChild);
|
||||
CloseAllReadStreamsWithoutReporting();
|
||||
RemoveFeature();
|
||||
RemoveWorkerHolder();
|
||||
}
|
||||
|
||||
bool
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "mozilla/dom/cache/Feature.h"
|
||||
#include "mozilla/dom/cache/CacheWorkerHolder.h"
|
||||
|
||||
#include "mozilla/dom/cache/ActorChild.h"
|
||||
#include "WorkerPrivate.h"
|
||||
|
@ -18,24 +18,25 @@ using mozilla::dom::workers::Status;
|
|||
using mozilla::dom::workers::WorkerPrivate;
|
||||
|
||||
// static
|
||||
already_AddRefed<Feature>
|
||||
Feature::Create(WorkerPrivate* aWorkerPrivate)
|
||||
already_AddRefed<CacheWorkerHolder>
|
||||
CacheWorkerHolder::Create(WorkerPrivate* aWorkerPrivate)
|
||||
{
|
||||
MOZ_ASSERT(aWorkerPrivate);
|
||||
|
||||
RefPtr<Feature> feature = new Feature(aWorkerPrivate);
|
||||
RefPtr<CacheWorkerHolder> workerHolder =
|
||||
new CacheWorkerHolder(aWorkerPrivate);
|
||||
|
||||
if (!aWorkerPrivate->AddFeature(feature)) {
|
||||
if (NS_WARN_IF(!workerHolder->HoldWorker(aWorkerPrivate))) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return feature.forget();
|
||||
return workerHolder.forget();
|
||||
}
|
||||
|
||||
void
|
||||
Feature::AddActor(ActorChild* aActor)
|
||||
CacheWorkerHolder::AddActor(ActorChild* aActor)
|
||||
{
|
||||
NS_ASSERT_OWNINGTHREAD(Feature);
|
||||
NS_ASSERT_OWNINGTHREAD(CacheWorkerHolder);
|
||||
MOZ_ASSERT(aActor);
|
||||
MOZ_ASSERT(!mActorList.Contains(aActor));
|
||||
|
||||
|
@ -51,9 +52,9 @@ Feature::AddActor(ActorChild* aActor)
|
|||
}
|
||||
|
||||
void
|
||||
Feature::RemoveActor(ActorChild* aActor)
|
||||
CacheWorkerHolder::RemoveActor(ActorChild* aActor)
|
||||
{
|
||||
NS_ASSERT_OWNINGTHREAD(Feature);
|
||||
NS_ASSERT_OWNINGTHREAD(CacheWorkerHolder);
|
||||
MOZ_ASSERT(aActor);
|
||||
|
||||
DebugOnly<bool> removed = mActorList.RemoveElement(aActor);
|
||||
|
@ -63,15 +64,15 @@ Feature::RemoveActor(ActorChild* aActor)
|
|||
}
|
||||
|
||||
bool
|
||||
Feature::Notified() const
|
||||
CacheWorkerHolder::Notified() const
|
||||
{
|
||||
return mNotified;
|
||||
}
|
||||
|
||||
bool
|
||||
Feature::Notify(Status aStatus)
|
||||
CacheWorkerHolder::Notify(Status aStatus)
|
||||
{
|
||||
NS_ASSERT_OWNINGTHREAD(Feature);
|
||||
NS_ASSERT_OWNINGTHREAD(CacheWorkerHolder);
|
||||
|
||||
// When the service worker thread is stopped we will get Terminating,
|
||||
// but nothing higher than that. We must shut things down at Terminating.
|
||||
|
@ -90,19 +91,17 @@ Feature::Notify(Status aStatus)
|
|||
return true;
|
||||
}
|
||||
|
||||
Feature::Feature(WorkerPrivate* aWorkerPrivate)
|
||||
CacheWorkerHolder::CacheWorkerHolder(WorkerPrivate* aWorkerPrivate)
|
||||
: mWorkerPrivate(aWorkerPrivate)
|
||||
, mNotified(false)
|
||||
{
|
||||
MOZ_ASSERT(mWorkerPrivate);
|
||||
}
|
||||
|
||||
Feature::~Feature()
|
||||
CacheWorkerHolder::~CacheWorkerHolder()
|
||||
{
|
||||
NS_ASSERT_OWNINGTHREAD(Feature);
|
||||
NS_ASSERT_OWNINGTHREAD(CacheWorkerHolder);
|
||||
MOZ_ASSERT(mActorList.IsEmpty());
|
||||
|
||||
mWorkerPrivate->RemoveFeature(this);
|
||||
}
|
||||
|
||||
} // namespace cache
|
|
@ -4,12 +4,12 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef mozilla_dom_cache_Feature_h
|
||||
#define mozilla_dom_cache_Feature_h
|
||||
#ifndef mozilla_dom_cache_CacheWorkerHolder_h
|
||||
#define mozilla_dom_cache_CacheWorkerHolder_h
|
||||
|
||||
#include "nsISupportsImpl.h"
|
||||
#include "nsTArray.h"
|
||||
#include "WorkerFeature.h"
|
||||
#include "WorkerHolder.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
|
@ -22,33 +22,34 @@ namespace cache {
|
|||
|
||||
class ActorChild;
|
||||
|
||||
class Feature final : public workers::WorkerFeature
|
||||
class CacheWorkerHolder final : public workers::WorkerHolder
|
||||
{
|
||||
public:
|
||||
static already_AddRefed<Feature> Create(workers::WorkerPrivate* aWorkerPrivate);
|
||||
static already_AddRefed<CacheWorkerHolder>
|
||||
Create(workers::WorkerPrivate* aWorkerPrivate);
|
||||
|
||||
void AddActor(ActorChild* aActor);
|
||||
void RemoveActor(ActorChild* aActor);
|
||||
|
||||
bool Notified() const;
|
||||
|
||||
// WorkerFeature methods
|
||||
// WorkerHolder methods
|
||||
virtual bool Notify(workers::Status aStatus) override;
|
||||
|
||||
private:
|
||||
explicit Feature(workers::WorkerPrivate *aWorkerPrivate);
|
||||
~Feature();
|
||||
explicit CacheWorkerHolder(workers::WorkerPrivate *aWorkerPrivate);
|
||||
~CacheWorkerHolder();
|
||||
|
||||
workers::WorkerPrivate* mWorkerPrivate;
|
||||
nsTArray<ActorChild*> mActorList;
|
||||
bool mNotified;
|
||||
|
||||
public:
|
||||
NS_INLINE_DECL_REFCOUNTING(mozilla::dom::cache::Feature)
|
||||
NS_INLINE_DECL_REFCOUNTING(mozilla::dom::cache::CacheWorkerHolder)
|
||||
};
|
||||
|
||||
} // namespace cache
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // mozilla_dom_cache_Feature_h
|
||||
#endif // mozilla_dom_cache_CacheWorkerHolder_h
|
|
@ -8,6 +8,7 @@
|
|||
#define mozilla_dom_cache_Connection_h
|
||||
|
||||
#include "mozIStorageConnection.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
|
|
@ -19,11 +19,11 @@ EXPORTS.mozilla.dom.cache += [
|
|||
'CacheStorageParent.h',
|
||||
'CacheStreamControlChild.h',
|
||||
'CacheStreamControlParent.h',
|
||||
'CacheWorkerHolder.h',
|
||||
'Connection.h',
|
||||
'Context.h',
|
||||
'DBAction.h',
|
||||
'DBSchema.h',
|
||||
'Feature.h',
|
||||
'FileUtils.h',
|
||||
'IPCUtils.h',
|
||||
'Manager.h',
|
||||
|
@ -52,11 +52,11 @@ UNIFIED_SOURCES += [
|
|||
'CacheStorageParent.cpp',
|
||||
'CacheStreamControlChild.cpp',
|
||||
'CacheStreamControlParent.cpp',
|
||||
'CacheWorkerHolder.cpp',
|
||||
'Connection.cpp',
|
||||
'Context.cpp',
|
||||
'DBAction.cpp',
|
||||
'DBSchema.cpp',
|
||||
'Feature.cpp',
|
||||
'FileUtils.cpp',
|
||||
'Manager.cpp',
|
||||
'ManagerId.cpp',
|
||||
|
|
|
@ -107,7 +107,7 @@ WebGLContextLossHandler::WebGLContextLossHandler(WebGLContext* webgl)
|
|||
, mIsTimerRunning(false)
|
||||
, mShouldRunTimerAgain(false)
|
||||
, mIsDisabled(false)
|
||||
, mFeatureAdded(false)
|
||||
, mWorkerHolderAdded(false)
|
||||
#ifdef DEBUG
|
||||
, mThread(NS_GetCurrentThread())
|
||||
#endif
|
||||
|
@ -186,9 +186,9 @@ WebGLContextLossHandler::RunTimer()
|
|||
dom::workers::GetCurrentThreadWorkerPrivate();
|
||||
nsCOMPtr<nsIEventTarget> target = workerPrivate->GetEventTarget();
|
||||
mTimer->SetTarget(new ContextLossWorkerEventTarget(target));
|
||||
if (!mFeatureAdded) {
|
||||
workerPrivate->AddFeature(this);
|
||||
mFeatureAdded = true;
|
||||
if (!mWorkerHolderAdded) {
|
||||
HoldWorker(workerPrivate);
|
||||
mWorkerHolderAdded = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -206,12 +206,12 @@ WebGLContextLossHandler::DisableTimer()
|
|||
|
||||
mIsDisabled = true;
|
||||
|
||||
if (mFeatureAdded) {
|
||||
if (mWorkerHolderAdded) {
|
||||
dom::workers::WorkerPrivate* workerPrivate =
|
||||
dom::workers::GetCurrentThreadWorkerPrivate();
|
||||
MOZ_RELEASE_ASSERT(workerPrivate, "GFX: No private worker created.");
|
||||
workerPrivate->RemoveFeature(this);
|
||||
mFeatureAdded = false;
|
||||
ReleaseWorker();
|
||||
mWorkerHolderAdded = false;
|
||||
}
|
||||
|
||||
// We can't just Cancel() the timer, as sometimes we end up
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
#include "mozilla/WeakPtr.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsISupportsImpl.h"
|
||||
#include "WorkerFeature.h"
|
||||
#include "WorkerHolder.h"
|
||||
|
||||
class nsIThread;
|
||||
class nsITimer;
|
||||
|
@ -18,14 +18,14 @@ class nsITimer;
|
|||
namespace mozilla {
|
||||
class WebGLContext;
|
||||
|
||||
class WebGLContextLossHandler : public dom::workers::WorkerFeature
|
||||
class WebGLContextLossHandler : public dom::workers::WorkerHolder
|
||||
{
|
||||
WeakPtr<WebGLContext> mWeakWebGL;
|
||||
nsCOMPtr<nsITimer> mTimer;
|
||||
bool mIsTimerRunning;
|
||||
bool mShouldRunTimerAgain;
|
||||
bool mIsDisabled;
|
||||
bool mFeatureAdded;
|
||||
bool mWorkerHolderAdded;
|
||||
#ifdef DEBUG
|
||||
nsIThread* mThread;
|
||||
#endif
|
||||
|
|
|
@ -314,7 +314,7 @@ private:
|
|||
};
|
||||
|
||||
class ConsoleRunnable : public Runnable
|
||||
, public WorkerFeature
|
||||
, public WorkerHolder
|
||||
, public StructuredCloneHolderBase
|
||||
{
|
||||
public:
|
||||
|
@ -382,7 +382,7 @@ private:
|
|||
return false;
|
||||
}
|
||||
|
||||
if (NS_WARN_IF(!mWorkerPrivate->AddFeature(this))) {
|
||||
if (NS_WARN_IF(!HoldWorker(mWorkerPrivate))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -427,7 +427,7 @@ private:
|
|||
mRunnable->ReleaseData();
|
||||
mRunnable->mConsole = nullptr;
|
||||
|
||||
aWorkerPrivate->RemoveFeature(mRunnable);
|
||||
mRunnable->ReleaseWorker();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -229,7 +229,7 @@ FetchRequest(nsIGlobalObject* aGlobal, const RequestOrUSVString& aInput,
|
|||
|
||||
RefPtr<WorkerFetchResolver> resolver = WorkerFetchResolver::Create(worker, p);
|
||||
if (!resolver) {
|
||||
NS_WARNING("Could not add WorkerFetchResolver feature to worker");
|
||||
NS_WARNING("Could not add WorkerFetchResolver workerHolder to worker");
|
||||
aRv.Throw(NS_ERROR_DOM_ABORT_ERR);
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -405,7 +405,7 @@ WorkerFetchResolver::OnResponseEnd()
|
|||
RefPtr<WorkerFetchResponseEndControlRunnable> cr =
|
||||
new WorkerFetchResponseEndControlRunnable(mPromiseProxy);
|
||||
// This can fail if the worker thread is canceled or killed causing
|
||||
// the PromiseWorkerProxy to give up its WorkerFeature immediately,
|
||||
// the PromiseWorkerProxy to give up its WorkerHolder immediately,
|
||||
// allowing the worker thread to become Dead.
|
||||
if (!cr->Dispatch()) {
|
||||
NS_WARNING("Failed to dispatch WorkerFetchResponseEndControlRunnable");
|
||||
|
@ -753,7 +753,7 @@ public:
|
|||
nonconstResult);
|
||||
if (!r->Dispatch()) {
|
||||
// XXXcatalinb: The worker is shutting down, the pump will be canceled
|
||||
// by FetchBodyFeature::Notify.
|
||||
// by FetchBodyWorkerHolder::Notify.
|
||||
NS_WARNING("Could not dispatch ConsumeBodyRunnable");
|
||||
// Return failure so that aResult is freed.
|
||||
return NS_ERROR_FAILURE;
|
||||
|
@ -819,20 +819,20 @@ public:
|
|||
} // namespace
|
||||
|
||||
template <class Derived>
|
||||
class FetchBodyFeature final : public workers::WorkerFeature
|
||||
class FetchBodyWorkerHolder final : public workers::WorkerHolder
|
||||
{
|
||||
// This is addrefed before the feature is created, and is released in ContinueConsumeBody()
|
||||
// so we can hold a rawptr.
|
||||
// This is addrefed before the workerHolder is created, and is released in
|
||||
// ContinueConsumeBody() so we can hold a rawptr.
|
||||
FetchBody<Derived>* mBody;
|
||||
bool mWasNotified;
|
||||
|
||||
public:
|
||||
explicit FetchBodyFeature(FetchBody<Derived>* aBody)
|
||||
explicit FetchBodyWorkerHolder(FetchBody<Derived>* aBody)
|
||||
: mBody(aBody)
|
||||
, mWasNotified(false)
|
||||
{ }
|
||||
|
||||
~FetchBodyFeature()
|
||||
~FetchBodyWorkerHolder()
|
||||
{ }
|
||||
|
||||
bool Notify(workers::Status aStatus) override
|
||||
|
@ -848,7 +848,7 @@ public:
|
|||
|
||||
template <class Derived>
|
||||
FetchBody<Derived>::FetchBody()
|
||||
: mFeature(nullptr)
|
||||
: mWorkerHolder(nullptr)
|
||||
, mBodyUsed(false)
|
||||
#ifdef DEBUG
|
||||
, mReadDone(false)
|
||||
|
@ -875,8 +875,8 @@ FetchBody<Derived>::~FetchBody()
|
|||
|
||||
// Returns true if addref succeeded.
|
||||
// Always succeeds on main thread.
|
||||
// May fail on worker if RegisterFeature() fails. In that case, it will release
|
||||
// the object before returning false.
|
||||
// May fail on worker if RegisterWorkerHolder() fails. In that case, it will
|
||||
// release the object before returning false.
|
||||
template <class Derived>
|
||||
bool
|
||||
FetchBody<Derived>::AddRefObject()
|
||||
|
@ -884,8 +884,8 @@ FetchBody<Derived>::AddRefObject()
|
|||
AssertIsOnTargetThread();
|
||||
DerivedClass()->AddRef();
|
||||
|
||||
if (mWorkerPrivate && !mFeature) {
|
||||
if (!RegisterFeature()) {
|
||||
if (mWorkerPrivate && !mWorkerHolder) {
|
||||
if (!RegisterWorkerHolder()) {
|
||||
ReleaseObject();
|
||||
return false;
|
||||
}
|
||||
|
@ -899,8 +899,8 @@ FetchBody<Derived>::ReleaseObject()
|
|||
{
|
||||
AssertIsOnTargetThread();
|
||||
|
||||
if (mWorkerPrivate && mFeature) {
|
||||
UnregisterFeature();
|
||||
if (mWorkerPrivate && mWorkerHolder) {
|
||||
UnregisterWorkerHolder();
|
||||
}
|
||||
|
||||
DerivedClass()->Release();
|
||||
|
@ -908,16 +908,16 @@ FetchBody<Derived>::ReleaseObject()
|
|||
|
||||
template <class Derived>
|
||||
bool
|
||||
FetchBody<Derived>::RegisterFeature()
|
||||
FetchBody<Derived>::RegisterWorkerHolder()
|
||||
{
|
||||
MOZ_ASSERT(mWorkerPrivate);
|
||||
mWorkerPrivate->AssertIsOnWorkerThread();
|
||||
MOZ_ASSERT(!mFeature);
|
||||
mFeature = new FetchBodyFeature<Derived>(this);
|
||||
MOZ_ASSERT(!mWorkerHolder);
|
||||
mWorkerHolder = new FetchBodyWorkerHolder<Derived>(this);
|
||||
|
||||
if (!mWorkerPrivate->AddFeature(mFeature)) {
|
||||
NS_WARNING("Failed to add feature");
|
||||
mFeature = nullptr;
|
||||
if (!mWorkerHolder->HoldWorker(mWorkerPrivate)) {
|
||||
NS_WARNING("Failed to add workerHolder");
|
||||
mWorkerHolder = nullptr;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -926,14 +926,14 @@ FetchBody<Derived>::RegisterFeature()
|
|||
|
||||
template <class Derived>
|
||||
void
|
||||
FetchBody<Derived>::UnregisterFeature()
|
||||
FetchBody<Derived>::UnregisterWorkerHolder()
|
||||
{
|
||||
MOZ_ASSERT(mWorkerPrivate);
|
||||
mWorkerPrivate->AssertIsOnWorkerThread();
|
||||
MOZ_ASSERT(mFeature);
|
||||
MOZ_ASSERT(mWorkerHolder);
|
||||
|
||||
mWorkerPrivate->RemoveFeature(mFeature);
|
||||
mFeature = nullptr;
|
||||
mWorkerHolder->ReleaseWorker();
|
||||
mWorkerHolder = nullptr;
|
||||
}
|
||||
|
||||
template <class Derived>
|
||||
|
@ -952,7 +952,7 @@ nsresult
|
|||
FetchBody<Derived>::BeginConsumeBody()
|
||||
{
|
||||
AssertIsOnTargetThread();
|
||||
MOZ_ASSERT(!mFeature);
|
||||
MOZ_ASSERT(!mWorkerHolder);
|
||||
MOZ_ASSERT(mConsumePromise);
|
||||
|
||||
// The FetchBody is not thread-safe refcounted. We addref it here and release
|
||||
|
@ -1036,7 +1036,7 @@ FetchBody<Derived>::ContinueConsumeBody(nsresult aStatus, uint32_t aResultLength
|
|||
// sync with a body read.
|
||||
MOZ_ASSERT(mBodyUsed);
|
||||
MOZ_ASSERT(!mReadDone);
|
||||
MOZ_ASSERT_IF(mWorkerPrivate, mFeature);
|
||||
MOZ_ASSERT_IF(mWorkerPrivate, mWorkerHolder);
|
||||
#ifdef DEBUG
|
||||
mReadDone = true;
|
||||
#endif
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
#include "mozilla/ErrorResult.h"
|
||||
#include "mozilla/dom/Promise.h"
|
||||
#include "mozilla/dom/RequestBinding.h"
|
||||
#include "mozilla/dom/workers/bindings/WorkerFeature.h"
|
||||
#include "mozilla/dom/workers/bindings/WorkerHolder.h"
|
||||
|
||||
class nsIGlobalObject;
|
||||
|
||||
|
@ -63,7 +63,7 @@ ExtractByteStreamFromBody(const ArrayBufferOrArrayBufferViewOrBlobOrFormDataOrUS
|
|||
nsCString& aContentType,
|
||||
uint64_t& aContentLength);
|
||||
|
||||
template <class Derived> class FetchBodyFeature;
|
||||
template <class Derived> class FetchBodyWorkerHolder;
|
||||
|
||||
/*
|
||||
* FetchBody's body consumption uses nsIInputStreamPump to read from the
|
||||
|
@ -155,7 +155,7 @@ public:
|
|||
|
||||
// Set when consuming the body is attempted on a worker.
|
||||
// Unset when consumption is done/aborted.
|
||||
nsAutoPtr<workers::WorkerFeature> mFeature;
|
||||
nsAutoPtr<workers::WorkerHolder> mWorkerHolder;
|
||||
|
||||
protected:
|
||||
FetchBody();
|
||||
|
@ -193,10 +193,10 @@ private:
|
|||
ReleaseObject();
|
||||
|
||||
bool
|
||||
RegisterFeature();
|
||||
RegisterWorkerHolder();
|
||||
|
||||
void
|
||||
UnregisterFeature();
|
||||
UnregisterWorkerHolder();
|
||||
|
||||
bool
|
||||
IsOnTargetThread()
|
||||
|
|
|
@ -903,7 +903,7 @@ protected:
|
|||
};
|
||||
|
||||
class WorkerPermissionChallenge final : public Runnable
|
||||
, public WorkerFeature
|
||||
, public WorkerHolder
|
||||
{
|
||||
public:
|
||||
WorkerPermissionChallenge(WorkerPrivate* aWorkerPrivate,
|
||||
|
@ -963,7 +963,7 @@ public:
|
|||
mActor = nullptr;
|
||||
|
||||
mWorkerPrivate->AssertIsOnWorkerThread();
|
||||
mWorkerPrivate->RemoveFeature(this);
|
||||
ReleaseWorker();
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -1415,7 +1415,7 @@ BackgroundFactoryRequestChild::RecvPermissionChallenge(
|
|||
new WorkerPermissionChallenge(workerPrivate, this, mFactory,
|
||||
aPrincipalInfo);
|
||||
|
||||
if (NS_WARN_IF(!workerPrivate->AddFeature(challenge))) {
|
||||
if (NS_WARN_IF(!challenge->HoldWorker(workerPrivate))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
#include "nsPIDOMWindow.h"
|
||||
#include "nsString.h"
|
||||
#include "ReportInternalError.h"
|
||||
#include "WorkerFeature.h"
|
||||
#include "WorkerHolder.h"
|
||||
#include "WorkerPrivate.h"
|
||||
|
||||
// Include this last to avoid path problems on Windows.
|
||||
|
@ -461,19 +461,19 @@ IDBRequest::PreHandleEvent(EventChainPreVisitor& aVisitor)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
class IDBOpenDBRequest::WorkerFeature final
|
||||
: public mozilla::dom::workers::WorkerFeature
|
||||
class IDBOpenDBRequest::WorkerHolder final
|
||||
: public mozilla::dom::workers::WorkerHolder
|
||||
{
|
||||
WorkerPrivate* mWorkerPrivate;
|
||||
#ifdef DEBUG
|
||||
// This is only here so that assertions work in the destructor even if
|
||||
// NoteAddFeatureFailed was called.
|
||||
// NoteAddWorkerHolderFailed was called.
|
||||
WorkerPrivate* mWorkerPrivateDEBUG;
|
||||
#endif
|
||||
|
||||
public:
|
||||
explicit
|
||||
WorkerFeature(WorkerPrivate* aWorkerPrivate)
|
||||
WorkerHolder(WorkerPrivate* aWorkerPrivate)
|
||||
: mWorkerPrivate(aWorkerPrivate)
|
||||
#ifdef DEBUG
|
||||
, mWorkerPrivateDEBUG(aWorkerPrivate)
|
||||
|
@ -482,24 +482,20 @@ public:
|
|||
MOZ_ASSERT(aWorkerPrivate);
|
||||
aWorkerPrivate->AssertIsOnWorkerThread();
|
||||
|
||||
MOZ_COUNT_CTOR(IDBOpenDBRequest::WorkerFeature);
|
||||
MOZ_COUNT_CTOR(IDBOpenDBRequest::WorkerHolder);
|
||||
}
|
||||
|
||||
~WorkerFeature()
|
||||
~WorkerHolder()
|
||||
{
|
||||
#ifdef DEBUG
|
||||
mWorkerPrivateDEBUG->AssertIsOnWorkerThread();
|
||||
#endif
|
||||
|
||||
MOZ_COUNT_DTOR(IDBOpenDBRequest::WorkerFeature);
|
||||
|
||||
if (mWorkerPrivate) {
|
||||
mWorkerPrivate->RemoveFeature(this);
|
||||
}
|
||||
MOZ_COUNT_DTOR(IDBOpenDBRequest::WorkerHolder);
|
||||
}
|
||||
|
||||
void
|
||||
NoteAddFeatureFailed()
|
||||
NoteAddWorkerHolderFailed()
|
||||
{
|
||||
MOZ_ASSERT(mWorkerPrivate);
|
||||
mWorkerPrivate->AssertIsOnWorkerThread();
|
||||
|
@ -577,13 +573,13 @@ IDBOpenDBRequest::CreateForJS(JSContext* aCx,
|
|||
|
||||
workerPrivate->AssertIsOnWorkerThread();
|
||||
|
||||
nsAutoPtr<WorkerFeature> feature(new WorkerFeature(workerPrivate));
|
||||
if (NS_WARN_IF(!workerPrivate->AddFeature(feature))) {
|
||||
feature->NoteAddFeatureFailed();
|
||||
nsAutoPtr<WorkerHolder> workerHolder(new WorkerHolder(workerPrivate));
|
||||
if (NS_WARN_IF(!workerHolder->HoldWorker(workerPrivate))) {
|
||||
workerHolder->NoteAddWorkerHolderFailed();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
request->mWorkerFeature = Move(feature);
|
||||
request->mWorkerHolder = Move(workerHolder);
|
||||
}
|
||||
|
||||
return request.forget();
|
||||
|
@ -603,11 +599,11 @@ void
|
|||
IDBOpenDBRequest::NoteComplete()
|
||||
{
|
||||
AssertIsOnOwningThread();
|
||||
MOZ_ASSERT_IF(!NS_IsMainThread(), mWorkerFeature);
|
||||
MOZ_ASSERT_IF(!NS_IsMainThread(), mWorkerHolder);
|
||||
|
||||
// If we have a WorkerFeature installed on the worker then nulling this out
|
||||
// If we have a WorkerHolder installed on the worker then nulling this out
|
||||
// will uninstall it from the worker.
|
||||
mWorkerFeature = nullptr;
|
||||
mWorkerHolder = nullptr;
|
||||
}
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_CLASS(IDBOpenDBRequest)
|
||||
|
@ -650,7 +646,7 @@ IDBOpenDBRequest::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
|||
|
||||
bool
|
||||
IDBOpenDBRequest::
|
||||
WorkerFeature::Notify(Status aStatus)
|
||||
WorkerHolder::Notify(Status aStatus)
|
||||
{
|
||||
MOZ_ASSERT(mWorkerPrivate);
|
||||
mWorkerPrivate->AssertIsOnWorkerThread();
|
||||
|
|
|
@ -226,12 +226,12 @@ protected:
|
|||
class IDBOpenDBRequest final
|
||||
: public IDBRequest
|
||||
{
|
||||
class WorkerFeature;
|
||||
class WorkerHolder;
|
||||
|
||||
// Only touched on the owning thread.
|
||||
RefPtr<IDBFactory> mFactory;
|
||||
|
||||
nsAutoPtr<WorkerFeature> mWorkerFeature;
|
||||
nsAutoPtr<WorkerHolder> mWorkerHolder;
|
||||
|
||||
const bool mFileHandleDisabled;
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
#include "nsTHashtable.h"
|
||||
#include "ProfilerHelpers.h"
|
||||
#include "ReportInternalError.h"
|
||||
#include "WorkerFeature.h"
|
||||
#include "WorkerHolder.h"
|
||||
#include "WorkerPrivate.h"
|
||||
|
||||
// Include this last to avoid path problems on Windows.
|
||||
|
@ -35,8 +35,8 @@ using namespace mozilla::dom::indexedDB;
|
|||
using namespace mozilla::dom::workers;
|
||||
using namespace mozilla::ipc;
|
||||
|
||||
class IDBTransaction::WorkerFeature final
|
||||
: public mozilla::dom::workers::WorkerFeature
|
||||
class IDBTransaction::WorkerHolder final
|
||||
: public mozilla::dom::workers::WorkerHolder
|
||||
{
|
||||
WorkerPrivate* mWorkerPrivate;
|
||||
|
||||
|
@ -45,7 +45,7 @@ class IDBTransaction::WorkerFeature final
|
|||
IDBTransaction* mTransaction;
|
||||
|
||||
public:
|
||||
WorkerFeature(WorkerPrivate* aWorkerPrivate, IDBTransaction* aTransaction)
|
||||
WorkerHolder(WorkerPrivate* aWorkerPrivate, IDBTransaction* aTransaction)
|
||||
: mWorkerPrivate(aWorkerPrivate)
|
||||
, mTransaction(aTransaction)
|
||||
{
|
||||
|
@ -54,16 +54,14 @@ public:
|
|||
aWorkerPrivate->AssertIsOnWorkerThread();
|
||||
aTransaction->AssertIsOnOwningThread();
|
||||
|
||||
MOZ_COUNT_CTOR(IDBTransaction::WorkerFeature);
|
||||
MOZ_COUNT_CTOR(IDBTransaction::WorkerHolder);
|
||||
}
|
||||
|
||||
~WorkerFeature()
|
||||
~WorkerHolder()
|
||||
{
|
||||
mWorkerPrivate->AssertIsOnWorkerThread();
|
||||
|
||||
MOZ_COUNT_DTOR(IDBTransaction::WorkerFeature);
|
||||
|
||||
mWorkerPrivate->RemoveFeature(this);
|
||||
MOZ_COUNT_DTOR(IDBTransaction::WorkerHolder);
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -241,8 +239,8 @@ IDBTransaction::Create(JSContext* aCx, IDBDatabase* aDatabase,
|
|||
|
||||
workerPrivate->AssertIsOnWorkerThread();
|
||||
|
||||
transaction->mWorkerFeature = new WorkerFeature(workerPrivate, transaction);
|
||||
MOZ_ALWAYS_TRUE(workerPrivate->AddFeature(transaction->mWorkerFeature));
|
||||
transaction->mWorkerHolder = new WorkerHolder(workerPrivate, transaction);
|
||||
MOZ_ALWAYS_TRUE(transaction->mWorkerHolder->HoldWorker(workerPrivate));
|
||||
}
|
||||
|
||||
return transaction.forget();
|
||||
|
@ -786,8 +784,8 @@ IDBTransaction::FireCompleteOrAbortEvents(nsresult aResult)
|
|||
mFiredCompleteOrAbort = true;
|
||||
#endif
|
||||
|
||||
// Make sure we drop the WorkerFeature when this function completes.
|
||||
nsAutoPtr<WorkerFeature> workerFeature = Move(mWorkerFeature);
|
||||
// Make sure we drop the WorkerHolder when this function completes.
|
||||
nsAutoPtr<WorkerHolder> workerHolder = Move(mWorkerHolder);
|
||||
|
||||
nsCOMPtr<nsIDOMEvent> event;
|
||||
if (NS_SUCCEEDED(aResult)) {
|
||||
|
@ -1030,7 +1028,7 @@ IDBTransaction::Run()
|
|||
|
||||
bool
|
||||
IDBTransaction::
|
||||
WorkerFeature::Notify(Status aStatus)
|
||||
WorkerHolder::Notify(Status aStatus)
|
||||
{
|
||||
MOZ_ASSERT(mWorkerPrivate);
|
||||
mWorkerPrivate->AssertIsOnWorkerThread();
|
||||
|
|
|
@ -50,8 +50,8 @@ class IDBTransaction final
|
|||
friend class indexedDB::BackgroundCursorChild;
|
||||
friend class indexedDB::BackgroundRequestChild;
|
||||
|
||||
class WorkerFeature;
|
||||
friend class WorkerFeature;
|
||||
class WorkerHolder;
|
||||
friend class WorkerHolder;
|
||||
|
||||
public:
|
||||
enum Mode
|
||||
|
@ -80,7 +80,7 @@ private:
|
|||
nsTArray<nsString> mObjectStoreNames;
|
||||
nsTArray<RefPtr<IDBObjectStore>> mObjectStores;
|
||||
nsTArray<RefPtr<IDBObjectStore>> mDeletedObjectStores;
|
||||
nsAutoPtr<WorkerFeature> mWorkerFeature;
|
||||
nsAutoPtr<WorkerHolder> mWorkerHolder;
|
||||
|
||||
// Tagged with mMode. If mMode is VERSION_CHANGE then mBackgroundActor will be
|
||||
// a BackgroundVersionChangeTransactionChild. Otherwise it will be a
|
||||
|
|
|
@ -195,16 +195,16 @@ NS_IMPL_RELEASE_INHERITED(MessagePort, DOMEventTargetHelper)
|
|||
|
||||
namespace {
|
||||
|
||||
class MessagePortFeature final : public workers::WorkerFeature
|
||||
class MessagePortWorkerHolder final : public workers::WorkerHolder
|
||||
{
|
||||
MessagePort* mPort;
|
||||
|
||||
public:
|
||||
explicit MessagePortFeature(MessagePort* aPort)
|
||||
explicit MessagePortWorkerHolder(MessagePort* aPort)
|
||||
: mPort(aPort)
|
||||
{
|
||||
MOZ_ASSERT(aPort);
|
||||
MOZ_COUNT_CTOR(MessagePortFeature);
|
||||
MOZ_COUNT_CTOR(MessagePortWorkerHolder);
|
||||
}
|
||||
|
||||
virtual bool Notify(workers::Status aStatus) override
|
||||
|
@ -219,9 +219,9 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
~MessagePortFeature()
|
||||
~MessagePortWorkerHolder()
|
||||
{
|
||||
MOZ_COUNT_DTOR(MessagePortFeature);
|
||||
MOZ_COUNT_DTOR(MessagePortWorkerHolder);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -287,7 +287,7 @@ MessagePort::MessagePort(nsIGlobalObject* aGlobal)
|
|||
MessagePort::~MessagePort()
|
||||
{
|
||||
CloseForced();
|
||||
MOZ_ASSERT(!mWorkerFeature);
|
||||
MOZ_ASSERT(!mWorkerHolder);
|
||||
}
|
||||
|
||||
/* static */ already_AddRefed<MessagePort>
|
||||
|
@ -340,7 +340,7 @@ MessagePort::Initialize(const nsID& aUUID,
|
|||
|
||||
if (mNeutered) {
|
||||
// If this port is neutered we don't want to keep it alive artificially nor
|
||||
// we want to add listeners or workerFeatures.
|
||||
// we want to add listeners or workerWorkerHolders.
|
||||
mState = eStateDisentangled;
|
||||
return;
|
||||
}
|
||||
|
@ -357,15 +357,15 @@ MessagePort::Initialize(const nsID& aUUID,
|
|||
if (!NS_IsMainThread()) {
|
||||
WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
|
||||
MOZ_ASSERT(workerPrivate);
|
||||
MOZ_ASSERT(!mWorkerFeature);
|
||||
MOZ_ASSERT(!mWorkerHolder);
|
||||
|
||||
nsAutoPtr<WorkerFeature> feature(new MessagePortFeature(this));
|
||||
if (NS_WARN_IF(!workerPrivate->AddFeature(feature))) {
|
||||
nsAutoPtr<WorkerHolder> workerHolder(new MessagePortWorkerHolder(this));
|
||||
if (NS_WARN_IF(!workerHolder->HoldWorker(workerPrivate))) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return;
|
||||
}
|
||||
|
||||
mWorkerFeature = Move(feature);
|
||||
mWorkerHolder = Move(workerHolder);
|
||||
} else if (GetOwner()) {
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
MOZ_ASSERT(GetOwner()->IsInnerWindow());
|
||||
|
@ -912,13 +912,8 @@ MessagePort::UpdateMustKeepAlive()
|
|||
mIsKeptAlive) {
|
||||
mIsKeptAlive = false;
|
||||
|
||||
if (mWorkerFeature) {
|
||||
WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
|
||||
MOZ_ASSERT(workerPrivate);
|
||||
|
||||
workerPrivate->RemoveFeature(mWorkerFeature);
|
||||
mWorkerFeature = nullptr;
|
||||
}
|
||||
// The DTOR of this WorkerHolder will release the worker for us.
|
||||
mWorkerHolder = nullptr;
|
||||
|
||||
if (NS_IsMainThread()) {
|
||||
nsCOMPtr<nsIObserverService> obs =
|
||||
|
|
|
@ -29,7 +29,7 @@ class PostMessageRunnable;
|
|||
class SharedMessagePortMessage;
|
||||
|
||||
namespace workers {
|
||||
class WorkerFeature;
|
||||
class WorkerHolder;
|
||||
} // namespace workers
|
||||
|
||||
class MessagePort final : public DOMEventTargetHelper
|
||||
|
@ -164,7 +164,7 @@ private:
|
|||
return mIsKeptAlive;
|
||||
}
|
||||
|
||||
nsAutoPtr<workers::WorkerFeature> mWorkerFeature;
|
||||
nsAutoPtr<workers::WorkerHolder> mWorkerHolder;
|
||||
|
||||
RefPtr<PostMessageRunnable> mPostMessageRunnable;
|
||||
|
||||
|
|
|
@ -458,9 +458,10 @@ public:
|
|||
}
|
||||
|
||||
// This is only required because Gecko runs script in a worker's onclose
|
||||
// handler (non-standard, Bug 790919) where calls to AddFeature() will fail.
|
||||
// Due to non-standardness and added complications if we decide to support
|
||||
// this, attempts to create a Notification in onclose just throw exceptions.
|
||||
// handler (non-standard, Bug 790919) where calls to HoldWorker() will
|
||||
// fail. Due to non-standardness and added complications if we decide to
|
||||
// support this, attempts to create a Notification in onclose just throw
|
||||
// exceptions.
|
||||
bool
|
||||
Initialized()
|
||||
{
|
||||
|
@ -1199,7 +1200,7 @@ Notification::~Notification()
|
|||
mData.setUndefined();
|
||||
mozilla::DropJSObjects(this);
|
||||
AssertIsOnTargetThread();
|
||||
MOZ_ASSERT(!mFeature);
|
||||
MOZ_ASSERT(!mWorkerHolder);
|
||||
MOZ_ASSERT(!mTempRef);
|
||||
}
|
||||
|
||||
|
@ -2440,10 +2441,10 @@ bool
|
|||
Notification::AddRefObject()
|
||||
{
|
||||
AssertIsOnTargetThread();
|
||||
MOZ_ASSERT_IF(mWorkerPrivate && !mFeature, mTaskCount == 0);
|
||||
MOZ_ASSERT_IF(mWorkerPrivate && mFeature, mTaskCount > 0);
|
||||
if (mWorkerPrivate && !mFeature) {
|
||||
if (!RegisterFeature()) {
|
||||
MOZ_ASSERT_IF(mWorkerPrivate && !mWorkerHolder, mTaskCount == 0);
|
||||
MOZ_ASSERT_IF(mWorkerPrivate && mWorkerHolder, mTaskCount > 0);
|
||||
if (mWorkerPrivate && !mWorkerHolder) {
|
||||
if (!RegisterWorkerHolder()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -2457,16 +2458,16 @@ Notification::ReleaseObject()
|
|||
{
|
||||
AssertIsOnTargetThread();
|
||||
MOZ_ASSERT(mTaskCount > 0);
|
||||
MOZ_ASSERT_IF(mWorkerPrivate, mFeature);
|
||||
MOZ_ASSERT_IF(mWorkerPrivate, mWorkerHolder);
|
||||
|
||||
--mTaskCount;
|
||||
if (mWorkerPrivate && mTaskCount == 0) {
|
||||
UnregisterFeature();
|
||||
UnregisterWorkerHolder();
|
||||
}
|
||||
Release();
|
||||
}
|
||||
|
||||
NotificationFeature::NotificationFeature(Notification* aNotification)
|
||||
NotificationWorkerHolder::NotificationWorkerHolder(Notification* aNotification)
|
||||
: mNotification(aNotification)
|
||||
{
|
||||
MOZ_ASSERT(mNotification->mWorkerPrivate);
|
||||
|
@ -2514,7 +2515,7 @@ class CloseNotificationRunnable final
|
|||
};
|
||||
|
||||
bool
|
||||
NotificationFeature::Notify(Status aStatus)
|
||||
NotificationWorkerHolder::Notify(Status aStatus)
|
||||
{
|
||||
if (aStatus >= Canceling) {
|
||||
// CloseNotificationRunnable blocks the worker by pushing a sync event loop
|
||||
|
@ -2557,28 +2558,26 @@ NotificationFeature::Notify(Status aStatus)
|
|||
}
|
||||
|
||||
bool
|
||||
Notification::RegisterFeature()
|
||||
Notification::RegisterWorkerHolder()
|
||||
{
|
||||
MOZ_ASSERT(mWorkerPrivate);
|
||||
mWorkerPrivate->AssertIsOnWorkerThread();
|
||||
MOZ_ASSERT(!mFeature);
|
||||
mFeature = MakeUnique<NotificationFeature>(this);
|
||||
bool added = mWorkerPrivate->AddFeature(mFeature.get());
|
||||
if (!added) {
|
||||
mFeature = nullptr;
|
||||
MOZ_ASSERT(!mWorkerHolder);
|
||||
mWorkerHolder = MakeUnique<NotificationWorkerHolder>(this);
|
||||
if (NS_WARN_IF(!mWorkerHolder->HoldWorker(mWorkerPrivate))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return added;
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
Notification::UnregisterFeature()
|
||||
Notification::UnregisterWorkerHolder()
|
||||
{
|
||||
MOZ_ASSERT(mWorkerPrivate);
|
||||
mWorkerPrivate->AssertIsOnWorkerThread();
|
||||
MOZ_ASSERT(mFeature);
|
||||
mWorkerPrivate->RemoveFeature(mFeature.get());
|
||||
mFeature = nullptr;
|
||||
MOZ_ASSERT(mWorkerHolder);
|
||||
mWorkerHolder = nullptr;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
#include "mozilla/DOMEventTargetHelper.h"
|
||||
#include "mozilla/UniquePtr.h"
|
||||
#include "mozilla/dom/NotificationBinding.h"
|
||||
#include "mozilla/dom/workers/bindings/WorkerFeature.h"
|
||||
#include "mozilla/dom/workers/bindings/WorkerHolder.h"
|
||||
|
||||
#include "nsIObserver.h"
|
||||
|
||||
|
@ -36,14 +36,14 @@ namespace workers {
|
|||
} // namespace workers
|
||||
|
||||
class Notification;
|
||||
class NotificationFeature final : public workers::WorkerFeature
|
||||
class NotificationWorkerHolder final : public workers::WorkerHolder
|
||||
{
|
||||
// Since the feature is strongly held by a Notification, it is ok to hold
|
||||
// a raw pointer here.
|
||||
Notification* mNotification;
|
||||
|
||||
public:
|
||||
explicit NotificationFeature(Notification* aNotification);
|
||||
explicit NotificationWorkerHolder(Notification* aNotification);
|
||||
|
||||
bool
|
||||
Notify(workers::Status aStatus) override;
|
||||
|
@ -448,13 +448,13 @@ private:
|
|||
return NS_IsMainThread() == !mWorkerPrivate;
|
||||
}
|
||||
|
||||
bool RegisterFeature();
|
||||
void UnregisterFeature();
|
||||
bool RegisterWorkerHolder();
|
||||
void UnregisterWorkerHolder();
|
||||
|
||||
nsresult ResolveIconAndSoundURL(nsString&, nsString&);
|
||||
|
||||
// Only used for Notifications on Workers, worker thread only.
|
||||
UniquePtr<NotificationFeature> mFeature;
|
||||
UniquePtr<NotificationWorkerHolder> mWorkerHolder;
|
||||
// Target thread only.
|
||||
uint32_t mTaskCount;
|
||||
};
|
||||
|
|
|
@ -2527,7 +2527,7 @@ Promise::AppendCallbacks(PromiseCallback* aResolveCallback,
|
|||
#if defined(DOM_PROMISE_DEPRECATED_REPORTING)
|
||||
// Now that there is a callback, we don't need to report anymore.
|
||||
mHadRejectCallback = true;
|
||||
RemoveFeature();
|
||||
RemoveWorkerHolder();
|
||||
#endif // defined(DOM_PROMISE_DEPRECATED_REPORTING)
|
||||
|
||||
mResolveCallbacks.AppendElement(aResolveCallback);
|
||||
|
@ -2767,10 +2767,9 @@ Promise::Settle(JS::Handle<JS::Value> aValue, PromiseState aState)
|
|||
MOZ_ASSERT(worker);
|
||||
worker->AssertIsOnWorkerThread();
|
||||
|
||||
mFeature = new PromiseReportRejectFeature(this);
|
||||
if (NS_WARN_IF(!worker->AddFeature(mFeature))) {
|
||||
// To avoid a false RemoveFeature().
|
||||
mFeature = nullptr;
|
||||
mWorkerHolder = new PromiseReportRejectWorkerHolder(this);
|
||||
if (NS_WARN_IF(!mWorkerHolder->HoldWorker(worker))) {
|
||||
mWorkerHolder = nullptr;
|
||||
// Worker is shutting down, report rejection immediately since it is
|
||||
// unlikely that reject callbacks will be added after this point.
|
||||
MaybeReportRejectedOnce();
|
||||
|
@ -2819,24 +2818,20 @@ Promise::TriggerPromiseReactions()
|
|||
|
||||
#if defined(DOM_PROMISE_DEPRECATED_REPORTING)
|
||||
void
|
||||
Promise::RemoveFeature()
|
||||
Promise::RemoveWorkerHolder()
|
||||
{
|
||||
NS_ASSERT_OWNINGTHREAD(Promise);
|
||||
|
||||
if (mFeature) {
|
||||
workers::WorkerPrivate* worker = GetCurrentThreadWorkerPrivate();
|
||||
MOZ_ASSERT(worker);
|
||||
worker->RemoveFeature(mFeature);
|
||||
mFeature = nullptr;
|
||||
}
|
||||
// The DTOR of this WorkerHolder will release the worker for us.
|
||||
mWorkerHolder = nullptr;
|
||||
}
|
||||
|
||||
bool
|
||||
PromiseReportRejectFeature::Notify(workers::Status aStatus)
|
||||
PromiseReportRejectWorkerHolder::Notify(workers::Status aStatus)
|
||||
{
|
||||
MOZ_ASSERT(aStatus > workers::Running);
|
||||
mPromise->MaybeReportRejectedOnce();
|
||||
// After this point, `this` has been deleted by RemoveFeature!
|
||||
// After this point, `this` has been deleted by RemoveWorkerHolder!
|
||||
return true;
|
||||
}
|
||||
#endif // defined(DOM_PROMISE_DEPRECATED_REPORTING)
|
||||
|
@ -2971,7 +2966,7 @@ PromiseWorkerProxy::PromiseWorkerProxy(workers::WorkerPrivate* aWorkerPrivate,
|
|||
, mCallbacks(aCallbacks)
|
||||
, mCleanUpLock("cleanUpLock")
|
||||
#ifdef DEBUG
|
||||
, mFeatureAdded(false)
|
||||
, mWorkerHolderAdded(false)
|
||||
#endif
|
||||
{
|
||||
}
|
||||
|
@ -2979,7 +2974,7 @@ PromiseWorkerProxy::PromiseWorkerProxy(workers::WorkerPrivate* aWorkerPrivate,
|
|||
PromiseWorkerProxy::~PromiseWorkerProxy()
|
||||
{
|
||||
MOZ_ASSERT(mCleanedUp);
|
||||
MOZ_ASSERT(!mFeatureAdded);
|
||||
MOZ_ASSERT(!mWorkerHolderAdded);
|
||||
MOZ_ASSERT(!mWorkerPromise);
|
||||
MOZ_ASSERT(!mWorkerPrivate);
|
||||
}
|
||||
|
@ -3007,13 +3002,13 @@ PromiseWorkerProxy::AddRefObject()
|
|||
{
|
||||
MOZ_ASSERT(mWorkerPrivate);
|
||||
mWorkerPrivate->AssertIsOnWorkerThread();
|
||||
MOZ_ASSERT(!mFeatureAdded);
|
||||
if (!mWorkerPrivate->AddFeature(this)) {
|
||||
MOZ_ASSERT(!mWorkerHolderAdded);
|
||||
if (NS_WARN_IF(!HoldWorker(mWorkerPrivate))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
mFeatureAdded = true;
|
||||
mWorkerHolderAdded = true;
|
||||
#endif
|
||||
// Maintain a reference so that we have a valid object to clean up when
|
||||
// removing the feature.
|
||||
|
@ -3032,7 +3027,7 @@ PromiseWorkerProxy::GetWorkerPrivate() const
|
|||
// Safe to check this without a lock since we assert lock ownership on the
|
||||
// main thread above.
|
||||
MOZ_ASSERT(!mCleanedUp);
|
||||
MOZ_ASSERT(mFeatureAdded);
|
||||
MOZ_ASSERT(mWorkerHolderAdded);
|
||||
|
||||
return mWorkerPrivate;
|
||||
}
|
||||
|
@ -3116,7 +3111,8 @@ PromiseWorkerProxy::CleanUp()
|
|||
MutexAutoLock lock(Lock());
|
||||
|
||||
// |mWorkerPrivate| is not safe to use anymore if we have already
|
||||
// cleaned up and RemoveFeature(), so we need to check |mCleanedUp| first.
|
||||
// cleaned up and RemoveWorkerHolder(), so we need to check |mCleanedUp|
|
||||
// first.
|
||||
if (CleanedUp()) {
|
||||
return;
|
||||
}
|
||||
|
@ -3127,10 +3123,10 @@ PromiseWorkerProxy::CleanUp()
|
|||
// Release the Promise and remove the PromiseWorkerProxy from the features of
|
||||
// the worker thread since the Promise has been resolved/rejected or the
|
||||
// worker thread has been cancelled.
|
||||
MOZ_ASSERT(mFeatureAdded);
|
||||
mWorkerPrivate->RemoveFeature(this);
|
||||
MOZ_ASSERT(mWorkerHolderAdded);
|
||||
ReleaseWorker();
|
||||
#ifdef DEBUG
|
||||
mFeatureAdded = false;
|
||||
mWorkerHolderAdded = false;
|
||||
#endif
|
||||
CleanProperties();
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
#define DOM_PROMISE_DEPRECATED_REPORTING !SPIDERMONKEY_PROMISE
|
||||
|
||||
#if defined(DOM_PROMISE_DEPRECATED_REPORTING)
|
||||
#include "mozilla/dom/workers/bindings/WorkerFeature.h"
|
||||
#include "mozilla/dom/workers/bindings/WorkerHolder.h"
|
||||
#endif // defined(DOM_PROMISE_DEPRECATED_REPORTING)
|
||||
|
||||
class nsIGlobalObject;
|
||||
|
@ -48,14 +48,15 @@ class PromiseDebugging;
|
|||
class Promise;
|
||||
|
||||
#if defined(DOM_PROMISE_DEPRECATED_REPORTING)
|
||||
class PromiseReportRejectFeature : public workers::WorkerFeature
|
||||
class PromiseReportRejectWorkerHolder : public workers::WorkerHolder
|
||||
{
|
||||
// PromiseReportRejectFeature is held by an nsAutoPtr on the Promise which
|
||||
// means that this object will be destroyed before the Promise is destroyed.
|
||||
// PromiseReportRejectWorkerHolder is held by an nsAutoPtr on the Promise
|
||||
// which means that this object will be destroyed before the Promise is
|
||||
// destroyed.
|
||||
Promise* MOZ_NON_OWNING_REF mPromise;
|
||||
|
||||
public:
|
||||
explicit PromiseReportRejectFeature(Promise* aPromise)
|
||||
explicit PromiseReportRejectWorkerHolder(Promise* aPromise)
|
||||
: mPromise(aPromise)
|
||||
{
|
||||
MOZ_ASSERT(mPromise);
|
||||
|
@ -84,7 +85,7 @@ class Promise : public nsISupports,
|
|||
friend class PromiseResolverTask;
|
||||
friend class PromiseTask;
|
||||
#if defined(DOM_PROMISE_DEPRECATED_REPORTING)
|
||||
friend class PromiseReportRejectFeature;
|
||||
friend class PromiseReportRejectWorkerHolder;
|
||||
#endif // defined(DOM_PROMISE_DEPRECATED_REPORTING)
|
||||
friend class PromiseWorkerProxy;
|
||||
friend class PromiseWorkerProxyRunnable;
|
||||
|
@ -409,7 +410,7 @@ private:
|
|||
|
||||
void MaybeReportRejectedOnce() {
|
||||
MaybeReportRejected();
|
||||
RemoveFeature();
|
||||
RemoveWorkerHolder();
|
||||
mResult.setUndefined();
|
||||
}
|
||||
#endif // defined(DOM_PROMISE_DEPRECATED_REPORTING)
|
||||
|
@ -464,7 +465,7 @@ private:
|
|||
CreateThenableFunction(JSContext* aCx, Promise* aPromise, uint32_t aTask);
|
||||
|
||||
#if defined(DOM_PROMISE_DEPRECATED_REPORTING)
|
||||
void RemoveFeature();
|
||||
void RemoveWorkerHolder();
|
||||
#endif // defined(DOM_PROMISE_DEPRECATED_REPORTING)
|
||||
|
||||
// Capture the current stack and store it in aTarget. If false is
|
||||
|
@ -503,7 +504,7 @@ private:
|
|||
// needs to know when the worker is shutting down, to report the error on the
|
||||
// console before the worker's context is deleted. This feature is used for
|
||||
// that purpose.
|
||||
nsAutoPtr<PromiseReportRejectFeature> mFeature;
|
||||
nsAutoPtr<PromiseReportRejectWorkerHolder> mWorkerHolder;
|
||||
#endif // defined(DOM_PROMISE_DEPRECATED_REPORTING)
|
||||
|
||||
bool mTaskPending;
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
#include "mozilla/dom/Promise.h"
|
||||
#include "mozilla/dom/PromiseNativeHandler.h"
|
||||
#include "mozilla/dom/StructuredCloneHolder.h"
|
||||
#include "mozilla/dom/workers/bindings/WorkerFeature.h"
|
||||
#include "mozilla/dom/workers/bindings/WorkerHolder.h"
|
||||
#include "nsProxyRelease.h"
|
||||
|
||||
#include "WorkerRunnable.h"
|
||||
|
@ -110,7 +110,7 @@ class WorkerPrivate;
|
|||
// references to it are dropped.
|
||||
|
||||
class PromiseWorkerProxy : public PromiseNativeHandler
|
||||
, public workers::WorkerFeature
|
||||
, public workers::WorkerHolder
|
||||
, public StructuredCloneHolderBase
|
||||
{
|
||||
friend class PromiseWorkerProxyRunnable;
|
||||
|
@ -229,7 +229,7 @@ private:
|
|||
|
||||
#ifdef DEBUG
|
||||
// Maybe get rid of this entirely and rely on mCleanedUp
|
||||
bool mFeatureAdded;
|
||||
bool mWorkerHolderAdded;
|
||||
#endif
|
||||
};
|
||||
} // namespace dom
|
||||
|
|
|
@ -58,7 +58,7 @@
|
|||
#include "mozilla/dom/ScriptSettings.h"
|
||||
#include "mozilla/UniquePtr.h"
|
||||
#include "Principal.h"
|
||||
#include "WorkerFeature.h"
|
||||
#include "WorkerHolder.h"
|
||||
#include "WorkerPrivate.h"
|
||||
#include "WorkerRunnable.h"
|
||||
#include "WorkerScope.h"
|
||||
|
@ -538,7 +538,7 @@ private:
|
|||
|
||||
NS_IMPL_ISUPPORTS(LoaderListener, nsIStreamLoaderObserver, nsIRequestObserver)
|
||||
|
||||
class ScriptLoaderRunnable final : public WorkerFeature
|
||||
class ScriptLoaderRunnable final : public WorkerHolder
|
||||
, public nsIRunnable
|
||||
{
|
||||
friend class ScriptExecutorRunnable;
|
||||
|
@ -1946,7 +1946,7 @@ ScriptExecutorRunnable::ShutdownScriptLoader(JSContext* aCx,
|
|||
}
|
||||
}
|
||||
|
||||
aWorkerPrivate->RemoveFeature(&mScriptLoader);
|
||||
mScriptLoader.ReleaseWorker();
|
||||
aWorkerPrivate->StopSyncLoop(mSyncLoopTarget, aResult);
|
||||
}
|
||||
|
||||
|
@ -1998,7 +1998,7 @@ LoadAllScripts(WorkerPrivate* aWorkerPrivate,
|
|||
|
||||
NS_ASSERTION(aLoadInfos.IsEmpty(), "Should have swapped!");
|
||||
|
||||
if (!aWorkerPrivate->AddFeature(loader)) {
|
||||
if (NS_WARN_IF(!loader->HoldWorker(aWorkerPrivate))) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return;
|
||||
}
|
||||
|
@ -2006,7 +2006,7 @@ LoadAllScripts(WorkerPrivate* aWorkerPrivate,
|
|||
if (NS_FAILED(NS_DispatchToMainThread(loader))) {
|
||||
NS_ERROR("Failed to dispatch!");
|
||||
|
||||
aWorkerPrivate->RemoveFeature(loader);
|
||||
loader->ReleaseWorker();
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -212,14 +212,14 @@ class KeepAliveHandler final
|
|||
// preemptively cleanup if the service worker is timed out and
|
||||
// terminated.
|
||||
class InternalHandler final : public PromiseNativeHandler
|
||||
, public WorkerFeature
|
||||
, public WorkerHolder
|
||||
{
|
||||
nsMainThreadPtrHandle<KeepAliveToken> mKeepAliveToken;
|
||||
|
||||
// Worker thread only
|
||||
WorkerPrivate* mWorkerPrivate;
|
||||
RefPtr<Promise> mPromise;
|
||||
bool mFeatureAdded;
|
||||
bool mWorkerHolderAdded;
|
||||
|
||||
~InternalHandler()
|
||||
{
|
||||
|
@ -227,13 +227,13 @@ class KeepAliveHandler final
|
|||
}
|
||||
|
||||
bool
|
||||
AddFeature()
|
||||
UseWorkerHolder()
|
||||
{
|
||||
MOZ_ASSERT(mWorkerPrivate);
|
||||
mWorkerPrivate->AssertIsOnWorkerThread();
|
||||
MOZ_ASSERT(!mFeatureAdded);
|
||||
mFeatureAdded = mWorkerPrivate->AddFeature(this);
|
||||
return mFeatureAdded;
|
||||
MOZ_ASSERT(!mWorkerHolderAdded);
|
||||
mWorkerHolderAdded = HoldWorker(mWorkerPrivate);
|
||||
return mWorkerHolderAdded;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -244,8 +244,8 @@ class KeepAliveHandler final
|
|||
if (!mPromise) {
|
||||
return;
|
||||
}
|
||||
if (mFeatureAdded) {
|
||||
mWorkerPrivate->RemoveFeature(this);
|
||||
if (mWorkerHolderAdded) {
|
||||
ReleaseWorker();
|
||||
}
|
||||
mPromise = nullptr;
|
||||
mKeepAliveToken = nullptr;
|
||||
|
@ -285,7 +285,7 @@ class KeepAliveHandler final
|
|||
: mKeepAliveToken(aKeepAliveToken)
|
||||
, mWorkerPrivate(aWorkerPrivate)
|
||||
, mPromise(aPromise)
|
||||
, mFeatureAdded(false)
|
||||
, mWorkerHolderAdded(false)
|
||||
{
|
||||
MOZ_ASSERT(mKeepAliveToken);
|
||||
MOZ_ASSERT(mWorkerPrivate);
|
||||
|
@ -302,7 +302,7 @@ class KeepAliveHandler final
|
|||
aWorkerPrivate,
|
||||
aPromise);
|
||||
|
||||
if (NS_WARN_IF(!ref->AddFeature())) {
|
||||
if (NS_WARN_IF(!ref->UseWorkerHolder())) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -518,7 +518,7 @@ private:
|
|||
* with advancing the job queue for install/activate tasks.
|
||||
*/
|
||||
class LifeCycleEventWatcher final : public PromiseNativeHandler,
|
||||
public WorkerFeature
|
||||
public WorkerHolder
|
||||
{
|
||||
WorkerPrivate* mWorkerPrivate;
|
||||
RefPtr<LifeCycleEventCallback> mCallback;
|
||||
|
@ -564,7 +564,7 @@ public:
|
|||
// case the registration/update promise will be rejected
|
||||
// 2. A new service worker is registered which will terminate the current
|
||||
// installing worker.
|
||||
if (NS_WARN_IF(!mWorkerPrivate->AddFeature(this))) {
|
||||
if (NS_WARN_IF(!HoldWorker(mWorkerPrivate))) {
|
||||
NS_WARNING("LifeCycleEventWatcher failed to add feature.");
|
||||
ReportResult(false);
|
||||
return false;
|
||||
|
@ -602,7 +602,7 @@ public:
|
|||
NS_RUNTIMEABORT("Failed to dispatch life cycle event handler.");
|
||||
}
|
||||
|
||||
mWorkerPrivate->RemoveFeature(this);
|
||||
ReleaseWorker();
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -861,7 +861,7 @@ ServiceWorkerRegistrationMainThread::GetPushManager(JSContext* aCx,
|
|||
// Worker Thread implementation
|
||||
|
||||
class ServiceWorkerRegistrationWorkerThread final : public ServiceWorkerRegistration
|
||||
, public WorkerFeature
|
||||
, public WorkerHolder
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
@ -1188,7 +1188,7 @@ ServiceWorkerRegistrationWorkerThread::InitListener()
|
|||
worker->AssertIsOnWorkerThread();
|
||||
|
||||
mListener = new WorkerListener(worker, this);
|
||||
if (!worker->AddFeature(this)) {
|
||||
if (!HoldWorker(worker)) {
|
||||
mListener = nullptr;
|
||||
NS_WARNING("Could not add feature");
|
||||
return;
|
||||
|
@ -1242,12 +1242,12 @@ ServiceWorkerRegistrationWorkerThread::ReleaseListener(Reason aReason)
|
|||
}
|
||||
|
||||
// We can assert worker here, because:
|
||||
// 1) We always AddFeature, so if the worker has shutdown already, we'll have
|
||||
// received Notify and removed it. If AddFeature had failed, mListener will
|
||||
// be null and we won't reach here.
|
||||
// 1) We always HoldWorker, so if the worker has shutdown already, we'll
|
||||
// have received Notify and removed it. If HoldWorker had failed,
|
||||
// mListener will be null and we won't reach here.
|
||||
// 2) Otherwise, worker is still around even if we are going away.
|
||||
mWorkerPrivate->AssertIsOnWorkerThread();
|
||||
mWorkerPrivate->RemoveFeature(this);
|
||||
ReleaseWorker();
|
||||
|
||||
mListener->ClearRegistration();
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
#include "mozilla/DOMEventTargetHelper.h"
|
||||
#include "mozilla/dom/ServiceWorkerBinding.h"
|
||||
#include "mozilla/dom/ServiceWorkerCommon.h"
|
||||
#include "mozilla/dom/workers/bindings/WorkerFeature.h"
|
||||
#include "mozilla/dom/workers/bindings/WorkerHolder.h"
|
||||
#include "nsContentUtils.h" // Required for nsContentUtils::PushEnabled
|
||||
|
||||
// Support for Notification API extension.
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "WorkerHolder.h"
|
||||
#include "WorkerPrivate.h"
|
||||
|
||||
BEGIN_WORKERS_NAMESPACE
|
||||
|
||||
WorkerHolder::WorkerHolder()
|
||||
: mWorkerPrivate(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
WorkerHolder::~WorkerHolder()
|
||||
{
|
||||
ReleaseWorkerInternal();
|
||||
MOZ_ASSERT(mWorkerPrivate == nullptr);
|
||||
}
|
||||
|
||||
bool
|
||||
WorkerHolder::HoldWorker(WorkerPrivate* aWorkerPrivate)
|
||||
{
|
||||
MOZ_ASSERT(aWorkerPrivate);
|
||||
aWorkerPrivate->AssertIsOnWorkerThread();
|
||||
|
||||
if (!aWorkerPrivate->AddHolder(this)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
mWorkerPrivate = aWorkerPrivate;
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
WorkerHolder::ReleaseWorker()
|
||||
{
|
||||
MOZ_ASSERT(mWorkerPrivate);
|
||||
ReleaseWorkerInternal();
|
||||
}
|
||||
|
||||
void
|
||||
WorkerHolder::ReleaseWorkerInternal()
|
||||
{
|
||||
if (mWorkerPrivate) {
|
||||
mWorkerPrivate->RemoveHolder(this);
|
||||
mWorkerPrivate = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
END_WORKERS_NAMESPACE
|
|
@ -4,8 +4,8 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef mozilla_dom_workers_workerfeature_h__
|
||||
#define mozilla_dom_workers_workerfeature_h__
|
||||
#ifndef mozilla_dom_workers_WorkerHolder_h
|
||||
#define mozilla_dom_workers_WorkerHolder_h
|
||||
|
||||
#include "mozilla/dom/workers/Workers.h"
|
||||
|
||||
|
@ -69,14 +69,23 @@ enum Status
|
|||
Dead
|
||||
};
|
||||
|
||||
class WorkerFeature
|
||||
class WorkerHolder
|
||||
{
|
||||
public:
|
||||
virtual ~WorkerFeature() { }
|
||||
WorkerHolder();
|
||||
virtual ~WorkerHolder();
|
||||
|
||||
bool HoldWorker(WorkerPrivate* aWorkerPrivate);
|
||||
void ReleaseWorker();
|
||||
|
||||
virtual bool Notify(Status aStatus) = 0;
|
||||
|
||||
protected:
|
||||
void ReleaseWorkerInternal();
|
||||
|
||||
WorkerPrivate* MOZ_NON_OWNING_REF mWorkerPrivate;
|
||||
};
|
||||
|
||||
END_WORKERS_NAMESPACE
|
||||
|
||||
#endif /* mozilla_dom_workers_workerfeature_h__ */
|
||||
#endif /* mozilla_dom_workers_WorkerHolder_h */
|
|
@ -102,7 +102,7 @@
|
|||
#include "ServiceWorkerWindowClient.h"
|
||||
#include "SharedWorker.h"
|
||||
#include "WorkerDebuggerManager.h"
|
||||
#include "WorkerFeature.h"
|
||||
#include "WorkerHolder.h"
|
||||
#include "WorkerNavigator.h"
|
||||
#include "WorkerRunnable.h"
|
||||
#include "WorkerScope.h"
|
||||
|
@ -4548,7 +4548,7 @@ WorkerPrivate::DoRunLoop(JSContext* aCx)
|
|||
|
||||
// If the close handler has finished and all features are done then we can
|
||||
// kill this thread.
|
||||
if (currentStatus != Running && !HasActiveFeatures()) {
|
||||
if (currentStatus != Running && !HasActiveHolders()) {
|
||||
if (mCloseHandlerFinished && currentStatus != Killing) {
|
||||
NotifyInternal(aCx, Killing);
|
||||
MOZ_ASSERT(!JS_IsExceptionPending(aCx));
|
||||
|
@ -5252,7 +5252,7 @@ WorkerPrivate::RemoveChildWorker(ParentType* aChildWorker)
|
|||
}
|
||||
|
||||
bool
|
||||
WorkerPrivate::AddFeature(WorkerFeature* aFeature)
|
||||
WorkerPrivate::AddHolder(WorkerHolder* aHolder)
|
||||
{
|
||||
AssertIsOnWorkerThread();
|
||||
|
||||
|
@ -5264,31 +5264,31 @@ WorkerPrivate::AddFeature(WorkerFeature* aFeature)
|
|||
}
|
||||
}
|
||||
|
||||
MOZ_ASSERT(!mFeatures.Contains(aFeature), "Already know about this one!");
|
||||
MOZ_ASSERT(!mHolders.Contains(aHolder), "Already know about this one!");
|
||||
|
||||
if (mFeatures.IsEmpty() && !ModifyBusyCountFromWorker(true)) {
|
||||
if (mHolders.IsEmpty() && !ModifyBusyCountFromWorker(true)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
mFeatures.AppendElement(aFeature);
|
||||
mHolders.AppendElement(aHolder);
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
WorkerPrivate::RemoveFeature(WorkerFeature* aFeature)
|
||||
WorkerPrivate::RemoveHolder(WorkerHolder* aHolder)
|
||||
{
|
||||
AssertIsOnWorkerThread();
|
||||
|
||||
MOZ_ASSERT(mFeatures.Contains(aFeature), "Didn't know about this one!");
|
||||
mFeatures.RemoveElement(aFeature);
|
||||
MOZ_ASSERT(mHolders.Contains(aHolder), "Didn't know about this one!");
|
||||
mHolders.RemoveElement(aHolder);
|
||||
|
||||
if (mFeatures.IsEmpty() && !ModifyBusyCountFromWorker(false)) {
|
||||
if (mHolders.IsEmpty() && !ModifyBusyCountFromWorker(false)) {
|
||||
NS_WARNING("Failed to modify busy count!");
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
WorkerPrivate::NotifyFeatures(JSContext* aCx, Status aStatus)
|
||||
WorkerPrivate::NotifyHolders(JSContext* aCx, Status aStatus)
|
||||
{
|
||||
AssertIsOnWorkerThread();
|
||||
MOZ_ASSERT(!JS_IsExceptionPending(aCx));
|
||||
|
@ -5299,9 +5299,9 @@ WorkerPrivate::NotifyFeatures(JSContext* aCx, Status aStatus)
|
|||
CancelAllTimeouts();
|
||||
}
|
||||
|
||||
nsTObserverArray<WorkerFeature*>::ForwardIterator iter(mFeatures);
|
||||
nsTObserverArray<WorkerHolder*>::ForwardIterator iter(mHolders);
|
||||
while (iter.HasMore()) {
|
||||
WorkerFeature* feature = iter.GetNext();
|
||||
WorkerHolder* feature = iter.GetNext();
|
||||
if (!feature->Notify(aStatus)) {
|
||||
NS_WARNING("Failed to notify feature!");
|
||||
}
|
||||
|
@ -5795,7 +5795,7 @@ WorkerPrivate::NotifyInternal(JSContext* aCx, Status aStatus)
|
|||
MOZ_ASSERT(previousStatus >= Canceling || mKillTime.IsNull());
|
||||
|
||||
// Let all our features know the new status.
|
||||
NotifyFeatures(aCx, aStatus);
|
||||
NotifyHolders(aCx, aStatus);
|
||||
MOZ_ASSERT(!JS_IsExceptionPending(aCx));
|
||||
|
||||
// If this is the first time our status has changed then we need to clear the
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
#include "nsTObserverArray.h"
|
||||
|
||||
#include "Queue.h"
|
||||
#include "WorkerFeature.h"
|
||||
#include "WorkerHolder.h"
|
||||
|
||||
#ifdef XP_WIN
|
||||
#undef PostMessage
|
||||
|
@ -862,6 +862,7 @@ private:
|
|||
|
||||
class WorkerPrivate : public WorkerPrivateParent<WorkerPrivate>
|
||||
{
|
||||
friend class WorkerHolder;
|
||||
friend class WorkerPrivateParent<WorkerPrivate>;
|
||||
typedef WorkerPrivateParent<WorkerPrivate> ParentType;
|
||||
friend class AutoSyncLoopHolder;
|
||||
|
@ -897,7 +898,7 @@ class WorkerPrivate : public WorkerPrivateParent<WorkerPrivate>
|
|||
RefPtr<WorkerGlobalScope> mScope;
|
||||
RefPtr<WorkerDebuggerGlobalScope> mDebuggerScope;
|
||||
nsTArray<ParentType*> mChildWorkers;
|
||||
nsTObserverArray<WorkerFeature*> mFeatures;
|
||||
nsTObserverArray<WorkerHolder*> mHolders;
|
||||
nsTArray<nsAutoPtr<TimeoutInfo>> mTimeouts;
|
||||
uint32_t mDebuggerEventLoopLevel;
|
||||
|
||||
|
@ -1075,22 +1076,6 @@ public:
|
|||
void
|
||||
RemoveChildWorker(ParentType* aChildWorker);
|
||||
|
||||
bool
|
||||
AddFeature(WorkerFeature* aFeature);
|
||||
|
||||
void
|
||||
RemoveFeature(WorkerFeature* aFeature);
|
||||
|
||||
void
|
||||
NotifyFeatures(JSContext* aCx, Status aStatus);
|
||||
|
||||
bool
|
||||
HasActiveFeatures()
|
||||
{
|
||||
return !(mChildWorkers.IsEmpty() && mTimeouts.IsEmpty() &&
|
||||
mFeatures.IsEmpty());
|
||||
}
|
||||
|
||||
void
|
||||
PostMessageToParent(JSContext* aCx,
|
||||
JS::Handle<JS::Value> aMessage,
|
||||
|
@ -1442,6 +1427,22 @@ private:
|
|||
|
||||
void
|
||||
ShutdownGCTimers();
|
||||
|
||||
bool
|
||||
AddHolder(WorkerHolder* aHolder);
|
||||
|
||||
void
|
||||
RemoveHolder(WorkerHolder* aHolder);
|
||||
|
||||
void
|
||||
NotifyHolders(JSContext* aCx, Status aStatus);
|
||||
|
||||
bool
|
||||
HasActiveHolders()
|
||||
{
|
||||
return !(mChildWorkers.IsEmpty() && mTimeouts.IsEmpty() &&
|
||||
mHolders.IsEmpty());
|
||||
}
|
||||
};
|
||||
|
||||
// This class is only used to trick the DOM bindings. We never create
|
||||
|
|
|
@ -1685,7 +1685,7 @@ XMLHttpRequest::MaybePin(ErrorResult& aRv)
|
|||
return;
|
||||
}
|
||||
|
||||
if (!mWorkerPrivate->AddFeature(this)) {
|
||||
if (!HoldWorker(mWorkerPrivate)) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return;
|
||||
}
|
||||
|
@ -1803,7 +1803,7 @@ XMLHttpRequest::Unpin()
|
|||
|
||||
MOZ_ASSERT(mRooted, "Mismatched calls to Unpin!");
|
||||
|
||||
mWorkerPrivate->RemoveFeature(this);
|
||||
ReleaseWorker();
|
||||
|
||||
mRooted = false;
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
#ifndef mozilla_dom_workers_xmlhttprequest_h__
|
||||
#define mozilla_dom_workers_xmlhttprequest_h__
|
||||
|
||||
#include "mozilla/dom/workers/bindings/WorkerFeature.h"
|
||||
#include "mozilla/dom/workers/bindings/WorkerHolder.h"
|
||||
|
||||
// Need this for XMLHttpRequestResponseType.
|
||||
#include "mozilla/dom/XMLHttpRequestBinding.h"
|
||||
|
@ -30,7 +30,7 @@ class XMLHttpRequestUpload;
|
|||
class WorkerPrivate;
|
||||
|
||||
class XMLHttpRequest final: public nsXHREventTarget,
|
||||
public WorkerFeature
|
||||
public WorkerHolder
|
||||
{
|
||||
public:
|
||||
struct StateData
|
||||
|
|
|
@ -38,7 +38,7 @@ EXPORTS.mozilla.dom.workers.bindings += [
|
|||
'ServiceWorkerWindowClient.h',
|
||||
'SharedWorker.h',
|
||||
'URL.h',
|
||||
'WorkerFeature.h',
|
||||
'WorkerHolder.h',
|
||||
'XMLHttpRequest.h',
|
||||
'XMLHttpRequestUpload.h',
|
||||
]
|
||||
|
@ -82,6 +82,7 @@ UNIFIED_SOURCES += [
|
|||
'SharedWorker.cpp',
|
||||
'URL.cpp',
|
||||
'WorkerDebuggerManager.cpp',
|
||||
'WorkerHolder.cpp',
|
||||
'WorkerLocation.cpp',
|
||||
'WorkerNavigator.cpp',
|
||||
'WorkerPrivate.cpp',
|
||||
|
|
|
@ -5,7 +5,8 @@ var p = new Promise(function(resolve, reject) {
|
|||
|
||||
// This prevents that runnable from running until the window calls terminate(),
|
||||
// at which point the worker goes into the Canceling state and then an
|
||||
// AddFeature() is attempted, which fails, which used to result in multiple
|
||||
// calls to the error reporter, one after the worker's context had been GCed.
|
||||
// HoldWorker() is attempted, which fails, which used to result in
|
||||
// multiple calls to the error reporter, one after the worker's context had
|
||||
// been GCed.
|
||||
while (true);
|
||||
});
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
#include "mozilla/unused.h"
|
||||
#include "mozilla/dom/PContentChild.h"
|
||||
#include "mozilla/dom/WorkerPrivate.h"
|
||||
#include "mozilla/dom/workers/bindings/WorkerFeature.h"
|
||||
#include "mozilla/dom/workers/bindings/WorkerHolder.h"
|
||||
#include "mozilla/ipc/PBackgroundChild.h"
|
||||
#include "nsIAsyncInputStream.h"
|
||||
#include "nsICancelableRunnable.h"
|
||||
|
@ -23,13 +23,13 @@ namespace ipc {
|
|||
using mozilla::dom::PContentChild;
|
||||
using mozilla::dom::workers::GetCurrentThreadWorkerPrivate;
|
||||
using mozilla::dom::workers::Status;
|
||||
using mozilla::dom::workers::WorkerFeature;
|
||||
using mozilla::dom::workers::WorkerHolder;
|
||||
using mozilla::dom::workers::WorkerPrivate;
|
||||
|
||||
namespace {
|
||||
|
||||
class SendStreamChildImpl final : public SendStreamChild
|
||||
, public WorkerFeature
|
||||
, public WorkerHolder
|
||||
{
|
||||
public:
|
||||
explicit SendStreamChildImpl(nsIAsyncInputStream* aStream);
|
||||
|
@ -39,7 +39,7 @@ public:
|
|||
void StartDestroy() override;
|
||||
|
||||
bool
|
||||
AddAsWorkerFeature(dom::workers::WorkerPrivate* aWorkerPrivate);
|
||||
AddAsWorkerHolder(dom::workers::WorkerPrivate* aWorkerPrivate);
|
||||
|
||||
private:
|
||||
class Callback;
|
||||
|
@ -51,7 +51,7 @@ private:
|
|||
virtual bool
|
||||
RecvRequestClose(const nsresult& aRv) override;
|
||||
|
||||
// WorkerFeature methods
|
||||
// WorkerHolder methods
|
||||
virtual bool
|
||||
Notify(Status aStatus) override;
|
||||
|
||||
|
@ -93,7 +93,7 @@ public:
|
|||
|
||||
// If this fails, then it means the owning thread is a Worker that has
|
||||
// been shutdown. Its ok to lose the event in this case because the
|
||||
// SendStreamChild listens for this event through the Feature.
|
||||
// SendStreamChild listens for this event through the WorkerHolder.
|
||||
nsresult rv = mOwningThread->Dispatch(this, nsIThread::DISPATCH_NORMAL);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_WARNING("Failed to dispatch stream readable event to owning thread");
|
||||
|
@ -117,7 +117,7 @@ public:
|
|||
{
|
||||
// Cancel() gets called when the Worker thread is being shutdown. We have
|
||||
// nothing to do here because SendStreamChild handles this case via
|
||||
// the Feature.
|
||||
// the WorkerHolder.
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -180,11 +180,11 @@ SendStreamChildImpl::StartDestroy()
|
|||
}
|
||||
|
||||
bool
|
||||
SendStreamChildImpl::AddAsWorkerFeature(WorkerPrivate* aWorkerPrivate)
|
||||
SendStreamChildImpl::AddAsWorkerHolder(WorkerPrivate* aWorkerPrivate)
|
||||
{
|
||||
NS_ASSERT_OWNINGTHREAD(SendStreamChild);
|
||||
MOZ_ASSERT(aWorkerPrivate);
|
||||
bool result = aWorkerPrivate->AddFeature(this);
|
||||
bool result = HoldWorker(aWorkerPrivate);
|
||||
if (result) {
|
||||
mWorkerPrivate = aWorkerPrivate;
|
||||
}
|
||||
|
@ -207,7 +207,7 @@ SendStreamChildImpl::ActorDestroy(ActorDestroyReason aReason)
|
|||
}
|
||||
|
||||
if (mWorkerPrivate) {
|
||||
mWorkerPrivate->RemoveFeature(this);
|
||||
ReleaseWorker();
|
||||
mWorkerPrivate = nullptr;
|
||||
}
|
||||
}
|
||||
|
@ -405,7 +405,7 @@ SendStreamChild::Create(nsIAsyncInputStream* aInputStream,
|
|||
|
||||
SendStreamChildImpl* actor = new SendStreamChildImpl(aInputStream);
|
||||
|
||||
if (workerPrivate && !actor->AddAsWorkerFeature(workerPrivate)) {
|
||||
if (workerPrivate && !actor->AddAsWorkerHolder(workerPrivate)) {
|
||||
delete actor;
|
||||
return nullptr;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче