CacheStorageChild.h (2860B)
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 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef mozilla_dom_cache_CacheStorageChild_h 8 #define mozilla_dom_cache_CacheStorageChild_h 9 10 #include "mozilla/dom/cache/ActorChild.h" 11 #include "mozilla/dom/cache/CacheOpChild.h" 12 #include "mozilla/dom/cache/PCacheStorageChild.h" 13 #include "mozilla/dom/cache/TypeUtils.h" 14 #include "mozilla/dom/cache/Types.h" 15 16 class nsIGlobalObject; 17 18 namespace mozilla::dom { 19 20 class Promise; 21 22 namespace cache { 23 24 class CacheOpArgs; 25 class CacheStorage; 26 class CacheWorkerRef; 27 class PCacheChild; 28 29 class CacheStorageChild final : public PCacheStorageChild, 30 public CacheActorChild { 31 friend class PCacheStorageChild; 32 33 public: 34 CacheStorageChild(CacheStorageChildListener* aListener, 35 SafeRefPtr<CacheWorkerRef> aWorkerRef, 36 ActorChild* aParentActor = nullptr); 37 38 // Must be called by the associated CacheStorage listener in its 39 // OnActorDestroy() method. Also, CacheStorage must call 40 // SendDestroyFromListener() on the actor in its destructor to trigger 41 // ActorDestroy() if it has not been called yet. 42 void ClearListener(); 43 44 template <typename PromiseType> 45 void ExecuteOp(nsIGlobalObject* aGlobal, PromiseType& aPromise, 46 nsISupports* aParent, const CacheOpArgs& aArgs) { 47 (void)SendPCacheOpConstructor( 48 new CacheOpChild(GetWorkerRefPtr().clonePtr(), aGlobal, aParent, 49 aPromise, this), 50 aArgs); 51 } 52 53 // Our parent Listener object has gone out of scope and is being destroyed. 54 void StartDestroyFromListener(); 55 56 NS_INLINE_DECL_REFCOUNTING(CacheStorageChild, override) 57 void NoteDeletedActor() override; 58 59 private: 60 ~CacheStorageChild(); 61 62 void DestroyInternal(); 63 64 // ActorChild methods 65 // CacheWorkerRef is trying to destroy due to worker shutdown. 66 virtual void StartDestroy() override; 67 68 // PCacheStorageChild methods 69 virtual void ActorDestroy(ActorDestroyReason aReason) override; 70 71 PCacheOpChild* AllocPCacheOpChild(const CacheOpArgs& aOpArgs); 72 73 bool DeallocPCacheOpChild(PCacheOpChild* aActor); 74 75 // utility methods 76 inline uint32_t NumChildActors() { return ManagedPCacheOpChild().Count(); } 77 78 ActorChild* mParentActor; 79 80 // Use a weak ref so actor does not hold DOM object alive past content use. 81 // The CacheStorage object must call ClearListener() to null this before its 82 // destroyed. 83 CacheStorageChildListener* MOZ_NON_OWNING_REF mListener; 84 bool mDelayedDestroy; 85 }; 86 87 } // namespace cache 88 } // namespace mozilla::dom 89 90 #endif // mozilla_dom_cache_CacheStorageChild_h