BoundStorageKeyChild.h (2522B)
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_BoundStorageKeyChild_h 8 #define mozilla_dom_cache_BoundStorageKeyChild_h 9 10 #include "mozilla/dom/cache/ActorChild.h" 11 #include "mozilla/dom/cache/ActorUtils.h" 12 #include "mozilla/dom/cache/PBoundStorageKeyChild.h" 13 #include "mozilla/dom/cache/TypeUtils.h" 14 #include "mozilla/dom/cache/Types.h" 15 #include "mozilla/ipc/ProtocolUtils.h" 16 17 class nsIGlobalObject; 18 19 namespace mozilla::dom::cache { 20 class CacheWorkerRef; 21 22 class PCacheChild; 23 class PCacheStreamControlChild; 24 class CacheOpArgs; 25 class PCacheChild; 26 class PCacheOpChild; 27 28 using ActorDestroyReason = ::mozilla::ipc::IProtocol::ActorDestroyReason; 29 class BoundStorageKeyChild final : public PBoundStorageKeyChild, 30 public ActorChild { 31 friend class PBoundStorageKeyChild; 32 33 public: 34 explicit BoundStorageKeyChild(BoundStorageKeyChildListener* aListener); 35 36 void ClearListener(); 37 38 // Our parent Listener object has gone out of scope and is being destroyed. 39 void StartDestroyFromListener(); 40 41 NS_INLINE_DECL_REFCOUNTING(BoundStorageKeyChild, override) 42 void NoteDeletedActor() override; 43 44 already_AddRefed<PCacheChild> AllocPCacheChild() { 45 return dom::cache::AllocPCacheChild(this); 46 } 47 48 already_AddRefed<PCacheStreamControlChild> AllocPCacheStreamControlChild() { 49 return dom::cache::AllocPCacheStreamControlChild(this); 50 } 51 52 private: 53 ~BoundStorageKeyChild(); 54 void DestroyInternal(); 55 56 // ActorChild methods 57 // CacheWorkerRef is trying to destroy due to worker shutdown. 58 virtual void StartDestroy() override; 59 60 // PBoundStorageKeyChild methods 61 virtual void ActorDestroy(ActorDestroyReason aReason) override; 62 63 // utility methods 64 inline uint32_t NumChildActors() { 65 return ManagedPCacheStorageChild().Count() + ManagedPCacheChild().Count() + 66 ManagedPCacheStreamControlChild().Count(); 67 } 68 69 // Use a weak ref so actor does not hold DOM object alive past content use. 70 // The BoundStorageKey object must call ClearListener() to null this before 71 // its destroyed. 72 BoundStorageKeyChildListener* MOZ_NON_OWNING_REF mListener; 73 bool mDelayedDestroy; 74 }; 75 76 } // namespace mozilla::dom::cache 77 78 #endif // mozilla_dom_cache_BoundStorageKeyChild_h