Backed out changeset 1c5d78c7ba43 (bug 1269154) for bustage on a CLOSED TREE

--HG--
rename : dom/cache/CacheWorkerHolder.cpp => dom/cache/Feature.cpp
rename : dom/cache/CacheWorkerHolder.h => dom/cache/Feature.h
rename : dom/workers/WorkerHolder.h => dom/workers/WorkerFeature.h
extra : rebase_source : 49f9e9ce0500ac441fe97878cf9308804926544f
This commit is contained in:
Carsten "Tomcat" Book 2016-06-23 10:13:54 +02:00
Родитель 8f44efbeeb
Коммит 47aeb86e2c
52 изменённых файлов: 434 добавлений и 493 удалений

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

@ -604,7 +604,7 @@ FileReader::OnInputStreamReady(nsIAsyncInputStream* aStream)
// We use this class to decrease the busy counter at the end of this method. // 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 // In theory we can do it immediatelly but, for debugging reasons, we want to
// be 100% sure we have a workerHolder when OnLoadEnd() is called. // be 100% sure we have a feature when OnLoadEnd() is called.
FileReaderDecreaseBusyCounter RAII(this); FileReaderDecreaseBusyCounter RAII(this);
uint64_t aCount; uint64_t aCount;
@ -701,7 +701,7 @@ nsresult
FileReader::IncreaseBusyCounter() FileReader::IncreaseBusyCounter()
{ {
if (mWorkerPrivate && mBusyCount++ == 0 && if (mWorkerPrivate && mBusyCount++ == 0 &&
!HoldWorker(mWorkerPrivate)) { !mWorkerPrivate->AddFeature(this)) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
@ -713,7 +713,7 @@ FileReader::DecreaseBusyCounter()
{ {
MOZ_ASSERT_IF(mWorkerPrivate, mBusyCount); MOZ_ASSERT_IF(mWorkerPrivate, mBusyCount);
if (mWorkerPrivate && --mBusyCount == 0) { if (mWorkerPrivate && --mBusyCount == 0) {
ReleaseWorker(); mWorkerPrivate->RemoveFeature(this);
} }
} }
@ -742,7 +742,7 @@ FileReader::Shutdown()
} }
if (mWorkerPrivate && mBusyCount != 0) { if (mWorkerPrivate && mBusyCount != 0) {
ReleaseWorker(); mWorkerPrivate->RemoveFeature(this);
mWorkerPrivate = nullptr; mWorkerPrivate = nullptr;
mBusyCount = 0; mBusyCount = 0;
} }

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

@ -15,7 +15,7 @@
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
#include "nsString.h" #include "nsString.h"
#include "nsWeakReference.h" #include "nsWeakReference.h"
#include "WorkerHolder.h" #include "WorkerFeature.h"
#define NS_PROGRESS_EVENT_INTERVAL 50 #define NS_PROGRESS_EVENT_INTERVAL 50
@ -41,7 +41,7 @@ class FileReader final : public DOMEventTargetHelper,
public nsSupportsWeakReference, public nsSupportsWeakReference,
public nsIInputStreamCallback, public nsIInputStreamCallback,
public nsITimerCallback, public nsITimerCallback,
public workers::WorkerHolder public workers::WorkerFeature
{ {
friend class FileReaderDecreaseBusyCounter; friend class FileReaderDecreaseBusyCounter;
@ -106,7 +106,7 @@ public:
ReadFileContent(aBlob, EmptyString(), FILE_AS_BINARY, aRv); ReadFileContent(aBlob, EmptyString(), FILE_AS_BINARY, aRv);
} }
// WorkerHolder // WorkerFeature
bool Notify(workers::Status) override; bool Notify(workers::Status) override;
private: private:
@ -190,7 +190,7 @@ private:
uint64_t mBusyCount; uint64_t mBusyCount;
// Kept alive with a WorkerHolder. // Kept alive with a WorkerFeature.
workers::WorkerPrivate* mWorkerPrivate; workers::WorkerPrivate* mWorkerPrivate;
}; };

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

@ -99,7 +99,7 @@ public:
, mInnerWindowID(0) , mInnerWindowID(0)
, mWorkerPrivate(nullptr) , mWorkerPrivate(nullptr)
#ifdef DEBUG #ifdef DEBUG
, mHasWorkerHolderRegistered(false) , mHasFeatureRegistered(false)
#endif #endif
, mIsMainThread(true) , mIsMainThread(true)
, mMutex("WebSocketImpl::mMutex") , mMutex("WebSocketImpl::mMutex")
@ -166,8 +166,8 @@ public:
void AddRefObject(); void AddRefObject();
void ReleaseObject(); void ReleaseObject();
bool RegisterWorkerHolder(); bool RegisterFeature();
void UnregisterWorkerHolder(); void UnregisterFeature();
nsresult CancelInternal(); nsresult CancelInternal();
@ -213,24 +213,24 @@ public:
uint64_t mInnerWindowID; uint64_t mInnerWindowID;
WorkerPrivate* mWorkerPrivate; WorkerPrivate* mWorkerPrivate;
nsAutoPtr<WorkerHolder> mWorkerHolder; nsAutoPtr<WorkerFeature> mWorkerFeature;
#ifdef DEBUG #ifdef DEBUG
// This is protected by mutex. // This is protected by mutex.
bool mHasWorkerHolderRegistered; bool mHasFeatureRegistered;
bool HasWorkerHolderRegistered() bool HasFeatureRegistered()
{ {
MOZ_ASSERT(mWebSocket); MOZ_ASSERT(mWebSocket);
MutexAutoLock lock(mWebSocket->mMutex); MutexAutoLock lock(mWebSocket->mMutex);
return mHasWorkerHolderRegistered; return mHasFeatureRegistered;
} }
void SetHasWorkerHolderRegistered(bool aValue) void SetHasFeatureRegistered(bool aValue)
{ {
MOZ_ASSERT(mWebSocket); MOZ_ASSERT(mWebSocket);
MutexAutoLock lock(mWebSocket->mMutex); MutexAutoLock lock(mWebSocket->mMutex);
mHasWorkerHolderRegistered = aValue; mHasFeatureRegistered = aValue;
} }
#endif #endif
@ -489,7 +489,7 @@ WebSocketImpl::CloseConnection(uint16_t aReasonCode,
// If this method is called because the worker is going away, we will not // 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 // receive the OnStop() method and we have to disconnect the WebSocket and
// release the WorkerHolder. // release the WorkerFeature.
MaybeDisconnect md(this); MaybeDisconnect md(this);
uint16_t readyState = mWebSocket->ReadyState(); uint16_t readyState = mWebSocket->ReadyState();
@ -610,7 +610,7 @@ WebSocketImpl::Disconnect()
AssertIsOnTargetThread(); AssertIsOnTargetThread();
// Disconnect can be called from some control event (such as Notify() of // Disconnect can be called from some control event (such as Notify() of
// WorkerHolder). This will be schedulated before any other sync/async // WorkerFeature). This will be schedulated before any other sync/async
// runnable. In order to prevent some double Disconnect() calls, we use this // runnable. In order to prevent some double Disconnect() calls, we use this
// boolean. // boolean.
mDisconnectingOrDisconnected = true; mDisconnectingOrDisconnected = true;
@ -640,8 +640,8 @@ WebSocketImpl::Disconnect()
mWebSocket->DontKeepAliveAnyMore(); mWebSocket->DontKeepAliveAnyMore();
mWebSocket->mImpl = nullptr; mWebSocket->mImpl = nullptr;
if (mWorkerPrivate && mWorkerHolder) { if (mWorkerPrivate && mWorkerFeature) {
UnregisterWorkerHolder(); UnregisterFeature();
} }
// We want to release the WebSocket in the correct thread. // We want to release the WebSocket in the correct thread.
@ -1262,9 +1262,9 @@ WebSocket::ConstructorCommon(const GlobalObject& aGlobal,
aUrl, protocolArray, EmptyCString(), aUrl, protocolArray, EmptyCString(),
0, 0, aRv, &connectionFailed); 0, 0, aRv, &connectionFailed);
} else { } else {
// In workers we have to keep the worker alive using a workerHolder in order // In workers we have to keep the worker alive using a feature in order to
// to dispatch messages correctly. // dispatch messages correctly.
if (!webSocket->mImpl->RegisterWorkerHolder()) { if (!webSocket->mImpl->RegisterFeature()) {
aRv.Throw(NS_ERROR_FAILURE); aRv.Throw(NS_ERROR_FAILURE);
return nullptr; return nullptr;
} }
@ -2204,10 +2204,10 @@ WebSocket::DontKeepAliveAnyMore()
namespace { namespace {
class WebSocketWorkerHolder final : public WorkerHolder class WebSocketWorkerFeature final : public WorkerFeature
{ {
public: public:
explicit WebSocketWorkerHolder(WebSocketImpl* aWebSocketImpl) explicit WebSocketWorkerFeature(WebSocketImpl* aWebSocketImpl)
: mWebSocketImpl(aWebSocketImpl) : mWebSocketImpl(aWebSocketImpl)
{ {
} }
@ -2250,39 +2250,39 @@ WebSocketImpl::ReleaseObject()
} }
bool bool
WebSocketImpl::RegisterWorkerHolder() WebSocketImpl::RegisterFeature()
{ {
mWorkerPrivate->AssertIsOnWorkerThread(); mWorkerPrivate->AssertIsOnWorkerThread();
MOZ_ASSERT(!mWorkerHolder); MOZ_ASSERT(!mWorkerFeature);
mWorkerHolder = new WebSocketWorkerHolder(this); mWorkerFeature = new WebSocketWorkerFeature(this);
if (NS_WARN_IF(!mWorkerHolder->HoldWorker(mWorkerPrivate))) { if (!mWorkerPrivate->AddFeature(mWorkerFeature)) {
mWorkerHolder = nullptr; NS_WARNING("Failed to register a feature.");
mWorkerFeature = nullptr;
return false; return false;
} }
#ifdef DEBUG #ifdef DEBUG
SetHasWorkerHolderRegistered(true); SetHasFeatureRegistered(true);
#endif #endif
return true; return true;
} }
void void
WebSocketImpl::UnregisterWorkerHolder() WebSocketImpl::UnregisterFeature()
{ {
MOZ_ASSERT(mDisconnectingOrDisconnected); MOZ_ASSERT(mDisconnectingOrDisconnected);
MOZ_ASSERT(mWorkerPrivate); MOZ_ASSERT(mWorkerPrivate);
mWorkerPrivate->AssertIsOnWorkerThread(); mWorkerPrivate->AssertIsOnWorkerThread();
MOZ_ASSERT(mWorkerHolder); MOZ_ASSERT(mWorkerFeature);
// The DTOR of this WorkerHolder will release the worker for us.
mWorkerHolder = nullptr;
mWorkerPrivate->RemoveFeature(mWorkerFeature);
mWorkerFeature = nullptr;
mWorkerPrivate = nullptr; mWorkerPrivate = nullptr;
#ifdef DEBUG #ifdef DEBUG
SetHasWorkerHolderRegistered(false); SetHasFeatureRegistered(false);
#endif #endif
} }
@ -2842,7 +2842,7 @@ WebSocketImpl::Dispatch(already_AddRefed<nsIRunnable> aEvent, uint32_t aFlags)
MOZ_ASSERT(mWorkerPrivate); MOZ_ASSERT(mWorkerPrivate);
#ifdef DEBUG #ifdef DEBUG
MOZ_ASSERT(HasWorkerHolderRegistered()); MOZ_ASSERT(HasFeatureRegistered());
#endif #endif
// If the target is a worker, we have to use a custom WorkerRunnableDispatcher // 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 // This runnable is used to write a deprecation message from a worker to the
// console running on the main-thread. // console running on the main-thread.
class DeprecationWarningRunnable final : public Runnable class DeprecationWarningRunnable final : public Runnable
, public WorkerHolder , public WorkerFeature
{ {
WorkerPrivate* mWorkerPrivate; WorkerPrivate* mWorkerPrivate;
nsIDocument::DeprecatedOperations mOperation; nsIDocument::DeprecatedOperations mOperation;
@ -3315,12 +3315,12 @@ public:
void void
Dispatch() Dispatch()
{ {
if (NS_WARN_IF(!HoldWorker(mWorkerPrivate))) { if (NS_WARN_IF(!mWorkerPrivate->AddFeature(this))) {
return; return;
} }
if (NS_WARN_IF(NS_FAILED(NS_DispatchToMainThread(this)))) { if (NS_WARN_IF(NS_FAILED(NS_DispatchToMainThread(this)))) {
ReleaseWorker(); mWorkerPrivate->RemoveFeature(this);
return; return;
} }
} }
@ -3351,12 +3351,12 @@ private:
window->GetExtantDoc()->WarnOnceAbout(mOperation); window->GetExtantDoc()->WarnOnceAbout(mOperation);
} }
ReleaseWorkerHolder(); ReleaseWorker();
return NS_OK; return NS_OK;
} }
void void
ReleaseWorkerHolder() ReleaseWorker()
{ {
class ReleaseRunnable final : public MainThreadWorkerRunnable class ReleaseRunnable final : public MainThreadWorkerRunnable
{ {
@ -3375,7 +3375,7 @@ private:
MOZ_ASSERT(aWorkerPrivate); MOZ_ASSERT(aWorkerPrivate);
aWorkerPrivate->AssertIsOnWorkerThread(); aWorkerPrivate->AssertIsOnWorkerThread();
mRunnable->ReleaseWorker(); aWorkerPrivate->RemoveFeature(mRunnable);
return true; return true;
} }
}; };

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

@ -266,15 +266,15 @@ private:
NS_IMPL_ISUPPORTS(TeardownRunnable, nsICancelableRunnable, nsIRunnable) NS_IMPL_ISUPPORTS(TeardownRunnable, nsICancelableRunnable, nsIRunnable)
class BroadcastChannelWorkerHolder final : public workers::WorkerHolder class BroadcastChannelFeature final : public workers::WorkerFeature
{ {
BroadcastChannel* mChannel; BroadcastChannel* mChannel;
public: public:
explicit BroadcastChannelWorkerHolder(BroadcastChannel* aChannel) explicit BroadcastChannelFeature(BroadcastChannel* aChannel)
: mChannel(aChannel) : mChannel(aChannel)
{ {
MOZ_COUNT_CTOR(BroadcastChannelWorkerHolder); MOZ_COUNT_CTOR(BroadcastChannelFeature);
} }
virtual bool Notify(workers::Status aStatus) override virtual bool Notify(workers::Status aStatus) override
@ -287,9 +287,9 @@ public:
} }
private: private:
~BroadcastChannelWorkerHolder() ~BroadcastChannelFeature()
{ {
MOZ_COUNT_DTOR(BroadcastChannelWorkerHolder); MOZ_COUNT_DTOR(BroadcastChannelFeature);
} }
}; };
@ -300,7 +300,7 @@ BroadcastChannel::BroadcastChannel(nsPIDOMWindowInner* aWindow,
const nsACString& aOrigin, const nsACString& aOrigin,
const nsAString& aChannel) const nsAString& aChannel)
: DOMEventTargetHelper(aWindow) : DOMEventTargetHelper(aWindow)
, mWorkerHolder(nullptr) , mWorkerFeature(nullptr)
, mPrincipalInfo(new PrincipalInfo(aPrincipalInfo)) , mPrincipalInfo(new PrincipalInfo(aPrincipalInfo))
, mOrigin(aOrigin) , mOrigin(aOrigin)
, mChannel(aChannel) , mChannel(aChannel)
@ -314,7 +314,7 @@ BroadcastChannel::BroadcastChannel(nsPIDOMWindowInner* aWindow,
BroadcastChannel::~BroadcastChannel() BroadcastChannel::~BroadcastChannel()
{ {
Shutdown(); Shutdown();
MOZ_ASSERT(!mWorkerHolder); MOZ_ASSERT(!mWorkerFeature);
} }
JSObject* JSObject*
@ -406,9 +406,10 @@ BroadcastChannel::Constructor(const GlobalObject& aGlobal,
obs->AddObserver(bc, "inner-window-destroyed", false); obs->AddObserver(bc, "inner-window-destroyed", false);
} }
} else { } else {
bc->mWorkerHolder = new BroadcastChannelWorkerHolder(bc); bc->mWorkerFeature = new BroadcastChannelFeature(bc);
if (NS_WARN_IF(!bc->mWorkerHolder->HoldWorker(workerPrivate))) { if (NS_WARN_IF(!workerPrivate->AddFeature(bc->mWorkerFeature))) {
bc->mWorkerHolder = nullptr; NS_WARNING("Failed to register the BroadcastChannel worker feature.");
bc->mWorkerFeature = nullptr;
aRv.Throw(NS_ERROR_FAILURE); aRv.Throw(NS_ERROR_FAILURE);
return nullptr; return nullptr;
} }
@ -527,8 +528,11 @@ BroadcastChannel::Shutdown()
{ {
mState = StateClosed; mState = StateClosed;
// The DTOR of this WorkerHolder will release the worker for us. if (mWorkerFeature) {
mWorkerHolder = nullptr; WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
workerPrivate->RemoveFeature(mWorkerFeature);
mWorkerFeature = nullptr;
}
if (mActor) { if (mActor) {
mActor->SetParent(nullptr); mActor->SetParent(nullptr);

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

@ -26,7 +26,7 @@ class PrincipalInfo;
namespace dom { namespace dom {
namespace workers { namespace workers {
class WorkerHolder; class WorkerFeature;
} // namespace workers } // namespace workers
class BroadcastChannelChild; class BroadcastChannelChild;
@ -110,7 +110,7 @@ private:
RefPtr<BroadcastChannelChild> mActor; RefPtr<BroadcastChannelChild> mActor;
nsTArray<RefPtr<BroadcastChannelMessage>> mPendingMessages; nsTArray<RefPtr<BroadcastChannelMessage>> mPendingMessages;
nsAutoPtr<workers::WorkerHolder> mWorkerHolder; nsAutoPtr<workers::WorkerFeature> mWorkerFeature;
nsAutoPtr<PrincipalInfo> mPrincipalInfo; nsAutoPtr<PrincipalInfo> mPrincipalInfo;

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

@ -6,7 +6,7 @@
#include "mozilla/dom/cache/ActorChild.h" #include "mozilla/dom/cache/ActorChild.h"
#include "mozilla/dom/cache/CacheWorkerHolder.h" #include "mozilla/dom/cache/Feature.h"
#include "nsThreadUtils.h" #include "nsThreadUtils.h"
namespace mozilla { namespace mozilla {
@ -14,42 +14,42 @@ namespace dom {
namespace cache { namespace cache {
void void
ActorChild::SetWorkerHolder(CacheWorkerHolder* aWorkerHolder) ActorChild::SetFeature(Feature* aFeature)
{ {
// Some of the Cache actors can have multiple DOM objects associated with // Some of the Cache actors can have multiple DOM objects associated with
// them. In this case the workerHolder will be added multiple times. This is // them. In this case the feature will be added multiple times. This is
// permitted, but the workerHolder should be the same each time. // permitted, but the feature should be the same each time.
if (mWorkerHolder) { if (mFeature) {
MOZ_ASSERT(mWorkerHolder == aWorkerHolder); MOZ_ASSERT(mFeature == aFeature);
return; return;
} }
mWorkerHolder = aWorkerHolder; mFeature = aFeature;
if (mWorkerHolder) { if (mFeature) {
mWorkerHolder->AddActor(this); mFeature->AddActor(this);
} }
} }
void void
ActorChild::RemoveWorkerHolder() ActorChild::RemoveFeature()
{ {
MOZ_ASSERT_IF(!NS_IsMainThread(), mWorkerHolder); MOZ_ASSERT_IF(!NS_IsMainThread(), mFeature);
if (mWorkerHolder) { if (mFeature) {
mWorkerHolder->RemoveActor(this); mFeature->RemoveActor(this);
mWorkerHolder = nullptr; mFeature = nullptr;
} }
} }
CacheWorkerHolder* Feature*
ActorChild::GetWorkerHolder() const ActorChild::GetFeature() const
{ {
return mWorkerHolder; return mFeature;
} }
bool bool
ActorChild::WorkerHolderNotified() const ActorChild::FeatureNotified() const
{ {
return mWorkerHolder && mWorkerHolder->Notified(); return mFeature && mFeature->Notified();
} }
ActorChild::ActorChild() ActorChild::ActorChild()
@ -58,7 +58,7 @@ ActorChild::ActorChild()
ActorChild::~ActorChild() ActorChild::~ActorChild()
{ {
MOZ_ASSERT(!mWorkerHolder); MOZ_ASSERT(!mFeature);
} }
} // namespace cache } // namespace cache

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

@ -13,7 +13,7 @@ namespace mozilla {
namespace dom { namespace dom {
namespace cache { namespace cache {
class CacheWorkerHolder; class Feature;
class ActorChild class ActorChild
{ {
@ -22,23 +22,23 @@ public:
StartDestroy() = 0; StartDestroy() = 0;
void void
SetWorkerHolder(CacheWorkerHolder* aWorkerHolder); SetFeature(Feature* aFeature);
void void
RemoveWorkerHolder(); RemoveFeature();
CacheWorkerHolder* Feature*
GetWorkerHolder() const; GetFeature() const;
bool bool
WorkerHolderNotified() const; FeatureNotified() const;
protected: protected:
ActorChild(); ActorChild();
~ActorChild(); ~ActorChild();
private: private:
RefPtr<CacheWorkerHolder> mWorkerHolder; RefPtr<Feature> mFeature;
}; };
} // namespace cache } // namespace cache

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

@ -15,7 +15,7 @@
#include "mozilla/dom/CacheBinding.h" #include "mozilla/dom/CacheBinding.h"
#include "mozilla/dom/cache/AutoUtils.h" #include "mozilla/dom/cache/AutoUtils.h"
#include "mozilla/dom/cache/CacheChild.h" #include "mozilla/dom/cache/CacheChild.h"
#include "mozilla/dom/cache/CacheWorkerHolder.h" #include "mozilla/dom/cache/Feature.h"
#include "mozilla/dom/cache/ReadStream.h" #include "mozilla/dom/cache/ReadStream.h"
#include "mozilla/ErrorResult.h" #include "mozilla/ErrorResult.h"
#include "mozilla/Preferences.h" #include "mozilla/Preferences.h"
@ -82,21 +82,21 @@ IsValidPutRequestMethod(const RequestOrUSVString& aRequest, ErrorResult& aRv)
} // namespace } // namespace
// Helper class to wait for Add()/AddAll() fetch requests to complete and // Helper class to wait for Add()/AddAll() fetch requests to complete and
// then perform a PutAll() with the responses. This class holds a WorkerHolder // then perform a PutAll() with the responses. This class holds a Feature
// to keep the Worker thread alive. This is mainly to ensure that Add/AddAll // 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 // act the same as other Cache operations that directly create a CacheOpChild
// actor. // actor.
class Cache::FetchHandler final : public PromiseNativeHandler class Cache::FetchHandler final : public PromiseNativeHandler
{ {
public: public:
FetchHandler(CacheWorkerHolder* aWorkerHolder, Cache* aCache, FetchHandler(Feature* aFeature, Cache* aCache,
nsTArray<RefPtr<Request>>&& aRequestList, Promise* aPromise) nsTArray<RefPtr<Request>>&& aRequestList, Promise* aPromise)
: mWorkerHolder(aWorkerHolder) : mFeature(aFeature)
, mCache(aCache) , mCache(aCache)
, mRequestList(Move(aRequestList)) , mRequestList(Move(aRequestList))
, mPromise(aPromise) , mPromise(aPromise)
{ {
MOZ_ASSERT_IF(!NS_IsMainThread(), mWorkerHolder); MOZ_ASSERT_IF(!NS_IsMainThread(), mFeature);
MOZ_ASSERT(mCache); MOZ_ASSERT(mCache);
MOZ_ASSERT(mPromise); MOZ_ASSERT(mPromise);
} }
@ -107,8 +107,8 @@ public:
NS_ASSERT_OWNINGTHREAD(FetchHandler); NS_ASSERT_OWNINGTHREAD(FetchHandler);
// Stop holding the worker alive when we leave this method. // Stop holding the worker alive when we leave this method.
RefPtr<CacheWorkerHolder> workerHolder; RefPtr<Feature> feature;
workerHolder.swap(mWorkerHolder); feature.swap(mFeature);
// Promise::All() passed an array of fetch() Promises should give us // Promise::All() passed an array of fetch() Promises should give us
// an Array of Response objects. The following code unwraps these // an Array of Response objects. The following code unwraps these
@ -217,7 +217,7 @@ private:
mPromise->MaybeReject(rv); mPromise->MaybeReject(rv);
} }
RefPtr<CacheWorkerHolder> mWorkerHolder; RefPtr<Feature> mFeature;
RefPtr<Cache> mCache; RefPtr<Cache> mCache;
nsTArray<RefPtr<Request>> mRequestList; nsTArray<RefPtr<Request>> mRequestList;
RefPtr<Promise> mPromise; RefPtr<Promise> mPromise;
@ -614,9 +614,8 @@ Cache::AddAll(const GlobalObject& aGlobal,
return nullptr; return nullptr;
} }
RefPtr<FetchHandler> handler = RefPtr<FetchHandler> handler = new FetchHandler(mActor->GetFeature(), this,
new FetchHandler(mActor->GetWorkerHolder(), this, Move(aRequestList), promise);
Move(aRequestList), promise);
RefPtr<Promise> fetchPromise = Promise::All(aGlobal, fetchList, aRv); RefPtr<Promise> fetchPromise = Promise::All(aGlobal, fetchList, aRv);
if (NS_WARN_IF(aRv.Failed())) { if (NS_WARN_IF(aRv.Failed())) {

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

@ -70,7 +70,7 @@ CacheChild::ExecuteOp(nsIGlobalObject* aGlobal, Promise* aPromise,
{ {
mNumChildActors += 1; mNumChildActors += 1;
MOZ_ALWAYS_TRUE(SendPCacheOpConstructor( MOZ_ALWAYS_TRUE(SendPCacheOpConstructor(
new CacheOpChild(GetWorkerHolder(), aGlobal, aParent, aPromise), aArgs)); new CacheOpChild(GetFeature(), aGlobal, aParent, aPromise), aArgs));
} }
void void
@ -103,7 +103,7 @@ CacheChild::StartDestroy()
RefPtr<Cache> listener = mListener; RefPtr<Cache> listener = mListener;
// StartDestroy() can get called from either Cache or the WorkerHolder. // StartDestroy() can get called from either Cache or the Feature.
// Theoretically we can get double called if the right race happens. Handle // Theoretically we can get double called if the right race happens. Handle
// that by just ignoring the second StartDestroy() call. // that by just ignoring the second StartDestroy() call.
if (!listener) { if (!listener) {
@ -130,7 +130,7 @@ CacheChild::ActorDestroy(ActorDestroyReason aReason)
MOZ_ASSERT(!mListener); MOZ_ASSERT(!mListener);
} }
RemoveWorkerHolder(); RemoveFeature();
} }
PCacheOpChild* PCacheOpChild*

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

@ -65,7 +65,7 @@ public:
private: private:
// ActorChild methods // ActorChild methods
// WorkerHolder is trying to destroy due to worker shutdown. // Feature is trying to destroy due to worker shutdown.
virtual void StartDestroy() override; virtual void StartDestroy() override;
// PCacheChild methods // PCacheChild methods

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

@ -22,49 +22,43 @@ using mozilla::ipc::PBackgroundChild;
namespace { namespace {
void void
AddWorkerHolderToStreamChild(const CacheReadStream& aReadStream, AddFeatureToStreamChild(const CacheReadStream& aReadStream, Feature* aFeature)
CacheWorkerHolder* aWorkerHolder)
{ {
MOZ_ASSERT_IF(!NS_IsMainThread(), aWorkerHolder); MOZ_ASSERT_IF(!NS_IsMainThread(), aFeature);
CacheStreamControlChild* cacheControl = CacheStreamControlChild* cacheControl =
static_cast<CacheStreamControlChild*>(aReadStream.controlChild()); static_cast<CacheStreamControlChild*>(aReadStream.controlChild());
if (cacheControl) { if (cacheControl) {
cacheControl->SetWorkerHolder(aWorkerHolder); cacheControl->SetFeature(aFeature);
} }
} }
void void
AddWorkerHolderToStreamChild(const CacheResponse& aResponse, AddFeatureToStreamChild(const CacheResponse& aResponse, Feature* aFeature)
CacheWorkerHolder* aWorkerHolder)
{ {
MOZ_ASSERT_IF(!NS_IsMainThread(), aWorkerHolder); MOZ_ASSERT_IF(!NS_IsMainThread(), aFeature);
if (aResponse.body().type() == CacheReadStreamOrVoid::Tvoid_t) { if (aResponse.body().type() == CacheReadStreamOrVoid::Tvoid_t) {
return; return;
} }
AddWorkerHolderToStreamChild(aResponse.body().get_CacheReadStream(), AddFeatureToStreamChild(aResponse.body().get_CacheReadStream(), aFeature);
aWorkerHolder);
} }
void void
AddWorkerHolderToStreamChild(const CacheRequest& aRequest, AddFeatureToStreamChild(const CacheRequest& aRequest, Feature* aFeature)
CacheWorkerHolder* aWorkerHolder)
{ {
MOZ_ASSERT_IF(!NS_IsMainThread(), aWorkerHolder); MOZ_ASSERT_IF(!NS_IsMainThread(), aFeature);
if (aRequest.body().type() == CacheReadStreamOrVoid::Tvoid_t) { if (aRequest.body().type() == CacheReadStreamOrVoid::Tvoid_t) {
return; return;
} }
AddWorkerHolderToStreamChild(aRequest.body().get_CacheReadStream(), AddFeatureToStreamChild(aRequest.body().get_CacheReadStream(), aFeature);
aWorkerHolder);
} }
} // namespace } // namespace
CacheOpChild::CacheOpChild(CacheWorkerHolder* aWorkerHolder, CacheOpChild::CacheOpChild(Feature* aFeature, nsIGlobalObject* aGlobal,
nsIGlobalObject* aGlobal,
nsISupports* aParent, Promise* aPromise) nsISupports* aParent, Promise* aPromise)
: mGlobal(aGlobal) : mGlobal(aGlobal)
, mParent(aParent) , mParent(aParent)
@ -74,8 +68,8 @@ CacheOpChild::CacheOpChild(CacheWorkerHolder* aWorkerHolder,
MOZ_ASSERT(mParent); MOZ_ASSERT(mParent);
MOZ_ASSERT(mPromise); MOZ_ASSERT(mPromise);
MOZ_ASSERT_IF(!NS_IsMainThread(), aWorkerHolder); MOZ_ASSERT_IF(!NS_IsMainThread(), aFeature);
SetWorkerHolder(aWorkerHolder); SetFeature(aFeature);
} }
CacheOpChild::~CacheOpChild() CacheOpChild::~CacheOpChild()
@ -96,7 +90,7 @@ CacheOpChild::ActorDestroy(ActorDestroyReason aReason)
mPromise = nullptr; mPromise = nullptr;
} }
RemoveWorkerHolder(); RemoveFeature();
} }
bool bool
@ -155,7 +149,7 @@ CacheOpChild::Recv__delete__(const ErrorResult& aRv,
{ {
auto actor = static_cast<CacheChild*>( auto actor = static_cast<CacheChild*>(
aResult.get_StorageOpenResult().actorChild()); aResult.get_StorageOpenResult().actorChild());
actor->SetWorkerHolder(GetWorkerHolder()); actor->SetFeature(GetFeature());
RefPtr<Cache> cache = new Cache(mGlobal, actor); RefPtr<Cache> cache = new Cache(mGlobal, actor);
mPromise->MaybeResolve(cache); mPromise->MaybeResolve(cache);
break; break;
@ -184,8 +178,8 @@ CacheOpChild::StartDestroy()
{ {
NS_ASSERT_OWNINGTHREAD(CacheOpChild); NS_ASSERT_OWNINGTHREAD(CacheOpChild);
// Do not cancel on-going operations when WorkerHolder calls this. Instead, // Do not cancel on-going operations when Feature calls this. Instead, keep
// keep the Worker alive until we are done. // the Worker alive until we are done.
} }
nsIGlobalObject* nsIGlobalObject*
@ -218,7 +212,7 @@ CacheOpChild::HandleResponse(const CacheResponseOrVoid& aResponseOrVoid)
const CacheResponse& cacheResponse = aResponseOrVoid.get_CacheResponse(); const CacheResponse& cacheResponse = aResponseOrVoid.get_CacheResponse();
AddWorkerHolderToStreamChild(cacheResponse, GetWorkerHolder()); AddFeatureToStreamChild(cacheResponse, GetFeature());
RefPtr<Response> response = ToResponse(cacheResponse); RefPtr<Response> response = ToResponse(cacheResponse);
mPromise->MaybeResolve(response); mPromise->MaybeResolve(response);
@ -231,7 +225,7 @@ CacheOpChild::HandleResponseList(const nsTArray<CacheResponse>& aResponseList)
responses.SetCapacity(aResponseList.Length()); responses.SetCapacity(aResponseList.Length());
for (uint32_t i = 0; i < aResponseList.Length(); ++i) { for (uint32_t i = 0; i < aResponseList.Length(); ++i) {
AddWorkerHolderToStreamChild(aResponseList[i], GetWorkerHolder()); AddFeatureToStreamChild(aResponseList[i], GetFeature());
responses.AppendElement(ToResponse(aResponseList[i])); responses.AppendElement(ToResponse(aResponseList[i]));
} }
@ -245,7 +239,7 @@ CacheOpChild::HandleRequestList(const nsTArray<CacheRequest>& aRequestList)
requests.SetCapacity(aRequestList.Length()); requests.SetCapacity(aRequestList.Length());
for (uint32_t i = 0; i < aRequestList.Length(); ++i) { for (uint32_t i = 0; i < aRequestList.Length(); ++i) {
AddWorkerHolderToStreamChild(aRequestList[i], GetWorkerHolder()); AddFeatureToStreamChild(aRequestList[i], GetFeature());
requests.AppendElement(ToRequest(aRequestList[i])); requests.AppendElement(ToRequest(aRequestList[i]));
} }

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

@ -31,7 +31,7 @@ class CacheOpChild final : public PCacheOpChild
private: private:
// This class must be constructed by CacheChild or CacheStorageChild using // This class must be constructed by CacheChild or CacheStorageChild using
// their ExecuteOp() factory method. // their ExecuteOp() factory method.
CacheOpChild(CacheWorkerHolder* aWorkerHolder, nsIGlobalObject* aGlobal, CacheOpChild(Feature* aFeature, nsIGlobalObject* aGlobal,
nsISupports* aParent, Promise* aPromise); nsISupports* aParent, Promise* aPromise);
~CacheOpChild(); ~CacheOpChild();

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

@ -14,7 +14,7 @@
#include "mozilla/dom/cache/Cache.h" #include "mozilla/dom/cache/Cache.h"
#include "mozilla/dom/cache/CacheChild.h" #include "mozilla/dom/cache/CacheChild.h"
#include "mozilla/dom/cache/CacheStorageChild.h" #include "mozilla/dom/cache/CacheStorageChild.h"
#include "mozilla/dom/cache/CacheWorkerHolder.h" #include "mozilla/dom/cache/Feature.h"
#include "mozilla/dom/cache/PCacheChild.h" #include "mozilla/dom/cache/PCacheChild.h"
#include "mozilla/dom/cache/ReadStream.h" #include "mozilla/dom/cache/ReadStream.h"
#include "mozilla/dom/cache/TypeUtils.h" #include "mozilla/dom/cache/TypeUtils.h"
@ -202,9 +202,8 @@ CacheStorage::CreateOnWorker(Namespace aNamespace, nsIGlobalObject* aGlobal,
return ref.forget(); return ref.forget();
} }
RefPtr<CacheWorkerHolder> workerHolder = RefPtr<Feature> feature = Feature::Create(aWorkerPrivate);
CacheWorkerHolder::Create(aWorkerPrivate); if (!feature) {
if (!workerHolder) {
NS_WARNING("Worker thread is shutting down."); NS_WARNING("Worker thread is shutting down.");
aRv.Throw(NS_ERROR_FAILURE); aRv.Throw(NS_ERROR_FAILURE);
return nullptr; return nullptr;
@ -237,7 +236,7 @@ CacheStorage::CreateOnWorker(Namespace aNamespace, nsIGlobalObject* aGlobal,
} }
RefPtr<CacheStorage> ref = new CacheStorage(aNamespace, aGlobal, RefPtr<CacheStorage> ref = new CacheStorage(aNamespace, aGlobal,
principalInfo, workerHolder); principalInfo, feature);
return ref.forget(); return ref.forget();
} }
@ -277,12 +276,11 @@ CacheStorage::DefineCaches(JSContext* aCx, JS::Handle<JSObject*> aGlobal)
} }
CacheStorage::CacheStorage(Namespace aNamespace, nsIGlobalObject* aGlobal, CacheStorage::CacheStorage(Namespace aNamespace, nsIGlobalObject* aGlobal,
const PrincipalInfo& aPrincipalInfo, const PrincipalInfo& aPrincipalInfo, Feature* aFeature)
CacheWorkerHolder* aWorkerHolder)
: mNamespace(aNamespace) : mNamespace(aNamespace)
, mGlobal(aGlobal) , mGlobal(aGlobal)
, mPrincipalInfo(MakeUnique<PrincipalInfo>(aPrincipalInfo)) , mPrincipalInfo(MakeUnique<PrincipalInfo>(aPrincipalInfo))
, mWorkerHolder(aWorkerHolder) , mFeature(aFeature)
, mActor(nullptr) , mActor(nullptr)
, mStatus(NS_OK) , mStatus(NS_OK)
{ {
@ -511,15 +509,15 @@ CacheStorage::ActorCreated(PBackgroundChild* aActor)
NS_ASSERT_OWNINGTHREAD(CacheStorage); NS_ASSERT_OWNINGTHREAD(CacheStorage);
MOZ_ASSERT(aActor); MOZ_ASSERT(aActor);
if (NS_WARN_IF(mWorkerHolder && mWorkerHolder->Notified())) { if (NS_WARN_IF(mFeature && mFeature->Notified())) {
ActorFailed(); ActorFailed();
return; return;
} }
// WorkerHolder ownership is passed to the CacheStorageChild actor and any // Feature ownership is passed to the CacheStorageChild actor and any actors
// actors it may create. The WorkerHolder will keep the worker thread alive // it may create. The Feature will keep the worker thread alive until the
// until the actors can gracefully shutdown. // actors can gracefully shutdown.
CacheStorageChild* newActor = new CacheStorageChild(this, mWorkerHolder); CacheStorageChild* newActor = new CacheStorageChild(this, mFeature);
PCacheStorageChild* constructedActor = PCacheStorageChild* constructedActor =
aActor->SendPCacheStorageConstructor(newActor, mNamespace, *mPrincipalInfo); aActor->SendPCacheStorageConstructor(newActor, mNamespace, *mPrincipalInfo);
@ -528,7 +526,7 @@ CacheStorage::ActorCreated(PBackgroundChild* aActor)
return; return;
} }
mWorkerHolder = nullptr; mFeature = nullptr;
MOZ_ASSERT(constructedActor == newActor); MOZ_ASSERT(constructedActor == newActor);
mActor = newActor; mActor = newActor;
@ -544,7 +542,7 @@ CacheStorage::ActorFailed()
MOZ_ASSERT(!NS_FAILED(mStatus)); MOZ_ASSERT(!NS_FAILED(mStatus));
mStatus = NS_ERROR_UNEXPECTED; mStatus = NS_ERROR_UNEXPECTED;
mWorkerHolder = nullptr; mFeature = nullptr;
for (uint32_t i = 0; i < mPendingRequests.Length(); ++i) { for (uint32_t i = 0; i < mPendingRequests.Length(); ++i) {
nsAutoPtr<Entry> entry(mPendingRequests[i].forget()); nsAutoPtr<Entry> entry(mPendingRequests[i].forget());

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

@ -38,7 +38,7 @@ namespace workers {
namespace cache { namespace cache {
class CacheStorageChild; class CacheStorageChild;
class CacheWorkerHolder; class Feature;
class CacheStorage final : public nsIIPCBackgroundChildCreateCallback class CacheStorage final : public nsIIPCBackgroundChildCreateCallback
, public nsWrapperCache , public nsWrapperCache
@ -97,8 +97,7 @@ public:
private: private:
CacheStorage(Namespace aNamespace, nsIGlobalObject* aGlobal, CacheStorage(Namespace aNamespace, nsIGlobalObject* aGlobal,
const mozilla::ipc::PrincipalInfo& aPrincipalInfo, const mozilla::ipc::PrincipalInfo& aPrincipalInfo, Feature* aFeature);
CacheWorkerHolder* aWorkerHolder);
explicit CacheStorage(nsresult aFailureResult); explicit CacheStorage(nsresult aFailureResult);
~CacheStorage(); ~CacheStorage();
@ -107,7 +106,7 @@ private:
const Namespace mNamespace; const Namespace mNamespace;
nsCOMPtr<nsIGlobalObject> mGlobal; nsCOMPtr<nsIGlobalObject> mGlobal;
UniquePtr<mozilla::ipc::PrincipalInfo> mPrincipalInfo; UniquePtr<mozilla::ipc::PrincipalInfo> mPrincipalInfo;
RefPtr<CacheWorkerHolder> mWorkerHolder; RefPtr<Feature> mFeature;
// weak ref cleared in DestroyInternal // weak ref cleared in DestroyInternal
CacheStorageChild* mActor; CacheStorageChild* mActor;

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

@ -22,8 +22,7 @@ DeallocPCacheStorageChild(PCacheStorageChild* aActor)
delete aActor; delete aActor;
} }
CacheStorageChild::CacheStorageChild(CacheStorage* aListener, CacheStorageChild::CacheStorageChild(CacheStorage* aListener, Feature* aFeature)
CacheWorkerHolder* aWorkerHolder)
: mListener(aListener) : mListener(aListener)
, mNumChildActors(0) , mNumChildActors(0)
, mDelayedDestroy(false) , mDelayedDestroy(false)
@ -31,7 +30,7 @@ CacheStorageChild::CacheStorageChild(CacheStorage* aListener,
MOZ_COUNT_CTOR(cache::CacheStorageChild); MOZ_COUNT_CTOR(cache::CacheStorageChild);
MOZ_ASSERT(mListener); MOZ_ASSERT(mListener);
SetWorkerHolder(aWorkerHolder); SetFeature(aFeature);
} }
CacheStorageChild::~CacheStorageChild() CacheStorageChild::~CacheStorageChild()
@ -55,7 +54,7 @@ CacheStorageChild::ExecuteOp(nsIGlobalObject* aGlobal, Promise* aPromise,
{ {
mNumChildActors += 1; mNumChildActors += 1;
Unused << SendPCacheOpConstructor( Unused << SendPCacheOpConstructor(
new CacheOpChild(GetWorkerHolder(), aGlobal, aParent, aPromise), aArgs); new CacheOpChild(GetFeature(), aGlobal, aParent, aPromise), aArgs);
} }
void void
@ -87,8 +86,7 @@ CacheStorageChild::StartDestroy()
RefPtr<CacheStorage> listener = mListener; RefPtr<CacheStorage> listener = mListener;
// StartDestroy() can get called from either CacheStorage or the // StartDestroy() can get called from either CacheStorage or the Feature.
// CacheWorkerHolder.
// Theoretically we can get double called if the right race happens. Handle // Theoretically we can get double called if the right race happens. Handle
// that by just ignoring the second StartDestroy() call. // that by just ignoring the second StartDestroy() call.
if (!listener) { if (!listener) {
@ -115,7 +113,7 @@ CacheStorageChild::ActorDestroy(ActorDestroyReason aReason)
MOZ_ASSERT(!mListener); MOZ_ASSERT(!mListener);
} }
RemoveWorkerHolder(); RemoveFeature();
} }
PCacheOpChild* PCacheOpChild*

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

@ -22,14 +22,14 @@ namespace cache {
class CacheOpArgs; class CacheOpArgs;
class CacheStorage; class CacheStorage;
class CacheWorkerHolder;
class PCacheChild; class PCacheChild;
class Feature;
class CacheStorageChild final : public PCacheStorageChild class CacheStorageChild final : public PCacheStorageChild
, public ActorChild , public ActorChild
{ {
public: public:
CacheStorageChild(CacheStorage* aListener, CacheWorkerHolder* aWorkerHolder); CacheStorageChild(CacheStorage* aListener, Feature* aFeature);
~CacheStorageChild(); ~CacheStorageChild();
// Must be called by the associated CacheStorage listener in its // Must be called by the associated CacheStorage listener in its
@ -48,7 +48,7 @@ public:
private: private:
// ActorChild methods // ActorChild methods
// CacheWorkerHolder is trying to destroy due to worker shutdown. // Feature is trying to destroy due to worker shutdown.
virtual void StartDestroy() override; virtual void StartDestroy() override;
// PCacheStorageChild methods // PCacheStorageChild methods

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

@ -58,8 +58,8 @@ CacheStreamControlChild::StartDestroy()
{ {
NS_ASSERT_OWNINGTHREAD(CacheStreamControlChild); NS_ASSERT_OWNINGTHREAD(CacheStreamControlChild);
// This can get called twice under some circumstances. For example, if the // This can get called twice under some circumstances. For example, if the
// actor is added to a CacheWorkerHolder that has already been notified and // actor is added to a Feature that has already been notified and the Cache
// the Cache actor has no mListener. // actor has no mListener.
if (mDestroyStarted) { if (mDestroyStarted) {
return; return;
} }
@ -135,7 +135,7 @@ CacheStreamControlChild::ActorDestroy(ActorDestroyReason aReason)
{ {
NS_ASSERT_OWNINGTHREAD(CacheStreamControlChild); NS_ASSERT_OWNINGTHREAD(CacheStreamControlChild);
CloseAllReadStreamsWithoutReporting(); CloseAllReadStreamsWithoutReporting();
RemoveWorkerHolder(); RemoveFeature();
} }
bool bool

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

@ -8,7 +8,6 @@
#define mozilla_dom_cache_Connection_h #define mozilla_dom_cache_Connection_h
#include "mozIStorageConnection.h" #include "mozIStorageConnection.h"
#include "nsCOMPtr.h"
namespace mozilla { namespace mozilla {
namespace dom { namespace dom {

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

@ -4,7 +4,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/dom/cache/CacheWorkerHolder.h" #include "mozilla/dom/cache/Feature.h"
#include "mozilla/dom/cache/ActorChild.h" #include "mozilla/dom/cache/ActorChild.h"
#include "WorkerPrivate.h" #include "WorkerPrivate.h"
@ -18,25 +18,24 @@ using mozilla::dom::workers::Status;
using mozilla::dom::workers::WorkerPrivate; using mozilla::dom::workers::WorkerPrivate;
// static // static
already_AddRefed<CacheWorkerHolder> already_AddRefed<Feature>
CacheWorkerHolder::Create(WorkerPrivate* aWorkerPrivate) Feature::Create(WorkerPrivate* aWorkerPrivate)
{ {
MOZ_ASSERT(aWorkerPrivate); MOZ_ASSERT(aWorkerPrivate);
RefPtr<CacheWorkerHolder> workerHolder = RefPtr<Feature> feature = new Feature(aWorkerPrivate);
new CacheWorkerHolder(aWorkerPrivate);
if (NS_WARN_IF(!workerHolder->HoldWorker(aWorkerPrivate))) { if (!aWorkerPrivate->AddFeature(feature)) {
return nullptr; return nullptr;
} }
return workerHolder.forget(); return feature.forget();
} }
void void
CacheWorkerHolder::AddActor(ActorChild* aActor) Feature::AddActor(ActorChild* aActor)
{ {
NS_ASSERT_OWNINGTHREAD(CacheWorkerHolder); NS_ASSERT_OWNINGTHREAD(Feature);
MOZ_ASSERT(aActor); MOZ_ASSERT(aActor);
MOZ_ASSERT(!mActorList.Contains(aActor)); MOZ_ASSERT(!mActorList.Contains(aActor));
@ -52,9 +51,9 @@ CacheWorkerHolder::AddActor(ActorChild* aActor)
} }
void void
CacheWorkerHolder::RemoveActor(ActorChild* aActor) Feature::RemoveActor(ActorChild* aActor)
{ {
NS_ASSERT_OWNINGTHREAD(CacheWorkerHolder); NS_ASSERT_OWNINGTHREAD(Feature);
MOZ_ASSERT(aActor); MOZ_ASSERT(aActor);
DebugOnly<bool> removed = mActorList.RemoveElement(aActor); DebugOnly<bool> removed = mActorList.RemoveElement(aActor);
@ -64,15 +63,15 @@ CacheWorkerHolder::RemoveActor(ActorChild* aActor)
} }
bool bool
CacheWorkerHolder::Notified() const Feature::Notified() const
{ {
return mNotified; return mNotified;
} }
bool bool
CacheWorkerHolder::Notify(Status aStatus) Feature::Notify(Status aStatus)
{ {
NS_ASSERT_OWNINGTHREAD(CacheWorkerHolder); NS_ASSERT_OWNINGTHREAD(Feature);
// When the service worker thread is stopped we will get Terminating, // When the service worker thread is stopped we will get Terminating,
// but nothing higher than that. We must shut things down at Terminating. // but nothing higher than that. We must shut things down at Terminating.
@ -91,17 +90,19 @@ CacheWorkerHolder::Notify(Status aStatus)
return true; return true;
} }
CacheWorkerHolder::CacheWorkerHolder(WorkerPrivate* aWorkerPrivate) Feature::Feature(WorkerPrivate* aWorkerPrivate)
: mWorkerPrivate(aWorkerPrivate) : mWorkerPrivate(aWorkerPrivate)
, mNotified(false) , mNotified(false)
{ {
MOZ_ASSERT(mWorkerPrivate); MOZ_ASSERT(mWorkerPrivate);
} }
CacheWorkerHolder::~CacheWorkerHolder() Feature::~Feature()
{ {
NS_ASSERT_OWNINGTHREAD(CacheWorkerHolder); NS_ASSERT_OWNINGTHREAD(Feature);
MOZ_ASSERT(mActorList.IsEmpty()); MOZ_ASSERT(mActorList.IsEmpty());
mWorkerPrivate->RemoveFeature(this);
} }
} // namespace cache } // namespace cache

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

@ -4,12 +4,12 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_dom_cache_CacheWorkerHolder_h #ifndef mozilla_dom_cache_Feature_h
#define mozilla_dom_cache_CacheWorkerHolder_h #define mozilla_dom_cache_Feature_h
#include "nsISupportsImpl.h" #include "nsISupportsImpl.h"
#include "nsTArray.h" #include "nsTArray.h"
#include "WorkerHolder.h" #include "WorkerFeature.h"
namespace mozilla { namespace mozilla {
@ -22,34 +22,33 @@ namespace cache {
class ActorChild; class ActorChild;
class CacheWorkerHolder final : public workers::WorkerHolder class Feature final : public workers::WorkerFeature
{ {
public: public:
static already_AddRefed<CacheWorkerHolder> static already_AddRefed<Feature> Create(workers::WorkerPrivate* aWorkerPrivate);
Create(workers::WorkerPrivate* aWorkerPrivate);
void AddActor(ActorChild* aActor); void AddActor(ActorChild* aActor);
void RemoveActor(ActorChild* aActor); void RemoveActor(ActorChild* aActor);
bool Notified() const; bool Notified() const;
// WorkerHolder methods // WorkerFeature methods
virtual bool Notify(workers::Status aStatus) override; virtual bool Notify(workers::Status aStatus) override;
private: private:
explicit CacheWorkerHolder(workers::WorkerPrivate *aWorkerPrivate); explicit Feature(workers::WorkerPrivate *aWorkerPrivate);
~CacheWorkerHolder(); ~Feature();
workers::WorkerPrivate* mWorkerPrivate; workers::WorkerPrivate* mWorkerPrivate;
nsTArray<ActorChild*> mActorList; nsTArray<ActorChild*> mActorList;
bool mNotified; bool mNotified;
public: public:
NS_INLINE_DECL_REFCOUNTING(mozilla::dom::cache::CacheWorkerHolder) NS_INLINE_DECL_REFCOUNTING(mozilla::dom::cache::Feature)
}; };
} // namespace cache } // namespace cache
} // namespace dom } // namespace dom
} // namespace mozilla } // namespace mozilla
#endif // mozilla_dom_cache_CacheWorkerHolder_h #endif // mozilla_dom_cache_Feature_h

4
dom/cache/moz.build поставляемый
Просмотреть файл

@ -19,11 +19,11 @@ EXPORTS.mozilla.dom.cache += [
'CacheStorageParent.h', 'CacheStorageParent.h',
'CacheStreamControlChild.h', 'CacheStreamControlChild.h',
'CacheStreamControlParent.h', 'CacheStreamControlParent.h',
'CacheWorkerHolder.h',
'Connection.h', 'Connection.h',
'Context.h', 'Context.h',
'DBAction.h', 'DBAction.h',
'DBSchema.h', 'DBSchema.h',
'Feature.h',
'FileUtils.h', 'FileUtils.h',
'IPCUtils.h', 'IPCUtils.h',
'Manager.h', 'Manager.h',
@ -52,11 +52,11 @@ UNIFIED_SOURCES += [
'CacheStorageParent.cpp', 'CacheStorageParent.cpp',
'CacheStreamControlChild.cpp', 'CacheStreamControlChild.cpp',
'CacheStreamControlParent.cpp', 'CacheStreamControlParent.cpp',
'CacheWorkerHolder.cpp',
'Connection.cpp', 'Connection.cpp',
'Context.cpp', 'Context.cpp',
'DBAction.cpp', 'DBAction.cpp',
'DBSchema.cpp', 'DBSchema.cpp',
'Feature.cpp',
'FileUtils.cpp', 'FileUtils.cpp',
'Manager.cpp', 'Manager.cpp',
'ManagerId.cpp', 'ManagerId.cpp',

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

@ -107,7 +107,7 @@ WebGLContextLossHandler::WebGLContextLossHandler(WebGLContext* webgl)
, mIsTimerRunning(false) , mIsTimerRunning(false)
, mShouldRunTimerAgain(false) , mShouldRunTimerAgain(false)
, mIsDisabled(false) , mIsDisabled(false)
, mWorkerHolderAdded(false) , mFeatureAdded(false)
#ifdef DEBUG #ifdef DEBUG
, mThread(NS_GetCurrentThread()) , mThread(NS_GetCurrentThread())
#endif #endif
@ -186,9 +186,9 @@ WebGLContextLossHandler::RunTimer()
dom::workers::GetCurrentThreadWorkerPrivate(); dom::workers::GetCurrentThreadWorkerPrivate();
nsCOMPtr<nsIEventTarget> target = workerPrivate->GetEventTarget(); nsCOMPtr<nsIEventTarget> target = workerPrivate->GetEventTarget();
mTimer->SetTarget(new ContextLossWorkerEventTarget(target)); mTimer->SetTarget(new ContextLossWorkerEventTarget(target));
if (!mWorkerHolderAdded) { if (!mFeatureAdded) {
HoldWorker(workerPrivate); workerPrivate->AddFeature(this);
mWorkerHolderAdded = true; mFeatureAdded = true;
} }
} }
@ -206,12 +206,12 @@ WebGLContextLossHandler::DisableTimer()
mIsDisabled = true; mIsDisabled = true;
if (mWorkerHolderAdded) { if (mFeatureAdded) {
dom::workers::WorkerPrivate* workerPrivate = dom::workers::WorkerPrivate* workerPrivate =
dom::workers::GetCurrentThreadWorkerPrivate(); dom::workers::GetCurrentThreadWorkerPrivate();
MOZ_RELEASE_ASSERT(workerPrivate, "GFX: No private worker created."); MOZ_RELEASE_ASSERT(workerPrivate, "GFX: No private worker created.");
ReleaseWorker(); workerPrivate->RemoveFeature(this);
mWorkerHolderAdded = false; mFeatureAdded = false;
} }
// We can't just Cancel() the timer, as sometimes we end up // We can't just Cancel() the timer, as sometimes we end up

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

@ -10,7 +10,7 @@
#include "mozilla/WeakPtr.h" #include "mozilla/WeakPtr.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
#include "nsISupportsImpl.h" #include "nsISupportsImpl.h"
#include "WorkerHolder.h" #include "WorkerFeature.h"
class nsIThread; class nsIThread;
class nsITimer; class nsITimer;
@ -18,14 +18,14 @@ class nsITimer;
namespace mozilla { namespace mozilla {
class WebGLContext; class WebGLContext;
class WebGLContextLossHandler : public dom::workers::WorkerHolder class WebGLContextLossHandler : public dom::workers::WorkerFeature
{ {
WeakPtr<WebGLContext> mWeakWebGL; WeakPtr<WebGLContext> mWeakWebGL;
nsCOMPtr<nsITimer> mTimer; nsCOMPtr<nsITimer> mTimer;
bool mIsTimerRunning; bool mIsTimerRunning;
bool mShouldRunTimerAgain; bool mShouldRunTimerAgain;
bool mIsDisabled; bool mIsDisabled;
bool mWorkerHolderAdded; bool mFeatureAdded;
#ifdef DEBUG #ifdef DEBUG
nsIThread* mThread; nsIThread* mThread;
#endif #endif

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

@ -314,7 +314,7 @@ private:
}; };
class ConsoleRunnable : public Runnable class ConsoleRunnable : public Runnable
, public WorkerHolder , public WorkerFeature
, public StructuredCloneHolderBase , public StructuredCloneHolderBase
{ {
public: public:
@ -382,7 +382,7 @@ private:
return false; return false;
} }
if (NS_WARN_IF(!HoldWorker(mWorkerPrivate))) { if (NS_WARN_IF(!mWorkerPrivate->AddFeature(this))) {
return false; return false;
} }
@ -427,7 +427,7 @@ private:
mRunnable->ReleaseData(); mRunnable->ReleaseData();
mRunnable->mConsole = nullptr; mRunnable->mConsole = nullptr;
mRunnable->ReleaseWorker(); aWorkerPrivate->RemoveFeature(mRunnable);
return true; return true;
} }

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

@ -229,7 +229,7 @@ FetchRequest(nsIGlobalObject* aGlobal, const RequestOrUSVString& aInput,
RefPtr<WorkerFetchResolver> resolver = WorkerFetchResolver::Create(worker, p); RefPtr<WorkerFetchResolver> resolver = WorkerFetchResolver::Create(worker, p);
if (!resolver) { if (!resolver) {
NS_WARNING("Could not add WorkerFetchResolver workerHolder to worker"); NS_WARNING("Could not add WorkerFetchResolver feature to worker");
aRv.Throw(NS_ERROR_DOM_ABORT_ERR); aRv.Throw(NS_ERROR_DOM_ABORT_ERR);
return nullptr; return nullptr;
} }
@ -405,7 +405,7 @@ WorkerFetchResolver::OnResponseEnd()
RefPtr<WorkerFetchResponseEndControlRunnable> cr = RefPtr<WorkerFetchResponseEndControlRunnable> cr =
new WorkerFetchResponseEndControlRunnable(mPromiseProxy); new WorkerFetchResponseEndControlRunnable(mPromiseProxy);
// This can fail if the worker thread is canceled or killed causing // This can fail if the worker thread is canceled or killed causing
// the PromiseWorkerProxy to give up its WorkerHolder immediately, // the PromiseWorkerProxy to give up its WorkerFeature immediately,
// allowing the worker thread to become Dead. // allowing the worker thread to become Dead.
if (!cr->Dispatch()) { if (!cr->Dispatch()) {
NS_WARNING("Failed to dispatch WorkerFetchResponseEndControlRunnable"); NS_WARNING("Failed to dispatch WorkerFetchResponseEndControlRunnable");
@ -753,7 +753,7 @@ public:
nonconstResult); nonconstResult);
if (!r->Dispatch()) { if (!r->Dispatch()) {
// XXXcatalinb: The worker is shutting down, the pump will be canceled // XXXcatalinb: The worker is shutting down, the pump will be canceled
// by FetchBodyWorkerHolder::Notify. // by FetchBodyFeature::Notify.
NS_WARNING("Could not dispatch ConsumeBodyRunnable"); NS_WARNING("Could not dispatch ConsumeBodyRunnable");
// Return failure so that aResult is freed. // Return failure so that aResult is freed.
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
@ -819,20 +819,20 @@ public:
} // namespace } // namespace
template <class Derived> template <class Derived>
class FetchBodyWorkerHolder final : public workers::WorkerHolder class FetchBodyFeature final : public workers::WorkerFeature
{ {
// This is addrefed before the workerHolder is created, and is released in // This is addrefed before the feature is created, and is released in ContinueConsumeBody()
// ContinueConsumeBody() so we can hold a rawptr. // so we can hold a rawptr.
FetchBody<Derived>* mBody; FetchBody<Derived>* mBody;
bool mWasNotified; bool mWasNotified;
public: public:
explicit FetchBodyWorkerHolder(FetchBody<Derived>* aBody) explicit FetchBodyFeature(FetchBody<Derived>* aBody)
: mBody(aBody) : mBody(aBody)
, mWasNotified(false) , mWasNotified(false)
{ } { }
~FetchBodyWorkerHolder() ~FetchBodyFeature()
{ } { }
bool Notify(workers::Status aStatus) override bool Notify(workers::Status aStatus) override
@ -848,7 +848,7 @@ public:
template <class Derived> template <class Derived>
FetchBody<Derived>::FetchBody() FetchBody<Derived>::FetchBody()
: mWorkerHolder(nullptr) : mFeature(nullptr)
, mBodyUsed(false) , mBodyUsed(false)
#ifdef DEBUG #ifdef DEBUG
, mReadDone(false) , mReadDone(false)
@ -875,8 +875,8 @@ FetchBody<Derived>::~FetchBody()
// Returns true if addref succeeded. // Returns true if addref succeeded.
// Always succeeds on main thread. // Always succeeds on main thread.
// May fail on worker if RegisterWorkerHolder() fails. In that case, it will // May fail on worker if RegisterFeature() fails. In that case, it will release
// release the object before returning false. // the object before returning false.
template <class Derived> template <class Derived>
bool bool
FetchBody<Derived>::AddRefObject() FetchBody<Derived>::AddRefObject()
@ -884,8 +884,8 @@ FetchBody<Derived>::AddRefObject()
AssertIsOnTargetThread(); AssertIsOnTargetThread();
DerivedClass()->AddRef(); DerivedClass()->AddRef();
if (mWorkerPrivate && !mWorkerHolder) { if (mWorkerPrivate && !mFeature) {
if (!RegisterWorkerHolder()) { if (!RegisterFeature()) {
ReleaseObject(); ReleaseObject();
return false; return false;
} }
@ -899,8 +899,8 @@ FetchBody<Derived>::ReleaseObject()
{ {
AssertIsOnTargetThread(); AssertIsOnTargetThread();
if (mWorkerPrivate && mWorkerHolder) { if (mWorkerPrivate && mFeature) {
UnregisterWorkerHolder(); UnregisterFeature();
} }
DerivedClass()->Release(); DerivedClass()->Release();
@ -908,16 +908,16 @@ FetchBody<Derived>::ReleaseObject()
template <class Derived> template <class Derived>
bool bool
FetchBody<Derived>::RegisterWorkerHolder() FetchBody<Derived>::RegisterFeature()
{ {
MOZ_ASSERT(mWorkerPrivate); MOZ_ASSERT(mWorkerPrivate);
mWorkerPrivate->AssertIsOnWorkerThread(); mWorkerPrivate->AssertIsOnWorkerThread();
MOZ_ASSERT(!mWorkerHolder); MOZ_ASSERT(!mFeature);
mWorkerHolder = new FetchBodyWorkerHolder<Derived>(this); mFeature = new FetchBodyFeature<Derived>(this);
if (!mWorkerHolder->HoldWorker(mWorkerPrivate)) { if (!mWorkerPrivate->AddFeature(mFeature)) {
NS_WARNING("Failed to add workerHolder"); NS_WARNING("Failed to add feature");
mWorkerHolder = nullptr; mFeature = nullptr;
return false; return false;
} }
@ -926,14 +926,14 @@ FetchBody<Derived>::RegisterWorkerHolder()
template <class Derived> template <class Derived>
void void
FetchBody<Derived>::UnregisterWorkerHolder() FetchBody<Derived>::UnregisterFeature()
{ {
MOZ_ASSERT(mWorkerPrivate); MOZ_ASSERT(mWorkerPrivate);
mWorkerPrivate->AssertIsOnWorkerThread(); mWorkerPrivate->AssertIsOnWorkerThread();
MOZ_ASSERT(mWorkerHolder); MOZ_ASSERT(mFeature);
mWorkerHolder->ReleaseWorker(); mWorkerPrivate->RemoveFeature(mFeature);
mWorkerHolder = nullptr; mFeature = nullptr;
} }
template <class Derived> template <class Derived>
@ -952,7 +952,7 @@ nsresult
FetchBody<Derived>::BeginConsumeBody() FetchBody<Derived>::BeginConsumeBody()
{ {
AssertIsOnTargetThread(); AssertIsOnTargetThread();
MOZ_ASSERT(!mWorkerHolder); MOZ_ASSERT(!mFeature);
MOZ_ASSERT(mConsumePromise); MOZ_ASSERT(mConsumePromise);
// The FetchBody is not thread-safe refcounted. We addref it here and release // 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. // sync with a body read.
MOZ_ASSERT(mBodyUsed); MOZ_ASSERT(mBodyUsed);
MOZ_ASSERT(!mReadDone); MOZ_ASSERT(!mReadDone);
MOZ_ASSERT_IF(mWorkerPrivate, mWorkerHolder); MOZ_ASSERT_IF(mWorkerPrivate, mFeature);
#ifdef DEBUG #ifdef DEBUG
mReadDone = true; mReadDone = true;
#endif #endif

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

@ -20,7 +20,7 @@
#include "mozilla/ErrorResult.h" #include "mozilla/ErrorResult.h"
#include "mozilla/dom/Promise.h" #include "mozilla/dom/Promise.h"
#include "mozilla/dom/RequestBinding.h" #include "mozilla/dom/RequestBinding.h"
#include "mozilla/dom/workers/bindings/WorkerHolder.h" #include "mozilla/dom/workers/bindings/WorkerFeature.h"
class nsIGlobalObject; class nsIGlobalObject;
@ -63,7 +63,7 @@ ExtractByteStreamFromBody(const ArrayBufferOrArrayBufferViewOrBlobOrFormDataOrUS
nsCString& aContentType, nsCString& aContentType,
uint64_t& aContentLength); uint64_t& aContentLength);
template <class Derived> class FetchBodyWorkerHolder; template <class Derived> class FetchBodyFeature;
/* /*
* FetchBody's body consumption uses nsIInputStreamPump to read from the * 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. // Set when consuming the body is attempted on a worker.
// Unset when consumption is done/aborted. // Unset when consumption is done/aborted.
nsAutoPtr<workers::WorkerHolder> mWorkerHolder; nsAutoPtr<workers::WorkerFeature> mFeature;
protected: protected:
FetchBody(); FetchBody();
@ -193,10 +193,10 @@ private:
ReleaseObject(); ReleaseObject();
bool bool
RegisterWorkerHolder(); RegisterFeature();
void void
UnregisterWorkerHolder(); UnregisterFeature();
bool bool
IsOnTargetThread() IsOnTargetThread()

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

@ -903,7 +903,7 @@ protected:
}; };
class WorkerPermissionChallenge final : public Runnable class WorkerPermissionChallenge final : public Runnable
, public WorkerHolder , public WorkerFeature
{ {
public: public:
WorkerPermissionChallenge(WorkerPrivate* aWorkerPrivate, WorkerPermissionChallenge(WorkerPrivate* aWorkerPrivate,
@ -963,7 +963,7 @@ public:
mActor = nullptr; mActor = nullptr;
mWorkerPrivate->AssertIsOnWorkerThread(); mWorkerPrivate->AssertIsOnWorkerThread();
ReleaseWorker(); mWorkerPrivate->RemoveFeature(this);
} }
private: private:
@ -1415,7 +1415,7 @@ BackgroundFactoryRequestChild::RecvPermissionChallenge(
new WorkerPermissionChallenge(workerPrivate, this, mFactory, new WorkerPermissionChallenge(workerPrivate, this, mFactory,
aPrincipalInfo); aPrincipalInfo);
if (NS_WARN_IF(!challenge->HoldWorker(workerPrivate))) { if (NS_WARN_IF(!workerPrivate->AddFeature(challenge))) {
return false; return false;
} }

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

@ -30,7 +30,7 @@
#include "nsPIDOMWindow.h" #include "nsPIDOMWindow.h"
#include "nsString.h" #include "nsString.h"
#include "ReportInternalError.h" #include "ReportInternalError.h"
#include "WorkerHolder.h" #include "WorkerFeature.h"
#include "WorkerPrivate.h" #include "WorkerPrivate.h"
// Include this last to avoid path problems on Windows. // Include this last to avoid path problems on Windows.
@ -461,19 +461,19 @@ IDBRequest::PreHandleEvent(EventChainPreVisitor& aVisitor)
return NS_OK; return NS_OK;
} }
class IDBOpenDBRequest::WorkerHolder final class IDBOpenDBRequest::WorkerFeature final
: public mozilla::dom::workers::WorkerHolder : public mozilla::dom::workers::WorkerFeature
{ {
WorkerPrivate* mWorkerPrivate; WorkerPrivate* mWorkerPrivate;
#ifdef DEBUG #ifdef DEBUG
// This is only here so that assertions work in the destructor even if // This is only here so that assertions work in the destructor even if
// NoteAddWorkerHolderFailed was called. // NoteAddFeatureFailed was called.
WorkerPrivate* mWorkerPrivateDEBUG; WorkerPrivate* mWorkerPrivateDEBUG;
#endif #endif
public: public:
explicit explicit
WorkerHolder(WorkerPrivate* aWorkerPrivate) WorkerFeature(WorkerPrivate* aWorkerPrivate)
: mWorkerPrivate(aWorkerPrivate) : mWorkerPrivate(aWorkerPrivate)
#ifdef DEBUG #ifdef DEBUG
, mWorkerPrivateDEBUG(aWorkerPrivate) , mWorkerPrivateDEBUG(aWorkerPrivate)
@ -482,20 +482,24 @@ public:
MOZ_ASSERT(aWorkerPrivate); MOZ_ASSERT(aWorkerPrivate);
aWorkerPrivate->AssertIsOnWorkerThread(); aWorkerPrivate->AssertIsOnWorkerThread();
MOZ_COUNT_CTOR(IDBOpenDBRequest::WorkerHolder); MOZ_COUNT_CTOR(IDBOpenDBRequest::WorkerFeature);
} }
~WorkerHolder() ~WorkerFeature()
{ {
#ifdef DEBUG #ifdef DEBUG
mWorkerPrivateDEBUG->AssertIsOnWorkerThread(); mWorkerPrivateDEBUG->AssertIsOnWorkerThread();
#endif #endif
MOZ_COUNT_DTOR(IDBOpenDBRequest::WorkerHolder); MOZ_COUNT_DTOR(IDBOpenDBRequest::WorkerFeature);
if (mWorkerPrivate) {
mWorkerPrivate->RemoveFeature(this);
}
} }
void void
NoteAddWorkerHolderFailed() NoteAddFeatureFailed()
{ {
MOZ_ASSERT(mWorkerPrivate); MOZ_ASSERT(mWorkerPrivate);
mWorkerPrivate->AssertIsOnWorkerThread(); mWorkerPrivate->AssertIsOnWorkerThread();
@ -573,13 +577,13 @@ IDBOpenDBRequest::CreateForJS(JSContext* aCx,
workerPrivate->AssertIsOnWorkerThread(); workerPrivate->AssertIsOnWorkerThread();
nsAutoPtr<WorkerHolder> workerHolder(new WorkerHolder(workerPrivate)); nsAutoPtr<WorkerFeature> feature(new WorkerFeature(workerPrivate));
if (NS_WARN_IF(!workerHolder->HoldWorker(workerPrivate))) { if (NS_WARN_IF(!workerPrivate->AddFeature(feature))) {
workerHolder->NoteAddWorkerHolderFailed(); feature->NoteAddFeatureFailed();
return nullptr; return nullptr;
} }
request->mWorkerHolder = Move(workerHolder); request->mWorkerFeature = Move(feature);
} }
return request.forget(); return request.forget();
@ -599,11 +603,11 @@ void
IDBOpenDBRequest::NoteComplete() IDBOpenDBRequest::NoteComplete()
{ {
AssertIsOnOwningThread(); AssertIsOnOwningThread();
MOZ_ASSERT_IF(!NS_IsMainThread(), mWorkerHolder); MOZ_ASSERT_IF(!NS_IsMainThread(), mWorkerFeature);
// If we have a WorkerHolder installed on the worker then nulling this out // If we have a WorkerFeature installed on the worker then nulling this out
// will uninstall it from the worker. // will uninstall it from the worker.
mWorkerHolder = nullptr; mWorkerFeature = nullptr;
} }
NS_IMPL_CYCLE_COLLECTION_CLASS(IDBOpenDBRequest) NS_IMPL_CYCLE_COLLECTION_CLASS(IDBOpenDBRequest)
@ -646,7 +650,7 @@ IDBOpenDBRequest::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
bool bool
IDBOpenDBRequest:: IDBOpenDBRequest::
WorkerHolder::Notify(Status aStatus) WorkerFeature::Notify(Status aStatus)
{ {
MOZ_ASSERT(mWorkerPrivate); MOZ_ASSERT(mWorkerPrivate);
mWorkerPrivate->AssertIsOnWorkerThread(); mWorkerPrivate->AssertIsOnWorkerThread();

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

@ -226,12 +226,12 @@ protected:
class IDBOpenDBRequest final class IDBOpenDBRequest final
: public IDBRequest : public IDBRequest
{ {
class WorkerHolder; class WorkerFeature;
// Only touched on the owning thread. // Only touched on the owning thread.
RefPtr<IDBFactory> mFactory; RefPtr<IDBFactory> mFactory;
nsAutoPtr<WorkerHolder> mWorkerHolder; nsAutoPtr<WorkerFeature> mWorkerFeature;
const bool mFileHandleDisabled; const bool mFileHandleDisabled;

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

@ -22,7 +22,7 @@
#include "nsTHashtable.h" #include "nsTHashtable.h"
#include "ProfilerHelpers.h" #include "ProfilerHelpers.h"
#include "ReportInternalError.h" #include "ReportInternalError.h"
#include "WorkerHolder.h" #include "WorkerFeature.h"
#include "WorkerPrivate.h" #include "WorkerPrivate.h"
// Include this last to avoid path problems on Windows. // 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::dom::workers;
using namespace mozilla::ipc; using namespace mozilla::ipc;
class IDBTransaction::WorkerHolder final class IDBTransaction::WorkerFeature final
: public mozilla::dom::workers::WorkerHolder : public mozilla::dom::workers::WorkerFeature
{ {
WorkerPrivate* mWorkerPrivate; WorkerPrivate* mWorkerPrivate;
@ -45,7 +45,7 @@ class IDBTransaction::WorkerHolder final
IDBTransaction* mTransaction; IDBTransaction* mTransaction;
public: public:
WorkerHolder(WorkerPrivate* aWorkerPrivate, IDBTransaction* aTransaction) WorkerFeature(WorkerPrivate* aWorkerPrivate, IDBTransaction* aTransaction)
: mWorkerPrivate(aWorkerPrivate) : mWorkerPrivate(aWorkerPrivate)
, mTransaction(aTransaction) , mTransaction(aTransaction)
{ {
@ -54,14 +54,16 @@ public:
aWorkerPrivate->AssertIsOnWorkerThread(); aWorkerPrivate->AssertIsOnWorkerThread();
aTransaction->AssertIsOnOwningThread(); aTransaction->AssertIsOnOwningThread();
MOZ_COUNT_CTOR(IDBTransaction::WorkerHolder); MOZ_COUNT_CTOR(IDBTransaction::WorkerFeature);
} }
~WorkerHolder() ~WorkerFeature()
{ {
mWorkerPrivate->AssertIsOnWorkerThread(); mWorkerPrivate->AssertIsOnWorkerThread();
MOZ_COUNT_DTOR(IDBTransaction::WorkerHolder); MOZ_COUNT_DTOR(IDBTransaction::WorkerFeature);
mWorkerPrivate->RemoveFeature(this);
} }
private: private:
@ -239,8 +241,8 @@ IDBTransaction::Create(JSContext* aCx, IDBDatabase* aDatabase,
workerPrivate->AssertIsOnWorkerThread(); workerPrivate->AssertIsOnWorkerThread();
transaction->mWorkerHolder = new WorkerHolder(workerPrivate, transaction); transaction->mWorkerFeature = new WorkerFeature(workerPrivate, transaction);
MOZ_ALWAYS_TRUE(transaction->mWorkerHolder->HoldWorker(workerPrivate)); MOZ_ALWAYS_TRUE(workerPrivate->AddFeature(transaction->mWorkerFeature));
} }
return transaction.forget(); return transaction.forget();
@ -784,8 +786,8 @@ IDBTransaction::FireCompleteOrAbortEvents(nsresult aResult)
mFiredCompleteOrAbort = true; mFiredCompleteOrAbort = true;
#endif #endif
// Make sure we drop the WorkerHolder when this function completes. // Make sure we drop the WorkerFeature when this function completes.
nsAutoPtr<WorkerHolder> workerHolder = Move(mWorkerHolder); nsAutoPtr<WorkerFeature> workerFeature = Move(mWorkerFeature);
nsCOMPtr<nsIDOMEvent> event; nsCOMPtr<nsIDOMEvent> event;
if (NS_SUCCEEDED(aResult)) { if (NS_SUCCEEDED(aResult)) {
@ -1028,7 +1030,7 @@ IDBTransaction::Run()
bool bool
IDBTransaction:: IDBTransaction::
WorkerHolder::Notify(Status aStatus) WorkerFeature::Notify(Status aStatus)
{ {
MOZ_ASSERT(mWorkerPrivate); MOZ_ASSERT(mWorkerPrivate);
mWorkerPrivate->AssertIsOnWorkerThread(); mWorkerPrivate->AssertIsOnWorkerThread();

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

@ -50,8 +50,8 @@ class IDBTransaction final
friend class indexedDB::BackgroundCursorChild; friend class indexedDB::BackgroundCursorChild;
friend class indexedDB::BackgroundRequestChild; friend class indexedDB::BackgroundRequestChild;
class WorkerHolder; class WorkerFeature;
friend class WorkerHolder; friend class WorkerFeature;
public: public:
enum Mode enum Mode
@ -80,7 +80,7 @@ private:
nsTArray<nsString> mObjectStoreNames; nsTArray<nsString> mObjectStoreNames;
nsTArray<RefPtr<IDBObjectStore>> mObjectStores; nsTArray<RefPtr<IDBObjectStore>> mObjectStores;
nsTArray<RefPtr<IDBObjectStore>> mDeletedObjectStores; nsTArray<RefPtr<IDBObjectStore>> mDeletedObjectStores;
nsAutoPtr<WorkerHolder> mWorkerHolder; nsAutoPtr<WorkerFeature> mWorkerFeature;
// Tagged with mMode. If mMode is VERSION_CHANGE then mBackgroundActor will be // Tagged with mMode. If mMode is VERSION_CHANGE then mBackgroundActor will be
// a BackgroundVersionChangeTransactionChild. Otherwise it will be a // a BackgroundVersionChangeTransactionChild. Otherwise it will be a

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

@ -195,16 +195,16 @@ NS_IMPL_RELEASE_INHERITED(MessagePort, DOMEventTargetHelper)
namespace { namespace {
class MessagePortWorkerHolder final : public workers::WorkerHolder class MessagePortFeature final : public workers::WorkerFeature
{ {
MessagePort* mPort; MessagePort* mPort;
public: public:
explicit MessagePortWorkerHolder(MessagePort* aPort) explicit MessagePortFeature(MessagePort* aPort)
: mPort(aPort) : mPort(aPort)
{ {
MOZ_ASSERT(aPort); MOZ_ASSERT(aPort);
MOZ_COUNT_CTOR(MessagePortWorkerHolder); MOZ_COUNT_CTOR(MessagePortFeature);
} }
virtual bool Notify(workers::Status aStatus) override virtual bool Notify(workers::Status aStatus) override
@ -219,9 +219,9 @@ public:
} }
private: private:
~MessagePortWorkerHolder() ~MessagePortFeature()
{ {
MOZ_COUNT_DTOR(MessagePortWorkerHolder); MOZ_COUNT_DTOR(MessagePortFeature);
} }
}; };
@ -287,7 +287,7 @@ MessagePort::MessagePort(nsIGlobalObject* aGlobal)
MessagePort::~MessagePort() MessagePort::~MessagePort()
{ {
CloseForced(); CloseForced();
MOZ_ASSERT(!mWorkerHolder); MOZ_ASSERT(!mWorkerFeature);
} }
/* static */ already_AddRefed<MessagePort> /* static */ already_AddRefed<MessagePort>
@ -340,7 +340,7 @@ MessagePort::Initialize(const nsID& aUUID,
if (mNeutered) { if (mNeutered) {
// If this port is neutered we don't want to keep it alive artificially nor // If this port is neutered we don't want to keep it alive artificially nor
// we want to add listeners or workerWorkerHolders. // we want to add listeners or workerFeatures.
mState = eStateDisentangled; mState = eStateDisentangled;
return; return;
} }
@ -357,15 +357,15 @@ MessagePort::Initialize(const nsID& aUUID,
if (!NS_IsMainThread()) { if (!NS_IsMainThread()) {
WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate(); WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
MOZ_ASSERT(workerPrivate); MOZ_ASSERT(workerPrivate);
MOZ_ASSERT(!mWorkerHolder); MOZ_ASSERT(!mWorkerFeature);
nsAutoPtr<WorkerHolder> workerHolder(new MessagePortWorkerHolder(this)); nsAutoPtr<WorkerFeature> feature(new MessagePortFeature(this));
if (NS_WARN_IF(!workerHolder->HoldWorker(workerPrivate))) { if (NS_WARN_IF(!workerPrivate->AddFeature(feature))) {
aRv.Throw(NS_ERROR_FAILURE); aRv.Throw(NS_ERROR_FAILURE);
return; return;
} }
mWorkerHolder = Move(workerHolder); mWorkerFeature = Move(feature);
} else if (GetOwner()) { } else if (GetOwner()) {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(GetOwner()->IsInnerWindow()); MOZ_ASSERT(GetOwner()->IsInnerWindow());
@ -912,8 +912,13 @@ MessagePort::UpdateMustKeepAlive()
mIsKeptAlive) { mIsKeptAlive) {
mIsKeptAlive = false; mIsKeptAlive = false;
// The DTOR of this WorkerHolder will release the worker for us. if (mWorkerFeature) {
mWorkerHolder = nullptr; WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
MOZ_ASSERT(workerPrivate);
workerPrivate->RemoveFeature(mWorkerFeature);
mWorkerFeature = nullptr;
}
if (NS_IsMainThread()) { if (NS_IsMainThread()) {
nsCOMPtr<nsIObserverService> obs = nsCOMPtr<nsIObserverService> obs =

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

@ -29,7 +29,7 @@ class PostMessageRunnable;
class SharedMessagePortMessage; class SharedMessagePortMessage;
namespace workers { namespace workers {
class WorkerHolder; class WorkerFeature;
} // namespace workers } // namespace workers
class MessagePort final : public DOMEventTargetHelper class MessagePort final : public DOMEventTargetHelper
@ -164,7 +164,7 @@ private:
return mIsKeptAlive; return mIsKeptAlive;
} }
nsAutoPtr<workers::WorkerHolder> mWorkerHolder; nsAutoPtr<workers::WorkerFeature> mWorkerFeature;
RefPtr<PostMessageRunnable> mPostMessageRunnable; RefPtr<PostMessageRunnable> mPostMessageRunnable;

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

@ -458,10 +458,9 @@ public:
} }
// This is only required because Gecko runs script in a worker's onclose // This is only required because Gecko runs script in a worker's onclose
// handler (non-standard, Bug 790919) where calls to HoldWorker() will // handler (non-standard, Bug 790919) where calls to AddFeature() will fail.
// fail. Due to non-standardness and added complications if we decide to // Due to non-standardness and added complications if we decide to support
// support this, attempts to create a Notification in onclose just throw // this, attempts to create a Notification in onclose just throw exceptions.
// exceptions.
bool bool
Initialized() Initialized()
{ {
@ -1200,7 +1199,7 @@ Notification::~Notification()
mData.setUndefined(); mData.setUndefined();
mozilla::DropJSObjects(this); mozilla::DropJSObjects(this);
AssertIsOnTargetThread(); AssertIsOnTargetThread();
MOZ_ASSERT(!mWorkerHolder); MOZ_ASSERT(!mFeature);
MOZ_ASSERT(!mTempRef); MOZ_ASSERT(!mTempRef);
} }
@ -2441,10 +2440,10 @@ bool
Notification::AddRefObject() Notification::AddRefObject()
{ {
AssertIsOnTargetThread(); AssertIsOnTargetThread();
MOZ_ASSERT_IF(mWorkerPrivate && !mWorkerHolder, mTaskCount == 0); MOZ_ASSERT_IF(mWorkerPrivate && !mFeature, mTaskCount == 0);
MOZ_ASSERT_IF(mWorkerPrivate && mWorkerHolder, mTaskCount > 0); MOZ_ASSERT_IF(mWorkerPrivate && mFeature, mTaskCount > 0);
if (mWorkerPrivate && !mWorkerHolder) { if (mWorkerPrivate && !mFeature) {
if (!RegisterWorkerHolder()) { if (!RegisterFeature()) {
return false; return false;
} }
} }
@ -2458,16 +2457,16 @@ Notification::ReleaseObject()
{ {
AssertIsOnTargetThread(); AssertIsOnTargetThread();
MOZ_ASSERT(mTaskCount > 0); MOZ_ASSERT(mTaskCount > 0);
MOZ_ASSERT_IF(mWorkerPrivate, mWorkerHolder); MOZ_ASSERT_IF(mWorkerPrivate, mFeature);
--mTaskCount; --mTaskCount;
if (mWorkerPrivate && mTaskCount == 0) { if (mWorkerPrivate && mTaskCount == 0) {
UnregisterWorkerHolder(); UnregisterFeature();
} }
Release(); Release();
} }
NotificationWorkerHolder::NotificationWorkerHolder(Notification* aNotification) NotificationFeature::NotificationFeature(Notification* aNotification)
: mNotification(aNotification) : mNotification(aNotification)
{ {
MOZ_ASSERT(mNotification->mWorkerPrivate); MOZ_ASSERT(mNotification->mWorkerPrivate);
@ -2515,7 +2514,7 @@ class CloseNotificationRunnable final
}; };
bool bool
NotificationWorkerHolder::Notify(Status aStatus) NotificationFeature::Notify(Status aStatus)
{ {
if (aStatus >= Canceling) { if (aStatus >= Canceling) {
// CloseNotificationRunnable blocks the worker by pushing a sync event loop // CloseNotificationRunnable blocks the worker by pushing a sync event loop
@ -2558,26 +2557,28 @@ NotificationWorkerHolder::Notify(Status aStatus)
} }
bool bool
Notification::RegisterWorkerHolder() Notification::RegisterFeature()
{ {
MOZ_ASSERT(mWorkerPrivate); MOZ_ASSERT(mWorkerPrivate);
mWorkerPrivate->AssertIsOnWorkerThread(); mWorkerPrivate->AssertIsOnWorkerThread();
MOZ_ASSERT(!mWorkerHolder); MOZ_ASSERT(!mFeature);
mWorkerHolder = MakeUnique<NotificationWorkerHolder>(this); mFeature = MakeUnique<NotificationFeature>(this);
if (NS_WARN_IF(!mWorkerHolder->HoldWorker(mWorkerPrivate))) { bool added = mWorkerPrivate->AddFeature(mFeature.get());
return false; if (!added) {
mFeature = nullptr;
} }
return true; return added;
} }
void void
Notification::UnregisterWorkerHolder() Notification::UnregisterFeature()
{ {
MOZ_ASSERT(mWorkerPrivate); MOZ_ASSERT(mWorkerPrivate);
mWorkerPrivate->AssertIsOnWorkerThread(); mWorkerPrivate->AssertIsOnWorkerThread();
MOZ_ASSERT(mWorkerHolder); MOZ_ASSERT(mFeature);
mWorkerHolder = nullptr; mWorkerPrivate->RemoveFeature(mFeature.get());
mFeature = nullptr;
} }
/* /*

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

@ -9,7 +9,7 @@
#include "mozilla/DOMEventTargetHelper.h" #include "mozilla/DOMEventTargetHelper.h"
#include "mozilla/UniquePtr.h" #include "mozilla/UniquePtr.h"
#include "mozilla/dom/NotificationBinding.h" #include "mozilla/dom/NotificationBinding.h"
#include "mozilla/dom/workers/bindings/WorkerHolder.h" #include "mozilla/dom/workers/bindings/WorkerFeature.h"
#include "nsIObserver.h" #include "nsIObserver.h"
@ -36,14 +36,14 @@ namespace workers {
} // namespace workers } // namespace workers
class Notification; class Notification;
class NotificationWorkerHolder final : public workers::WorkerHolder class NotificationFeature final : public workers::WorkerFeature
{ {
// Since the feature is strongly held by a Notification, it is ok to hold // Since the feature is strongly held by a Notification, it is ok to hold
// a raw pointer here. // a raw pointer here.
Notification* mNotification; Notification* mNotification;
public: public:
explicit NotificationWorkerHolder(Notification* aNotification); explicit NotificationFeature(Notification* aNotification);
bool bool
Notify(workers::Status aStatus) override; Notify(workers::Status aStatus) override;
@ -448,13 +448,13 @@ private:
return NS_IsMainThread() == !mWorkerPrivate; return NS_IsMainThread() == !mWorkerPrivate;
} }
bool RegisterWorkerHolder(); bool RegisterFeature();
void UnregisterWorkerHolder(); void UnregisterFeature();
nsresult ResolveIconAndSoundURL(nsString&, nsString&); nsresult ResolveIconAndSoundURL(nsString&, nsString&);
// Only used for Notifications on Workers, worker thread only. // Only used for Notifications on Workers, worker thread only.
UniquePtr<NotificationWorkerHolder> mWorkerHolder; UniquePtr<NotificationFeature> mFeature;
// Target thread only. // Target thread only.
uint32_t mTaskCount; uint32_t mTaskCount;
}; };

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

@ -2527,7 +2527,7 @@ Promise::AppendCallbacks(PromiseCallback* aResolveCallback,
#if defined(DOM_PROMISE_DEPRECATED_REPORTING) #if defined(DOM_PROMISE_DEPRECATED_REPORTING)
// Now that there is a callback, we don't need to report anymore. // Now that there is a callback, we don't need to report anymore.
mHadRejectCallback = true; mHadRejectCallback = true;
RemoveWorkerHolder(); RemoveFeature();
#endif // defined(DOM_PROMISE_DEPRECATED_REPORTING) #endif // defined(DOM_PROMISE_DEPRECATED_REPORTING)
mResolveCallbacks.AppendElement(aResolveCallback); mResolveCallbacks.AppendElement(aResolveCallback);
@ -2767,9 +2767,10 @@ Promise::Settle(JS::Handle<JS::Value> aValue, PromiseState aState)
MOZ_ASSERT(worker); MOZ_ASSERT(worker);
worker->AssertIsOnWorkerThread(); worker->AssertIsOnWorkerThread();
mWorkerHolder = new PromiseReportRejectWorkerHolder(this); mFeature = new PromiseReportRejectFeature(this);
if (NS_WARN_IF(!mWorkerHolder->HoldWorker(worker))) { if (NS_WARN_IF(!worker->AddFeature(mFeature))) {
mWorkerHolder = nullptr; // To avoid a false RemoveFeature().
mFeature = nullptr;
// Worker is shutting down, report rejection immediately since it is // Worker is shutting down, report rejection immediately since it is
// unlikely that reject callbacks will be added after this point. // unlikely that reject callbacks will be added after this point.
MaybeReportRejectedOnce(); MaybeReportRejectedOnce();
@ -2818,20 +2819,24 @@ Promise::TriggerPromiseReactions()
#if defined(DOM_PROMISE_DEPRECATED_REPORTING) #if defined(DOM_PROMISE_DEPRECATED_REPORTING)
void void
Promise::RemoveWorkerHolder() Promise::RemoveFeature()
{ {
NS_ASSERT_OWNINGTHREAD(Promise); NS_ASSERT_OWNINGTHREAD(Promise);
// The DTOR of this WorkerHolder will release the worker for us. if (mFeature) {
mWorkerHolder = nullptr; workers::WorkerPrivate* worker = GetCurrentThreadWorkerPrivate();
MOZ_ASSERT(worker);
worker->RemoveFeature(mFeature);
mFeature = nullptr;
}
} }
bool bool
PromiseReportRejectWorkerHolder::Notify(workers::Status aStatus) PromiseReportRejectFeature::Notify(workers::Status aStatus)
{ {
MOZ_ASSERT(aStatus > workers::Running); MOZ_ASSERT(aStatus > workers::Running);
mPromise->MaybeReportRejectedOnce(); mPromise->MaybeReportRejectedOnce();
// After this point, `this` has been deleted by RemoveWorkerHolder! // After this point, `this` has been deleted by RemoveFeature!
return true; return true;
} }
#endif // defined(DOM_PROMISE_DEPRECATED_REPORTING) #endif // defined(DOM_PROMISE_DEPRECATED_REPORTING)
@ -2966,7 +2971,7 @@ PromiseWorkerProxy::PromiseWorkerProxy(workers::WorkerPrivate* aWorkerPrivate,
, mCallbacks(aCallbacks) , mCallbacks(aCallbacks)
, mCleanUpLock("cleanUpLock") , mCleanUpLock("cleanUpLock")
#ifdef DEBUG #ifdef DEBUG
, mWorkerHolderAdded(false) , mFeatureAdded(false)
#endif #endif
{ {
} }
@ -2974,7 +2979,7 @@ PromiseWorkerProxy::PromiseWorkerProxy(workers::WorkerPrivate* aWorkerPrivate,
PromiseWorkerProxy::~PromiseWorkerProxy() PromiseWorkerProxy::~PromiseWorkerProxy()
{ {
MOZ_ASSERT(mCleanedUp); MOZ_ASSERT(mCleanedUp);
MOZ_ASSERT(!mWorkerHolderAdded); MOZ_ASSERT(!mFeatureAdded);
MOZ_ASSERT(!mWorkerPromise); MOZ_ASSERT(!mWorkerPromise);
MOZ_ASSERT(!mWorkerPrivate); MOZ_ASSERT(!mWorkerPrivate);
} }
@ -3002,13 +3007,13 @@ PromiseWorkerProxy::AddRefObject()
{ {
MOZ_ASSERT(mWorkerPrivate); MOZ_ASSERT(mWorkerPrivate);
mWorkerPrivate->AssertIsOnWorkerThread(); mWorkerPrivate->AssertIsOnWorkerThread();
MOZ_ASSERT(!mWorkerHolderAdded); MOZ_ASSERT(!mFeatureAdded);
if (NS_WARN_IF(!HoldWorker(mWorkerPrivate))) { if (!mWorkerPrivate->AddFeature(this)) {
return false; return false;
} }
#ifdef DEBUG #ifdef DEBUG
mWorkerHolderAdded = true; mFeatureAdded = true;
#endif #endif
// Maintain a reference so that we have a valid object to clean up when // Maintain a reference so that we have a valid object to clean up when
// removing the feature. // removing the feature.
@ -3027,7 +3032,7 @@ PromiseWorkerProxy::GetWorkerPrivate() const
// Safe to check this without a lock since we assert lock ownership on the // Safe to check this without a lock since we assert lock ownership on the
// main thread above. // main thread above.
MOZ_ASSERT(!mCleanedUp); MOZ_ASSERT(!mCleanedUp);
MOZ_ASSERT(mWorkerHolderAdded); MOZ_ASSERT(mFeatureAdded);
return mWorkerPrivate; return mWorkerPrivate;
} }
@ -3111,8 +3116,7 @@ PromiseWorkerProxy::CleanUp()
MutexAutoLock lock(Lock()); MutexAutoLock lock(Lock());
// |mWorkerPrivate| is not safe to use anymore if we have already // |mWorkerPrivate| is not safe to use anymore if we have already
// cleaned up and RemoveWorkerHolder(), so we need to check |mCleanedUp| // cleaned up and RemoveFeature(), so we need to check |mCleanedUp| first.
// first.
if (CleanedUp()) { if (CleanedUp()) {
return; return;
} }
@ -3123,10 +3127,10 @@ PromiseWorkerProxy::CleanUp()
// Release the Promise and remove the PromiseWorkerProxy from the features of // Release the Promise and remove the PromiseWorkerProxy from the features of
// the worker thread since the Promise has been resolved/rejected or the // the worker thread since the Promise has been resolved/rejected or the
// worker thread has been cancelled. // worker thread has been cancelled.
MOZ_ASSERT(mWorkerHolderAdded); MOZ_ASSERT(mFeatureAdded);
ReleaseWorker(); mWorkerPrivate->RemoveFeature(this);
#ifdef DEBUG #ifdef DEBUG
mWorkerHolderAdded = false; mFeatureAdded = false;
#endif #endif
CleanProperties(); CleanProperties();
} }

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

@ -29,7 +29,7 @@
#define DOM_PROMISE_DEPRECATED_REPORTING !SPIDERMONKEY_PROMISE #define DOM_PROMISE_DEPRECATED_REPORTING !SPIDERMONKEY_PROMISE
#if defined(DOM_PROMISE_DEPRECATED_REPORTING) #if defined(DOM_PROMISE_DEPRECATED_REPORTING)
#include "mozilla/dom/workers/bindings/WorkerHolder.h" #include "mozilla/dom/workers/bindings/WorkerFeature.h"
#endif // defined(DOM_PROMISE_DEPRECATED_REPORTING) #endif // defined(DOM_PROMISE_DEPRECATED_REPORTING)
class nsIGlobalObject; class nsIGlobalObject;
@ -48,15 +48,14 @@ class PromiseDebugging;
class Promise; class Promise;
#if defined(DOM_PROMISE_DEPRECATED_REPORTING) #if defined(DOM_PROMISE_DEPRECATED_REPORTING)
class PromiseReportRejectWorkerHolder : public workers::WorkerHolder class PromiseReportRejectFeature : public workers::WorkerFeature
{ {
// PromiseReportRejectWorkerHolder is held by an nsAutoPtr on the Promise // PromiseReportRejectFeature is held by an nsAutoPtr on the Promise which
// which means that this object will be destroyed before the Promise is // means that this object will be destroyed before the Promise is destroyed.
// destroyed.
Promise* MOZ_NON_OWNING_REF mPromise; Promise* MOZ_NON_OWNING_REF mPromise;
public: public:
explicit PromiseReportRejectWorkerHolder(Promise* aPromise) explicit PromiseReportRejectFeature(Promise* aPromise)
: mPromise(aPromise) : mPromise(aPromise)
{ {
MOZ_ASSERT(mPromise); MOZ_ASSERT(mPromise);
@ -85,7 +84,7 @@ class Promise : public nsISupports,
friend class PromiseResolverTask; friend class PromiseResolverTask;
friend class PromiseTask; friend class PromiseTask;
#if defined(DOM_PROMISE_DEPRECATED_REPORTING) #if defined(DOM_PROMISE_DEPRECATED_REPORTING)
friend class PromiseReportRejectWorkerHolder; friend class PromiseReportRejectFeature;
#endif // defined(DOM_PROMISE_DEPRECATED_REPORTING) #endif // defined(DOM_PROMISE_DEPRECATED_REPORTING)
friend class PromiseWorkerProxy; friend class PromiseWorkerProxy;
friend class PromiseWorkerProxyRunnable; friend class PromiseWorkerProxyRunnable;
@ -410,7 +409,7 @@ private:
void MaybeReportRejectedOnce() { void MaybeReportRejectedOnce() {
MaybeReportRejected(); MaybeReportRejected();
RemoveWorkerHolder(); RemoveFeature();
mResult.setUndefined(); mResult.setUndefined();
} }
#endif // defined(DOM_PROMISE_DEPRECATED_REPORTING) #endif // defined(DOM_PROMISE_DEPRECATED_REPORTING)
@ -465,7 +464,7 @@ private:
CreateThenableFunction(JSContext* aCx, Promise* aPromise, uint32_t aTask); CreateThenableFunction(JSContext* aCx, Promise* aPromise, uint32_t aTask);
#if defined(DOM_PROMISE_DEPRECATED_REPORTING) #if defined(DOM_PROMISE_DEPRECATED_REPORTING)
void RemoveWorkerHolder(); void RemoveFeature();
#endif // defined(DOM_PROMISE_DEPRECATED_REPORTING) #endif // defined(DOM_PROMISE_DEPRECATED_REPORTING)
// Capture the current stack and store it in aTarget. If false is // Capture the current stack and store it in aTarget. If false is
@ -504,7 +503,7 @@ private:
// needs to know when the worker is shutting down, to report the error on the // 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 // console before the worker's context is deleted. This feature is used for
// that purpose. // that purpose.
nsAutoPtr<PromiseReportRejectWorkerHolder> mWorkerHolder; nsAutoPtr<PromiseReportRejectFeature> mFeature;
#endif // defined(DOM_PROMISE_DEPRECATED_REPORTING) #endif // defined(DOM_PROMISE_DEPRECATED_REPORTING)
bool mTaskPending; bool mTaskPending;

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

@ -11,7 +11,7 @@
#include "mozilla/dom/Promise.h" #include "mozilla/dom/Promise.h"
#include "mozilla/dom/PromiseNativeHandler.h" #include "mozilla/dom/PromiseNativeHandler.h"
#include "mozilla/dom/StructuredCloneHolder.h" #include "mozilla/dom/StructuredCloneHolder.h"
#include "mozilla/dom/workers/bindings/WorkerHolder.h" #include "mozilla/dom/workers/bindings/WorkerFeature.h"
#include "nsProxyRelease.h" #include "nsProxyRelease.h"
#include "WorkerRunnable.h" #include "WorkerRunnable.h"
@ -110,7 +110,7 @@ class WorkerPrivate;
// references to it are dropped. // references to it are dropped.
class PromiseWorkerProxy : public PromiseNativeHandler class PromiseWorkerProxy : public PromiseNativeHandler
, public workers::WorkerHolder , public workers::WorkerFeature
, public StructuredCloneHolderBase , public StructuredCloneHolderBase
{ {
friend class PromiseWorkerProxyRunnable; friend class PromiseWorkerProxyRunnable;
@ -229,7 +229,7 @@ private:
#ifdef DEBUG #ifdef DEBUG
// Maybe get rid of this entirely and rely on mCleanedUp // Maybe get rid of this entirely and rely on mCleanedUp
bool mWorkerHolderAdded; bool mFeatureAdded;
#endif #endif
}; };
} // namespace dom } // namespace dom

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

@ -58,7 +58,7 @@
#include "mozilla/dom/ScriptSettings.h" #include "mozilla/dom/ScriptSettings.h"
#include "mozilla/UniquePtr.h" #include "mozilla/UniquePtr.h"
#include "Principal.h" #include "Principal.h"
#include "WorkerHolder.h" #include "WorkerFeature.h"
#include "WorkerPrivate.h" #include "WorkerPrivate.h"
#include "WorkerRunnable.h" #include "WorkerRunnable.h"
#include "WorkerScope.h" #include "WorkerScope.h"
@ -538,7 +538,7 @@ private:
NS_IMPL_ISUPPORTS(LoaderListener, nsIStreamLoaderObserver, nsIRequestObserver) NS_IMPL_ISUPPORTS(LoaderListener, nsIStreamLoaderObserver, nsIRequestObserver)
class ScriptLoaderRunnable final : public WorkerHolder class ScriptLoaderRunnable final : public WorkerFeature
, public nsIRunnable , public nsIRunnable
{ {
friend class ScriptExecutorRunnable; friend class ScriptExecutorRunnable;
@ -1946,7 +1946,7 @@ ScriptExecutorRunnable::ShutdownScriptLoader(JSContext* aCx,
} }
} }
mScriptLoader.ReleaseWorker(); aWorkerPrivate->RemoveFeature(&mScriptLoader);
aWorkerPrivate->StopSyncLoop(mSyncLoopTarget, aResult); aWorkerPrivate->StopSyncLoop(mSyncLoopTarget, aResult);
} }
@ -1998,7 +1998,7 @@ LoadAllScripts(WorkerPrivate* aWorkerPrivate,
NS_ASSERTION(aLoadInfos.IsEmpty(), "Should have swapped!"); NS_ASSERTION(aLoadInfos.IsEmpty(), "Should have swapped!");
if (NS_WARN_IF(!loader->HoldWorker(aWorkerPrivate))) { if (!aWorkerPrivate->AddFeature(loader)) {
aRv.Throw(NS_ERROR_FAILURE); aRv.Throw(NS_ERROR_FAILURE);
return; return;
} }
@ -2006,7 +2006,7 @@ LoadAllScripts(WorkerPrivate* aWorkerPrivate,
if (NS_FAILED(NS_DispatchToMainThread(loader))) { if (NS_FAILED(NS_DispatchToMainThread(loader))) {
NS_ERROR("Failed to dispatch!"); NS_ERROR("Failed to dispatch!");
loader->ReleaseWorker(); aWorkerPrivate->RemoveFeature(loader);
aRv.Throw(NS_ERROR_FAILURE); aRv.Throw(NS_ERROR_FAILURE);
return; return;
} }

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

@ -212,14 +212,14 @@ class KeepAliveHandler final
// preemptively cleanup if the service worker is timed out and // preemptively cleanup if the service worker is timed out and
// terminated. // terminated.
class InternalHandler final : public PromiseNativeHandler class InternalHandler final : public PromiseNativeHandler
, public WorkerHolder , public WorkerFeature
{ {
nsMainThreadPtrHandle<KeepAliveToken> mKeepAliveToken; nsMainThreadPtrHandle<KeepAliveToken> mKeepAliveToken;
// Worker thread only // Worker thread only
WorkerPrivate* mWorkerPrivate; WorkerPrivate* mWorkerPrivate;
RefPtr<Promise> mPromise; RefPtr<Promise> mPromise;
bool mWorkerHolderAdded; bool mFeatureAdded;
~InternalHandler() ~InternalHandler()
{ {
@ -227,13 +227,13 @@ class KeepAliveHandler final
} }
bool bool
UseWorkerHolder() AddFeature()
{ {
MOZ_ASSERT(mWorkerPrivate); MOZ_ASSERT(mWorkerPrivate);
mWorkerPrivate->AssertIsOnWorkerThread(); mWorkerPrivate->AssertIsOnWorkerThread();
MOZ_ASSERT(!mWorkerHolderAdded); MOZ_ASSERT(!mFeatureAdded);
mWorkerHolderAdded = HoldWorker(mWorkerPrivate); mFeatureAdded = mWorkerPrivate->AddFeature(this);
return mWorkerHolderAdded; return mFeatureAdded;
} }
void void
@ -244,8 +244,8 @@ class KeepAliveHandler final
if (!mPromise) { if (!mPromise) {
return; return;
} }
if (mWorkerHolderAdded) { if (mFeatureAdded) {
ReleaseWorker(); mWorkerPrivate->RemoveFeature(this);
} }
mPromise = nullptr; mPromise = nullptr;
mKeepAliveToken = nullptr; mKeepAliveToken = nullptr;
@ -285,7 +285,7 @@ class KeepAliveHandler final
: mKeepAliveToken(aKeepAliveToken) : mKeepAliveToken(aKeepAliveToken)
, mWorkerPrivate(aWorkerPrivate) , mWorkerPrivate(aWorkerPrivate)
, mPromise(aPromise) , mPromise(aPromise)
, mWorkerHolderAdded(false) , mFeatureAdded(false)
{ {
MOZ_ASSERT(mKeepAliveToken); MOZ_ASSERT(mKeepAliveToken);
MOZ_ASSERT(mWorkerPrivate); MOZ_ASSERT(mWorkerPrivate);
@ -302,7 +302,7 @@ class KeepAliveHandler final
aWorkerPrivate, aWorkerPrivate,
aPromise); aPromise);
if (NS_WARN_IF(!ref->UseWorkerHolder())) { if (NS_WARN_IF(!ref->AddFeature())) {
return nullptr; return nullptr;
} }
@ -518,7 +518,7 @@ private:
* with advancing the job queue for install/activate tasks. * with advancing the job queue for install/activate tasks.
*/ */
class LifeCycleEventWatcher final : public PromiseNativeHandler, class LifeCycleEventWatcher final : public PromiseNativeHandler,
public WorkerHolder public WorkerFeature
{ {
WorkerPrivate* mWorkerPrivate; WorkerPrivate* mWorkerPrivate;
RefPtr<LifeCycleEventCallback> mCallback; RefPtr<LifeCycleEventCallback> mCallback;
@ -564,7 +564,7 @@ public:
// case the registration/update promise will be rejected // case the registration/update promise will be rejected
// 2. A new service worker is registered which will terminate the current // 2. A new service worker is registered which will terminate the current
// installing worker. // installing worker.
if (NS_WARN_IF(!HoldWorker(mWorkerPrivate))) { if (NS_WARN_IF(!mWorkerPrivate->AddFeature(this))) {
NS_WARNING("LifeCycleEventWatcher failed to add feature."); NS_WARNING("LifeCycleEventWatcher failed to add feature.");
ReportResult(false); ReportResult(false);
return false; return false;
@ -602,7 +602,7 @@ public:
NS_RUNTIMEABORT("Failed to dispatch life cycle event handler."); NS_RUNTIMEABORT("Failed to dispatch life cycle event handler.");
} }
ReleaseWorker(); mWorkerPrivate->RemoveFeature(this);
} }
void void

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

@ -861,7 +861,7 @@ ServiceWorkerRegistrationMainThread::GetPushManager(JSContext* aCx,
// Worker Thread implementation // Worker Thread implementation
class ServiceWorkerRegistrationWorkerThread final : public ServiceWorkerRegistration class ServiceWorkerRegistrationWorkerThread final : public ServiceWorkerRegistration
, public WorkerHolder , public WorkerFeature
{ {
public: public:
NS_DECL_ISUPPORTS_INHERITED NS_DECL_ISUPPORTS_INHERITED
@ -1188,7 +1188,7 @@ ServiceWorkerRegistrationWorkerThread::InitListener()
worker->AssertIsOnWorkerThread(); worker->AssertIsOnWorkerThread();
mListener = new WorkerListener(worker, this); mListener = new WorkerListener(worker, this);
if (!HoldWorker(worker)) { if (!worker->AddFeature(this)) {
mListener = nullptr; mListener = nullptr;
NS_WARNING("Could not add feature"); NS_WARNING("Could not add feature");
return; return;
@ -1242,12 +1242,12 @@ ServiceWorkerRegistrationWorkerThread::ReleaseListener(Reason aReason)
} }
// We can assert worker here, because: // We can assert worker here, because:
// 1) We always HoldWorker, so if the worker has shutdown already, we'll // 1) We always AddFeature, so if the worker has shutdown already, we'll have
// have received Notify and removed it. If HoldWorker had failed, // received Notify and removed it. If AddFeature had failed, mListener will
// mListener will be null and we won't reach here. // be null and we won't reach here.
// 2) Otherwise, worker is still around even if we are going away. // 2) Otherwise, worker is still around even if we are going away.
mWorkerPrivate->AssertIsOnWorkerThread(); mWorkerPrivate->AssertIsOnWorkerThread();
ReleaseWorker(); mWorkerPrivate->RemoveFeature(this);
mListener->ClearRegistration(); mListener->ClearRegistration();

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

@ -10,7 +10,7 @@
#include "mozilla/DOMEventTargetHelper.h" #include "mozilla/DOMEventTargetHelper.h"
#include "mozilla/dom/ServiceWorkerBinding.h" #include "mozilla/dom/ServiceWorkerBinding.h"
#include "mozilla/dom/ServiceWorkerCommon.h" #include "mozilla/dom/ServiceWorkerCommon.h"
#include "mozilla/dom/workers/bindings/WorkerHolder.h" #include "mozilla/dom/workers/bindings/WorkerFeature.h"
#include "nsContentUtils.h" // Required for nsContentUtils::PushEnabled #include "nsContentUtils.h" // Required for nsContentUtils::PushEnabled
// Support for Notification API extension. // Support for Notification API extension.

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

@ -4,8 +4,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_dom_workers_WorkerHolder_h #ifndef mozilla_dom_workers_workerfeature_h__
#define mozilla_dom_workers_WorkerHolder_h #define mozilla_dom_workers_workerfeature_h__
#include "mozilla/dom/workers/Workers.h" #include "mozilla/dom/workers/Workers.h"
@ -69,23 +69,14 @@ enum Status
Dead Dead
}; };
class WorkerHolder class WorkerFeature
{ {
public: public:
WorkerHolder(); virtual ~WorkerFeature() { }
virtual ~WorkerHolder();
bool HoldWorker(WorkerPrivate* aWorkerPrivate);
void ReleaseWorker();
virtual bool Notify(Status aStatus) = 0; virtual bool Notify(Status aStatus) = 0;
protected:
void ReleaseWorkerInternal();
WorkerPrivate* MOZ_NON_OWNING_REF mWorkerPrivate;
}; };
END_WORKERS_NAMESPACE END_WORKERS_NAMESPACE
#endif /* mozilla_dom_workers_WorkerHolder_h */ #endif /* mozilla_dom_workers_workerfeature_h__ */

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

@ -1,53 +0,0 @@
/* -*- 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

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

@ -102,7 +102,7 @@
#include "ServiceWorkerWindowClient.h" #include "ServiceWorkerWindowClient.h"
#include "SharedWorker.h" #include "SharedWorker.h"
#include "WorkerDebuggerManager.h" #include "WorkerDebuggerManager.h"
#include "WorkerHolder.h" #include "WorkerFeature.h"
#include "WorkerNavigator.h" #include "WorkerNavigator.h"
#include "WorkerRunnable.h" #include "WorkerRunnable.h"
#include "WorkerScope.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 // If the close handler has finished and all features are done then we can
// kill this thread. // kill this thread.
if (currentStatus != Running && !HasActiveHolders()) { if (currentStatus != Running && !HasActiveFeatures()) {
if (mCloseHandlerFinished && currentStatus != Killing) { if (mCloseHandlerFinished && currentStatus != Killing) {
NotifyInternal(aCx, Killing); NotifyInternal(aCx, Killing);
MOZ_ASSERT(!JS_IsExceptionPending(aCx)); MOZ_ASSERT(!JS_IsExceptionPending(aCx));
@ -5252,7 +5252,7 @@ WorkerPrivate::RemoveChildWorker(ParentType* aChildWorker)
} }
bool bool
WorkerPrivate::AddHolder(WorkerHolder* aHolder) WorkerPrivate::AddFeature(WorkerFeature* aFeature)
{ {
AssertIsOnWorkerThread(); AssertIsOnWorkerThread();
@ -5264,31 +5264,31 @@ WorkerPrivate::AddHolder(WorkerHolder* aHolder)
} }
} }
MOZ_ASSERT(!mHolders.Contains(aHolder), "Already know about this one!"); MOZ_ASSERT(!mFeatures.Contains(aFeature), "Already know about this one!");
if (mHolders.IsEmpty() && !ModifyBusyCountFromWorker(true)) { if (mFeatures.IsEmpty() && !ModifyBusyCountFromWorker(true)) {
return false; return false;
} }
mHolders.AppendElement(aHolder); mFeatures.AppendElement(aFeature);
return true; return true;
} }
void void
WorkerPrivate::RemoveHolder(WorkerHolder* aHolder) WorkerPrivate::RemoveFeature(WorkerFeature* aFeature)
{ {
AssertIsOnWorkerThread(); AssertIsOnWorkerThread();
MOZ_ASSERT(mHolders.Contains(aHolder), "Didn't know about this one!"); MOZ_ASSERT(mFeatures.Contains(aFeature), "Didn't know about this one!");
mHolders.RemoveElement(aHolder); mFeatures.RemoveElement(aFeature);
if (mHolders.IsEmpty() && !ModifyBusyCountFromWorker(false)) { if (mFeatures.IsEmpty() && !ModifyBusyCountFromWorker(false)) {
NS_WARNING("Failed to modify busy count!"); NS_WARNING("Failed to modify busy count!");
} }
} }
void void
WorkerPrivate::NotifyHolders(JSContext* aCx, Status aStatus) WorkerPrivate::NotifyFeatures(JSContext* aCx, Status aStatus)
{ {
AssertIsOnWorkerThread(); AssertIsOnWorkerThread();
MOZ_ASSERT(!JS_IsExceptionPending(aCx)); MOZ_ASSERT(!JS_IsExceptionPending(aCx));
@ -5299,9 +5299,9 @@ WorkerPrivate::NotifyHolders(JSContext* aCx, Status aStatus)
CancelAllTimeouts(); CancelAllTimeouts();
} }
nsTObserverArray<WorkerHolder*>::ForwardIterator iter(mHolders); nsTObserverArray<WorkerFeature*>::ForwardIterator iter(mFeatures);
while (iter.HasMore()) { while (iter.HasMore()) {
WorkerHolder* feature = iter.GetNext(); WorkerFeature* feature = iter.GetNext();
if (!feature->Notify(aStatus)) { if (!feature->Notify(aStatus)) {
NS_WARNING("Failed to notify feature!"); NS_WARNING("Failed to notify feature!");
} }
@ -5795,7 +5795,7 @@ WorkerPrivate::NotifyInternal(JSContext* aCx, Status aStatus)
MOZ_ASSERT(previousStatus >= Canceling || mKillTime.IsNull()); MOZ_ASSERT(previousStatus >= Canceling || mKillTime.IsNull());
// Let all our features know the new status. // Let all our features know the new status.
NotifyHolders(aCx, aStatus); NotifyFeatures(aCx, aStatus);
MOZ_ASSERT(!JS_IsExceptionPending(aCx)); MOZ_ASSERT(!JS_IsExceptionPending(aCx));
// If this is the first time our status has changed then we need to clear the // If this is the first time our status has changed then we need to clear the

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

@ -30,7 +30,7 @@
#include "nsTObserverArray.h" #include "nsTObserverArray.h"
#include "Queue.h" #include "Queue.h"
#include "WorkerHolder.h" #include "WorkerFeature.h"
#ifdef XP_WIN #ifdef XP_WIN
#undef PostMessage #undef PostMessage
@ -862,7 +862,6 @@ private:
class WorkerPrivate : public WorkerPrivateParent<WorkerPrivate> class WorkerPrivate : public WorkerPrivateParent<WorkerPrivate>
{ {
friend class WorkerHolder;
friend class WorkerPrivateParent<WorkerPrivate>; friend class WorkerPrivateParent<WorkerPrivate>;
typedef WorkerPrivateParent<WorkerPrivate> ParentType; typedef WorkerPrivateParent<WorkerPrivate> ParentType;
friend class AutoSyncLoopHolder; friend class AutoSyncLoopHolder;
@ -898,7 +897,7 @@ class WorkerPrivate : public WorkerPrivateParent<WorkerPrivate>
RefPtr<WorkerGlobalScope> mScope; RefPtr<WorkerGlobalScope> mScope;
RefPtr<WorkerDebuggerGlobalScope> mDebuggerScope; RefPtr<WorkerDebuggerGlobalScope> mDebuggerScope;
nsTArray<ParentType*> mChildWorkers; nsTArray<ParentType*> mChildWorkers;
nsTObserverArray<WorkerHolder*> mHolders; nsTObserverArray<WorkerFeature*> mFeatures;
nsTArray<nsAutoPtr<TimeoutInfo>> mTimeouts; nsTArray<nsAutoPtr<TimeoutInfo>> mTimeouts;
uint32_t mDebuggerEventLoopLevel; uint32_t mDebuggerEventLoopLevel;
@ -1076,6 +1075,22 @@ public:
void void
RemoveChildWorker(ParentType* aChildWorker); 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 void
PostMessageToParent(JSContext* aCx, PostMessageToParent(JSContext* aCx,
JS::Handle<JS::Value> aMessage, JS::Handle<JS::Value> aMessage,
@ -1427,22 +1442,6 @@ private:
void void
ShutdownGCTimers(); 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 // This class is only used to trick the DOM bindings. We never create

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

@ -1685,7 +1685,7 @@ XMLHttpRequest::MaybePin(ErrorResult& aRv)
return; return;
} }
if (!HoldWorker(mWorkerPrivate)) { if (!mWorkerPrivate->AddFeature(this)) {
aRv.Throw(NS_ERROR_FAILURE); aRv.Throw(NS_ERROR_FAILURE);
return; return;
} }
@ -1803,7 +1803,7 @@ XMLHttpRequest::Unpin()
MOZ_ASSERT(mRooted, "Mismatched calls to Unpin!"); MOZ_ASSERT(mRooted, "Mismatched calls to Unpin!");
ReleaseWorker(); mWorkerPrivate->RemoveFeature(this);
mRooted = false; mRooted = false;

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

@ -7,7 +7,7 @@
#ifndef mozilla_dom_workers_xmlhttprequest_h__ #ifndef mozilla_dom_workers_xmlhttprequest_h__
#define mozilla_dom_workers_xmlhttprequest_h__ #define mozilla_dom_workers_xmlhttprequest_h__
#include "mozilla/dom/workers/bindings/WorkerHolder.h" #include "mozilla/dom/workers/bindings/WorkerFeature.h"
// Need this for XMLHttpRequestResponseType. // Need this for XMLHttpRequestResponseType.
#include "mozilla/dom/XMLHttpRequestBinding.h" #include "mozilla/dom/XMLHttpRequestBinding.h"
@ -30,7 +30,7 @@ class XMLHttpRequestUpload;
class WorkerPrivate; class WorkerPrivate;
class XMLHttpRequest final: public nsXHREventTarget, class XMLHttpRequest final: public nsXHREventTarget,
public WorkerHolder public WorkerFeature
{ {
public: public:
struct StateData struct StateData

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

@ -38,7 +38,7 @@ EXPORTS.mozilla.dom.workers.bindings += [
'ServiceWorkerWindowClient.h', 'ServiceWorkerWindowClient.h',
'SharedWorker.h', 'SharedWorker.h',
'URL.h', 'URL.h',
'WorkerHolder.h', 'WorkerFeature.h',
'XMLHttpRequest.h', 'XMLHttpRequest.h',
'XMLHttpRequestUpload.h', 'XMLHttpRequestUpload.h',
] ]
@ -82,7 +82,6 @@ UNIFIED_SOURCES += [
'SharedWorker.cpp', 'SharedWorker.cpp',
'URL.cpp', 'URL.cpp',
'WorkerDebuggerManager.cpp', 'WorkerDebuggerManager.cpp',
'WorkerHolder.cpp',
'WorkerLocation.cpp', 'WorkerLocation.cpp',
'WorkerNavigator.cpp', 'WorkerNavigator.cpp',
'WorkerPrivate.cpp', 'WorkerPrivate.cpp',

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

@ -5,8 +5,7 @@ var p = new Promise(function(resolve, reject) {
// This prevents that runnable from running until the window calls terminate(), // This prevents that runnable from running until the window calls terminate(),
// at which point the worker goes into the Canceling state and then an // at which point the worker goes into the Canceling state and then an
// HoldWorker() is attempted, which fails, which used to result in // AddFeature() is attempted, which fails, which used to result in multiple
// multiple calls to the error reporter, one after the worker's context had // calls to the error reporter, one after the worker's context had been GCed.
// been GCed.
while (true); while (true);
}); });

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

@ -9,7 +9,7 @@
#include "mozilla/unused.h" #include "mozilla/unused.h"
#include "mozilla/dom/PContentChild.h" #include "mozilla/dom/PContentChild.h"
#include "mozilla/dom/WorkerPrivate.h" #include "mozilla/dom/WorkerPrivate.h"
#include "mozilla/dom/workers/bindings/WorkerHolder.h" #include "mozilla/dom/workers/bindings/WorkerFeature.h"
#include "mozilla/ipc/PBackgroundChild.h" #include "mozilla/ipc/PBackgroundChild.h"
#include "nsIAsyncInputStream.h" #include "nsIAsyncInputStream.h"
#include "nsICancelableRunnable.h" #include "nsICancelableRunnable.h"
@ -23,13 +23,13 @@ namespace ipc {
using mozilla::dom::PContentChild; using mozilla::dom::PContentChild;
using mozilla::dom::workers::GetCurrentThreadWorkerPrivate; using mozilla::dom::workers::GetCurrentThreadWorkerPrivate;
using mozilla::dom::workers::Status; using mozilla::dom::workers::Status;
using mozilla::dom::workers::WorkerHolder; using mozilla::dom::workers::WorkerFeature;
using mozilla::dom::workers::WorkerPrivate; using mozilla::dom::workers::WorkerPrivate;
namespace { namespace {
class SendStreamChildImpl final : public SendStreamChild class SendStreamChildImpl final : public SendStreamChild
, public WorkerHolder , public WorkerFeature
{ {
public: public:
explicit SendStreamChildImpl(nsIAsyncInputStream* aStream); explicit SendStreamChildImpl(nsIAsyncInputStream* aStream);
@ -39,7 +39,7 @@ public:
void StartDestroy() override; void StartDestroy() override;
bool bool
AddAsWorkerHolder(dom::workers::WorkerPrivate* aWorkerPrivate); AddAsWorkerFeature(dom::workers::WorkerPrivate* aWorkerPrivate);
private: private:
class Callback; class Callback;
@ -51,7 +51,7 @@ private:
virtual bool virtual bool
RecvRequestClose(const nsresult& aRv) override; RecvRequestClose(const nsresult& aRv) override;
// WorkerHolder methods // WorkerFeature methods
virtual bool virtual bool
Notify(Status aStatus) override; Notify(Status aStatus) override;
@ -93,7 +93,7 @@ public:
// If this fails, then it means the owning thread is a Worker that has // 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 // been shutdown. Its ok to lose the event in this case because the
// SendStreamChild listens for this event through the WorkerHolder. // SendStreamChild listens for this event through the Feature.
nsresult rv = mOwningThread->Dispatch(this, nsIThread::DISPATCH_NORMAL); nsresult rv = mOwningThread->Dispatch(this, nsIThread::DISPATCH_NORMAL);
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
NS_WARNING("Failed to dispatch stream readable event to owning thread"); 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 // Cancel() gets called when the Worker thread is being shutdown. We have
// nothing to do here because SendStreamChild handles this case via // nothing to do here because SendStreamChild handles this case via
// the WorkerHolder. // the Feature.
return NS_OK; return NS_OK;
} }
@ -180,11 +180,11 @@ SendStreamChildImpl::StartDestroy()
} }
bool bool
SendStreamChildImpl::AddAsWorkerHolder(WorkerPrivate* aWorkerPrivate) SendStreamChildImpl::AddAsWorkerFeature(WorkerPrivate* aWorkerPrivate)
{ {
NS_ASSERT_OWNINGTHREAD(SendStreamChild); NS_ASSERT_OWNINGTHREAD(SendStreamChild);
MOZ_ASSERT(aWorkerPrivate); MOZ_ASSERT(aWorkerPrivate);
bool result = HoldWorker(aWorkerPrivate); bool result = aWorkerPrivate->AddFeature(this);
if (result) { if (result) {
mWorkerPrivate = aWorkerPrivate; mWorkerPrivate = aWorkerPrivate;
} }
@ -207,7 +207,7 @@ SendStreamChildImpl::ActorDestroy(ActorDestroyReason aReason)
} }
if (mWorkerPrivate) { if (mWorkerPrivate) {
ReleaseWorker(); mWorkerPrivate->RemoveFeature(this);
mWorkerPrivate = nullptr; mWorkerPrivate = nullptr;
} }
} }
@ -405,7 +405,7 @@ SendStreamChild::Create(nsIAsyncInputStream* aInputStream,
SendStreamChildImpl* actor = new SendStreamChildImpl(aInputStream); SendStreamChildImpl* actor = new SendStreamChildImpl(aInputStream);
if (workerPrivate && !actor->AddAsWorkerHolder(workerPrivate)) { if (workerPrivate && !actor->AddAsWorkerFeature(workerPrivate)) {
delete actor; delete actor;
return nullptr; return nullptr;
} }