Coverage Report

Created: 2018-09-25 14:53

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