Source code

Revision control

Other Tools

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/. */
6
7
#ifndef mozilla_dom_indexeddb_actorschild_h__
8
#define mozilla_dom_indexeddb_actorschild_h__
9
10
#include "IDBTransaction.h"
11
#include "js/RootingAPI.h"
12
#include "mozilla/Attributes.h"
13
#include "mozilla/dom/indexedDB/PBackgroundIDBCursorChild.h"
14
#include "mozilla/dom/indexedDB/PBackgroundIDBDatabaseChild.h"
15
#include "mozilla/dom/indexedDB/PBackgroundIDBDatabaseRequestChild.h"
16
#include "mozilla/dom/indexedDB/PBackgroundIDBFactoryChild.h"
17
#include "mozilla/dom/indexedDB/PBackgroundIDBFactoryRequestChild.h"
18
#include "mozilla/dom/indexedDB/PBackgroundIDBRequestChild.h"
19
#include "mozilla/dom/indexedDB/PBackgroundIDBSharedTypes.h"
20
#include "mozilla/dom/indexedDB/PBackgroundIDBTransactionChild.h"
21
#include "mozilla/dom/indexedDB/PBackgroundIDBVersionChangeTransactionChild.h"
22
#include "mozilla/dom/indexedDB/PBackgroundIndexedDBUtilsChild.h"
23
#include "mozilla/dom/PBackgroundFileHandleChild.h"
24
#include "mozilla/dom/PBackgroundFileRequestChild.h"
25
#include "mozilla/dom/PBackgroundMutableFileChild.h"
26
#include "nsAutoPtr.h"
27
#include "nsCOMPtr.h"
28
#include "nsTArray.h"
29
30
class nsIEventTarget;
31
struct nsID;
32
33
namespace mozilla {
34
namespace ipc {
35
36
class BackgroundChildImpl;
37
38
} // namespace ipc
39
40
namespace dom {
41
42
class IDBCursor;
43
class IDBDatabase;
44
class IDBFactory;
45
class IDBFileHandle;
46
class IDBFileRequest;
47
class IDBMutableFile;
48
class IDBOpenDBRequest;
49
class IDBRequest;
50
class IndexedDatabaseManager;
51
52
namespace indexedDB {
53
54
class Key;
55
class PermissionRequestChild;
56
class PermissionRequestParent;
57
class SerializedStructuredCloneReadInfo;
58
struct CloneInfo;
59
60
} // namespace indexedDB
61
} // namespace dom
62
} // namespace mozilla
63
64
DECLARE_USE_COPY_CONSTRUCTORS(mozilla::dom::indexedDB::CloneInfo)
65
66
namespace mozilla {
67
namespace dom {
68
namespace indexedDB {
69
70
class ThreadLocal {
71
friend class nsAutoPtr<ThreadLocal>;
72
friend IDBFactory;
73
74
LoggingInfo mLoggingInfo;
75
IDBTransaction* mCurrentTransaction;
76
nsCString mLoggingIdString;
77
78
NS_DECL_OWNINGTHREAD
79
80
public:
81
ThreadLocal() = delete;
82
ThreadLocal(const ThreadLocal& aOther) = delete;
83
84
void AssertIsOnOwningThread() const { NS_ASSERT_OWNINGTHREAD(ThreadLocal); }
85
86
const LoggingInfo& GetLoggingInfo() const {
87
AssertIsOnOwningThread();
88
89
return mLoggingInfo;
90
}
91
92
const nsID& Id() const {
93
AssertIsOnOwningThread();
94
95
return mLoggingInfo.backgroundChildLoggingId();
96
}
97
98
const nsCString& IdString() const {
99
AssertIsOnOwningThread();
100
101
return mLoggingIdString;
102
}
103
104
int64_t NextTransactionSN(IDBTransaction::Mode aMode) {
105
AssertIsOnOwningThread();
106
MOZ_ASSERT(mLoggingInfo.nextTransactionSerialNumber() < INT64_MAX);
107
MOZ_ASSERT(mLoggingInfo.nextVersionChangeTransactionSerialNumber() >
108
INT64_MIN);
109
110
if (aMode == IDBTransaction::Mode::VersionChange) {
111
return mLoggingInfo.nextVersionChangeTransactionSerialNumber()--;
112
}
113
114
return mLoggingInfo.nextTransactionSerialNumber()++;
115
}
116
117
uint64_t NextRequestSN() {
118
AssertIsOnOwningThread();
119
MOZ_ASSERT(mLoggingInfo.nextRequestSerialNumber() < UINT64_MAX);
120
121
return mLoggingInfo.nextRequestSerialNumber()++;
122
}
123
124
void SetCurrentTransaction(IDBTransaction* aCurrentTransaction) {
125
AssertIsOnOwningThread();
126
127
mCurrentTransaction = aCurrentTransaction;
128
}
129
130
IDBTransaction* GetCurrentTransaction() const {
131
AssertIsOnOwningThread();
132
133
return mCurrentTransaction;
134
}
135
136
private:
137
explicit ThreadLocal(const nsID& aBackgroundChildLoggingId);
138
~ThreadLocal();
139
};
140
141
class BackgroundFactoryChild final : public PBackgroundIDBFactoryChild {
142
friend class mozilla::ipc::BackgroundChildImpl;
143
friend IDBFactory;
144
145
IDBFactory* mFactory;
146
147
NS_DECL_OWNINGTHREAD
148
149
public:
150
void AssertIsOnOwningThread() const {
151
NS_ASSERT_OWNINGTHREAD(BackgroundFactoryChild);
152
}
153
154
IDBFactory* GetDOMObject() const {
155
AssertIsOnOwningThread();
156
return mFactory;
157
}
158
159
bool SendDeleteMe() = delete;
160
161
private:
162
// Only created by IDBFactory.
163
explicit BackgroundFactoryChild(IDBFactory* aFactory);
164
165
// Only destroyed by mozilla::ipc::BackgroundChildImpl.
166
~BackgroundFactoryChild();
167
168
void SendDeleteMeInternal();
169
170
// IPDL methods are only called by IPDL.
171
void ActorDestroy(ActorDestroyReason aWhy) override;
172
173
PBackgroundIDBFactoryRequestChild* AllocPBackgroundIDBFactoryRequestChild(
174
const FactoryRequestParams& aParams) override;
175
176
bool DeallocPBackgroundIDBFactoryRequestChild(
177
PBackgroundIDBFactoryRequestChild* aActor) override;
178
179
PBackgroundIDBDatabaseChild* AllocPBackgroundIDBDatabaseChild(
180
const DatabaseSpec& aSpec,
181
PBackgroundIDBFactoryRequestChild* aRequest) override;
182
183
bool DeallocPBackgroundIDBDatabaseChild(
184
PBackgroundIDBDatabaseChild* aActor) override;
185
186
mozilla::ipc::IPCResult RecvPBackgroundIDBDatabaseConstructor(
187
PBackgroundIDBDatabaseChild* aActor, const DatabaseSpec& aSpec,
188
PBackgroundIDBFactoryRequestChild* aRequest) override;
189
};
190
191
class BackgroundDatabaseChild;
192
193
class BackgroundRequestChildBase {
194
protected:
195
RefPtr<IDBRequest> mRequest;
196
197
public:
198
void AssertIsOnOwningThread() const
199
#ifdef DEBUG
200
;
201
#else
202
{
203
}
204
#endif
205
206
protected:
207
explicit BackgroundRequestChildBase(IDBRequest* aRequest);
208
209
virtual ~BackgroundRequestChildBase();
210
};
211
212
class BackgroundFactoryRequestChild final
213
: public BackgroundRequestChildBase,
214
public PBackgroundIDBFactoryRequestChild {
215
typedef mozilla::dom::quota::PersistenceType PersistenceType;
216
217
friend IDBFactory;
218
friend class BackgroundFactoryChild;
219
friend class BackgroundDatabaseChild;
220
friend class PermissionRequestChild;
221
friend class PermissionRequestParent;
222
223
const RefPtr<IDBFactory> mFactory;
224
225
// Normally when opening of a database is successful, we receive a database
226
// actor in request response, so we can use it to call ReleaseDOMObject()
227
// which clears temporary strong reference to IDBDatabase.
228
// However, when there's an error, we don't receive a database actor and
229
// IDBRequest::mTransaction is already cleared (must be). So the only way how
230
// to call ReleaseDOMObject() is to have a back-reference to database actor.
231
// This creates a weak ref cycle between
232
// BackgroundFactoryRequestChild (using mDatabaseActor member) and
233
// BackgroundDatabaseChild actor (using mOpenRequestActor member).
234
// mDatabaseActor is set in EnsureDOMObject() and cleared in
235
// ReleaseDOMObject().
236
BackgroundDatabaseChild* mDatabaseActor;
237
238
const uint64_t mRequestedVersion;
239
const bool mIsDeleteOp;
240
241
public:
242
IDBOpenDBRequest* GetOpenDBRequest() const;
243
244
private:
245
// Only created by IDBFactory.
246
BackgroundFactoryRequestChild(IDBFactory* aFactory,
247
IDBOpenDBRequest* aOpenRequest,
248
bool aIsDeleteOp, uint64_t aRequestedVersion);
249
250
// Only destroyed by BackgroundFactoryChild.
251
~BackgroundFactoryRequestChild();
252
253
void SetDatabaseActor(BackgroundDatabaseChild* aActor);
254
255
bool HandleResponse(nsresult aResponse);
256
257
bool HandleResponse(const OpenDatabaseRequestResponse& aResponse);
258
259
bool HandleResponse(const DeleteDatabaseRequestResponse& aResponse);
260
261
// IPDL methods are only called by IPDL.
262
void ActorDestroy(ActorDestroyReason aWhy) override;
263
264
mozilla::ipc::IPCResult Recv__delete__(
265
const FactoryRequestResponse& aResponse) override;
266
267
mozilla::ipc::IPCResult RecvPermissionChallenge(
268
const PrincipalInfo& aPrincipalInfo) override;
269
270
mozilla::ipc::IPCResult RecvBlocked(const uint64_t& aCurrentVersion) override;
271
};
272
273
class BackgroundDatabaseChild final : public PBackgroundIDBDatabaseChild {
274
friend class BackgroundFactoryChild;
275
friend class BackgroundFactoryRequestChild;
276
friend IDBDatabase;
277
278
nsAutoPtr<DatabaseSpec> mSpec;
279
RefPtr<IDBDatabase> mTemporaryStrongDatabase;
280
BackgroundFactoryRequestChild* mOpenRequestActor;
281
IDBDatabase* mDatabase;
282
283
public:
284
void AssertIsOnOwningThread() const
285
#ifdef DEBUG
286
;
287
#else
288
{
289
}
290
#endif
291
292
const DatabaseSpec* Spec() const {
293
AssertIsOnOwningThread();
294
return mSpec;
295
}
296
297
IDBDatabase* GetDOMObject() const {
298
AssertIsOnOwningThread();
299
return mDatabase;
300
}
301
302
bool SendDeleteMe() = delete;
303
304
private:
305
// Only constructed by BackgroundFactoryChild.
306
BackgroundDatabaseChild(const DatabaseSpec& aSpec,
307
BackgroundFactoryRequestChild* aOpenRequest);
308
309
// Only destroyed by BackgroundFactoryChild.
310
~BackgroundDatabaseChild();
311
312
void SendDeleteMeInternal();
313
314
void EnsureDOMObject();
315
316
void ReleaseDOMObject();
317
318
// IPDL methods are only called by IPDL.
319
void ActorDestroy(ActorDestroyReason aWhy) override;
320
321
PBackgroundIDBDatabaseFileChild* AllocPBackgroundIDBDatabaseFileChild(
322
const IPCBlob& aIPCBlob) override;
323
324
bool DeallocPBackgroundIDBDatabaseFileChild(
325
PBackgroundIDBDatabaseFileChild* aActor) override;
326
327
PBackgroundIDBDatabaseRequestChild* AllocPBackgroundIDBDatabaseRequestChild(
328
const DatabaseRequestParams& aParams) override;
329
330
bool DeallocPBackgroundIDBDatabaseRequestChild(
331
PBackgroundIDBDatabaseRequestChild* aActor) override;
332
333
PBackgroundIDBTransactionChild* AllocPBackgroundIDBTransactionChild(
334
const nsTArray<nsString>& aObjectStoreNames, const Mode& aMode) override;
335
336
bool DeallocPBackgroundIDBTransactionChild(
337
PBackgroundIDBTransactionChild* aActor) override;
338
339
PBackgroundIDBVersionChangeTransactionChild*
340
AllocPBackgroundIDBVersionChangeTransactionChild(
341
const uint64_t& aCurrentVersion, const uint64_t& aRequestedVersion,
342
const int64_t& aNextObjectStoreId, const int64_t& aNextIndexId) override;
343
344
mozilla::ipc::IPCResult RecvPBackgroundIDBVersionChangeTransactionConstructor(
345
PBackgroundIDBVersionChangeTransactionChild* aActor,
346
const uint64_t& aCurrentVersion, const uint64_t& aRequestedVersion,
347
const int64_t& aNextObjectStoreId, const int64_t& aNextIndexId) override;
348
349
bool DeallocPBackgroundIDBVersionChangeTransactionChild(
350
PBackgroundIDBVersionChangeTransactionChild* aActor) override;
351
352
PBackgroundMutableFileChild* AllocPBackgroundMutableFileChild(
353
const nsString& aName, const nsString& aType) override;
354
355
bool DeallocPBackgroundMutableFileChild(
356
PBackgroundMutableFileChild* aActor) override;
357
358
mozilla::ipc::IPCResult RecvVersionChange(
359
const uint64_t& aOldVersion, const Maybe<uint64_t>& aNewVersion) override;
360
361
mozilla::ipc::IPCResult RecvInvalidate() override;
362
363
mozilla::ipc::IPCResult RecvCloseAfterInvalidationComplete() override;
364
};
365
366
class BackgroundDatabaseRequestChild final
367
: public BackgroundRequestChildBase,
368
public PBackgroundIDBDatabaseRequestChild {
369
friend class BackgroundDatabaseChild;
370
friend IDBDatabase;
371
372
RefPtr<IDBDatabase> mDatabase;
373
374
private:
375
// Only created by IDBDatabase.
376
BackgroundDatabaseRequestChild(IDBDatabase* aDatabase, IDBRequest* aRequest);
377
378
// Only destroyed by BackgroundDatabaseChild.
379
~BackgroundDatabaseRequestChild();
380
381
bool HandleResponse(nsresult aResponse);
382
383
bool HandleResponse(const CreateFileRequestResponse& aResponse);
384
385
// IPDL methods are only called by IPDL.
386
mozilla::ipc::IPCResult Recv__delete__(
387
const DatabaseRequestResponse& aResponse) override;
388
};
389
390
class BackgroundVersionChangeTransactionChild;
391
392
class BackgroundTransactionBase {
393
friend class BackgroundVersionChangeTransactionChild;
394
395
// mTemporaryStrongTransaction is strong and is only valid until the end of
396
// NoteComplete() member function or until the NoteActorDestroyed() member
397
// function is called.
398
RefPtr<IDBTransaction> mTemporaryStrongTransaction;
399
400
protected:
401
// mTransaction is weak and is valid until the NoteActorDestroyed() member
402
// function is called.
403
IDBTransaction* mTransaction;
404
405
public:
406
#ifdef DEBUG
407
virtual void AssertIsOnOwningThread() const = 0;
408
#else
409
void AssertIsOnOwningThread() const {}
410
#endif
411
412
IDBTransaction* GetDOMObject() const {
413
AssertIsOnOwningThread();
414
return mTransaction;
415
}
416
417
protected:
418
BackgroundTransactionBase();
419
explicit BackgroundTransactionBase(IDBTransaction* aTransaction);
420
421
virtual ~BackgroundTransactionBase();
422
423
void NoteActorDestroyed();
424
425
void NoteComplete();
426
427
private:
428
// Only called by BackgroundVersionChangeTransactionChild.
429
void SetDOMTransaction(IDBTransaction* aTransaction);
430
};
431
432
class BackgroundTransactionChild final : public BackgroundTransactionBase,
433
public PBackgroundIDBTransactionChild {
434
friend class BackgroundDatabaseChild;
435
friend IDBDatabase;
436
437
public:
438
#ifdef DEBUG
439
void AssertIsOnOwningThread() const override;
440
#endif
441
442
void SendDeleteMeInternal();
443
444
bool SendDeleteMe() = delete;
445
446
private:
447
// Only created by IDBDatabase.
448
explicit BackgroundTransactionChild(IDBTransaction* aTransaction);
449
450
// Only destroyed by BackgroundDatabaseChild.
451
~BackgroundTransactionChild();
452
453
// IPDL methods are only called by IPDL.
454
void ActorDestroy(ActorDestroyReason aWhy) override;
455
456
mozilla::ipc::IPCResult RecvComplete(const nsresult& aResult) override;
457
458
PBackgroundIDBRequestChild* AllocPBackgroundIDBRequestChild(
459
const RequestParams& aParams) override;
460
461
bool DeallocPBackgroundIDBRequestChild(
462
PBackgroundIDBRequestChild* aActor) override;
463
464
PBackgroundIDBCursorChild* AllocPBackgroundIDBCursorChild(
465
const OpenCursorParams& aParams) override;
466
467
bool DeallocPBackgroundIDBCursorChild(
468
PBackgroundIDBCursorChild* aActor) override;
469
};
470
471
class BackgroundVersionChangeTransactionChild final
472
: public BackgroundTransactionBase,
473
public PBackgroundIDBVersionChangeTransactionChild {
474
friend class BackgroundDatabaseChild;
475
476
IDBOpenDBRequest* mOpenDBRequest;
477
478
public:
479
#ifdef DEBUG
480
void AssertIsOnOwningThread() const override;
481
#endif
482
483
void SendDeleteMeInternal(bool aFailedConstructor);
484
485
bool SendDeleteMe() = delete;
486
487
private:
488
// Only created by BackgroundDatabaseChild.
489
explicit BackgroundVersionChangeTransactionChild(
490
IDBOpenDBRequest* aOpenDBRequest);
491
492
// Only destroyed by BackgroundDatabaseChild.
493
~BackgroundVersionChangeTransactionChild();
494
495
// Only called by BackgroundDatabaseChild.
496
void SetDOMTransaction(IDBTransaction* aDOMObject) {
497
BackgroundTransactionBase::SetDOMTransaction(aDOMObject);
498
}
499
500
// IPDL methods are only called by IPDL.
501
void ActorDestroy(ActorDestroyReason aWhy) override;
502
503
mozilla::ipc::IPCResult RecvComplete(const nsresult& aResult) override;
504
505
PBackgroundIDBRequestChild* AllocPBackgroundIDBRequestChild(
506
const RequestParams& aParams) override;
507
508
bool DeallocPBackgroundIDBRequestChild(
509
PBackgroundIDBRequestChild* aActor) override;
510
511
PBackgroundIDBCursorChild* AllocPBackgroundIDBCursorChild(
512
const OpenCursorParams& aParams) override;
513
514
bool DeallocPBackgroundIDBCursorChild(
515
PBackgroundIDBCursorChild* aActor) override;
516
};
517
518
class BackgroundMutableFileChild final : public PBackgroundMutableFileChild {
519
friend class BackgroundDatabaseChild;
520
friend IDBMutableFile;
521
522
RefPtr<IDBMutableFile> mTemporaryStrongMutableFile;
523
IDBMutableFile* mMutableFile;
524
nsString mName;
525
nsString mType;
526
527
public:
528
void AssertIsOnOwningThread() const
529
#ifdef DEBUG
530
;
531
#else
532
{
533
}
534
#endif
535
536
void EnsureDOMObject();
537
538
IDBMutableFile* GetDOMObject() const {
539
AssertIsOnOwningThread();
540
return mMutableFile;
541
}
542
543
void ReleaseDOMObject();
544
545
bool SendDeleteMe() = delete;
546
547
private:
548
// Only constructed by BackgroundDatabaseChild.
549
BackgroundMutableFileChild(const nsAString& aName, const nsAString& aType);
550
551
// Only destroyed by BackgroundDatabaseChild.
552
~BackgroundMutableFileChild();
553
554
void SendDeleteMeInternal();
555
556
// IPDL methods are only called by IPDL.
557
void ActorDestroy(ActorDestroyReason aWhy) override;
558
559
PBackgroundFileHandleChild* AllocPBackgroundFileHandleChild(
560
const FileMode& aMode) override;
561
562
bool DeallocPBackgroundFileHandleChild(
563
PBackgroundFileHandleChild* aActor) override;
564
};
565
566
class BackgroundRequestChild final : public BackgroundRequestChildBase,
567
public PBackgroundIDBRequestChild {
568
friend class BackgroundTransactionChild;
569
friend class BackgroundVersionChangeTransactionChild;
570
friend struct CloneInfo;
571
friend IDBTransaction;
572
573
class PreprocessHelper;
574
575
RefPtr<IDBTransaction> mTransaction;
576
nsTArray<CloneInfo> mCloneInfos;
577
uint32_t mRunningPreprocessHelpers;
578
uint32_t mCurrentCloneDataIndex;
579
nsresult mPreprocessResultCode;
580
bool mGetAll;
581
582
private:
583
// Only created by IDBTransaction.
584
explicit BackgroundRequestChild(IDBRequest* aRequest);
585
586
// Only destroyed by BackgroundTransactionChild or
587
// BackgroundVersionChangeTransactionChild.
588
~BackgroundRequestChild();
589
590
void MaybeSendContinue();
591
592
void OnPreprocessFinished(uint32_t aCloneDataIndex,
593
UniquePtr<JSStructuredCloneData> aCloneData);
594
595
void OnPreprocessFailed(uint32_t aCloneDataIndex, nsresult aErrorCode);
596
597
UniquePtr<JSStructuredCloneData> GetNextCloneData();
598
599
void HandleResponse(nsresult aResponse);
600
601
void HandleResponse(const Key& aResponse);
602
603
void HandleResponse(const nsTArray<Key>& aResponse);
604
605
void HandleResponse(const SerializedStructuredCloneReadInfo& aResponse);
606
607
void HandleResponse(
608
const nsTArray<SerializedStructuredCloneReadInfo>& aResponse);
609
610
void HandleResponse(JS::Handle<JS::Value> aResponse);
611
612
void HandleResponse(uint64_t aResponse);
613
614
nsresult HandlePreprocess(const PreprocessInfo& aPreprocessInfo);
615
616
nsresult HandlePreprocess(const nsTArray<PreprocessInfo>& aPreprocessInfos);
617
618
nsresult HandlePreprocessInternal(
619
const nsTArray<PreprocessInfo>& aPreprocessInfos);
620
621
// IPDL methods are only called by IPDL.
622
void ActorDestroy(ActorDestroyReason aWhy) override;
623
624
mozilla::ipc::IPCResult Recv__delete__(
625
const RequestResponse& aResponse) override;
626
627
mozilla::ipc::IPCResult RecvPreprocess(
628
const PreprocessParams& aParams) override;
629
};
630
631
struct CloneInfo {
632
RefPtr<BackgroundRequestChild::PreprocessHelper> mPreprocessHelper;
633
UniquePtr<JSStructuredCloneData> mCloneData;
634
};
635
636
// TODO: Consider defining different subclasses for the different cursor types,
637
// possibly using the CRTP, which would remove the need for various case
638
// distinctions.
639
class BackgroundCursorChild final : public PBackgroundIDBCursorChild {
640
friend class BackgroundTransactionChild;
641
friend class BackgroundVersionChangeTransactionChild;
642
643
class DelayedActionRunnable;
644
645
struct CachedResponse {
646
CachedResponse() = delete;
647
648
CachedResponse(Key aKey, StructuredCloneReadInfo&& aCloneInfo);
649
CachedResponse(Key aKey, Key aLocaleAwareKey, Key aObjectStoreKey,
650
StructuredCloneReadInfo&& aCloneInfo);
651
explicit CachedResponse(Key aKey);
652
CachedResponse(Key aKey, Key aLocaleAwareKey, Key aObjectStoreKey);
653
654
CachedResponse(CachedResponse&& aOther) = default;
655
CachedResponse& operator=(CachedResponse&& aOther) = default;
656
CachedResponse(const CachedResponse& aOther) = delete;
657
CachedResponse& operator=(const CachedResponse& aOther) = delete;
658
659
Key mKey;
660
Key mLocaleAwareKey;
661
Key mObjectStoreKey;
662
StructuredCloneReadInfo mCloneInfo;
663
};
664
665
IDBRequest* mRequest;
666
IDBTransaction* mTransaction;
667
IDBObjectStore* mObjectStore;
668
IDBIndex* mIndex;
669
IDBCursor* mCursor;
670
671
// These are only set while a request is in progress.
672
RefPtr<IDBRequest> mStrongRequest;
673
RefPtr<IDBCursor> mStrongCursor;
674
675
Direction mDirection;
676
677
NS_DECL_OWNINGTHREAD
678
679
std::deque<CachedResponse> mCachedResponses, mDelayedResponses;
680
bool mInFlightResponseInvalidationNeeded;
681
682
public:
683
BackgroundCursorChild(IDBRequest* aRequest, IDBObjectStore* aObjectStore,
684
Direction aDirection);
685
686
BackgroundCursorChild(IDBRequest* aRequest, IDBIndex* aIndex,
687
Direction aDirection);
688
689
void AssertIsOnOwningThread() const {
690
NS_ASSERT_OWNINGTHREAD(BackgroundCursorChild);
691
}
692
693
void SendContinueInternal(const CursorRequestParams& aParams,
694
const Key& aCurrentKey,
695
const Key& aCurrentObjectStoreKey);
696
697
void SendDeleteMeInternal();
698
699
void InvalidateCachedResponses();
700
701
template <typename Condition>
702
void DiscardCachedResponses(const Condition& aConditionFunc);
703
704
IDBRequest* GetRequest() const {
705
AssertIsOnOwningThread();
706
707
return mRequest;
708
}
709
710
IDBObjectStore* GetObjectStore() const {
711
AssertIsOnOwningThread();
712
713
return mObjectStore;
714
}
715
716
IDBIndex* GetIndex() const {
717
AssertIsOnOwningThread();
718
719
return mIndex;
720
}
721
722
Direction GetDirection() const {
723
AssertIsOnOwningThread();
724
725
return mDirection;
726
}
727
728
private:
729
// Only destroyed by BackgroundTransactionChild or
730
// BackgroundVersionChangeTransactionChild.
731
~BackgroundCursorChild();
732
733
void CompleteContinueRequestFromCache();
734
735
void HandleResponse(nsresult aResponse);
736
737
void HandleResponse(const void_t& aResponse);
738
739
void HandleResponse(const nsTArray<ObjectStoreCursorResponse>& aResponses);
740
741
void HandleResponse(const nsTArray<ObjectStoreKeyCursorResponse>& aResponses);
742
743
void HandleResponse(const nsTArray<IndexCursorResponse>& aResponses);
744
745
template <typename T, typename Func>
746
void HandleMultipleCursorResponses(const nsTArray<T>& aResponses,
747
const Func& aHandleRecord);
748
749
void HandleResponse(const nsTArray<IndexKeyCursorResponse>& aResponses);
750
751
template <typename... Args>
752
MOZ_MUST_USE RefPtr<IDBCursor> HandleIndividualCursorResponse(
753
bool aUseAsCurrentResult, Args&&... aArgs);
754
755
// IPDL methods are only called by IPDL.
756
void ActorDestroy(ActorDestroyReason aWhy) override;
757
758
mozilla::ipc::IPCResult RecvResponse(
759
const CursorResponse& aResponse) override;
760
761
public:
762
// Force callers to use SendContinueInternal.
763
bool SendContinue(const CursorRequestParams& aParams, const Key& aCurrentKey,
764
const Key& aCurrentObjectStoreKey) = delete;
765
766
bool SendDeleteMe() = delete;
767
};
768
769
class BackgroundFileHandleChild : public PBackgroundFileHandleChild {
770
friend class BackgroundMutableFileChild;
771
friend IDBMutableFile;
772
773
// mTemporaryStrongFileHandle is strong and is only valid until the end of
774
// NoteComplete() member function or until the NoteActorDestroyed() member
775
// function is called.
776
RefPtr<IDBFileHandle> mTemporaryStrongFileHandle;
777
778
// mFileHandle is weak and is valid until the NoteActorDestroyed() member
779
// function is called.
780
IDBFileHandle* mFileHandle;
781
782
public:
783
void AssertIsOnOwningThread() const
784
#ifdef DEBUG
785
;
786
#else
787
{
788
}
789
#endif
790
791
void SendDeleteMeInternal();
792
793
bool SendDeleteMe() = delete;
794
795
private:
796
// Only created by IDBMutableFile.
797
explicit BackgroundFileHandleChild(IDBFileHandle* aFileHandle);
798
799
~BackgroundFileHandleChild();
800
801
void NoteActorDestroyed();
802
803
void NoteComplete();
804
805
// IPDL methods are only called by IPDL.
806
void ActorDestroy(ActorDestroyReason aWhy) override;
807
808
mozilla::ipc::IPCResult RecvComplete(const bool& aAborted) override;
809
810
PBackgroundFileRequestChild* AllocPBackgroundFileRequestChild(
811
const FileRequestParams& aParams) override;
812
813
bool DeallocPBackgroundFileRequestChild(
814
PBackgroundFileRequestChild* aActor) override;
815
};
816
817
class BackgroundFileRequestChild final : public PBackgroundFileRequestChild {
818
friend class BackgroundFileHandleChild;
819
friend IDBFileHandle;
820
821
RefPtr<IDBFileRequest> mFileRequest;
822
RefPtr<IDBFileHandle> mFileHandle;
823
bool mActorDestroyed;
824
825
public:
826
void AssertIsOnOwningThread() const
827
#ifdef DEBUG
828
;
829
#else
830
{
831
}
832
#endif
833
834
private:
835
// Only created by IDBFileHandle.
836
explicit BackgroundFileRequestChild(IDBFileRequest* aFileRequest);
837
838
// Only destroyed by BackgroundFileHandleChild.
839
~BackgroundFileRequestChild();
840
841
void HandleResponse(nsresult aResponse);
842
843
void HandleResponse(const FileRequestGetFileResponse& aResponse);
844
845
void HandleResponse(const nsCString& aResponse);
846
847
void HandleResponse(const FileRequestMetadata& aResponse);
848
849
void HandleResponse(JS::Handle<JS::Value> aResponse);
850
851
// IPDL methods are only called by IPDL.
852
void ActorDestroy(ActorDestroyReason aWhy) override;
853
854
mozilla::ipc::IPCResult Recv__delete__(
855
const FileRequestResponse& aResponse) override;
856
857
mozilla::ipc::IPCResult RecvProgress(const uint64_t& aProgress,
858
const uint64_t& aProgressMax) override;
859
};
860
861
class BackgroundUtilsChild final : public PBackgroundIndexedDBUtilsChild {
862
friend class mozilla::ipc::BackgroundChildImpl;
863
friend IndexedDatabaseManager;
864
865
IndexedDatabaseManager* mManager;
866
867
NS_DECL_OWNINGTHREAD
868
869
public:
870
void AssertIsOnOwningThread() const {
871
NS_ASSERT_OWNINGTHREAD(BackgroundUtilsChild);
872
}
873
874
bool SendDeleteMe() = delete;
875
876
private:
877
// Only created by IndexedDatabaseManager.
878
explicit BackgroundUtilsChild(IndexedDatabaseManager* aManager);
879
880
// Only destroyed by mozilla::ipc::BackgroundChildImpl.
881
~BackgroundUtilsChild();
882
883
void SendDeleteMeInternal();
884
885
// IPDL methods are only called by IPDL.
886
void ActorDestroy(ActorDestroyReason aWhy) override;
887
};
888
889
} // namespace indexedDB
890
} // namespace dom
891
} // namespace mozilla
892
893
#endif // mozilla_dom_indexeddb_actorschild_h__