Bug 1572460 - Refactor `selection` out of the `InspectorFront`. r=yulia
[gecko.git] / dom / cache / CacheChild.h
blob274d8fff27bb2b9770f7489cafdbcabf4bd85b64
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 {
17 namespace dom {
19 class Promise;
21 namespace cache {
23 class Cache;
24 class CacheOpArgs;
26 class CacheChild final : public PCacheChild, public ActorChild {
27 friend class PCacheChild;
29 public:
30 class MOZ_RAII AutoLock final {
31 CacheChild* mActor;
33 public:
34 explicit AutoLock(CacheChild* aActor) : mActor(aActor) {
35 MOZ_DIAGNOSTIC_ASSERT(mActor);
36 mActor->Lock();
39 ~AutoLock() { mActor->Unlock(); }
42 CacheChild();
43 ~CacheChild();
45 void SetListener(Cache* aListener);
47 // Must be called by the associated Cache listener in its DestroyInternal()
48 // method. Also, Cache must call StartDestroyFromListener() on the actor in
49 // its destructor to trigger ActorDestroy() if it has not been called yet.
50 void ClearListener();
52 void ExecuteOp(nsIGlobalObject* aGlobal, Promise* aPromise,
53 nsISupports* aParent, const CacheOpArgs& aArgs);
55 // Our parent Listener object has gone out of scope and is being destroyed.
56 void StartDestroyFromListener();
58 private:
59 // ActorChild methods
61 // WorkerRef is trying to destroy due to worker shutdown.
62 virtual void StartDestroy() override;
64 // PCacheChild methods
65 virtual void ActorDestroy(ActorDestroyReason aReason) override;
67 PCacheOpChild* AllocPCacheOpChild(const CacheOpArgs& aOpArgs);
69 bool DeallocPCacheOpChild(PCacheOpChild* aActor);
71 // utility methods
72 void NoteDeletedActor();
74 void MaybeFlushDelayedDestroy();
76 // Methods used to temporarily force the actor alive. Only called from
77 // AutoLock.
78 void Lock();
80 void Unlock();
82 // Use a weak ref so actor does not hold DOM object alive past content use.
83 // The Cache object must call ClearListener() to null this before its
84 // destroyed.
85 Cache* MOZ_NON_OWNING_REF mListener;
86 uint32_t mNumChildActors;
87 bool mDelayedDestroy;
88 bool mLocked;
90 NS_DECL_OWNINGTHREAD
93 } // namespace cache
94 } // namespace dom
95 } // namespace mozilla
97 #endif // mozilla_dom_cache_CacheChild_h