mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-27 06:43:32 +00:00
Bug 1457157 P3 Replace ClientHandleOpChild MozPromise direct std::function callbacks. r=baku
This commit is contained in:
parent
00d42d9d6b
commit
24a39442fe
@ -37,32 +37,27 @@ ClientHandle::Shutdown()
|
||||
mManager = nullptr;
|
||||
}
|
||||
|
||||
already_AddRefed<ClientOpPromise>
|
||||
ClientHandle::StartOp(const ClientOpConstructorArgs& aArgs)
|
||||
void
|
||||
ClientHandle::StartOp(const ClientOpConstructorArgs& aArgs,
|
||||
const ClientOpCallback&& aResolveCallback,
|
||||
const ClientOpCallback&& aRejectCallback)
|
||||
{
|
||||
RefPtr<ClientOpPromise::Private> promise =
|
||||
new ClientOpPromise::Private(__func__);
|
||||
|
||||
// Hold a ref to the client until the remote operation completes. Otherwise
|
||||
// the ClientHandle might get de-refed and teardown the actor before we
|
||||
// get an answer.
|
||||
RefPtr<ClientHandle> kungFuGrip = this;
|
||||
promise->Then(mSerialEventTarget, __func__,
|
||||
[kungFuGrip] (const ClientOpResult &) { },
|
||||
[kungFuGrip] (nsresult) { });
|
||||
|
||||
MaybeExecute([aArgs, promise] (ClientHandleChild* aActor) {
|
||||
ClientHandleOpChild* actor = new ClientHandleOpChild(aArgs, promise);
|
||||
MaybeExecute([aArgs, kungFuGrip, aRejectCallback,
|
||||
resolve = Move(aResolveCallback)] (ClientHandleChild* aActor) {
|
||||
ClientHandleOpChild* actor =
|
||||
new ClientHandleOpChild(aArgs, Move(resolve), Move(aRejectCallback));
|
||||
if (!aActor->SendPClientHandleOpConstructor(actor, aArgs)) {
|
||||
// Constructor failure will reject promise via ActorDestroy()
|
||||
// Constructor failure will call reject callback via ActorDestroy()
|
||||
return;
|
||||
}
|
||||
}, [promise] {
|
||||
promise->Reject(NS_ERROR_DOM_INVALID_STATE_ERR, __func__);
|
||||
}, [aRejectCallback, kungFuGrip] {
|
||||
aRejectCallback(NS_ERROR_DOM_INVALID_STATE_ERR);
|
||||
});
|
||||
|
||||
RefPtr<ClientOpPromise> ref = promise.get();
|
||||
return ref.forget();
|
||||
}
|
||||
|
||||
void
|
||||
@ -124,10 +119,7 @@ ClientHandle::Control(const ServiceWorkerDescriptor& aServiceWorker)
|
||||
RefPtr<GenericPromise::Private> outerPromise =
|
||||
new GenericPromise::Private(__func__);
|
||||
|
||||
RefPtr<ClientOpPromise> innerPromise =
|
||||
StartOp(ClientControlledArgs(aServiceWorker.ToIPC()));
|
||||
|
||||
innerPromise->Then(mSerialEventTarget, __func__,
|
||||
StartOp(ClientControlledArgs(aServiceWorker.ToIPC()),
|
||||
[outerPromise](const ClientOpResult& aResult) {
|
||||
outerPromise->Resolve(true, __func__);
|
||||
},
|
||||
@ -144,9 +136,7 @@ ClientHandle::Focus()
|
||||
RefPtr<ClientStatePromise::Private> outerPromise =
|
||||
new ClientStatePromise::Private(__func__);
|
||||
|
||||
RefPtr<ClientOpPromise> innerPromise = StartOp(ClientFocusArgs());
|
||||
|
||||
innerPromise->Then(mSerialEventTarget, __func__,
|
||||
StartOp(ClientFocusArgs(),
|
||||
[outerPromise](const ClientOpResult& aResult) {
|
||||
outerPromise->Resolve(ClientState::FromIPC(aResult.get_IPCClientState()), __func__);
|
||||
}, [outerPromise](const ClientOpResult& aResult) {
|
||||
@ -180,8 +170,7 @@ ClientHandle::PostMessage(StructuredCloneData& aData,
|
||||
RefPtr<GenericPromise::Private> outerPromise =
|
||||
new GenericPromise::Private(__func__);
|
||||
|
||||
RefPtr<ClientOpPromise> innerPromise = StartOp(args);
|
||||
innerPromise->Then(mSerialEventTarget, __func__,
|
||||
StartOp(args,
|
||||
[outerPromise](const ClientOpResult& aResult) {
|
||||
outerPromise->Resolve(true, __func__);
|
||||
}, [outerPromise](const ClientOpResult& aResult) {
|
||||
|
@ -50,8 +50,10 @@ class ClientHandle final : public ClientThing<ClientHandleChild>
|
||||
void
|
||||
Shutdown();
|
||||
|
||||
already_AddRefed<ClientOpPromise>
|
||||
StartOp(const ClientOpConstructorArgs& aArgs);
|
||||
void
|
||||
StartOp(const ClientOpConstructorArgs& aArgs,
|
||||
const ClientOpCallback&& aResolveCallback,
|
||||
const ClientOpCallback&& aRejectCallback);
|
||||
|
||||
// ClientThing interface
|
||||
void
|
||||
|
@ -12,10 +12,7 @@ namespace dom {
|
||||
void
|
||||
ClientHandleOpChild::ActorDestroy(ActorDestroyReason aReason)
|
||||
{
|
||||
if (mPromise) {
|
||||
mPromise->Reject(NS_ERROR_ABORT, __func__);
|
||||
mPromise = nullptr;
|
||||
}
|
||||
mRejectCallback(NS_ERROR_DOM_ABORT_ERR);
|
||||
}
|
||||
|
||||
mozilla::ipc::IPCResult
|
||||
@ -23,25 +20,21 @@ ClientHandleOpChild::Recv__delete__(const ClientOpResult& aResult)
|
||||
{
|
||||
if (aResult.type() == ClientOpResult::Tnsresult &&
|
||||
NS_FAILED(aResult.get_nsresult())) {
|
||||
mPromise->Reject(aResult.get_nsresult(), __func__);
|
||||
mPromise = nullptr;
|
||||
mRejectCallback(aResult.get_nsresult());
|
||||
return IPC_OK();
|
||||
}
|
||||
mPromise->Resolve(aResult, __func__);
|
||||
mPromise = nullptr;
|
||||
mResolveCallback(aResult);
|
||||
return IPC_OK();
|
||||
}
|
||||
|
||||
ClientHandleOpChild::ClientHandleOpChild(const ClientOpConstructorArgs& aArgs,
|
||||
ClientOpPromise::Private* aPromise)
|
||||
: mPromise(aPromise)
|
||||
const ClientOpCallback&& aResolveCallback,
|
||||
const ClientOpCallback&& aRejectCallback)
|
||||
: mResolveCallback(Move(aResolveCallback))
|
||||
, mRejectCallback(Move(aRejectCallback))
|
||||
{
|
||||
MOZ_DIAGNOSTIC_ASSERT(mPromise);
|
||||
}
|
||||
|
||||
ClientHandleOpChild::~ClientHandleOpChild()
|
||||
{
|
||||
MOZ_DIAGNOSTIC_ASSERT(!mPromise);
|
||||
MOZ_DIAGNOSTIC_ASSERT(mResolveCallback);
|
||||
MOZ_DIAGNOSTIC_ASSERT(mRejectCallback);
|
||||
}
|
||||
|
||||
} // namespace dom
|
||||
|
@ -8,14 +8,14 @@
|
||||
|
||||
#include "mozilla/dom/ClientOpPromise.h"
|
||||
#include "mozilla/dom/PClientHandleOpChild.h"
|
||||
#include "mozilla/MozPromise.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
class ClientHandleOpChild final : public PClientHandleOpChild
|
||||
{
|
||||
RefPtr<ClientOpPromise::Private> mPromise;
|
||||
const ClientOpCallback mResolveCallback;
|
||||
const ClientOpCallback mRejectCallback;
|
||||
|
||||
// PClientHandleOpChild interface
|
||||
void
|
||||
@ -26,9 +26,10 @@ class ClientHandleOpChild final : public PClientHandleOpChild
|
||||
|
||||
public:
|
||||
ClientHandleOpChild(const ClientOpConstructorArgs& aArgs,
|
||||
ClientOpPromise::Private* aPromise);
|
||||
const ClientOpCallback&& aResolveCallback,
|
||||
const ClientOpCallback&& aRejectCallback);
|
||||
|
||||
~ClientHandleOpChild();
|
||||
~ClientHandleOpChild() = default;
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
|
@ -18,6 +18,8 @@ typedef MozPromise<ClientOpResult, nsresult, false> ClientOpPromise;
|
||||
|
||||
typedef MozPromise<ClientState, nsresult, false> ClientStatePromise;
|
||||
|
||||
typedef std::function<void(const ClientOpResult&)> ClientOpCallback;
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user