Skip to content
This repository has been archived by the owner on Aug 4, 2022. It is now read-only.

Commit

Permalink
Bug 1269154 - Get rid of WorkerFeature: WorkerHolder, r=khuey
Browse files Browse the repository at this point in the history
  • Loading branch information
bakulf committed Jun 23, 2016
1 parent 4e0dcdf commit 246e38e
Show file tree
Hide file tree
Showing 52 changed files with 493 additions and 439 deletions.
8 changes: 4 additions & 4 deletions dom/base/FileReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ FileReader::OnInputStreamReady(nsIAsyncInputStream* aStream)

// We use this class to decrease the busy counter at the end of this method.
// In theory we can do it immediatelly but, for debugging reasons, we want to
// be 100% sure we have a feature when OnLoadEnd() is called.
// be 100% sure we have a workerHolder when OnLoadEnd() is called.
FileReaderDecreaseBusyCounter RAII(this);

uint64_t aCount;
Expand Down Expand Up @@ -701,7 +701,7 @@ nsresult
FileReader::IncreaseBusyCounter()
{
if (mWorkerPrivate && mBusyCount++ == 0 &&
!mWorkerPrivate->AddFeature(this)) {
!HoldWorker(mWorkerPrivate)) {
return NS_ERROR_FAILURE;
}

Expand All @@ -713,7 +713,7 @@ FileReader::DecreaseBusyCounter()
{
MOZ_ASSERT_IF(mWorkerPrivate, mBusyCount);
if (mWorkerPrivate && --mBusyCount == 0) {
mWorkerPrivate->RemoveFeature(this);
ReleaseWorker();
}
}

Expand Down Expand Up @@ -742,7 +742,7 @@ FileReader::Shutdown()
}

if (mWorkerPrivate && mBusyCount != 0) {
mWorkerPrivate->RemoveFeature(this);
ReleaseWorker();
mWorkerPrivate = nullptr;
mBusyCount = 0;
}
Expand Down
8 changes: 4 additions & 4 deletions dom/base/FileReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "nsCOMPtr.h"
#include "nsString.h"
#include "nsWeakReference.h"
#include "WorkerFeature.h"
#include "WorkerHolder.h"

#define NS_PROGRESS_EVENT_INTERVAL 50

Expand All @@ -41,7 +41,7 @@ class FileReader final : public DOMEventTargetHelper,
public nsSupportsWeakReference,
public nsIInputStreamCallback,
public nsITimerCallback,
public workers::WorkerFeature
public workers::WorkerHolder
{
friend class FileReaderDecreaseBusyCounter;

Expand Down Expand Up @@ -106,7 +106,7 @@ class FileReader final : public DOMEventTargetHelper,
ReadFileContent(aBlob, EmptyString(), FILE_AS_BINARY, aRv);
}

// WorkerFeature
// WorkerHolder
bool Notify(workers::Status) override;

private:
Expand Down Expand Up @@ -190,7 +190,7 @@ class FileReader final : public DOMEventTargetHelper,

uint64_t mBusyCount;

// Kept alive with a WorkerFeature.
// Kept alive with a WorkerHolder.
workers::WorkerPrivate* mWorkerPrivate;
};

Expand Down
62 changes: 31 additions & 31 deletions dom/base/WebSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class WebSocketImpl final : public nsIInterfaceRequestor
, mInnerWindowID(0)
, mWorkerPrivate(nullptr)
#ifdef DEBUG
, mHasFeatureRegistered(false)
, mHasWorkerHolderRegistered(false)
#endif
, mIsMainThread(true)
, mMutex("WebSocketImpl::mMutex")
Expand Down Expand Up @@ -166,8 +166,8 @@ class WebSocketImpl final : public nsIInterfaceRequestor
void AddRefObject();
void ReleaseObject();

bool RegisterFeature();
void UnregisterFeature();
bool RegisterWorkerHolder();
void UnregisterWorkerHolder();

nsresult CancelInternal();

Expand Down Expand Up @@ -213,24 +213,24 @@ class WebSocketImpl final : public nsIInterfaceRequestor
uint64_t mInnerWindowID;

WorkerPrivate* mWorkerPrivate;
nsAutoPtr<WorkerFeature> mWorkerFeature;
nsAutoPtr<WorkerHolder> mWorkerHolder;

#ifdef DEBUG
// This is protected by mutex.
bool mHasFeatureRegistered;
bool mHasWorkerHolderRegistered;

bool HasFeatureRegistered()
bool HasWorkerHolderRegistered()
{
MOZ_ASSERT(mWebSocket);
MutexAutoLock lock(mWebSocket->mMutex);
return mHasFeatureRegistered;
return mHasWorkerHolderRegistered;
}

void SetHasFeatureRegistered(bool aValue)
void SetHasWorkerHolderRegistered(bool aValue)
{
MOZ_ASSERT(mWebSocket);
MutexAutoLock lock(mWebSocket->mMutex);
mHasFeatureRegistered = aValue;
mHasWorkerHolderRegistered = aValue;
}
#endif

Expand Down Expand Up @@ -489,7 +489,7 @@ WebSocketImpl::CloseConnection(uint16_t aReasonCode,

// If this method is called because the worker is going away, we will not
// receive the OnStop() method and we have to disconnect the WebSocket and
// release the WorkerFeature.
// release the WorkerHolder.
MaybeDisconnect md(this);

uint16_t readyState = mWebSocket->ReadyState();
Expand Down Expand Up @@ -610,7 +610,7 @@ WebSocketImpl::Disconnect()
AssertIsOnTargetThread();

// Disconnect can be called from some control event (such as Notify() of
// WorkerFeature). This will be schedulated before any other sync/async
// WorkerHolder). This will be schedulated before any other sync/async
// runnable. In order to prevent some double Disconnect() calls, we use this
// boolean.
mDisconnectingOrDisconnected = true;
Expand Down Expand Up @@ -640,8 +640,8 @@ WebSocketImpl::Disconnect()
mWebSocket->DontKeepAliveAnyMore();
mWebSocket->mImpl = nullptr;

if (mWorkerPrivate && mWorkerFeature) {
UnregisterFeature();
if (mWorkerPrivate && mWorkerHolder) {
UnregisterWorkerHolder();
}

// We want to release the WebSocket in the correct thread.
Expand Down Expand Up @@ -1262,9 +1262,9 @@ WebSocket::ConstructorCommon(const GlobalObject& aGlobal,
aUrl, protocolArray, EmptyCString(),
0, 0, aRv, &connectionFailed);
} else {
// In workers we have to keep the worker alive using a feature in order to
// dispatch messages correctly.
if (!webSocket->mImpl->RegisterFeature()) {
// In workers we have to keep the worker alive using a workerHolder in order
// to dispatch messages correctly.
if (!webSocket->mImpl->RegisterWorkerHolder()) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
Expand Down Expand Up @@ -2204,10 +2204,10 @@ WebSocket::DontKeepAliveAnyMore()

namespace {

class WebSocketWorkerFeature final : public WorkerFeature
class WebSocketWorkerHolder final : public WorkerHolder
{
public:
explicit WebSocketWorkerFeature(WebSocketImpl* aWebSocketImpl)
explicit WebSocketWorkerHolder(WebSocketImpl* aWebSocketImpl)
: mWebSocketImpl(aWebSocketImpl)
{
}
Expand Down Expand Up @@ -2250,39 +2250,39 @@ WebSocketImpl::ReleaseObject()
}

bool
WebSocketImpl::RegisterFeature()
WebSocketImpl::RegisterWorkerHolder()
{
mWorkerPrivate->AssertIsOnWorkerThread();
MOZ_ASSERT(!mWorkerFeature);
mWorkerFeature = new WebSocketWorkerFeature(this);
MOZ_ASSERT(!mWorkerHolder);
mWorkerHolder = new WebSocketWorkerHolder(this);

if (!mWorkerPrivate->AddFeature(mWorkerFeature)) {
NS_WARNING("Failed to register a feature.");
mWorkerFeature = nullptr;
if (NS_WARN_IF(!mWorkerHolder->HoldWorker(mWorkerPrivate))) {
mWorkerHolder = nullptr;
return false;
}

#ifdef DEBUG
SetHasFeatureRegistered(true);
SetHasWorkerHolderRegistered(true);
#endif

return true;
}

void
WebSocketImpl::UnregisterFeature()
WebSocketImpl::UnregisterWorkerHolder()
{
MOZ_ASSERT(mDisconnectingOrDisconnected);
MOZ_ASSERT(mWorkerPrivate);
mWorkerPrivate->AssertIsOnWorkerThread();
MOZ_ASSERT(mWorkerFeature);
MOZ_ASSERT(mWorkerHolder);

// The DTOR of this WorkerHolder will release the worker for us.
mWorkerHolder = nullptr;

mWorkerPrivate->RemoveFeature(mWorkerFeature);
mWorkerFeature = nullptr;
mWorkerPrivate = nullptr;

#ifdef DEBUG
SetHasFeatureRegistered(false);
SetHasWorkerHolderRegistered(false);
#endif
}

Expand Down Expand Up @@ -2842,7 +2842,7 @@ WebSocketImpl::Dispatch(already_AddRefed<nsIRunnable> aEvent, uint32_t aFlags)
MOZ_ASSERT(mWorkerPrivate);

#ifdef DEBUG
MOZ_ASSERT(HasFeatureRegistered());
MOZ_ASSERT(HasWorkerHolderRegistered());
#endif

// If the target is a worker, we have to use a custom WorkerRunnableDispatcher
Expand Down
12 changes: 6 additions & 6 deletions dom/bindings/BindingUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3298,7 +3298,7 @@ namespace {
// This runnable is used to write a deprecation message from a worker to the
// console running on the main-thread.
class DeprecationWarningRunnable final : public Runnable
, public WorkerFeature
, public WorkerHolder
{
WorkerPrivate* mWorkerPrivate;
nsIDocument::DeprecatedOperations mOperation;
Expand All @@ -3315,12 +3315,12 @@ class DeprecationWarningRunnable final : public Runnable
void
Dispatch()
{
if (NS_WARN_IF(!mWorkerPrivate->AddFeature(this))) {
if (NS_WARN_IF(!HoldWorker(mWorkerPrivate))) {
return;
}

if (NS_WARN_IF(NS_FAILED(NS_DispatchToMainThread(this)))) {
mWorkerPrivate->RemoveFeature(this);
ReleaseWorker();
return;
}
}
Expand Down Expand Up @@ -3351,12 +3351,12 @@ class DeprecationWarningRunnable final : public Runnable
window->GetExtantDoc()->WarnOnceAbout(mOperation);
}

ReleaseWorker();
ReleaseWorkerHolder();
return NS_OK;
}

void
ReleaseWorker()
ReleaseWorkerHolder()
{
class ReleaseRunnable final : public MainThreadWorkerRunnable
{
Expand All @@ -3375,7 +3375,7 @@ class DeprecationWarningRunnable final : public Runnable
MOZ_ASSERT(aWorkerPrivate);
aWorkerPrivate->AssertIsOnWorkerThread();

aWorkerPrivate->RemoveFeature(mRunnable);
mRunnable->ReleaseWorker();
return true;
}
};
Expand Down
28 changes: 12 additions & 16 deletions dom/broadcastchannel/BroadcastChannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,15 +266,15 @@ class TeardownRunnable final : public nsIRunnable,

NS_IMPL_ISUPPORTS(TeardownRunnable, nsICancelableRunnable, nsIRunnable)

class BroadcastChannelFeature final : public workers::WorkerFeature
class BroadcastChannelWorkerHolder final : public workers::WorkerHolder
{
BroadcastChannel* mChannel;

public:
explicit BroadcastChannelFeature(BroadcastChannel* aChannel)
explicit BroadcastChannelWorkerHolder(BroadcastChannel* aChannel)
: mChannel(aChannel)
{
MOZ_COUNT_CTOR(BroadcastChannelFeature);
MOZ_COUNT_CTOR(BroadcastChannelWorkerHolder);
}

virtual bool Notify(workers::Status aStatus) override
Expand All @@ -287,9 +287,9 @@ class BroadcastChannelFeature final : public workers::WorkerFeature
}

private:
~BroadcastChannelFeature()
~BroadcastChannelWorkerHolder()
{
MOZ_COUNT_DTOR(BroadcastChannelFeature);
MOZ_COUNT_DTOR(BroadcastChannelWorkerHolder);
}
};

Expand All @@ -300,7 +300,7 @@ BroadcastChannel::BroadcastChannel(nsPIDOMWindowInner* aWindow,
const nsACString& aOrigin,
const nsAString& aChannel)
: DOMEventTargetHelper(aWindow)
, mWorkerFeature(nullptr)
, mWorkerHolder(nullptr)
, mPrincipalInfo(new PrincipalInfo(aPrincipalInfo))
, mOrigin(aOrigin)
, mChannel(aChannel)
Expand All @@ -314,7 +314,7 @@ BroadcastChannel::BroadcastChannel(nsPIDOMWindowInner* aWindow,
BroadcastChannel::~BroadcastChannel()
{
Shutdown();
MOZ_ASSERT(!mWorkerFeature);
MOZ_ASSERT(!mWorkerHolder);
}

JSObject*
Expand Down Expand Up @@ -406,10 +406,9 @@ BroadcastChannel::Constructor(const GlobalObject& aGlobal,
obs->AddObserver(bc, "inner-window-destroyed", false);
}
} else {
bc->mWorkerFeature = new BroadcastChannelFeature(bc);
if (NS_WARN_IF(!workerPrivate->AddFeature(bc->mWorkerFeature))) {
NS_WARNING("Failed to register the BroadcastChannel worker feature.");
bc->mWorkerFeature = nullptr;
bc->mWorkerHolder = new BroadcastChannelWorkerHolder(bc);
if (NS_WARN_IF(!bc->mWorkerHolder->HoldWorker(workerPrivate))) {
bc->mWorkerHolder = nullptr;
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
Expand Down Expand Up @@ -528,11 +527,8 @@ BroadcastChannel::Shutdown()
{
mState = StateClosed;

if (mWorkerFeature) {
WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
workerPrivate->RemoveFeature(mWorkerFeature);
mWorkerFeature = nullptr;
}
// The DTOR of this WorkerHolder will release the worker for us.
mWorkerHolder = nullptr;

if (mActor) {
mActor->SetParent(nullptr);
Expand Down
4 changes: 2 additions & 2 deletions dom/broadcastchannel/BroadcastChannel.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class PrincipalInfo;
namespace dom {

namespace workers {
class WorkerFeature;
class WorkerHolder;
} // namespace workers

class BroadcastChannelChild;
Expand Down Expand Up @@ -110,7 +110,7 @@ class BroadcastChannel final
RefPtr<BroadcastChannelChild> mActor;
nsTArray<RefPtr<BroadcastChannelMessage>> mPendingMessages;

nsAutoPtr<workers::WorkerFeature> mWorkerFeature;
nsAutoPtr<workers::WorkerHolder> mWorkerHolder;

nsAutoPtr<PrincipalInfo> mPrincipalInfo;

Expand Down
Loading

0 comments on commit 246e38e

Please sign in to comment.