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


#include "mozilla/dom/indexedDB/PBackgroundIDBTransactionParent.h"
#include "mozilla/ProfilerLabels.h"
#include "mozilla/dom/indexedDB/ActorsChild.h"
#include "mozilla/dom/indexedDB/Key.h"
#include "mozilla/dom/indexedDB/KeyPath.h"
#include "mozilla/dom/indexedDB/SerializationHelpers.h"
#include "mozilla/dom/quota/SerializationHelpers.h"
#include "mozilla/ipc/IPCCore.h"

#include "mozilla/dom/indexedDB/PBackgroundIDBCursorParent.h"
#include "mozilla/dom/indexedDB/PBackgroundIDBDatabaseParent.h"
#include "mozilla/dom/indexedDB/PBackgroundIDBDatabaseFileParent.h"
#include "mozilla/dom/indexedDB/PBackgroundIDBRequestParent.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 {
namespace indexedDB {


auto PBackgroundIDBTransactionParent::RecvPBackgroundIDBCursorConstructor(
        PBackgroundIDBCursorParent* actor,
        const int64_t& requestId,
        const OpenCursorParams& params) -> mozilla::ipc::IPCResult
{
    return IPC_OK();
}

auto PBackgroundIDBTransactionParent::RecvPBackgroundIDBRequestConstructor(
        PBackgroundIDBRequestParent* actor,
        const int64_t& requestId,
        const RequestParams& params) -> mozilla::ipc::IPCResult
{
    return IPC_OK();
}

MOZ_IMPLICIT PBackgroundIDBTransactionParent::PBackgroundIDBTransactionParent() :
    mozilla::ipc::IRefCountedProtocol(kProtocolId, mozilla::ipc::ParentSide)
{
    MOZ_COUNT_CTOR(PBackgroundIDBTransactionParent);
}

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

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

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

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

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

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

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

auto PBackgroundIDBTransactionParent::ManagedPBackgroundIDBCursorParent(nsTArray<PBackgroundIDBCursorParent*>& aArr) const -> void
{
    mManagedPBackgroundIDBCursorParent.ToArray(aArr);
}

auto PBackgroundIDBTransactionParent::ManagedPBackgroundIDBCursorParent() const -> const ManagedContainer<PBackgroundIDBCursorParent>&
{
    return mManagedPBackgroundIDBCursorParent;
}

auto PBackgroundIDBTransactionParent::ManagedPBackgroundIDBRequestParent(nsTArray<PBackgroundIDBRequestParent*>& aArr) const -> void
{
    mManagedPBackgroundIDBRequestParent.ToArray(aArr);
}

auto PBackgroundIDBTransactionParent::ManagedPBackgroundIDBRequestParent() const -> const ManagedContainer<PBackgroundIDBRequestParent>&
{
    return mManagedPBackgroundIDBRequestParent;
}

auto PBackgroundIDBTransactionParent::ManagedProtocolIds() const -> mozilla::Span<mozilla::ipc::ProtocolId const>
{
    static constexpr ::mozilla::ipc::ProtocolId sIds[] = {
        PBackgroundIDBCursorMsgStart,
        PBackgroundIDBRequestMsgStart
    };
    return sIds;
}

auto PBackgroundIDBTransactionParent::GetManagedActors(mozilla::ipc::ProtocolId aProtocol) -> UntypedManagedContainer*
{
    switch (aProtocol) {
    case PBackgroundIDBCursorMsgStart:
        return (&(mManagedPBackgroundIDBCursorParent));
    case PBackgroundIDBRequestMsgStart:
        return (&(mManagedPBackgroundIDBRequestParent));
    default:
        return nullptr;
    }
}

auto PBackgroundIDBTransactionParent::OpenPBackgroundIDBCursorEndpoint(PBackgroundIDBCursorParent* aActor) -> ManagedEndpoint<PBackgroundIDBCursorChild>
{
    if (!aActor) {
        NS_WARNING("Cannot bind null PBackgroundIDBCursorParent actor");
        return ManagedEndpoint<PBackgroundIDBCursorChild>();
    }

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

    // 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<PBackgroundIDBCursorChild>(mozilla::ipc::PrivateIPDLInterface(), aActor);
}

auto PBackgroundIDBTransactionParent::BindPBackgroundIDBCursorEndpoint(
        ManagedEndpoint<PBackgroundIDBCursorParent> aEndpoint,
        PBackgroundIDBCursorParent* aActor) -> bool
{
    return aEndpoint.Bind(mozilla::ipc::PrivateIPDLInterface(), aActor, this);
}

auto PBackgroundIDBTransactionParent::OpenPBackgroundIDBRequestEndpoint(PBackgroundIDBRequestParent* aActor) -> ManagedEndpoint<PBackgroundIDBRequestChild>
{
    if (!aActor) {
        NS_WARNING("Cannot bind null PBackgroundIDBRequestParent actor");
        return ManagedEndpoint<PBackgroundIDBRequestChild>();
    }

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

    // 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<PBackgroundIDBRequestChild>(mozilla::ipc::PrivateIPDLInterface(), aActor);
}

auto PBackgroundIDBTransactionParent::BindPBackgroundIDBRequestEndpoint(
        ManagedEndpoint<PBackgroundIDBRequestParent> aEndpoint,
        PBackgroundIDBRequestParent* aActor) -> bool
{
    return aEndpoint.Bind(mozilla::ipc::PrivateIPDLInterface(), aActor, this);
}

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


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

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

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

auto PBackgroundIDBTransactionParent::SendComplete(const nsresult& result) -> bool
{
    UniquePtr<IPC::Message> msg__ = PBackgroundIDBTransaction::Msg_Complete(Id());
    IPC::MessageWriter writer__{
            (*(msg__)),
            this};

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


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

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

auto PBackgroundIDBTransactionParent::DeallocManagee(
        mozilla::ipc::ProtocolId aProtocolId,
        IProtocol* aListener) -> void
{
    switch (aProtocolId) {
    case PBackgroundIDBRequestMsgStart:
        this->DeallocPBackgroundIDBRequestParent(static_cast<PBackgroundIDBRequestParent*>(aListener));
        return;
    default:
        FatalError("unreached");
        return;
    }
}

auto PBackgroundIDBTransactionParent::OnMessageReceived(const Message& msg__) -> PBackgroundIDBTransactionParent::Result
{
    if (!CanSend()) {
        if (mozilla::ipc::LoggingEnabledFor("PBackgroundIDBTransaction", mozilla::ipc::ParentSide)) {
            mozilla::ipc::LogMessageForProtocol(
                "PBackgroundIDBTransactionParent",
                this->ToplevelProtocol()->OtherPidMaybeInvalid(),
                "Ignored message for dead actor",
                (&(msg__))->type(),
                mozilla::ipc::MessageDirection::eSending);
        }
        return MsgProcessed;

    }
    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 PBackgroundIDBTransaction::Msg_DeleteMe__ID:
        {
            if (mozilla::ipc::LoggingEnabledFor("PBackgroundIDBTransaction", mozilla::ipc::ParentSide)) {
                mozilla::ipc::LogMessageForProtocol(
                    "PBackgroundIDBTransactionParent",
                    this->ToplevelProtocol()->OtherPidMaybeInvalid(),
                    "Received ",
                    (&(msg__))->type(),
                    mozilla::ipc::MessageDirection::eReceiving);
            }
            AUTO_PROFILER_LABEL("PBackgroundIDBTransaction::Msg_DeleteMe", OTHER);

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

            return MsgProcessed;
        }
    case PBackgroundIDBTransaction::Msg_Commit__ID:
        {
            if (mozilla::ipc::LoggingEnabledFor("PBackgroundIDBTransaction", mozilla::ipc::ParentSide)) {
                mozilla::ipc::LogMessageForProtocol(
                    "PBackgroundIDBTransactionParent",
                    this->ToplevelProtocol()->OtherPidMaybeInvalid(),
                    "Received ",
                    (&(msg__))->type(),
                    mozilla::ipc::MessageDirection::eReceiving);
            }
            AUTO_PROFILER_LABEL("PBackgroundIDBTransaction::Msg_Commit", OTHER);

            IPC::MessageReader reader__{
                    msg__,
                    this};

            auto maybe__lastRequest = IPC::ReadParam<mozilla::Maybe<int64_t>>((&(reader__)));
            if (!maybe__lastRequest) {
                FatalError("Error deserializing 'int64_t?'");
                return MsgValueError;

            }
            auto& lastRequest = *maybe__lastRequest;
            // Sentinel = 'lastRequest'
            if ((!(((&(reader__)))->ReadSentinel(458359966)))) {
                mozilla::ipc::SentinelReadError("Error deserializing 'int64_t?'");
                return MsgValueError;
            }
            reader__.EndRead();
            mozilla::ipc::IPCResult __ok = (this)->RecvCommit(std::move(lastRequest));
            if ((!(__ok))) {
                mozilla::ipc::ProtocolErrorBreakpoint("Handler returned error code!");
                // Error handled in mozilla::ipc::IPCResult
                return MsgProcessingError;
            }

            return MsgProcessed;
        }
    case PBackgroundIDBTransaction::Msg_Abort__ID:
        {
            if (mozilla::ipc::LoggingEnabledFor("PBackgroundIDBTransaction", mozilla::ipc::ParentSide)) {
                mozilla::ipc::LogMessageForProtocol(
                    "PBackgroundIDBTransactionParent",
                    this->ToplevelProtocol()->OtherPidMaybeInvalid(),
                    "Received ",
                    (&(msg__))->type(),
                    mozilla::ipc::MessageDirection::eReceiving);
            }
            AUTO_PROFILER_LABEL("PBackgroundIDBTransaction::Msg_Abort", OTHER);

            IPC::MessageReader reader__{
                    msg__,
                    this};

            auto maybe__resultCode = IPC::ReadParam<nsresult>((&(reader__)));
            if (!maybe__resultCode) {
                FatalError("Error deserializing 'nsresult'");
                return MsgValueError;

            }
            auto& resultCode = *maybe__resultCode;
            // Sentinel = 'resultCode'
            if ((!(((&(reader__)))->ReadSentinel(388498459)))) {
                mozilla::ipc::SentinelReadError("Error deserializing 'nsresult'");
                return MsgValueError;
            }
            reader__.EndRead();
            mozilla::ipc::IPCResult __ok = (this)->RecvAbort(std::move(resultCode));
            if ((!(__ok))) {
                mozilla::ipc::ProtocolErrorBreakpoint("Handler returned error code!");
                // Error handled in mozilla::ipc::IPCResult
                return MsgProcessingError;
            }

            return MsgProcessed;
        }
    case PBackgroundIDBTransaction::Msg_PBackgroundIDBCursorConstructor__ID:
        {
            if (mozilla::ipc::LoggingEnabledFor("PBackgroundIDBTransaction", mozilla::ipc::ParentSide)) {
                mozilla::ipc::LogMessageForProtocol(
                    "PBackgroundIDBTransactionParent",
                    this->ToplevelProtocol()->OtherPidMaybeInvalid(),
                    "Received ",
                    (&(msg__))->type(),
                    mozilla::ipc::MessageDirection::eReceiving);
            }
            AUTO_PROFILER_LABEL("PBackgroundIDBTransaction::Msg_PBackgroundIDBCursorConstructor", 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__requestId = IPC::ReadParam<int64_t>((&(reader__)));
            if (!maybe__requestId) {
                FatalError("Error deserializing 'int64_t'");
                return MsgValueError;

            }
            auto& requestId = *maybe__requestId;
            // Sentinel = 'requestId'
            if ((!(((&(reader__)))->ReadSentinel(320799671)))) {
                mozilla::ipc::SentinelReadError("Error deserializing 'int64_t'");
                return MsgValueError;
            }
            auto maybe__params = IPC::ReadParam<OpenCursorParams>((&(reader__)));
            if (!maybe__params) {
                FatalError("Error deserializing 'OpenCursorParams'");
                return MsgValueError;

            }
            auto& params = *maybe__params;
            // Sentinel = 'params'
            if ((!(((&(reader__)))->ReadSentinel(146997893)))) {
                mozilla::ipc::SentinelReadError("Error deserializing 'OpenCursorParams'");
                return MsgValueError;
            }
            reader__.EndRead();
            // Ensure the ID which was sent to us is valid, and reserve a spot
            // in the table for the new actor before we bother to alloc it.
            if (!ToplevelProtocol()->TryReserve(actorid__)) {
                NS_WARNING("Failed to reserve ActorId for constructor");
                return MsgValueError;
            }

            RefPtr<PBackgroundIDBCursorParent> actor = (this)->AllocPBackgroundIDBCursorParent(requestId, params);

            if (!actor) {
                NS_WARNING("Alloc function returned null");
                // Clean up the reservation taken above if this fails, to avoid
                // leaving zombie entries in the map.
                ToplevelProtocol()->ClearReservation(actorid__);
                return MsgValueError;
            }

            // NOTE: SetManagerAndRegister unconditionally consumes the
            // reservation taken by TryReserve, so we don't need to clear it on
            // failure.
            if (!actor->SetManagerAndRegister(this, actorid__)) {
                NS_WARNING("Failed to set manager for constructor");
                return MsgValueError;
            }
            mozilla::ipc::IPCResult __ok = (this)->RecvPBackgroundIDBCursorConstructor(actor, std::move(requestId), std::move(params));
            if ((!(__ok))) {
                mozilla::ipc::ProtocolErrorBreakpoint("Handler returned error code!");
                // Error handled in mozilla::ipc::IPCResult
                return MsgProcessingError;
            }

            return MsgProcessed;
        }
    case PBackgroundIDBTransaction::Msg_PBackgroundIDBRequestConstructor__ID:
        {
            if (mozilla::ipc::LoggingEnabledFor("PBackgroundIDBTransaction", mozilla::ipc::ParentSide)) {
                mozilla::ipc::LogMessageForProtocol(
                    "PBackgroundIDBTransactionParent",
                    this->ToplevelProtocol()->OtherPidMaybeInvalid(),
                    "Received ",
                    (&(msg__))->type(),
                    mozilla::ipc::MessageDirection::eReceiving);
            }
            AUTO_PROFILER_LABEL("PBackgroundIDBTransaction::Msg_PBackgroundIDBRequestConstructor", 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__requestId = IPC::ReadParam<int64_t>((&(reader__)));
            if (!maybe__requestId) {
                FatalError("Error deserializing 'int64_t'");
                return MsgValueError;

            }
            auto& requestId = *maybe__requestId;
            // Sentinel = 'requestId'
            if ((!(((&(reader__)))->ReadSentinel(320799671)))) {
                mozilla::ipc::SentinelReadError("Error deserializing 'int64_t'");
                return MsgValueError;
            }
            auto maybe__params = IPC::ReadParam<RequestParams>((&(reader__)));
            if (!maybe__params) {
                FatalError("Error deserializing 'RequestParams'");
                return MsgValueError;

            }
            auto& params = *maybe__params;
            // Sentinel = 'params'
            if ((!(((&(reader__)))->ReadSentinel(146997893)))) {
                mozilla::ipc::SentinelReadError("Error deserializing 'RequestParams'");
                return MsgValueError;
            }
            reader__.EndRead();
            // Ensure the ID which was sent to us is valid, and reserve a spot
            // in the table for the new actor before we bother to alloc it.
            if (!ToplevelProtocol()->TryReserve(actorid__)) {
                NS_WARNING("Failed to reserve ActorId for constructor");
                return MsgValueError;
            }

            PBackgroundIDBRequestParent* actor = (this)->AllocPBackgroundIDBRequestParent(requestId, params);

            if (!actor) {
                NS_WARNING("Alloc function returned null");
                // Clean up the reservation taken above if this fails, to avoid
                // leaving zombie entries in the map.
                ToplevelProtocol()->ClearReservation(actorid__);
                return MsgValueError;
            }

            // NOTE: SetManagerAndRegister unconditionally consumes the
            // reservation taken by TryReserve, so we don't need to clear it on
            // failure.
            if (!actor->SetManagerAndRegister(this, actorid__)) {
                NS_WARNING("Failed to set manager for constructor");
                return MsgValueError;
            }
            mozilla::ipc::IPCResult __ok = (this)->RecvPBackgroundIDBRequestConstructor(std::move(actor), std::move(requestId), std::move(params));
            if ((!(__ok))) {
                mozilla::ipc::ProtocolErrorBreakpoint("Handler returned error code!");
                // Error handled in mozilla::ipc::IPCResult
                return MsgProcessingError;
            }

            return MsgProcessed;
        }
    case PBackgroundIDBTransaction::Reply___delete____ID:
        {
            return MsgProcessed;
        }
    default:
        return MsgNotKnown;
    }
}

auto PBackgroundIDBTransactionParent::OnMessageReceived(
        const Message& msg__,
        UniquePtr<Message>& reply__) -> PBackgroundIDBTransactionParent::Result
{
    if (!CanSend()) {
        return MsgDropped;

    }
    return MsgNotKnown;
}



} // namespace indexedDB
} // namespace dom
} // namespace mozilla
