зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1435263 - Get rid of WorkerPrivateParent template - part 0 - WorkerPrivate::EventTarget, r=bkelly
This commit is contained in:
Родитель
94e0ff94f0
Коммит
2dfbe16467
|
@ -964,9 +964,7 @@ public:
|
||||||
NS_IMPL_ISUPPORTS_INHERITED0(TopLevelWorkerFinishedRunnable, Runnable)
|
NS_IMPL_ISUPPORTS_INHERITED0(TopLevelWorkerFinishedRunnable, Runnable)
|
||||||
|
|
||||||
|
|
||||||
template <class Derived>
|
class WorkerPrivate::EventTarget final : public nsISerialEventTarget
|
||||||
class WorkerPrivateParent<Derived>::EventTarget final
|
|
||||||
: public nsISerialEventTarget
|
|
||||||
{
|
{
|
||||||
// This mutex protects mWorkerPrivate and must be acquired *before* the
|
// This mutex protects mWorkerPrivate and must be acquired *before* the
|
||||||
// WorkerPrivate's mutex whenever they must both be held.
|
// WorkerPrivate's mutex whenever they must both be held.
|
||||||
|
@ -977,14 +975,14 @@ class WorkerPrivateParent<Derived>::EventTarget final
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit EventTarget(WorkerPrivate* aWorkerPrivate)
|
explicit EventTarget(WorkerPrivate* aWorkerPrivate)
|
||||||
: mMutex("WorkerPrivateParent::EventTarget::mMutex"),
|
: mMutex("WorkerPrivate::EventTarget::mMutex"),
|
||||||
mWorkerPrivate(aWorkerPrivate), mWeakNestedEventTarget(nullptr)
|
mWorkerPrivate(aWorkerPrivate), mWeakNestedEventTarget(nullptr)
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(aWorkerPrivate);
|
MOZ_ASSERT(aWorkerPrivate);
|
||||||
}
|
}
|
||||||
|
|
||||||
EventTarget(WorkerPrivate* aWorkerPrivate, nsIEventTarget* aNestedEventTarget)
|
EventTarget(WorkerPrivate* aWorkerPrivate, nsIEventTarget* aNestedEventTarget)
|
||||||
: mMutex("WorkerPrivateParent::EventTarget::mMutex"),
|
: mMutex("WorkerPrivate::EventTarget::mMutex"),
|
||||||
mWorkerPrivate(aWorkerPrivate), mWeakNestedEventTarget(aNestedEventTarget),
|
mWorkerPrivate(aWorkerPrivate), mWeakNestedEventTarget(aNestedEventTarget),
|
||||||
mNestedEventTarget(aNestedEventTarget)
|
mNestedEventTarget(aNestedEventTarget)
|
||||||
{
|
{
|
||||||
|
@ -1652,23 +1650,20 @@ WorkerPrivateParent<Derived>::Traverse(nsCycleCollectionTraversalCallback& aCb)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Derived>
|
|
||||||
nsresult
|
nsresult
|
||||||
WorkerPrivateParent<Derived>::DispatchPrivate(already_AddRefed<WorkerRunnable> aRunnable,
|
WorkerPrivate::DispatchPrivate(already_AddRefed<WorkerRunnable> aRunnable,
|
||||||
nsIEventTarget* aSyncLoopTarget)
|
nsIEventTarget* aSyncLoopTarget)
|
||||||
{
|
{
|
||||||
// May be called on any thread!
|
// May be called on any thread!
|
||||||
RefPtr<WorkerRunnable> runnable(aRunnable);
|
RefPtr<WorkerRunnable> runnable(aRunnable);
|
||||||
|
|
||||||
WorkerPrivate* self = ParentAsWorkerPrivate();
|
|
||||||
|
|
||||||
{
|
{
|
||||||
MutexAutoLock lock(mMutex);
|
MutexAutoLock lock(mMutex);
|
||||||
|
|
||||||
MOZ_ASSERT_IF(aSyncLoopTarget, self->mThread);
|
MOZ_ASSERT_IF(aSyncLoopTarget, mThread);
|
||||||
|
|
||||||
if (!self->mThread) {
|
if (!mThread) {
|
||||||
if (ParentStatus() == Pending || self->mStatus == Pending) {
|
if (ParentStatus() == Pending || mStatus == Pending) {
|
||||||
mPreStartRunnables.AppendElement(runnable);
|
mPreStartRunnables.AppendElement(runnable);
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
@ -1678,7 +1673,7 @@ WorkerPrivateParent<Derived>::DispatchPrivate(already_AddRefed<WorkerRunnable> a
|
||||||
return NS_ERROR_UNEXPECTED;
|
return NS_ERROR_UNEXPECTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self->mStatus == Dead ||
|
if (mStatus == Dead ||
|
||||||
(!aSyncLoopTarget && ParentStatus() > Running)) {
|
(!aSyncLoopTarget && ParentStatus() > Running)) {
|
||||||
NS_WARNING("A runnable was posted to a worker that is already shutting "
|
NS_WARNING("A runnable was posted to a worker that is already shutting "
|
||||||
"down!");
|
"down!");
|
||||||
|
@ -1689,7 +1684,7 @@ WorkerPrivateParent<Derived>::DispatchPrivate(already_AddRefed<WorkerRunnable> a
|
||||||
if (aSyncLoopTarget) {
|
if (aSyncLoopTarget) {
|
||||||
rv = aSyncLoopTarget->Dispatch(runnable.forget(), NS_DISPATCH_NORMAL);
|
rv = aSyncLoopTarget->Dispatch(runnable.forget(), NS_DISPATCH_NORMAL);
|
||||||
} else {
|
} else {
|
||||||
rv = self->mThread->DispatchAnyThread(WorkerThreadFriendKey(), runnable.forget());
|
rv = mThread->DispatchAnyThread(WorkerThreadFriendKey(), runnable.forget());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||||
|
@ -1729,6 +1724,14 @@ WorkerPrivateParent<Derived>::DisableDebugger()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class Derived>
|
||||||
|
nsresult
|
||||||
|
WorkerPrivateParent<Derived>::Dispatch(already_AddRefed<WorkerRunnable> aRunnable)
|
||||||
|
{
|
||||||
|
WorkerPrivate* self = ParentAsWorkerPrivate();
|
||||||
|
return self->DispatchPrivate(Move(aRunnable), nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
template <class Derived>
|
template <class Derived>
|
||||||
nsresult
|
nsresult
|
||||||
WorkerPrivateParent<Derived>::DispatchControlRunnable(
|
WorkerPrivateParent<Derived>::DispatchControlRunnable(
|
||||||
|
@ -5354,14 +5357,10 @@ WorkerPrivate::GetPerformanceStorage()
|
||||||
|
|
||||||
NS_IMPL_ISUPPORTS_INHERITED0(ExternalRunnableWrapper, WorkerRunnable)
|
NS_IMPL_ISUPPORTS_INHERITED0(ExternalRunnableWrapper, WorkerRunnable)
|
||||||
|
|
||||||
template <class Derived>
|
NS_IMPL_ADDREF(WorkerPrivate::EventTarget)
|
||||||
NS_IMPL_ADDREF(WorkerPrivateParent<Derived>::EventTarget)
|
NS_IMPL_RELEASE(WorkerPrivate::EventTarget)
|
||||||
|
|
||||||
template <class Derived>
|
NS_INTERFACE_MAP_BEGIN(WorkerPrivate::EventTarget)
|
||||||
NS_IMPL_RELEASE(WorkerPrivateParent<Derived>::EventTarget)
|
|
||||||
|
|
||||||
template <class Derived>
|
|
||||||
NS_INTERFACE_MAP_BEGIN(WorkerPrivateParent<Derived>::EventTarget)
|
|
||||||
NS_INTERFACE_MAP_ENTRY(nsISerialEventTarget)
|
NS_INTERFACE_MAP_ENTRY(nsISerialEventTarget)
|
||||||
NS_INTERFACE_MAP_ENTRY(nsIEventTarget)
|
NS_INTERFACE_MAP_ENTRY(nsIEventTarget)
|
||||||
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
||||||
|
@ -5376,19 +5375,17 @@ NS_INTERFACE_MAP_BEGIN(WorkerPrivateParent<Derived>::EventTarget)
|
||||||
#endif
|
#endif
|
||||||
NS_INTERFACE_MAP_END
|
NS_INTERFACE_MAP_END
|
||||||
|
|
||||||
template <class Derived>
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
WorkerPrivateParent<Derived>::
|
WorkerPrivate::EventTarget::DispatchFromScript(nsIRunnable* aRunnable,
|
||||||
EventTarget::DispatchFromScript(nsIRunnable* aRunnable, uint32_t aFlags)
|
uint32_t aFlags)
|
||||||
{
|
{
|
||||||
nsCOMPtr<nsIRunnable> event(aRunnable);
|
nsCOMPtr<nsIRunnable> event(aRunnable);
|
||||||
return Dispatch(event.forget(), aFlags);
|
return Dispatch(event.forget(), aFlags);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Derived>
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
WorkerPrivateParent<Derived>::
|
WorkerPrivate::EventTarget::Dispatch(already_AddRefed<nsIRunnable> aRunnable,
|
||||||
EventTarget::Dispatch(already_AddRefed<nsIRunnable> aRunnable, uint32_t aFlags)
|
uint32_t aFlags)
|
||||||
{
|
{
|
||||||
// May be called on any thread!
|
// May be called on any thread!
|
||||||
nsCOMPtr<nsIRunnable> event(aRunnable);
|
nsCOMPtr<nsIRunnable> event(aRunnable);
|
||||||
|
@ -5421,18 +5418,16 @@ EventTarget::Dispatch(already_AddRefed<nsIRunnable> aRunnable, uint32_t aFlags)
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Derived>
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
WorkerPrivateParent<Derived>::
|
WorkerPrivate::EventTarget::DelayedDispatch(already_AddRefed<nsIRunnable>,
|
||||||
EventTarget::DelayedDispatch(already_AddRefed<nsIRunnable>, uint32_t)
|
uint32_t)
|
||||||
|
|
||||||
{
|
{
|
||||||
return NS_ERROR_NOT_IMPLEMENTED;
|
return NS_ERROR_NOT_IMPLEMENTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Derived>
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
WorkerPrivateParent<Derived>::
|
WorkerPrivate::EventTarget::IsOnCurrentThread(bool* aIsOnCurrentThread)
|
||||||
EventTarget::IsOnCurrentThread(bool* aIsOnCurrentThread)
|
|
||||||
{
|
{
|
||||||
// May be called on any thread!
|
// May be called on any thread!
|
||||||
|
|
||||||
|
@ -5449,10 +5444,8 @@ EventTarget::IsOnCurrentThread(bool* aIsOnCurrentThread)
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Derived>
|
|
||||||
NS_IMETHODIMP_(bool)
|
NS_IMETHODIMP_(bool)
|
||||||
WorkerPrivateParent<Derived>::
|
WorkerPrivate::EventTarget::IsOnCurrentThreadInfallible()
|
||||||
EventTarget::IsOnCurrentThreadInfallible()
|
|
||||||
{
|
{
|
||||||
// May be called on any thread!
|
// May be called on any thread!
|
||||||
|
|
||||||
|
|
|
@ -104,9 +104,6 @@ template <class Derived>
|
||||||
class WorkerPrivateParent
|
class WorkerPrivateParent
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
class EventTarget;
|
|
||||||
friend class EventTarget;
|
|
||||||
|
|
||||||
typedef mozilla::ipc::PrincipalInfo PrincipalInfo;
|
typedef mozilla::ipc::PrincipalInfo PrincipalInfo;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -220,9 +217,6 @@ private:
|
||||||
return NotifyPrivate(Terminating);
|
return NotifyPrivate(Terminating);
|
||||||
}
|
}
|
||||||
|
|
||||||
nsresult
|
|
||||||
DispatchPrivate(already_AddRefed<WorkerRunnable> aRunnable, nsIEventTarget* aSyncLoopTarget);
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
NS_INLINE_DECL_REFCOUNTING(WorkerPrivateParent)
|
NS_INLINE_DECL_REFCOUNTING(WorkerPrivateParent)
|
||||||
|
|
||||||
|
@ -245,10 +239,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
nsresult
|
nsresult
|
||||||
Dispatch(already_AddRefed<WorkerRunnable> aRunnable)
|
Dispatch(already_AddRefed<WorkerRunnable> aRunnable);
|
||||||
{
|
|
||||||
return DispatchPrivate(Move(aRunnable), nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
nsresult
|
nsresult
|
||||||
DispatchControlRunnable(already_AddRefed<WorkerControlRunnable> aWorkerControlRunnable);
|
DispatchControlRunnable(already_AddRefed<WorkerControlRunnable> aWorkerControlRunnable);
|
||||||
|
@ -875,6 +866,8 @@ public:
|
||||||
|
|
||||||
class WorkerPrivate : public WorkerPrivateParent<WorkerPrivate>
|
class WorkerPrivate : public WorkerPrivateParent<WorkerPrivate>
|
||||||
{
|
{
|
||||||
|
class EventTarget;
|
||||||
|
friend class EventTarget;
|
||||||
friend class mozilla::dom::WorkerHolder;
|
friend class mozilla::dom::WorkerHolder;
|
||||||
friend class WorkerPrivateParent<WorkerPrivate>;
|
friend class WorkerPrivateParent<WorkerPrivate>;
|
||||||
typedef WorkerPrivateParent<WorkerPrivate> ParentType;
|
typedef WorkerPrivateParent<WorkerPrivate> ParentType;
|
||||||
|
@ -1400,6 +1393,10 @@ private:
|
||||||
const nsACString& aServiceWorkerScope,
|
const nsACString& aServiceWorkerScope,
|
||||||
WorkerLoadInfo& aLoadInfo);
|
WorkerLoadInfo& aLoadInfo);
|
||||||
|
|
||||||
|
nsresult
|
||||||
|
DispatchPrivate(already_AddRefed<WorkerRunnable> aRunnable,
|
||||||
|
nsIEventTarget* aSyncLoopTarget);
|
||||||
|
|
||||||
bool
|
bool
|
||||||
MayContinueRunning()
|
MayContinueRunning()
|
||||||
{
|
{
|
||||||
|
|
Загрузка…
Ссылка в новой задаче