/src/mozilla-central/dom/clients/manager/ClientThing.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 | | #ifndef _mozilla_dom_ClientThing_h |
7 | | #define _mozilla_dom_ClientThing_h |
8 | | |
9 | | #include "nsTArray.h" |
10 | | |
11 | | namespace mozilla { |
12 | | namespace dom { |
13 | | |
14 | | // Base class representing various Client "things" such as ClientHandle, |
15 | | // ClientSource, and ClientManager. Currently it provides a common set |
16 | | // of code for handling activation and shutdown of IPC actors. |
17 | | template <typename ActorType> |
18 | | class ClientThing |
19 | | { |
20 | | #ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED |
21 | | static const uint32_t kMagic1 = 0xC9FE2C9C; |
22 | | static const uint32_t kMagic2 = 0x832072D4; |
23 | | #endif |
24 | | |
25 | | ActorType* mActor; |
26 | | #ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED |
27 | | uint32_t mMagic1; |
28 | | uint32_t mMagic2; |
29 | | #endif |
30 | | bool mShutdown; |
31 | | |
32 | | protected: |
33 | | ClientThing() |
34 | | : mActor(nullptr) |
35 | | #ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED |
36 | | , mMagic1(kMagic1) |
37 | | , mMagic2(kMagic2) |
38 | | #endif |
39 | | , mShutdown(false) |
40 | 0 | { |
41 | 0 | } Unexecuted instantiation: mozilla::dom::ClientThing<mozilla::dom::ClientHandleChild>::ClientThing() Unexecuted instantiation: mozilla::dom::ClientThing<mozilla::dom::ClientManagerChild>::ClientThing() Unexecuted instantiation: mozilla::dom::ClientThing<mozilla::dom::ClientSourceChild>::ClientThing() |
42 | | |
43 | | ~ClientThing() |
44 | 0 | { |
45 | 0 | AssertIsValid(); |
46 | 0 | ShutdownThing(); |
47 | 0 | #ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED |
48 | 0 | mMagic1 = 0; |
49 | 0 | mMagic2 = 0; |
50 | 0 | #endif |
51 | 0 | } Unexecuted instantiation: mozilla::dom::ClientThing<mozilla::dom::ClientHandleChild>::~ClientThing() Unexecuted instantiation: mozilla::dom::ClientThing<mozilla::dom::ClientManagerChild>::~ClientThing() Unexecuted instantiation: mozilla::dom::ClientThing<mozilla::dom::ClientSourceChild>::~ClientThing() |
52 | | |
53 | | void |
54 | | AssertIsValid() const |
55 | 0 | { |
56 | 0 | MOZ_DIAGNOSTIC_ASSERT(mMagic1 == kMagic1); |
57 | 0 | MOZ_DIAGNOSTIC_ASSERT(mMagic2 == kMagic2); |
58 | 0 | } Unexecuted instantiation: mozilla::dom::ClientThing<mozilla::dom::ClientHandleChild>::AssertIsValid() const Unexecuted instantiation: mozilla::dom::ClientThing<mozilla::dom::ClientManagerChild>::AssertIsValid() const Unexecuted instantiation: mozilla::dom::ClientThing<mozilla::dom::ClientSourceChild>::AssertIsValid() const |
59 | | |
60 | | // Return the current actor. |
61 | | ActorType* |
62 | | GetActor() const |
63 | 0 | { |
64 | 0 | AssertIsValid(); |
65 | 0 | return mActor; |
66 | 0 | } Unexecuted instantiation: mozilla::dom::ClientThing<mozilla::dom::ClientHandleChild>::GetActor() const Unexecuted instantiation: mozilla::dom::ClientThing<mozilla::dom::ClientManagerChild>::GetActor() const Unexecuted instantiation: mozilla::dom::ClientThing<mozilla::dom::ClientSourceChild>::GetActor() const |
67 | | |
68 | | // Returns true if ShutdownThing() has been called. |
69 | | bool |
70 | | IsShutdown() const |
71 | 0 | { |
72 | 0 | AssertIsValid(); |
73 | 0 | return mShutdown; |
74 | 0 | } Unexecuted instantiation: mozilla::dom::ClientThing<mozilla::dom::ClientHandleChild>::IsShutdown() const Unexecuted instantiation: mozilla::dom::ClientThing<mozilla::dom::ClientManagerChild>::IsShutdown() const Unexecuted instantiation: mozilla::dom::ClientThing<mozilla::dom::ClientSourceChild>::IsShutdown() const |
75 | | |
76 | | // Conditionally execute the given callable based on the current state. |
77 | | template<typename Callable> |
78 | | void |
79 | | MaybeExecute(const Callable& aSuccess, |
80 | 0 | const std::function<void()>& aFailure = []{}) Unexecuted instantiation: Unified_cpp_dom_clients_manager1.cpp:void mozilla::dom::ClientThing<mozilla::dom::ClientSourceChild>::MaybeExecute<mozilla::dom::ClientSource::ExecutionReady(mozilla::dom::ClientSourceExecutionReadyArgs const&)::$_2>(mozilla::dom::ClientSource::ExecutionReady(mozilla::dom::ClientSourceExecutionReadyArgs const&)::$_2 const&, std::__1::function<void ()> const&)::{default arg#1}::{lambda()#1}::operator()() const Unexecuted instantiation: Unified_cpp_dom_clients_manager1.cpp:void mozilla::dom::ClientThing<mozilla::dom::ClientSourceChild>::MaybeExecute<mozilla::dom::ClientSource::Freeze()::$_3>(mozilla::dom::ClientSource::Freeze()::$_3 const&, std::__1::function<void ()> const&)::{default arg#1}::{lambda()#1}::operator()() const Unexecuted instantiation: Unified_cpp_dom_clients_manager1.cpp:void mozilla::dom::ClientThing<mozilla::dom::ClientSourceChild>::MaybeExecute<mozilla::dom::ClientSource::Thaw()::$_4>(mozilla::dom::ClientSource::Thaw()::$_4 const&, std::__1::function<void ()> const&)::{default arg#1}::{lambda()#1}::operator()() const Unexecuted instantiation: Unified_cpp_dom_clients_manager1.cpp:void mozilla::dom::ClientThing<mozilla::dom::ClientSourceChild>::MaybeExecute<mozilla::dom::ClientSource::InheritController(mozilla::dom::ServiceWorkerDescriptor const&)::$_5>(mozilla::dom::ClientSource::InheritController(mozilla::dom::ServiceWorkerDescriptor const&)::$_5 const&, std::__1::function<void ()> const&)::{default arg#1}::{lambda()#1}::operator()() const Unexecuted instantiation: Unified_cpp_dom_clients_manager1.cpp:void mozilla::dom::ClientThing<mozilla::dom::ClientSourceChild>::MaybeExecute<mozilla::dom::ClientSource::NoteDOMContentLoaded()::$_6>(mozilla::dom::ClientSource::NoteDOMContentLoaded()::$_6 const&, std::__1::function<void ()> const&)::{default arg#1}::{lambda()#1}::operator()() const |
81 | 0 | { |
82 | 0 | AssertIsValid(); |
83 | 0 | if (mShutdown) { |
84 | 0 | aFailure(); |
85 | 0 | return; |
86 | 0 | } |
87 | 0 | MOZ_DIAGNOSTIC_ASSERT(mActor); |
88 | 0 | aSuccess(mActor); |
89 | 0 | } Unexecuted instantiation: Unified_cpp_dom_clients_manager0.cpp:void mozilla::dom::ClientThing<mozilla::dom::ClientHandleChild>::MaybeExecute<mozilla::dom::ClientHandle::StartOp(mozilla::dom::ClientOpConstructorArgs const&, std::__1::function<void (mozilla::dom::ClientOpResult const&)> const&&, std::__1::function<void (mozilla::dom::ClientOpResult const&)> const&&)::$_0>(mozilla::dom::ClientHandle::StartOp(mozilla::dom::ClientOpConstructorArgs const&, std::__1::function<void (mozilla::dom::ClientOpResult const&)> const&&, std::__1::function<void (mozilla::dom::ClientOpResult const&)> const&&)::$_0 const&, std::__1::function<void ()> const&) Unexecuted instantiation: Unified_cpp_dom_clients_manager0.cpp:void mozilla::dom::ClientThing<mozilla::dom::ClientManagerChild>::MaybeExecute<mozilla::dom::ClientManager::StartOp(mozilla::dom::ClientOpConstructorArgs const&, nsISerialEventTarget*)::$_10>(mozilla::dom::ClientManager::StartOp(mozilla::dom::ClientOpConstructorArgs const&, nsISerialEventTarget*)::$_10 const&, std::__1::function<void ()> const&) Unexecuted instantiation: Unified_cpp_dom_clients_manager1.cpp:void mozilla::dom::ClientThing<mozilla::dom::ClientSourceChild>::MaybeExecute<mozilla::dom::ClientSource::ExecutionReady(mozilla::dom::ClientSourceExecutionReadyArgs const&)::$_2>(mozilla::dom::ClientSource::ExecutionReady(mozilla::dom::ClientSourceExecutionReadyArgs const&)::$_2 const&, std::__1::function<void ()> const&) Unexecuted instantiation: Unified_cpp_dom_clients_manager1.cpp:void mozilla::dom::ClientThing<mozilla::dom::ClientSourceChild>::MaybeExecute<mozilla::dom::ClientSource::Freeze()::$_3>(mozilla::dom::ClientSource::Freeze()::$_3 const&, std::__1::function<void ()> const&) Unexecuted instantiation: Unified_cpp_dom_clients_manager1.cpp:void mozilla::dom::ClientThing<mozilla::dom::ClientSourceChild>::MaybeExecute<mozilla::dom::ClientSource::Thaw()::$_4>(mozilla::dom::ClientSource::Thaw()::$_4 const&, std::__1::function<void ()> const&) Unexecuted instantiation: Unified_cpp_dom_clients_manager1.cpp:void mozilla::dom::ClientThing<mozilla::dom::ClientSourceChild>::MaybeExecute<mozilla::dom::ClientSource::InheritController(mozilla::dom::ServiceWorkerDescriptor const&)::$_5>(mozilla::dom::ClientSource::InheritController(mozilla::dom::ServiceWorkerDescriptor const&)::$_5 const&, std::__1::function<void ()> const&) Unexecuted instantiation: Unified_cpp_dom_clients_manager1.cpp:void mozilla::dom::ClientThing<mozilla::dom::ClientSourceChild>::MaybeExecute<mozilla::dom::ClientSource::NoteDOMContentLoaded()::$_6>(mozilla::dom::ClientSource::NoteDOMContentLoaded()::$_6 const&, std::__1::function<void ()> const&) |
90 | | |
91 | | // Attach activate the thing by attaching its underlying IPC actor. This |
92 | | // will make the thing register as the actor's owner as well. The actor |
93 | | // must call RevokeActor() to clear this weak back reference before its |
94 | | // destroyed. |
95 | | void |
96 | | ActivateThing(ActorType* aActor) |
97 | 0 | { |
98 | 0 | AssertIsValid(); |
99 | 0 | MOZ_DIAGNOSTIC_ASSERT(aActor); |
100 | 0 | MOZ_DIAGNOSTIC_ASSERT(!mActor); |
101 | 0 | MOZ_DIAGNOSTIC_ASSERT(!mShutdown); |
102 | 0 | mActor = aActor; |
103 | 0 | mActor->SetOwner(this); |
104 | 0 | } Unexecuted instantiation: mozilla::dom::ClientThing<mozilla::dom::ClientHandleChild>::ActivateThing(mozilla::dom::ClientHandleChild*) Unexecuted instantiation: mozilla::dom::ClientThing<mozilla::dom::ClientManagerChild>::ActivateThing(mozilla::dom::ClientManagerChild*) Unexecuted instantiation: mozilla::dom::ClientThing<mozilla::dom::ClientSourceChild>::ActivateThing(mozilla::dom::ClientSourceChild*) |
105 | | |
106 | | // Start destroying the underlying actor and disconnect the thing. |
107 | | void |
108 | | ShutdownThing() |
109 | 0 | { |
110 | 0 | AssertIsValid(); |
111 | 0 | if (mShutdown) { |
112 | 0 | return; |
113 | 0 | } |
114 | 0 | mShutdown = true; |
115 | 0 |
|
116 | 0 | // If we are shutdown before the actor, then clear the weak references |
117 | 0 | // between the actor and the thing. |
118 | 0 | if (mActor) { |
119 | 0 | mActor->RevokeOwner(this); |
120 | 0 | mActor->MaybeStartTeardown(); |
121 | 0 | mActor = nullptr; |
122 | 0 | } |
123 | 0 |
|
124 | 0 | OnShutdownThing(); |
125 | 0 | } Unexecuted instantiation: mozilla::dom::ClientThing<mozilla::dom::ClientHandleChild>::ShutdownThing() Unexecuted instantiation: mozilla::dom::ClientThing<mozilla::dom::ClientManagerChild>::ShutdownThing() Unexecuted instantiation: mozilla::dom::ClientThing<mozilla::dom::ClientSourceChild>::ShutdownThing() |
126 | | |
127 | | // Allow extending classes to take action when shutdown. |
128 | | virtual void |
129 | | OnShutdownThing() |
130 | 0 | { |
131 | 0 | // by default do nothing |
132 | 0 | } Unexecuted instantiation: mozilla::dom::ClientThing<mozilla::dom::ClientHandleChild>::OnShutdownThing() Unexecuted instantiation: mozilla::dom::ClientThing<mozilla::dom::ClientManagerChild>::OnShutdownThing() Unexecuted instantiation: mozilla::dom::ClientThing<mozilla::dom::ClientSourceChild>::OnShutdownThing() |
133 | | |
134 | | public: |
135 | | // Clear the weak references between the thing and its IPC actor. |
136 | | void |
137 | | RevokeActor(ActorType* aActor) |
138 | 0 | { |
139 | 0 | AssertIsValid(); |
140 | 0 | MOZ_DIAGNOSTIC_ASSERT(mActor); |
141 | 0 | MOZ_DIAGNOSTIC_ASSERT(mActor == aActor); |
142 | 0 | mActor->RevokeOwner(this); |
143 | 0 | mActor = nullptr; |
144 | 0 |
|
145 | 0 | // Also consider the ClientThing shutdown. We simply set the flag |
146 | 0 | // instead of calling ShutdownThing() to avoid calling MaybeStartTeardown() |
147 | 0 | // on the destroyed actor. |
148 | 0 | mShutdown = true; |
149 | 0 |
|
150 | 0 | OnShutdownThing(); |
151 | 0 | } Unexecuted instantiation: mozilla::dom::ClientThing<mozilla::dom::ClientHandleChild>::RevokeActor(mozilla::dom::ClientHandleChild*) Unexecuted instantiation: mozilla::dom::ClientThing<mozilla::dom::ClientManagerChild>::RevokeActor(mozilla::dom::ClientManagerChild*) Unexecuted instantiation: mozilla::dom::ClientThing<mozilla::dom::ClientSourceChild>::RevokeActor(mozilla::dom::ClientSourceChild*) |
152 | | }; |
153 | | |
154 | | } // namespace dom |
155 | | } // namespace mozilla |
156 | | |
157 | | #endif // _mozilla_dom_ClientThing_h |