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