tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

CacheChild.h (2775B)


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