зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1425975 P1 Add ClientHandle::OnDetach() which returns a MozPromise that resolves on actor destruction. r=asuth
This commit is contained in:
Родитель
7356e0ba3b
Коммит
8e2abf779f
|
@ -65,6 +65,16 @@ ClientHandle::StartOp(const ClientOpConstructorArgs& aArgs)
|
|||
return ref.forget();
|
||||
}
|
||||
|
||||
void
|
||||
ClientHandle::OnShutdownThing()
|
||||
{
|
||||
NS_ASSERT_OWNINGTHREAD(ClientHandle);
|
||||
if (!mDetachPromise) {
|
||||
return;
|
||||
}
|
||||
mDetachPromise->Resolve(true, __func__);
|
||||
}
|
||||
|
||||
ClientHandle::ClientHandle(ClientManager* aManager,
|
||||
nsISerialEventTarget* aSerialEventTarget,
|
||||
const ClientInfo& aClientInfo)
|
||||
|
@ -182,5 +192,21 @@ ClientHandle::PostMessage(StructuredCloneData& aData,
|
|||
return ref.forget();
|
||||
}
|
||||
|
||||
RefPtr<GenericPromise>
|
||||
ClientHandle::OnDetach()
|
||||
{
|
||||
NS_ASSERT_OWNINGTHREAD(ClientSource);
|
||||
|
||||
if (!mDetachPromise) {
|
||||
mDetachPromise = new GenericPromise::Private(__func__);
|
||||
if (IsShutdown()) {
|
||||
mDetachPromise->Resolve(true, __func__);
|
||||
}
|
||||
}
|
||||
|
||||
RefPtr<GenericPromise> ref(mDetachPromise);
|
||||
return Move(ref);
|
||||
}
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
|
|
@ -42,6 +42,7 @@ class ClientHandle final : public ClientThing<ClientHandleChild>
|
|||
|
||||
RefPtr<ClientManager> mManager;
|
||||
nsCOMPtr<nsISerialEventTarget> mSerialEventTarget;
|
||||
RefPtr<GenericPromise::Private> mDetachPromise;
|
||||
ClientInfo mClientInfo;
|
||||
|
||||
~ClientHandle();
|
||||
|
@ -52,6 +53,10 @@ class ClientHandle final : public ClientThing<ClientHandleChild>
|
|||
already_AddRefed<ClientOpPromise>
|
||||
StartOp(const ClientOpConstructorArgs& aArgs);
|
||||
|
||||
// ClientThing interface
|
||||
void
|
||||
OnShutdownThing() override;
|
||||
|
||||
// Private methods called by ClientHandleChild
|
||||
void
|
||||
ExecutionReady(const ClientInfo& aClientInfo);
|
||||
|
@ -90,6 +95,17 @@ public:
|
|||
PostMessage(ipc::StructuredCloneData& aData,
|
||||
const ServiceWorkerDescriptor& aSource);
|
||||
|
||||
// Return a Promise that resolves when the ClientHandle object is detached
|
||||
// from its remote actors. This will happen if the ClientSource is destroyed
|
||||
// and triggers the cleanup of the handle actors. It will also naturally
|
||||
// happen when the ClientHandle is de-referenced and tears down its own
|
||||
// actors.
|
||||
//
|
||||
// Note: This method can only be called on the ClientHandle owning thread,
|
||||
// but the MozPromise lets you Then() to another thread.
|
||||
RefPtr<GenericPromise>
|
||||
OnDetach();
|
||||
|
||||
NS_INLINE_DECL_REFCOUNTING(ClientHandle);
|
||||
};
|
||||
|
||||
|
|
|
@ -90,6 +90,15 @@ protected:
|
|||
mActor->MaybeStartTeardown();
|
||||
mActor = nullptr;
|
||||
}
|
||||
|
||||
OnShutdownThing();
|
||||
}
|
||||
|
||||
// Allow extending classes to take action when shutdown.
|
||||
virtual void
|
||||
OnShutdownThing()
|
||||
{
|
||||
// by default do nothing
|
||||
}
|
||||
|
||||
public:
|
||||
|
@ -106,6 +115,8 @@ public:
|
|||
// instead of calling ShutdownThing() to avoid calling MaybeStartTeardown()
|
||||
// on the destroyed actor.
|
||||
mShutdown = true;
|
||||
|
||||
OnShutdownThing();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче