Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / dom / localstorage / ActorsChild.h
blob679d45605b27c3582297ef56d135eb55b39d9535
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 file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_localstorage_ActorsChild_h
8 #define mozilla_dom_localstorage_ActorsChild_h
10 #include <cstdint>
11 #include "mozilla/RefPtr.h"
12 #include "mozilla/dom/PBackgroundLSDatabaseChild.h"
13 #include "mozilla/dom/PBackgroundLSObserverChild.h"
14 #include "mozilla/dom/PBackgroundLSRequest.h"
15 #include "mozilla/dom/PBackgroundLSRequestChild.h"
16 #include "mozilla/dom/PBackgroundLSSimpleRequest.h"
17 #include "mozilla/dom/PBackgroundLSSimpleRequestChild.h"
18 #include "mozilla/dom/PBackgroundLSSnapshotChild.h"
19 #include "mozilla/ipc/ProtocolUtils.h"
20 #include "nsISupports.h"
21 #include "nsStringFwd.h"
22 #include "nscore.h"
24 namespace mozilla {
26 namespace ipc {
28 class BackgroundChildImpl;
30 } // namespace ipc
32 namespace dom {
34 class LocalStorageManager2;
35 class LSDatabase;
36 class LSObject;
37 class LSObserver;
38 class LSRequestChildCallback;
39 class LSSimpleRequestChildCallback;
40 class LSSnapshot;
42 /**
43 * Minimal glue actor with standard IPC-managed new/delete existence that exists
44 * primarily to track the continued existence of the LSDatabase in the child.
45 * Most of the interesting bits happen via PBackgroundLSSnapshot.
47 * Mutual raw pointers are maintained between LSDatabase and this class that are
48 * cleared at either (expected) when the child starts the deletion process
49 * (SendDeleteMeInternal) or unexpected actor death (ActorDestroy).
51 * See `PBackgroundLSDatabase.ipdl` for more information.
54 * ## Low-Level Lifecycle ##
55 * - Created by LSObject::EnsureDatabase if it had to create a database.
56 * - Deletion begun by LSDatabase's destructor invoking SendDeleteMeInternal
57 * which will result in the parent sending __delete__ which destroys the
58 * actor.
60 class LSDatabaseChild final : public PBackgroundLSDatabaseChild {
61 friend class mozilla::ipc::BackgroundChildImpl;
62 friend class LSDatabase;
63 friend class LSObject;
65 LSDatabase* mDatabase;
67 NS_INLINE_DECL_REFCOUNTING(LSDatabaseChild, override)
69 public:
70 void AssertIsOnOwningThread() const {
71 NS_ASSERT_OWNINGTHREAD(LSDatabaseChild);
74 private:
75 // Only created by LSObject.
76 explicit LSDatabaseChild(LSDatabase* aDatabase);
78 ~LSDatabaseChild();
80 void SendDeleteMeInternal();
82 // IPDL methods are only called by IPDL.
83 void ActorDestroy(ActorDestroyReason aWhy) override;
85 mozilla::ipc::IPCResult RecvRequestAllowToClose() override;
87 PBackgroundLSSnapshotChild* AllocPBackgroundLSSnapshotChild(
88 const nsAString& aDocumentURI, const nsAString& aKey,
89 const bool& aIncreasePeakUsage, const int64_t& aMinSize,
90 LSSnapshotInitInfo* aInitInfo) override;
92 bool DeallocPBackgroundLSSnapshotChild(
93 PBackgroundLSSnapshotChild* aActor) override;
96 /**
97 * Minimal IPC-managed (new/delete) actor that exists to receive and relay
98 * "storage" events from changes to LocalStorage that take place in other
99 * processes as their Snapshots are checkpointed to the canonical Datastore in
100 * the parent process.
102 * See `PBackgroundLSObserver.ipdl` for more info.
104 class LSObserverChild final : public PBackgroundLSObserverChild {
105 friend class mozilla::ipc::BackgroundChildImpl;
106 friend class LSObserver;
107 friend class LSObject;
109 LSObserver* mObserver;
111 NS_DECL_OWNINGTHREAD
113 public:
114 void AssertIsOnOwningThread() const {
115 NS_ASSERT_OWNINGTHREAD(LSObserverChild);
118 private:
119 // Only created by LSObject.
120 explicit LSObserverChild(LSObserver* aObserver);
122 // Only destroyed by mozilla::ipc::BackgroundChildImpl.
123 ~LSObserverChild();
125 void SendDeleteMeInternal();
127 // IPDL methods are only called by IPDL.
128 void ActorDestroy(ActorDestroyReason aWhy) override;
130 mozilla::ipc::IPCResult RecvObserve(const PrincipalInfo& aPrinciplaInfo,
131 const uint32_t& aPrivateBrowsingId,
132 const nsAString& aDocumentURI,
133 const nsAString& aKey,
134 const LSValue& aOldValue,
135 const LSValue& aNewValue) override;
139 * Minimal glue IPC-managed (new/delete) actor that is used by LSObject and its
140 * RequestHelper to perform synchronous requests on top of an asynchronous
141 * protocol.
143 * Takes an `LSReuestChildCallback` to be invoked when a response is received
144 * via __delete__.
146 * See `PBackgroundLSRequest.ipdl`, `LSObject`, and `RequestHelper` for more
147 * info.
149 class LSRequestChild final : public PBackgroundLSRequestChild {
150 friend class LSObject;
151 friend class LocalStorageManager2;
153 RefPtr<LSRequestChildCallback> mCallback;
155 bool mFinishing;
157 NS_DECL_OWNINGTHREAD
159 public:
160 void AssertIsOnOwningThread() const {
161 NS_ASSERT_OWNINGTHREAD(LSReqeustChild);
164 bool Finishing() const;
166 private:
167 // Only created by LSObject.
168 LSRequestChild();
170 // Only destroyed by mozilla::ipc::BackgroundChildImpl.
171 ~LSRequestChild();
173 void SetCallback(LSRequestChildCallback* aCallback);
175 // IPDL methods are only called by IPDL.
176 void ActorDestroy(ActorDestroyReason aWhy) override;
178 mozilla::ipc::IPCResult Recv__delete__(
179 const LSRequestResponse& aResponse) override;
181 mozilla::ipc::IPCResult RecvReady() override;
184 class NS_NO_VTABLE LSRequestChildCallback {
185 public:
186 NS_INLINE_DECL_PURE_VIRTUAL_REFCOUNTING
188 virtual void OnResponse(const LSRequestResponse& aResponse) = 0;
190 protected:
191 virtual ~LSRequestChildCallback() = default;
195 * Minimal glue IPC-managed (new/delete) actor used by `LocalStorageManager2` to
196 * issue asynchronous requests in an asynchronous fashion.
198 * Takes an `LSSimpleRequestChildCallback` to be invoked when a response is
199 * received via __delete__.
201 * See `PBackgroundLSSimpleRequest.ipdl` for more info.
203 class LSSimpleRequestChild final : public PBackgroundLSSimpleRequestChild {
204 friend class LocalStorageManager2;
206 RefPtr<LSSimpleRequestChildCallback> mCallback;
208 NS_DECL_OWNINGTHREAD
210 public:
211 void AssertIsOnOwningThread() const {
212 NS_ASSERT_OWNINGTHREAD(LSSimpleReqeustChild);
215 private:
216 // Only created by LocalStorageManager2.
217 LSSimpleRequestChild();
219 void SetCallback(LSSimpleRequestChildCallback* aCallback);
221 // Only destroyed by mozilla::ipc::BackgroundChildImpl.
222 ~LSSimpleRequestChild();
224 // IPDL methods are only called by IPDL.
225 void ActorDestroy(ActorDestroyReason aWhy) override;
227 mozilla::ipc::IPCResult Recv__delete__(
228 const LSSimpleRequestResponse& aResponse) override;
231 class NS_NO_VTABLE LSSimpleRequestChildCallback {
232 public:
233 NS_INLINE_DECL_PURE_VIRTUAL_REFCOUNTING
235 virtual void OnResponse(const LSSimpleRequestResponse& aResponse) = 0;
237 protected:
238 virtual ~LSSimpleRequestChildCallback() = default;
242 * Minimal IPC-managed (new/delete) actor that lasts as long as its owning
243 * LSSnapshot.
245 * Mutual raw pointers are maintained between LSSnapshot and this class that are
246 * cleared at either (expected) when the child starts the deletion process
247 * (SendDeleteMeInternal) or unexpected actor death (ActorDestroy).
249 * See `PBackgroundLSSnapshot.ipdl` and `LSSnapshot` for more info.
251 class LSSnapshotChild final : public PBackgroundLSSnapshotChild {
252 friend class LSDatabase;
253 friend class LSSnapshot;
255 LSSnapshot* mSnapshot;
257 NS_DECL_OWNINGTHREAD
259 public:
260 void AssertIsOnOwningThread() const {
261 NS_ASSERT_OWNINGTHREAD(LSSnapshotChild);
264 private:
265 // Only created by LSDatabase.
266 explicit LSSnapshotChild(LSSnapshot* aSnapshot);
268 // Only destroyed by LSDatabaseChild.
269 ~LSSnapshotChild();
271 void SendDeleteMeInternal();
273 // IPDL methods are only called by IPDL.
274 void ActorDestroy(ActorDestroyReason aWhy) override;
276 mozilla::ipc::IPCResult RecvMarkDirty() override;
279 } // namespace dom
280 } // namespace mozilla
282 #endif // mozilla_dom_localstorage_ActorsChild_h