Commit 81492289 authored by Ben Kelly's avatar Ben Kelly
Browse files

Bug 1413606 P2 Add IPC actor structure and boilerplate. r=baku

parent 072e5016
Loading
Loading
Loading
Loading
+76 −0
Original line number Diff line number Diff line
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "ClientHandleChild.h"

#include "ClientHandleOpChild.h"
#include "mozilla/dom/ClientIPCTypes.h"

namespace mozilla {
namespace dom {

using mozilla::ipc::IPCResult;

void
ClientHandleChild::ActorDestroy(ActorDestroyReason aReason)
{
  if (mHandle) {
    mHandle->RevokeActor(this);

    // Revoking the actor link should automatically cause the owner
    // to call RevokeOwner() as well.
    MOZ_DIAGNOSTIC_ASSERT(!mHandle);
  }
}

PClientHandleOpChild*
ClientHandleChild::AllocPClientHandleOpChild(const ClientOpConstructorArgs& aArgs)
{
  MOZ_ASSERT_UNREACHABLE("ClientHandleOpChild must be explicitly constructed.");
  return nullptr;
}

bool
ClientHandleChild::DeallocPClientHandleOpChild(PClientHandleOpChild* aActor)
{
  delete aActor;
  return true;
}

ClientHandleChild::ClientHandleChild()
  : mHandle(nullptr)
  , mTeardownStarted(false)
{
}

void
ClientHandleChild::SetOwner(ClientThing<ClientHandleChild>* aThing)
{
  MOZ_DIAGNOSTIC_ASSERT(!mHandle);
  mHandle = aThing;
  MOZ_DIAGNOSTIC_ASSERT(mHandle);
}

void
ClientHandleChild::RevokeOwner(ClientThing<ClientHandleChild>* aThing)
{
  MOZ_DIAGNOSTIC_ASSERT(mHandle);
  MOZ_DIAGNOSTIC_ASSERT(mHandle == aThing);
  mHandle = nullptr;
}

void
ClientHandleChild::MaybeStartTeardown()
{
  if (mTeardownStarted) {
    return;
  }
  mTeardownStarted = true;
  Unused << SendTeardown();
}

} // namespace dom
} // namespace mozilla
+51 −0
Original line number Diff line number Diff line
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef _mozilla_dom_ClientHandleChild_h
#define _mozilla_dom_ClientHandleChild_h

#include "ClientThing.h"
#include "mozilla/dom/PClientHandleChild.h"

namespace mozilla {
namespace dom {

class ClientHandle;
class ClientInfo;

template <typename ActorType> class ClientThing;

class ClientHandleChild final : public PClientHandleChild
{
  ClientThing<ClientHandleChild>* mHandle;
  bool mTeardownStarted;

  // PClientHandleChild interface
  void
  ActorDestroy(ActorDestroyReason aReason) override;

  PClientHandleOpChild*
  AllocPClientHandleOpChild(const ClientOpConstructorArgs& aArgs) override;

  bool
  DeallocPClientHandleOpChild(PClientHandleOpChild* aActor) override;

public:
  ClientHandleChild();

  void
  SetOwner(ClientThing<ClientHandleChild>* aThing);

  void
  RevokeOwner(ClientThing<ClientHandleChild>* aThing);

  void
  MaybeStartTeardown();
};

} // namespace dom
} // namespace mozilla

#endif // _mozilla_dom_ClientHandleChild_h
+48 −0
Original line number Diff line number Diff line
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "ClientHandleOpChild.h"

namespace mozilla {
namespace dom {

void
ClientHandleOpChild::ActorDestroy(ActorDestroyReason aReason)
{
  if (mPromise) {
    mPromise->Reject(NS_ERROR_ABORT, __func__);
    mPromise = nullptr;
  }
}

IPCResult
ClientHandleOpChild::Recv__delete__(const ClientOpResult& aResult)
{
  if (aResult.type() == ClientOpResult::Tnsresult &&
      NS_FAILED(aResult.get_nsresult())) {
    mPromise->Reject(aResult.get_nsresult(), __func__);
    mPromise = nullptr;
    return IPC_OK();
  }
  mPromise->Resolve(aResult, __func__);
  mPromise = nullptr;
  return IPC_OK();
}

ClientHandleOpChild::ClientHandleOpChild(const ClientOpConstructorArgs& aArgs,
                                         ClientOpPromise::Private* aPromise)
  : mPromise(aPromise)
{
  MOZ_DIAGNOSTIC_ASSERT(mPromise);
}

ClientHandleOpChild::~ClientHandleOpChild()
{
  MOZ_DIAGNOSTIC_ASSERT(!mPromise);
}

} // namespace dom
} // namespace mozilla
+37 −0
Original line number Diff line number Diff line
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef _mozilla_dom_ClientHandleOpChild_h
#define _mozilla_dom_ClientHandleOpChild_h

#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;

  // PClientHandleOpChild interface
  void
  ActorDestroy(ActorDestroyReason aReason) override;

  mozilla::ipc::IPCResult
  Recv__delete__(const ClientOpResult& aResult) override;

public:
  ClientHandleOpChild(const ClientOpConstructorArgs& aArgs,
                      ClientOpPromise::Private* aPromise);

  ~ClientHandleOpChild();
};

} // namespace dom
} // namespace mozilla

#endif // _mozilla_dom_ClientHandleOpChild_h
+23 −0
Original line number Diff line number Diff line
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "ClientHandleOpParent.h"

namespace mozilla {
namespace dom {

void
ClientHandleOpParent::ActorDestroy(ActorDestroyReason aReason)
{
}

void
ClientHandleOpParent::Init(const ClientOpConstructorArgs& aArgs)
{
}

} // namespace dom
} // namespace mozilla
Loading