Source code

Revision control

Other Tools

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/. */
6
7
#ifndef MOZILLA_LAYERS_IPDLACTOR_H
8
#define MOZILLA_LAYERS_IPDLACTOR_H
9
10
#include "mozilla/ipc/ProtocolUtils.h"
11
#include "mozilla/layers/CompositableForwarder.h"
12
#include "mozilla/Unused.h"
13
#include "gfxPlatform.h"
14
15
namespace mozilla {
16
namespace layers {
17
18
/// A base class to facilitate the deallocation of IPDL actors.
19
///
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 {
24
public:
25
ParentActor() : mDestroyed(false) {}
26
27
~ParentActor() { MOZ_ASSERT(mDestroyed); }
28
29
bool CanSend() const { return !mDestroyed; }
30
31
// Override this rather than ActorDestroy
32
virtual void Destroy() {}
33
34
mozilla::ipc::IPCResult RecvDestroy() final {
35
DestroyIfNeeded();
36
Unused << Protocol::Send__delete__(this);
37
return IPC_OK();
38
}
39
40
typedef ipc::IProtocol::ActorDestroyReason Why;
41
42
void ActorDestroy(Why) override { DestroyIfNeeded(); }
43
44
protected:
45
void DestroyIfNeeded() {
46
if (!mDestroyed) {
47
Destroy();
48
mDestroyed = true;
49
}
50
}
51
52
private:
53
bool mDestroyed;
54
};
55
56
} // namespace layers
57
} // namespace mozilla
58
59
#endif