Bug 1826136 [wpt PR 39338] - Update wpt metadata, a=testonly
[gecko.git] / dom / cache / CacheChild.h
blob7f37c790643c9a565c717f1f560003ce3c6c358d
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/. */
7 #ifndef mozilla_dom_cache_CacheChild_h
8 #define mozilla_dom_cache_CacheChild_h
10 #include "mozilla/dom/cache/ActorChild.h"
11 #include "mozilla/dom/cache/PCacheChild.h"
13 class nsIAsyncInputStream;
14 class nsIGlobalObject;
16 namespace mozilla::dom {
18 class Promise;
20 namespace cache {
22 class Cache;
23 class CacheOpArgs;
25 class CacheChild final : public PCacheChild, public ActorChild {
26 friend class PCacheChild;
28 public:
29 friend class mozilla::detail::BaseAutoLock<CacheChild&>;
30 using AutoLock = mozilla::detail::BaseAutoLock<CacheChild&>;
32 CacheChild();
34 void SetListener(Cache* aListener);
36 // Must be called by the associated Cache listener in its DestroyInternal()
37 // method. Also, Cache must call StartDestroyFromListener() on the actor in
38 // its destructor to trigger ActorDestroy() if it has not been called yet.
39 void ClearListener();
41 void ExecuteOp(nsIGlobalObject* aGlobal, Promise* aPromise,
42 nsISupports* aParent, const CacheOpArgs& aArgs);
44 // Our parent Listener object has gone out of scope and is being destroyed.
45 void StartDestroyFromListener();
46 void NoteDeletedActor() override;
48 NS_INLINE_DECL_REFCOUNTING(CacheChild, override);
50 private:
51 ~CacheChild();
53 void DestroyInternal();
54 // ActorChild methods
55 // WorkerRef is trying to destroy due to worker shutdown.
56 virtual void StartDestroy() override;
58 // PCacheChild methods
59 virtual void ActorDestroy(ActorDestroyReason aReason) override;
61 already_AddRefed<PCacheOpChild> AllocPCacheOpChild(
62 const CacheOpArgs& aOpArgs);
64 // utility methods
65 inline uint32_t NumChildActors() { return ManagedPCacheOpChild().Count(); }
67 // Methods used to temporarily force the actor alive. Only called from
68 // AutoLock.
69 void Lock();
71 void Unlock();
73 // Use a weak ref so actor does not hold DOM object alive past content use.
74 // The Cache object must call ClearListener() to null this before its
75 // destroyed.
76 Cache* MOZ_NON_OWNING_REF mListener;
77 bool mLocked;
78 bool mDelayedDestroy;
81 } // namespace cache
82 } // namespace mozilla::dom
84 #endif // mozilla_dom_cache_CacheChild_h