/src/mozilla-central/gfx/layers/IPDLActor.h
Line | Count | Source (jump to first uncovered line) |
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 | | { |
25 | | public: |
26 | 0 | ParentActor() : mDestroyed(false) {} |
27 | | |
28 | 0 | ~ParentActor() { MOZ_ASSERT(mDestroyed); } |
29 | | |
30 | | bool CanSend() const { return !mDestroyed; } |
31 | | |
32 | | // Override this rather than ActorDestroy |
33 | 0 | virtual void Destroy() {} |
34 | | |
35 | | virtual mozilla::ipc::IPCResult RecvDestroy() override |
36 | 0 | { |
37 | 0 | DestroyIfNeeded(); |
38 | 0 | Unused << Protocol::Send__delete__(this); |
39 | 0 | return IPC_OK(); |
40 | 0 | } |
41 | | |
42 | | typedef ipc::IProtocol::ActorDestroyReason Why; |
43 | | |
44 | 0 | virtual void ActorDestroy(Why) override { |
45 | 0 | DestroyIfNeeded(); |
46 | 0 | } |
47 | | |
48 | | protected: |
49 | 0 | void DestroyIfNeeded() { |
50 | 0 | if (!mDestroyed) { |
51 | 0 | Destroy(); |
52 | 0 | mDestroyed = true; |
53 | 0 | } |
54 | 0 | } |
55 | | |
56 | | private: |
57 | | bool mDestroyed; |
58 | | }; |
59 | | |
60 | | } // namespace |
61 | | } // namespace |
62 | | |
63 | | #endif |