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
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"
28 class BackgroundChildImpl
;
34 class LocalStorageManager2
;
38 class LSRequestChildCallback
;
39 class LSSimpleRequestChildCallback
;
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
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
)
70 void AssertIsOnOwningThread() const {
71 NS_ASSERT_OWNINGTHREAD(LSDatabaseChild
);
75 // Only created by LSObject.
76 explicit LSDatabaseChild(LSDatabase
* aDatabase
);
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
;
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
;
114 void AssertIsOnOwningThread() const {
115 NS_ASSERT_OWNINGTHREAD(LSObserverChild
);
119 // Only created by LSObject.
120 explicit LSObserverChild(LSObserver
* aObserver
);
122 // Only destroyed by mozilla::ipc::BackgroundChildImpl.
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
143 * Takes an `LSReuestChildCallback` to be invoked when a response is received
146 * See `PBackgroundLSRequest.ipdl`, `LSObject`, and `RequestHelper` for more
149 class LSRequestChild final
: public PBackgroundLSRequestChild
{
150 friend class LSObject
;
151 friend class LocalStorageManager2
;
153 RefPtr
<LSRequestChildCallback
> mCallback
;
160 void AssertIsOnOwningThread() const {
161 NS_ASSERT_OWNINGTHREAD(LSReqeustChild
);
164 bool Finishing() const;
167 // Only created by LSObject.
170 // Only destroyed by mozilla::ipc::BackgroundChildImpl.
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
{
186 NS_INLINE_DECL_PURE_VIRTUAL_REFCOUNTING
188 virtual void OnResponse(const LSRequestResponse
& aResponse
) = 0;
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
;
211 void AssertIsOnOwningThread() const {
212 NS_ASSERT_OWNINGTHREAD(LSSimpleReqeustChild
);
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
{
233 NS_INLINE_DECL_PURE_VIRTUAL_REFCOUNTING
235 virtual void OnResponse(const LSSimpleRequestResponse
& aResponse
) = 0;
238 virtual ~LSSimpleRequestChildCallback() = default;
242 * Minimal IPC-managed (new/delete) actor that lasts as long as its owning
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
;
260 void AssertIsOnOwningThread() const {
261 NS_ASSERT_OWNINGTHREAD(LSSnapshotChild
);
265 // Only created by LSDatabase.
266 explicit LSSnapshotChild(LSSnapshot
* aSnapshot
);
268 // Only destroyed by LSDatabaseChild.
271 void SendDeleteMeInternal();
273 // IPDL methods are only called by IPDL.
274 void ActorDestroy(ActorDestroyReason aWhy
) override
;
276 mozilla::ipc::IPCResult
RecvMarkDirty() override
;
280 } // namespace mozilla
282 #endif // mozilla_dom_localstorage_ActorsChild_h