1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_dom_localstorage_ActorsChild_h
#define mozilla_dom_localstorage_ActorsChild_h
#include <cstdint>
#include "mozilla/RefPtr.h"
#include "mozilla/dom/PBackgroundLSDatabaseChild.h"
#include "mozilla/dom/PBackgroundLSObserverChild.h"
#include "mozilla/dom/PBackgroundLSRequest.h"
#include "mozilla/dom/PBackgroundLSRequestChild.h"
#include "mozilla/dom/PBackgroundLSSimpleRequest.h"
#include "mozilla/dom/PBackgroundLSSimpleRequestChild.h"
#include "mozilla/dom/PBackgroundLSSnapshotChild.h"
#include "mozilla/ipc/ProtocolUtils.h"
#include "nsISupports.h"
#include "nsStringFwd.h"
#include "nscore.h"
namespace mozilla {
namespace ipc {
class BackgroundChildImpl;
} // namespace ipc
namespace dom {
class LocalStorageManager2;
class LSDatabase;
class LSObject;
class LSObserver;
class LSRequestChildCallback;
class LSSimpleRequestChildCallback;
class LSSnapshot;
/**
* Minimal glue actor with standard IPC-managed new/delete existence that exists
* primarily to track the continued existence of the LSDatabase in the child.
* Most of the interesting bits happen via PBackgroundLSSnapshot.
*
* Mutual raw pointers are maintained between LSDatabase and this class that are
* cleared at either (expected) when the child starts the deletion process
* (SendDeleteMeInternal) or unexpected actor death (ActorDestroy).
*
* See `PBackgroundLSDatabase.ipdl` for more information.
*
*
* ## Low-Level Lifecycle ##
* - Created by LSObject::EnsureDatabase if it had to create a database.
* - Deletion begun by LSDatabase's destructor invoking SendDeleteMeInternal
* which will result in the parent sending __delete__ which destroys the
* actor.
*/
class LSDatabaseChild final : public PBackgroundLSDatabaseChild {
friend class mozilla::ipc::BackgroundChildImpl;
friend class LSDatabase;
friend class LSObject;
LSDatabase* mDatabase;
NS_INLINE_DECL_REFCOUNTING(LSDatabaseChild, override)
public:
void AssertIsOnOwningThread() const {
NS_ASSERT_OWNINGTHREAD(LSDatabaseChild);
}
private:
// Only created by LSObject.
explicit LSDatabaseChild(LSDatabase* aDatabase);
~LSDatabaseChild();
void SendDeleteMeInternal();
// IPDL methods are only called by IPDL.
void ActorDestroy(ActorDestroyReason aWhy) override;
mozilla::ipc::IPCResult RecvRequestAllowToClose() override;
PBackgroundLSSnapshotChild* AllocPBackgroundLSSnapshotChild(
const nsAString& aDocumentURI, const nsAString& aKey,
const bool& aIncreasePeakUsage, const int64_t& aMinSize,
LSSnapshotInitInfo* aInitInfo) override;
bool DeallocPBackgroundLSSnapshotChild(
PBackgroundLSSnapshotChild* aActor) override;
};
/**
* Minimal IPC-managed (new/delete) actor that exists to receive and relay
* "storage" events from changes to LocalStorage that take place in other
* processes as their Snapshots are checkpointed to the canonical Datastore in
* the parent process.
*
* See `PBackgroundLSObserver.ipdl` for more info.
*/
class LSObserverChild final : public PBackgroundLSObserverChild {
friend class mozilla::ipc::BackgroundChildImpl;
friend class LSObserver;
friend class LSObject;
LSObserver* mObserver;
NS_DECL_OWNINGTHREAD
public:
void AssertIsOnOwningThread() const {
NS_ASSERT_OWNINGTHREAD(LSObserverChild);
}
private:
// Only created by LSObject.
explicit LSObserverChild(LSObserver* aObserver);
// Only destroyed by mozilla::ipc::BackgroundChildImpl.
~LSObserverChild();
void SendDeleteMeInternal();
// IPDL methods are only called by IPDL.
void ActorDestroy(ActorDestroyReason aWhy) override;
mozilla::ipc::IPCResult RecvObserve(const PrincipalInfo& aPrinciplaInfo,
const uint32_t& aPrivateBrowsingId,
const nsAString& aDocumentURI,
const nsAString& aKey,
const LSValue& aOldValue,
const LSValue& aNewValue) override;
};
/**
* Minimal glue IPC-managed (new/delete) actor that is used by LSObject and its
* RequestHelper to perform synchronous requests on top of an asynchronous
* protocol.
*
* Takes an `LSReuestChildCallback` to be invoked when a response is received
* via __delete__.
*
* See `PBackgroundLSRequest.ipdl`, `LSObject`, and `RequestHelper` for more
* info.
*/
class LSRequestChild final : public PBackgroundLSRequestChild {
friend class LSObject;
friend class LocalStorageManager2;
RefPtr<LSRequestChildCallback> mCallback;
bool mFinishing;
NS_DECL_OWNINGTHREAD
public:
void AssertIsOnOwningThread() const {
NS_ASSERT_OWNINGTHREAD(LSReqeustChild);
}
bool Finishing() const;
private:
// Only created by LSObject.
LSRequestChild();
// Only destroyed by mozilla::ipc::BackgroundChildImpl.
~LSRequestChild();
void SetCallback(LSRequestChildCallback* aCallback);
// IPDL methods are only called by IPDL.
void ActorDestroy(ActorDestroyReason aWhy) override;
mozilla::ipc::IPCResult Recv__delete__(
const LSRequestResponse& aResponse) override;
mozilla::ipc::IPCResult RecvReady() override;
};
class NS_NO_VTABLE LSRequestChildCallback {
public:
NS_INLINE_DECL_PURE_VIRTUAL_REFCOUNTING
virtual void OnResponse(const LSRequestResponse& aResponse) = 0;
protected:
virtual ~LSRequestChildCallback() = default;
};
/**
* Minimal glue IPC-managed (new/delete) actor used by `LocalStorageManager2` to
* issue asynchronous requests in an asynchronous fashion.
*
* Takes an `LSSimpleRequestChildCallback` to be invoked when a response is
* received via __delete__.
*
* See `PBackgroundLSSimpleRequest.ipdl` for more info.
*/
class LSSimpleRequestChild final : public PBackgroundLSSimpleRequestChild {
friend class LocalStorageManager2;
RefPtr<LSSimpleRequestChildCallback> mCallback;
NS_DECL_OWNINGTHREAD
public:
void AssertIsOnOwningThread() const {
NS_ASSERT_OWNINGTHREAD(LSSimpleReqeustChild);
}
private:
// Only created by LocalStorageManager2.
LSSimpleRequestChild();
void SetCallback(LSSimpleRequestChildCallback* aCallback);
// Only destroyed by mozilla::ipc::BackgroundChildImpl.
~LSSimpleRequestChild();
// IPDL methods are only called by IPDL.
void ActorDestroy(ActorDestroyReason aWhy) override;
mozilla::ipc::IPCResult Recv__delete__(
const LSSimpleRequestResponse& aResponse) override;
};
class NS_NO_VTABLE LSSimpleRequestChildCallback {
public:
NS_INLINE_DECL_PURE_VIRTUAL_REFCOUNTING
virtual void OnResponse(const LSSimpleRequestResponse& aResponse) = 0;
protected:
virtual ~LSSimpleRequestChildCallback() = default;
};
/**
* Minimal IPC-managed (new/delete) actor that lasts as long as its owning
* LSSnapshot.
*
* Mutual raw pointers are maintained between LSSnapshot and this class that are
* cleared at either (expected) when the child starts the deletion process
* (SendDeleteMeInternal) or unexpected actor death (ActorDestroy).
*
* See `PBackgroundLSSnapshot.ipdl` and `LSSnapshot` for more info.
*/
class LSSnapshotChild final : public PBackgroundLSSnapshotChild {
friend class LSDatabase;
friend class LSSnapshot;
LSSnapshot* mSnapshot;
NS_DECL_OWNINGTHREAD
public:
void AssertIsOnOwningThread() const {
NS_ASSERT_OWNINGTHREAD(LSSnapshotChild);
}
private:
// Only created by LSDatabase.
explicit LSSnapshotChild(LSSnapshot* aSnapshot);
// Only destroyed by LSDatabaseChild.
~LSSnapshotChild();
void SendDeleteMeInternal();
// IPDL methods are only called by IPDL.
void ActorDestroy(ActorDestroyReason aWhy) override;
mozilla::ipc::IPCResult RecvMarkDirty() override;
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_localstorage_ActorsChild_h
|