1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef MOZILLA_LAYERS_IPDLACTOR_H
8 #define MOZILLA_LAYERS_IPDLACTOR_H
10 #include "mozilla/ipc/ProtocolUtils.h"
11 #include "mozilla/layers/CompositableForwarder.h"
12 #include "mozilla/Unused.h"
13 #include "gfxPlatform.h"
18 /// A base class to facilitate the deallocation of IPDL actors.
20 /// Implements the parent side of the simple deallocation handshake.
21 /// Override the Destroy method rather than the ActorDestroy method.
22 template <typename Protocol
>
23 class ParentActor
: public Protocol
{
25 ParentActor() : mDestroyed(false) {}
27 ~ParentActor() { MOZ_ASSERT(mDestroyed
); }
29 bool CanSend() const { return !mDestroyed
; }
31 // Override this rather than ActorDestroy
32 virtual void Destroy() {}
34 mozilla::ipc::IPCResult
RecvDestroy() final
{
36 Unused
<< Protocol::Send__delete__(this);
40 typedef ipc::IProtocol::ActorDestroyReason Why
;
42 void ActorDestroy(Why
) override
{ DestroyIfNeeded(); }
45 void DestroyIfNeeded() {
57 } // namespace mozilla