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


#include "mozilla/dom/PBackgroundLSDatabaseParent.h"
#include "mozilla/ProfilerLabels.h"
#include "mozilla/dom/localstorage/SerializationHelpers.h"

#include "mozilla/dom/PBackgroundLSSnapshotParent.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 {


auto PBackgroundLSDatabaseParent::RecvPBackgroundLSSnapshotConstructor(
        PBackgroundLSSnapshotParent* actor,
        const nsAString& documentURI,
        const nsAString& key,
        const bool& increasePeakUsage,
        const int64_t& minSize,
        LSSnapshotInitInfo* initInfo) -> mozilla::ipc::IPCResult
{
    return IPC_OK();
}

auto PBackgroundLSDatabaseParent::ProcessingError(
        Result aCode,
        const char* aReason) -> void
{
}

auto PBackgroundLSDatabaseParent::ShouldContinueFromReplyTimeout() -> bool
{
    return true;
}

MOZ_IMPLICIT PBackgroundLSDatabaseParent::PBackgroundLSDatabaseParent() :
    mozilla::ipc::IToplevelProtocol("PBackgroundLSDatabaseParent", kProtocolId, mozilla::ipc::ParentSide)
{
    MOZ_COUNT_CTOR(PBackgroundLSDatabaseParent);
}

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

auto PBackgroundLSDatabaseParent::ActorAlloc() -> void
{
    MOZ_RELEASE_ASSERT(XRE_IsParentProcess(), "Invalid process for `PBackgroundLSDatabaseParent'");
    AddRef();
}

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

auto PBackgroundLSDatabaseParent::ManagedPBackgroundLSSnapshotParent(nsTArray<PBackgroundLSSnapshotParent*>& aArr) const -> void
{
    mManagedPBackgroundLSSnapshotParent.ToArray(aArr);
}

auto PBackgroundLSDatabaseParent::ManagedPBackgroundLSSnapshotParent() const -> const ManagedContainer<PBackgroundLSSnapshotParent>&
{
    return mManagedPBackgroundLSSnapshotParent;
}

auto PBackgroundLSDatabaseParent::ManagedProtocolIds() const -> mozilla::Span<mozilla::ipc::ProtocolId const>
{
    static constexpr ::mozilla::ipc::ProtocolId sIds[] = {
        PBackgroundLSSnapshotMsgStart
    };
    return sIds;
}

auto PBackgroundLSDatabaseParent::GetManagedActors(mozilla::ipc::ProtocolId aProtocol) -> UntypedManagedContainer*
{
    switch (aProtocol) {
    case PBackgroundLSSnapshotMsgStart:
        return (&(mManagedPBackgroundLSSnapshotParent));
    default:
        return nullptr;
    }
}

auto PBackgroundLSDatabaseParent::OpenPBackgroundLSSnapshotEndpoint(PBackgroundLSSnapshotParent* aActor) -> ManagedEndpoint<PBackgroundLSSnapshotChild>
{
    if (!aActor) {
        NS_WARNING("Cannot bind null PBackgroundLSSnapshotParent actor");
        return ManagedEndpoint<PBackgroundLSSnapshotChild>();
    }

    if (!aActor->SetManagerAndRegister(this)) {
        NS_WARNING("Failed to bind PBackgroundLSSnapshotParent actor");
        return ManagedEndpoint<PBackgroundLSSnapshotChild>();
    }

    // Mark our actor as awaiting the other side to be bound. This will
    // be cleared when a `MANAGED_ENDPOINT_{DROPPED,BOUND}` message is
    // received.
    aActor->mAwaitingManagedEndpointBind = true;
    return ManagedEndpoint<PBackgroundLSSnapshotChild>(mozilla::ipc::PrivateIPDLInterface(), aActor);
}

auto PBackgroundLSDatabaseParent::BindPBackgroundLSSnapshotEndpoint(
        ManagedEndpoint<PBackgroundLSSnapshotParent> aEndpoint,
        PBackgroundLSSnapshotParent* aActor) -> bool
{
    return aEndpoint.Bind(mozilla::ipc::PrivateIPDLInterface(), aActor, this);
}

auto PBackgroundLSDatabaseParent::SendRequestAllowToClose() -> bool
{
    UniquePtr<IPC::Message> msg__ = PBackgroundLSDatabase::Msg_RequestAllowToClose(MSG_ROUTING_CONTROL);
    IPC::MessageWriter writer__{
            (*(msg__)),
            this};



    if (mozilla::ipc::LoggingEnabledFor("PBackgroundLSDatabase", mozilla::ipc::ParentSide)) {
        mozilla::ipc::LogMessageForProtocol(
            "PBackgroundLSDatabaseParent",
            this->ToplevelProtocol()->OtherPidMaybeInvalid(),
            "Sending ",
            msg__->type(),
            mozilla::ipc::MessageDirection::eSending);
    }
    AUTO_PROFILER_LABEL("PBackgroundLSDatabase::Msg_RequestAllowToClose", OTHER);

    bool sendok__ = ChannelSend(std::move(msg__));
    return sendok__;
}

auto PBackgroundLSDatabaseParent::DeallocManagee(
        mozilla::ipc::ProtocolId aProtocolId,
        IProtocol* aListener) -> void
{
    switch (aProtocolId) {
    case PBackgroundLSSnapshotMsgStart:
        this->DeallocPBackgroundLSSnapshotParent(static_cast<PBackgroundLSSnapshotParent*>(aListener));
        return;
    default:
        FatalError("unreached");
        return;
    }
}

auto PBackgroundLSDatabaseParent::OnMessageReceived(const Message& msg__) -> PBackgroundLSDatabaseParent::Result
{
    IPC::Message::routeid_t route__ = msg__.routing_id();
    if (MSG_ROUTING_CONTROL != route__) {
        IProtocol* routed__ = Lookup(route__);
        if (!routed__ || !routed__->GetLifecycleProxy()) {
            if (mozilla::ipc::LoggingEnabledFor("PBackgroundLSDatabase", mozilla::ipc::ParentSide)) {
                mozilla::ipc::LogMessageForProtocol(
                    "PBackgroundLSDatabaseParent",
                    this->ToplevelProtocol()->OtherPidMaybeInvalid(),
                    "Ignored message for dead actor",
                    (&(msg__))->type(),
                    mozilla::ipc::MessageDirection::eSending);
            }
            return MsgProcessed;

        }

        RefPtr<mozilla::ipc::ActorLifecycleProxy> proxy__ =
            routed__->GetLifecycleProxy();
        return proxy__->Get()->OnMessageReceived(msg__);
    }

    switch (msg__.type()) {
    case PBackgroundLSDatabase::Msg_AllowToClose__ID:
        {
            if (mozilla::ipc::LoggingEnabledFor("PBackgroundLSDatabase", mozilla::ipc::ParentSide)) {
                mozilla::ipc::LogMessageForProtocol(
                    "PBackgroundLSDatabaseParent",
                    this->ToplevelProtocol()->OtherPidMaybeInvalid(),
                    "Received ",
                    (&(msg__))->type(),
                    mozilla::ipc::MessageDirection::eReceiving);
            }
            AUTO_PROFILER_LABEL("PBackgroundLSDatabase::Msg_AllowToClose", OTHER);

            mozilla::ipc::IPCResult __ok = (this)->RecvAllowToClose();
            if ((!(__ok))) {
                mozilla::ipc::ProtocolErrorBreakpoint("Handler returned error code!");
                // Error handled in mozilla::ipc::IPCResult
                return MsgProcessingError;
            }

            return MsgProcessed;
        }
    default:
        return MsgNotKnown;
    case SHMEM_CREATED_MESSAGE_TYPE:
        {
            if (!ShmemCreated(msg__)) {
                return MsgPayloadError;
            }
            return MsgProcessed;
        }
    case SHMEM_DESTROYED_MESSAGE_TYPE:
        {
            if (!ShmemDestroyed(msg__)) {
                return MsgPayloadError;
            }
            return MsgProcessed;
        }
    }
}

auto PBackgroundLSDatabaseParent::OnMessageReceived(
        const Message& msg__,
        UniquePtr<Message>& reply__) -> PBackgroundLSDatabaseParent::Result
{
    IPC::Message::routeid_t route__ = msg__.routing_id();
    if (MSG_ROUTING_CONTROL != route__) {
        IProtocol* routed__ = Lookup(route__);
        if (!routed__ || !routed__->GetLifecycleProxy()) {
            return MsgDropped;

        }

        RefPtr<mozilla::ipc::ActorLifecycleProxy> proxy__ =
            routed__->GetLifecycleProxy();
        return proxy__->Get()->OnMessageReceived(msg__, reply__);
    }

    switch (msg__.type()) {
    case PBackgroundLSDatabase::Msg_PBackgroundLSSnapshotConstructor__ID:
        {
            if (mozilla::ipc::LoggingEnabledFor("PBackgroundLSDatabase", mozilla::ipc::ParentSide)) {
                mozilla::ipc::LogMessageForProtocol(
                    "PBackgroundLSDatabaseParent",
                    this->ToplevelProtocol()->OtherPidMaybeInvalid(),
                    "Received ",
                    (&(msg__))->type(),
                    mozilla::ipc::MessageDirection::eReceiving);
            }
            AUTO_PROFILER_LABEL("PBackgroundLSDatabase::Msg_PBackgroundLSSnapshotConstructor", OTHER);

            IPC::MessageReader reader__{
                    msg__,
                    this};

            auto maybe__actorid__ = IPC::ReadParam<mozilla::ipc::ActorId>((&(reader__)));
            if (!maybe__actorid__) {
                FatalError("Error deserializing 'mozilla::ipc::ActorId'");
                return MsgValueError;

            }
            auto& actorid__ = *maybe__actorid__;
            // Sentinel = 'actorid'
            if ((!(((&(reader__)))->ReadSentinel(193725159)))) {
                mozilla::ipc::SentinelReadError("Error deserializing 'mozilla::ipc::ActorId'");
                return MsgValueError;
            }
            auto maybe__documentURI = IPC::ReadParam<nsString>((&(reader__)));
            if (!maybe__documentURI) {
                FatalError("Error deserializing 'nsString'");
                return MsgValueError;

            }
            auto& documentURI = *maybe__documentURI;
            // Sentinel = 'documentURI'
            if ((!(((&(reader__)))->ReadSentinel(453706832)))) {
                mozilla::ipc::SentinelReadError("Error deserializing 'nsString'");
                return MsgValueError;
            }
            auto maybe__key = IPC::ReadParam<nsString>((&(reader__)));
            if (!maybe__key) {
                FatalError("Error deserializing 'nsString'");
                return MsgValueError;

            }
            auto& key = *maybe__key;
            // Sentinel = 'key'
            if ((!(((&(reader__)))->ReadSentinel(42402122)))) {
                mozilla::ipc::SentinelReadError("Error deserializing 'nsString'");
                return MsgValueError;
            }
            auto maybe__increasePeakUsage = IPC::ReadParam<bool>((&(reader__)));
            if (!maybe__increasePeakUsage) {
                FatalError("Error deserializing 'bool'");
                return MsgValueError;

            }
            auto& increasePeakUsage = *maybe__increasePeakUsage;
            // Sentinel = 'increasePeakUsage'
            if ((!(((&(reader__)))->ReadSentinel(1030686401)))) {
                mozilla::ipc::SentinelReadError("Error deserializing 'bool'");
                return MsgValueError;
            }
            auto maybe__minSize = IPC::ReadParam<int64_t>((&(reader__)));
            if (!maybe__minSize) {
                FatalError("Error deserializing 'int64_t'");
                return MsgValueError;

            }
            auto& minSize = *maybe__minSize;
            // Sentinel = 'minSize'
            if ((!(((&(reader__)))->ReadSentinel(192807648)))) {
                mozilla::ipc::SentinelReadError("Error deserializing 'int64_t'");
                return MsgValueError;
            }
            reader__.EndRead();
            LSSnapshotInitInfo initInfo{};
            PBackgroundLSSnapshotParent* actor = (this)->AllocPBackgroundLSSnapshotParent(documentURI, key, increasePeakUsage, minSize, (&(initInfo)));
            if (!actor) {
                NS_WARNING("Cannot bind null PBackgroundLSSnapshotParent actor");
                return MsgValueError;
            }

            if (!actor->SetManagerAndRegister(this, actorid__)) {
                NS_WARNING("Failed to bind PBackgroundLSSnapshotParent actor");
                return MsgValueError;
            }

            mozilla::ipc::ActorId id__ = MSG_ROUTING_CONTROL;
            mozilla::ipc::IPCResult __ok = (this)->RecvPBackgroundLSSnapshotConstructor(std::move(actor), std::move(documentURI), std::move(key), std::move(increasePeakUsage), std::move(minSize), (&(initInfo)));
            if ((!(__ok))) {
                mozilla::ipc::ProtocolErrorBreakpoint("Handler returned error code!");
                // Error handled in mozilla::ipc::IPCResult
                return MsgProcessingError;
            }
            reply__ = PBackgroundLSDatabase::Reply_PBackgroundLSSnapshotConstructor(id__);
            IPC::MessageWriter writer__{
                    (*(reply__)),
                    this};

            IPC::WriteParam((&(writer__)), initInfo);
            // Sentinel = 'initInfo'
            ((&(writer__)))->WriteSentinel(246743873);
            if (mozilla::ipc::LoggingEnabledFor("PBackgroundLSDatabase", mozilla::ipc::ParentSide)) {
                mozilla::ipc::LogMessageForProtocol(
                    "PBackgroundLSDatabaseParent",
                    this->ToplevelProtocol()->OtherPidMaybeInvalid(),
                    "Sending reply ",
                    reply__->type(),
                    mozilla::ipc::MessageDirection::eSending);
            }

            return MsgProcessed;
        }
    default:
        return MsgNotKnown;
    }
}



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

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

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

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

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

} // namespace IPC
