//
// Automatically generated by ipdlc.
// Edit at your own risk
//


#include "mozilla/dom/PServiceWorkerContainerChild.h"
#include "ipc/ErrorIPCUtils.h"
#include "mozilla/ProfilerLabels.h"
#include "mozilla/dom/BindingIPCUtils.h"
#include "mozilla/dom/ClientIPCUtils.h"
#include "mozilla/dom/ServiceWorkerIPCUtils.h"
#include "mozilla/dom/WorkerIPCUtils.h"

#include "mozilla/ipc/PBackgroundChild.h"

#include "ipc/IPCMessageUtils.h"
#include "ipc/IPCMessageUtilsSpecializations.h"
#include "nsIFile.h"
#include "mozilla/ipc/Endpoint.h"
#include "mozilla/ipc/ProtocolMessageUtils.h"
#include "mozilla/ipc/ProtocolUtils.h"
#include "mozilla/ipc/ShmemMessageUtils.h"
#include "mozilla/ipc/TaintingIPCUtils.h"

namespace mozilla {
namespace dom {


MOZ_IMPLICIT PServiceWorkerContainerChild::PServiceWorkerContainerChild() :
    mozilla::ipc::IRefCountedProtocol(kProtocolId, mozilla::ipc::ChildSide)
{
    MOZ_COUNT_CTOR(PServiceWorkerContainerChild);
}

PServiceWorkerContainerChild::~PServiceWorkerContainerChild()
{
    MOZ_COUNT_DTOR(PServiceWorkerContainerChild);
}

auto PServiceWorkerContainerChild::ActorAlloc() -> void
{
    AddRef();
}

auto PServiceWorkerContainerChild::ActorDealloc() -> void
{
    Release();
}

auto PServiceWorkerContainerChild::OtherPid() const -> ::base::ProcessId
{
    ::base::ProcessId pid =
        ::mozilla::ipc::IProtocol::ToplevelProtocol()->OtherPidMaybeInvalid();
    MOZ_RELEASE_ASSERT(pid != ::base::kInvalidProcessId);
    return pid;
}

auto PServiceWorkerContainerChild::OtherChildID() const -> ::GeckoChildID
{
    ::GeckoChildID childID =
        ::mozilla::ipc::IProtocol::ToplevelProtocol()->OtherChildIDMaybeInvalid();
    MOZ_RELEASE_ASSERT(childID != -1);
    return childID;
}

auto PServiceWorkerContainerChild::OtherEndpointProcInfo() const -> ::mozilla::ipc::EndpointProcInfo
{
    return ::mozilla::ipc::EndpointProcInfo{OtherPid(), OtherChildID()};
}

auto PServiceWorkerContainerChild::Manager() const -> PBackgroundChild*
{
    return static_cast<PBackgroundChild*>(IProtocol::Manager());
}

auto PServiceWorkerContainerChild::ManagedProtocolIds() const -> mozilla::Span<mozilla::ipc::ProtocolId const>
{
    return {};
}

auto PServiceWorkerContainerChild::GetManagedActors(mozilla::ipc::ProtocolId aProtocol) -> UntypedManagedContainer*
{
    switch (aProtocol) {
    default:
        return nullptr;
    }
}

auto PServiceWorkerContainerChild::RejectPendingResponses(ResponseRejectReason aReason) -> void
{
    mAsyncCallbacks.RejectPendingResponses(aReason);
}

auto PServiceWorkerContainerChild::SendRegister(
        const IPCClientInfo& aClientInfo,
        const nsACString& aScopeURL,
        const WorkerType& aType,
        const nsACString& aScriptURL,
        const ServiceWorkerUpdateViaCache& aUpdateViaCache,
        mozilla::ipc::ResolveCallback<IPCServiceWorkerRegistrationDescriptorOrCopyableErrorResult>&& aResolve,
        mozilla::ipc::RejectCallback&& aReject) -> void
{
    UniquePtr<IPC::Message> msg__ = PServiceWorkerContainer::Msg_Register(Id());
    IPC::MessageWriter writer__{
            (*(msg__)),
            this};

    IPC::WriteParam((&(writer__)), aClientInfo);
    // Sentinel = 'aClientInfo'
    ((&(writer__)))->WriteSentinel(422315085);
    IPC::WriteParam((&(writer__)), aScopeURL);
    // Sentinel = 'aScopeURL'
    ((&(writer__)))->WriteSentinel(285999951);
    IPC::WriteParam((&(writer__)), aType);
    // Sentinel = 'aType'
    ((&(writer__)))->WriteSentinel(99222020);
    IPC::WriteParam((&(writer__)), aScriptURL);
    // Sentinel = 'aScriptURL'
    ((&(writer__)))->WriteSentinel(358220746);
    IPC::WriteParam((&(writer__)), aUpdateViaCache);
    // Sentinel = 'aUpdateViaCache'
    ((&(writer__)))->WriteSentinel(772408761);


    if (mozilla::ipc::LoggingEnabledFor("PServiceWorkerContainer", mozilla::ipc::ChildSide)) {
        mozilla::ipc::LogMessageForProtocol(
            "PServiceWorkerContainerChild",
            this->ToplevelProtocol()->OtherPidMaybeInvalid(),
            "Sending ",
            msg__->type(),
            mozilla::ipc::MessageDirection::eSending);
    }
    AUTO_PROFILER_LABEL("PServiceWorkerContainer::Msg_Register", OTHER);

    IPC::Message::seqno_t seqno__ = 0;
    if (ChannelSend(std::move(msg__), (&(seqno__)))) {
        mAsyncCallbacks.AddCallback(seqno__, PServiceWorkerContainer::Reply_Register__ID, [resolve=std::move(aResolve)](IPC::MessageReader* aReader) mutable {
            auto maybe__aResult = IPC::ReadParam<IPCServiceWorkerRegistrationDescriptorOrCopyableErrorResult>(aReader);
            if (!maybe__aResult) {
                (aReader)->FatalError("Error deserializing 'IPCServiceWorkerRegistrationDescriptorOrCopyableErrorResult'");
                return MsgValueError;

            }
            auto& aResult = *maybe__aResult;
            // Sentinel = 'aResult'
            if ((!((aReader)->ReadSentinel(185205473)))) {
                mozilla::ipc::SentinelReadError("Error deserializing 'IPCServiceWorkerRegistrationDescriptorOrCopyableErrorResult'");
                return MsgValueError;
            }


            aReader->EndRead();

            resolve(std::move(aResult));
            return MsgProcessed;
        }, std::move(aReject));
    }
    else {
        aReject(::mozilla::ipc::ResponseRejectReason::SendError);
    }
    return;
}

auto PServiceWorkerContainerChild::SendRegister(
        const IPCClientInfo& aClientInfo,
        const nsACString& aScopeURL,
        const WorkerType& aType,
        const nsACString& aScriptURL,
        const ServiceWorkerUpdateViaCache& aUpdateViaCache) -> RefPtr<RegisterPromise>
{
    RefPtr<MozPromise<IPCServiceWorkerRegistrationDescriptorOrCopyableErrorResult, ResponseRejectReason, true>::Private> promise__ = new MozPromise<IPCServiceWorkerRegistrationDescriptorOrCopyableErrorResult, ResponseRejectReason, true>::Private(__func__);
    promise__->UseDirectTaskDispatch(__func__);
    SendRegister(std::move(aClientInfo), std::move(aScopeURL), std::move(aType), std::move(aScriptURL), std::move(aUpdateViaCache), [promise__](IPCServiceWorkerRegistrationDescriptorOrCopyableErrorResult&& aValue) {
        promise__->Resolve(std::move(aValue), __func__);
    }, [promise__](ResponseRejectReason&& aReason) {
        promise__->Reject(std::move(aReason), __func__);
    });
    return promise__;
}

auto PServiceWorkerContainerChild::SendGetRegistration(
        const IPCClientInfo& aClientInfo,
        const nsACString& aURL,
        mozilla::ipc::ResolveCallback<IPCServiceWorkerRegistrationDescriptorOrCopyableErrorResult>&& aResolve,
        mozilla::ipc::RejectCallback&& aReject) -> void
{
    UniquePtr<IPC::Message> msg__ = PServiceWorkerContainer::Msg_GetRegistration(Id());
    IPC::MessageWriter writer__{
            (*(msg__)),
            this};

    IPC::WriteParam((&(writer__)), aClientInfo);
    // Sentinel = 'aClientInfo'
    ((&(writer__)))->WriteSentinel(422315085);
    IPC::WriteParam((&(writer__)), aURL);
    // Sentinel = 'aURL'
    ((&(writer__)))->WriteSentinel(58130773);


    if (mozilla::ipc::LoggingEnabledFor("PServiceWorkerContainer", mozilla::ipc::ChildSide)) {
        mozilla::ipc::LogMessageForProtocol(
            "PServiceWorkerContainerChild",
            this->ToplevelProtocol()->OtherPidMaybeInvalid(),
            "Sending ",
            msg__->type(),
            mozilla::ipc::MessageDirection::eSending);
    }
    AUTO_PROFILER_LABEL("PServiceWorkerContainer::Msg_GetRegistration", OTHER);

    IPC::Message::seqno_t seqno__ = 0;
    if (ChannelSend(std::move(msg__), (&(seqno__)))) {
        mAsyncCallbacks.AddCallback(seqno__, PServiceWorkerContainer::Reply_GetRegistration__ID, [resolve=std::move(aResolve)](IPC::MessageReader* aReader) mutable {
            auto maybe__aResult = IPC::ReadParam<IPCServiceWorkerRegistrationDescriptorOrCopyableErrorResult>(aReader);
            if (!maybe__aResult) {
                (aReader)->FatalError("Error deserializing 'IPCServiceWorkerRegistrationDescriptorOrCopyableErrorResult'");
                return MsgValueError;

            }
            auto& aResult = *maybe__aResult;
            // Sentinel = 'aResult'
            if ((!((aReader)->ReadSentinel(185205473)))) {
                mozilla::ipc::SentinelReadError("Error deserializing 'IPCServiceWorkerRegistrationDescriptorOrCopyableErrorResult'");
                return MsgValueError;
            }


            aReader->EndRead();

            resolve(std::move(aResult));
            return MsgProcessed;
        }, std::move(aReject));
    }
    else {
        aReject(::mozilla::ipc::ResponseRejectReason::SendError);
    }
    return;
}

auto PServiceWorkerContainerChild::SendGetRegistration(
        const IPCClientInfo& aClientInfo,
        const nsACString& aURL) -> RefPtr<GetRegistrationPromise>
{
    RefPtr<MozPromise<IPCServiceWorkerRegistrationDescriptorOrCopyableErrorResult, ResponseRejectReason, true>::Private> promise__ = new MozPromise<IPCServiceWorkerRegistrationDescriptorOrCopyableErrorResult, ResponseRejectReason, true>::Private(__func__);
    promise__->UseDirectTaskDispatch(__func__);
    SendGetRegistration(std::move(aClientInfo), std::move(aURL), [promise__](IPCServiceWorkerRegistrationDescriptorOrCopyableErrorResult&& aValue) {
        promise__->Resolve(std::move(aValue), __func__);
    }, [promise__](ResponseRejectReason&& aReason) {
        promise__->Reject(std::move(aReason), __func__);
    });
    return promise__;
}

auto PServiceWorkerContainerChild::SendGetRegistrations(
        const IPCClientInfo& aClientInfo,
        mozilla::ipc::ResolveCallback<IPCServiceWorkerRegistrationDescriptorListOrCopyableErrorResult>&& aResolve,
        mozilla::ipc::RejectCallback&& aReject) -> void
{
    UniquePtr<IPC::Message> msg__ = PServiceWorkerContainer::Msg_GetRegistrations(Id());
    IPC::MessageWriter writer__{
            (*(msg__)),
            this};

    IPC::WriteParam((&(writer__)), aClientInfo);
    // Sentinel = 'aClientInfo'
    ((&(writer__)))->WriteSentinel(422315085);


    if (mozilla::ipc::LoggingEnabledFor("PServiceWorkerContainer", mozilla::ipc::ChildSide)) {
        mozilla::ipc::LogMessageForProtocol(
            "PServiceWorkerContainerChild",
            this->ToplevelProtocol()->OtherPidMaybeInvalid(),
            "Sending ",
            msg__->type(),
            mozilla::ipc::MessageDirection::eSending);
    }
    AUTO_PROFILER_LABEL("PServiceWorkerContainer::Msg_GetRegistrations", OTHER);

    IPC::Message::seqno_t seqno__ = 0;
    if (ChannelSend(std::move(msg__), (&(seqno__)))) {
        mAsyncCallbacks.AddCallback(seqno__, PServiceWorkerContainer::Reply_GetRegistrations__ID, [resolve=std::move(aResolve)](IPC::MessageReader* aReader) mutable {
            auto maybe__aResult = IPC::ReadParam<IPCServiceWorkerRegistrationDescriptorListOrCopyableErrorResult>(aReader);
            if (!maybe__aResult) {
                (aReader)->FatalError("Error deserializing 'IPCServiceWorkerRegistrationDescriptorListOrCopyableErrorResult'");
                return MsgValueError;

            }
            auto& aResult = *maybe__aResult;
            // Sentinel = 'aResult'
            if ((!((aReader)->ReadSentinel(185205473)))) {
                mozilla::ipc::SentinelReadError("Error deserializing 'IPCServiceWorkerRegistrationDescriptorListOrCopyableErrorResult'");
                return MsgValueError;
            }


            aReader->EndRead();

            resolve(std::move(aResult));
            return MsgProcessed;
        }, std::move(aReject));
    }
    else {
        aReject(::mozilla::ipc::ResponseRejectReason::SendError);
    }
    return;
}

auto PServiceWorkerContainerChild::SendGetRegistrations(const IPCClientInfo& aClientInfo) -> RefPtr<GetRegistrationsPromise>
{
    RefPtr<MozPromise<IPCServiceWorkerRegistrationDescriptorListOrCopyableErrorResult, ResponseRejectReason, true>::Private> promise__ = new MozPromise<IPCServiceWorkerRegistrationDescriptorListOrCopyableErrorResult, ResponseRejectReason, true>::Private(__func__);
    promise__->UseDirectTaskDispatch(__func__);
    SendGetRegistrations(std::move(aClientInfo), [promise__](IPCServiceWorkerRegistrationDescriptorListOrCopyableErrorResult&& aValue) {
        promise__->Resolve(std::move(aValue), __func__);
    }, [promise__](ResponseRejectReason&& aReason) {
        promise__->Reject(std::move(aReason), __func__);
    });
    return promise__;
}

auto PServiceWorkerContainerChild::SendGetReady(
        const IPCClientInfo& aClientInfo,
        mozilla::ipc::ResolveCallback<IPCServiceWorkerRegistrationDescriptorOrCopyableErrorResult>&& aResolve,
        mozilla::ipc::RejectCallback&& aReject) -> void
{
    UniquePtr<IPC::Message> msg__ = PServiceWorkerContainer::Msg_GetReady(Id());
    IPC::MessageWriter writer__{
            (*(msg__)),
            this};

    IPC::WriteParam((&(writer__)), aClientInfo);
    // Sentinel = 'aClientInfo'
    ((&(writer__)))->WriteSentinel(422315085);


    if (mozilla::ipc::LoggingEnabledFor("PServiceWorkerContainer", mozilla::ipc::ChildSide)) {
        mozilla::ipc::LogMessageForProtocol(
            "PServiceWorkerContainerChild",
            this->ToplevelProtocol()->OtherPidMaybeInvalid(),
            "Sending ",
            msg__->type(),
            mozilla::ipc::MessageDirection::eSending);
    }
    AUTO_PROFILER_LABEL("PServiceWorkerContainer::Msg_GetReady", OTHER);

    IPC::Message::seqno_t seqno__ = 0;
    if (ChannelSend(std::move(msg__), (&(seqno__)))) {
        mAsyncCallbacks.AddCallback(seqno__, PServiceWorkerContainer::Reply_GetReady__ID, [resolve=std::move(aResolve)](IPC::MessageReader* aReader) mutable {
            auto maybe__aResult = IPC::ReadParam<IPCServiceWorkerRegistrationDescriptorOrCopyableErrorResult>(aReader);
            if (!maybe__aResult) {
                (aReader)->FatalError("Error deserializing 'IPCServiceWorkerRegistrationDescriptorOrCopyableErrorResult'");
                return MsgValueError;

            }
            auto& aResult = *maybe__aResult;
            // Sentinel = 'aResult'
            if ((!((aReader)->ReadSentinel(185205473)))) {
                mozilla::ipc::SentinelReadError("Error deserializing 'IPCServiceWorkerRegistrationDescriptorOrCopyableErrorResult'");
                return MsgValueError;
            }


            aReader->EndRead();

            resolve(std::move(aResult));
            return MsgProcessed;
        }, std::move(aReject));
    }
    else {
        aReject(::mozilla::ipc::ResponseRejectReason::SendError);
    }
    return;
}

auto PServiceWorkerContainerChild::SendGetReady(const IPCClientInfo& aClientInfo) -> RefPtr<GetReadyPromise>
{
    RefPtr<MozPromise<IPCServiceWorkerRegistrationDescriptorOrCopyableErrorResult, ResponseRejectReason, true>::Private> promise__ = new MozPromise<IPCServiceWorkerRegistrationDescriptorOrCopyableErrorResult, ResponseRejectReason, true>::Private(__func__);
    promise__->UseDirectTaskDispatch(__func__);
    SendGetReady(std::move(aClientInfo), [promise__](IPCServiceWorkerRegistrationDescriptorOrCopyableErrorResult&& aValue) {
        promise__->Resolve(std::move(aValue), __func__);
    }, [promise__](ResponseRejectReason&& aReason) {
        promise__->Reject(std::move(aReason), __func__);
    });
    return promise__;
}

auto PServiceWorkerContainerChild::Send__delete__(PServiceWorkerContainerChild* actor) -> bool
{
    if (!actor || !actor->CanSend()) {
        NS_WARNING("Attempt to __delete__ missing or closed actor");
        return false;
    }
    UniquePtr<IPC::Message> msg__ = PServiceWorkerContainer::Msg___delete__((actor)->Id());
    IPC::MessageWriter writer__{
            (*(msg__)),
            actor};


    if (mozilla::ipc::LoggingEnabledFor("PServiceWorkerContainer", mozilla::ipc::ChildSide)) {
        mozilla::ipc::LogMessageForProtocol(
            "PServiceWorkerContainerChild",
            actor->ToplevelProtocol()->OtherPidMaybeInvalid(),
            "Sending ",
            msg__->type(),
            mozilla::ipc::MessageDirection::eSending);
    }
    AUTO_PROFILER_LABEL("PServiceWorkerContainer::Msg___delete__", OTHER);

    bool sendok__ = (actor)->ChannelSend(std::move(msg__));

    actor->ActorDisconnected(Deletion);
    return sendok__;
}

auto PServiceWorkerContainerChild::DeallocManagee(
        mozilla::ipc::ProtocolId aProtocolId,
        IProtocol* aListener) -> void
{
    FatalError("unreached");
    return;
}

auto PServiceWorkerContainerChild::OnMessageReceived(const Message& msg__) -> PServiceWorkerContainerChild::Result
{
    switch (msg__.type()) {
    case MANAGED_ENDPOINT_BOUND_MESSAGE_TYPE:
        {
            if (!mAwaitingManagedEndpointBind) {
                NS_WARNING("Unexpected managed endpoint lifecycle message after actor bound!");
                return MsgNotAllowed;
            }
            mAwaitingManagedEndpointBind = false;
            return MsgProcessed;
        }
    case MANAGED_ENDPOINT_DROPPED_MESSAGE_TYPE:
        {
            if (!mAwaitingManagedEndpointBind) {
                NS_WARNING("Unexpected managed endpoint lifecycle message after actor bound!");
                return MsgNotAllowed;
            }
            mAwaitingManagedEndpointBind = false;
            this->ActorDisconnected(ManagedEndpointDropped);
            return MsgProcessed;
        }
    case PServiceWorkerContainer::Reply_Register__ID:
        {
            if (mozilla::ipc::LoggingEnabledFor("PServiceWorkerContainer", mozilla::ipc::ChildSide)) {
                mozilla::ipc::LogMessageForProtocol(
                    "PServiceWorkerContainerChild",
                    this->ToplevelProtocol()->OtherPidMaybeInvalid(),
                    "Received ",
                    (&(msg__))->type(),
                    mozilla::ipc::MessageDirection::eReceiving);
            }

            AUTO_PROFILER_LABEL("PServiceWorkerContainer::Msg_Register", OTHER);


            return mAsyncCallbacks.GotReply(this, msg__);
        }
    case PServiceWorkerContainer::Reply_GetRegistration__ID:
        {
            if (mozilla::ipc::LoggingEnabledFor("PServiceWorkerContainer", mozilla::ipc::ChildSide)) {
                mozilla::ipc::LogMessageForProtocol(
                    "PServiceWorkerContainerChild",
                    this->ToplevelProtocol()->OtherPidMaybeInvalid(),
                    "Received ",
                    (&(msg__))->type(),
                    mozilla::ipc::MessageDirection::eReceiving);
            }

            AUTO_PROFILER_LABEL("PServiceWorkerContainer::Msg_GetRegistration", OTHER);


            return mAsyncCallbacks.GotReply(this, msg__);
        }
    case PServiceWorkerContainer::Reply_GetRegistrations__ID:
        {
            if (mozilla::ipc::LoggingEnabledFor("PServiceWorkerContainer", mozilla::ipc::ChildSide)) {
                mozilla::ipc::LogMessageForProtocol(
                    "PServiceWorkerContainerChild",
                    this->ToplevelProtocol()->OtherPidMaybeInvalid(),
                    "Received ",
                    (&(msg__))->type(),
                    mozilla::ipc::MessageDirection::eReceiving);
            }

            AUTO_PROFILER_LABEL("PServiceWorkerContainer::Msg_GetRegistrations", OTHER);


            return mAsyncCallbacks.GotReply(this, msg__);
        }
    case PServiceWorkerContainer::Reply_GetReady__ID:
        {
            if (mozilla::ipc::LoggingEnabledFor("PServiceWorkerContainer", mozilla::ipc::ChildSide)) {
                mozilla::ipc::LogMessageForProtocol(
                    "PServiceWorkerContainerChild",
                    this->ToplevelProtocol()->OtherPidMaybeInvalid(),
                    "Received ",
                    (&(msg__))->type(),
                    mozilla::ipc::MessageDirection::eReceiving);
            }

            AUTO_PROFILER_LABEL("PServiceWorkerContainer::Msg_GetReady", OTHER);


            return mAsyncCallbacks.GotReply(this, msg__);
        }
    case PServiceWorkerContainer::Reply___delete____ID:
        {
            return MsgProcessed;
        }
    default:
        return MsgNotKnown;
    }
}

auto PServiceWorkerContainerChild::OnMessageReceived(
        const Message& msg__,
        UniquePtr<Message>& reply__) -> PServiceWorkerContainerChild::Result
{
    return MsgNotKnown;
}



} // namespace dom
} // namespace mozilla
namespace IPC {
auto ParamTraits<::mozilla::dom::PServiceWorkerContainerChild*>::Write(
        IPC::MessageWriter* aWriter,
        const paramType& aVar) -> void
{
    IPC::WriteParam(aWriter, static_cast<mozilla::ipc::IProtocol*>(aVar));
    // Sentinel = 'PServiceWorkerContainer'
    (aWriter)->WriteSentinel(1828784447);
}

auto ParamTraits<::mozilla::dom::PServiceWorkerContainerChild*>::Read(IPC::MessageReader* aReader) -> IPC::ReadResult<paramType>
{
    auto maybe__actor = IPC::ReadParam<mozilla::ipc::IProtocol*>(aReader);
    if (!maybe__actor) {
        aReader->FatalError("Error deserializing managed PServiceWorkerContainer actor");
        return {};

    }
    auto& actor = *maybe__actor;
    // Sentinel = 'PServiceWorkerContainer'
    if ((!((aReader)->ReadSentinel(1828784447)))) {
        mozilla::ipc::SentinelReadError("Error deserializing managed PServiceWorkerContainer actor");
        return {};
    }

    if (actor && actor->GetProtocolId() != PServiceWorkerContainerMsgStart) {
        aReader->FatalError("Unexpected actor type (expected PServiceWorkerContainer)");

        return {};
    }
    return static_cast<::mozilla::dom::PServiceWorkerContainerChild*>(actor);
}

} // namespace IPC
