Bug 1277226 - Implement MainThreadWorkerRunnable, r=sicking

This commit is contained in:
Andrea Marchesini 2016-06-08 07:12:05 +02:00
parent eaa1d08d90
commit 43a1cd6c16
6 changed files with 45 additions and 125 deletions

View File

@ -2607,11 +2607,11 @@ WebSocketImpl::GetStatus(nsresult* aStatus)
namespace {
class CancelRunnable final : public WorkerRunnable
class CancelRunnable final : public MainThreadWorkerRunnable
{
public:
CancelRunnable(WorkerPrivate* aWorkerPrivate, WebSocketImpl* aImpl)
: WorkerRunnable(aWorkerPrivate, WorkerThreadUnchangedBusyCount)
: MainThreadWorkerRunnable(aWorkerPrivate)
, mImpl(aImpl)
{
}
@ -2629,23 +2629,6 @@ public:
aWorkerPrivate->ModifyBusyCountFromWorker(false);
}
bool
PreDispatch(WorkerPrivate* aWorkerPrivate) override
{
// We don't call WorkerRunnable::PreDispatch because it would assert the
// wrong thing about which thread we're on.
AssertIsOnMainThread();
return true;
}
void
PostDispatch(WorkerPrivate* aWorkerPrivate, bool aDispatchResult) override
{
// We don't call WorkerRunnable::PostDispatch because it would assert the
// wrong thing about which thread we're on.
AssertIsOnMainThread();
}
private:
RefPtr<WebSocketImpl> mImpl;
};

View File

@ -3358,14 +3358,14 @@ private:
void
ReleaseWorker()
{
class ReleaseRunnable final : public WorkerRunnable
class ReleaseRunnable final : public MainThreadWorkerRunnable
{
RefPtr<DeprecationWarningRunnable> mRunnable;
public:
ReleaseRunnable(WorkerPrivate* aWorkerPrivate,
DeprecationWarningRunnable* aRunnable)
: WorkerRunnable(aWorkerPrivate, WorkerThreadUnchangedBusyCount)
: MainThreadWorkerRunnable(aWorkerPrivate)
, mRunnable(aRunnable)
{}
@ -3378,19 +3378,6 @@ private:
aWorkerPrivate->RemoveFeature(mRunnable);
return true;
}
virtual bool
PreDispatch(WorkerPrivate* aWorkerPrivate) override
{
AssertIsOnMainThread();
return true;
}
virtual void
PostDispatch(WorkerPrivate* aWorkerPrivate,
bool aDispatchResult) override
{
}
};
RefPtr<ReleaseRunnable> runnable =

View File

@ -262,7 +262,7 @@ MainThreadFetchResolver::~MainThreadFetchResolver()
NS_ASSERT_OWNINGTHREAD(MainThreadFetchResolver);
}
class WorkerFetchResponseRunnable final : public WorkerRunnable
class WorkerFetchResponseRunnable final : public MainThreadWorkerRunnable
{
RefPtr<WorkerFetchResolver> mResolver;
// Passed from main thread to worker thread after being initialized.
@ -271,7 +271,7 @@ public:
WorkerFetchResponseRunnable(WorkerPrivate* aWorkerPrivate,
WorkerFetchResolver* aResolver,
InternalResponse* aResponse)
: WorkerRunnable(aWorkerPrivate, WorkerThreadUnchangedBusyCount)
: MainThreadWorkerRunnable(aWorkerPrivate)
, mResolver(aResolver)
, mInternalResponse(aResponse)
{
@ -296,25 +296,6 @@ public:
}
return true;
}
bool
PreDispatch(WorkerPrivate* aWorkerPrivate) override
{
// Don't call default PreDispatch() since it incorrectly asserts we are
// dispatching from the parent worker thread. We always dispatch from
// the main thread.
AssertIsOnMainThread();
return true;
}
void
PostDispatch(WorkerPrivate* aWorkerPrivate, bool aDispatchResult) override
{
// Don't call default PostDispatch() since it incorrectly asserts we are
// dispatching from the parent worker thread. We always dispatch from
// the main thread.
AssertIsOnMainThread();
}
};
class WorkerFetchResponseEndBase
@ -336,13 +317,12 @@ public:
}
};
class WorkerFetchResponseEndRunnable final : public WorkerRunnable
class WorkerFetchResponseEndRunnable final : public MainThreadWorkerRunnable
, public WorkerFetchResponseEndBase
{
public:
explicit WorkerFetchResponseEndRunnable(PromiseWorkerProxy* aPromiseProxy)
: WorkerRunnable(aPromiseProxy->GetWorkerPrivate(),
WorkerThreadUnchangedBusyCount)
: MainThreadWorkerRunnable(aPromiseProxy->GetWorkerPrivate())
, WorkerFetchResponseEndBase(aPromiseProxy)
{
}
@ -362,25 +342,6 @@ public:
Run();
return WorkerRunnable::Cancel();
}
bool
PreDispatch(WorkerPrivate* aWorkerPrivate) override
{
// Don't call default PreDispatch() since it incorrectly asserts we are
// dispatching from the parent worker thread. We always dispatch from
// the main thread.
AssertIsOnMainThread();
return true;
}
void
PostDispatch(WorkerPrivate* aWorkerPrivate, bool aDispatchResult) override
{
// Don't call default PostDispatch() since it incorrectly asserts we are
// dispatching from the parent worker thread. We always dispatch from
// the main thread.
AssertIsOnMainThread();
}
};
class WorkerFetchResponseEndControlRunnable final : public MainThreadWorkerControlRunnable
@ -643,7 +604,7 @@ namespace {
* Called on successfully reading the complete stream.
*/
template <class Derived>
class ContinueConsumeBodyRunnable final : public WorkerRunnable
class ContinueConsumeBodyRunnable final : public MainThreadWorkerRunnable
{
// This has been addrefed before this runnable is dispatched,
// released in WorkerRun().
@ -655,7 +616,7 @@ class ContinueConsumeBodyRunnable final : public WorkerRunnable
public:
ContinueConsumeBodyRunnable(FetchBody<Derived>* aFetchBody, nsresult aStatus,
uint32_t aLength, uint8_t* aResult)
: WorkerRunnable(aFetchBody->mWorkerPrivate, WorkerThreadUnchangedBusyCount)
: MainThreadWorkerRunnable(aFetchBody->mWorkerPrivate)
, mFetchBody(aFetchBody)
, mStatus(aStatus)
, mLength(aLength)
@ -670,25 +631,6 @@ public:
mFetchBody->ContinueConsumeBody(mStatus, mLength, mResult);
return true;
}
bool
PreDispatch(WorkerPrivate* aWorkerPrivate) override
{
// Don't call default PreDispatch() since it incorrectly asserts we are
// dispatching from the parent worker thread. We always dispatch from
// the main thread.
AssertIsOnMainThread();
return true;
}
void
PostDispatch(WorkerPrivate* aWorkerPrivate, bool aDispatchResult) override
{
// Don't call default PostDispatch() since it incorrectly asserts we are
// dispatching from the parent worker thread. We always dispatch from
// the main thread.
AssertIsOnMainThread();
}
};
// OnStreamComplete always adopts the buffer, utility class to release it in

View File

@ -361,31 +361,14 @@ CheckScope(nsIPrincipal* aPrincipal, const nsACString& aScope)
// Subclass that can be directly dispatched to child workers from the main
// thread.
class NotificationWorkerRunnable : public WorkerRunnable
class NotificationWorkerRunnable : public MainThreadWorkerRunnable
{
protected:
explicit NotificationWorkerRunnable(WorkerPrivate* aWorkerPrivate)
: WorkerRunnable(aWorkerPrivate, WorkerThreadUnchangedBusyCount)
: MainThreadWorkerRunnable(aWorkerPrivate)
{
}
bool
PreDispatch(WorkerPrivate* aWorkerPrivate) override
{
// We don't call WorkerRunnable::PreDispatch because it would assert the
// wrong thing about which thread we're on.
AssertIsOnMainThread();
return true;
}
void
PostDispatch(WorkerPrivate* aWorkerPrivate, bool aDispatchResult) override
{
// We don't call WorkerRunnable::PostDispatch because it would assert the
// wrong thing about which thread we're on.
AssertIsOnMainThread();
}
bool
WorkerRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate) override
{

View File

@ -603,13 +603,6 @@ WorkerControlRunnable::DispatchInternal()
return NS_SUCCEEDED(mainThread->Dispatch(runnable.forget(), NS_DISPATCH_NORMAL));
}
void
MainThreadWorkerControlRunnable::PostDispatch(WorkerPrivate* aWorkerPrivate,
bool aDispatchResult)
{
AssertIsOnMainThread();
}
NS_IMPL_ISUPPORTS_INHERITED0(WorkerControlRunnable, WorkerRunnable)
WorkerMainThreadRunnable::WorkerMainThreadRunnable(WorkerPrivate* aWorkerPrivate,

View File

@ -300,6 +300,35 @@ private:
using WorkerRunnable::Cancel;
};
// A convenience class for WorkerRunnables that originate on the main
// thread.
class MainThreadWorkerRunnable : public WorkerRunnable
{
protected:
explicit MainThreadWorkerRunnable(WorkerPrivate* aWorkerPrivate)
: WorkerRunnable(aWorkerPrivate, WorkerThreadUnchangedBusyCount)
{
AssertIsOnMainThread();
}
virtual ~MainThreadWorkerRunnable()
{}
virtual bool
PreDispatch(WorkerPrivate* aWorkerPrivate) override
{
AssertIsOnMainThread();
return true;
}
virtual void
PostDispatch(WorkerPrivate* aWorkerPrivate,
bool aDispatchResult) override
{
AssertIsOnMainThread();
}
};
// A convenience class for WorkerControlRunnables that originate on the main
// thread.
class MainThreadWorkerControlRunnable : public WorkerControlRunnable
@ -320,7 +349,10 @@ protected:
}
virtual void
PostDispatch(WorkerPrivate* aWorkerPrivate, bool aDispatchResult) override;
PostDispatch(WorkerPrivate* aWorkerPrivate, bool aDispatchResult) override
{
AssertIsOnMainThread();
}
};
// A WorkerRunnable that should be dispatched from the worker to itself for