CacheChild.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #ifndef mozilla_dom_cache_CacheChild_h
  6. #define mozilla_dom_cache_CacheChild_h
  7. #include "mozilla/dom/cache/ActorChild.h"
  8. #include "mozilla/dom/cache/PCacheChild.h"
  9. class nsIAsyncInputStream;
  10. class nsIGlobalObject;
  11. namespace mozilla {
  12. namespace dom {
  13. class Promise;
  14. namespace cache {
  15. class Cache;
  16. class CacheOpArgs;
  17. class CacheChild final : public PCacheChild
  18. , public ActorChild
  19. {
  20. public:
  21. class MOZ_RAII AutoLock final
  22. {
  23. CacheChild* mActor;
  24. public:
  25. explicit AutoLock(CacheChild* aActor)
  26. : mActor(aActor)
  27. {
  28. MOZ_DIAGNOSTIC_ASSERT(mActor);
  29. mActor->Lock();
  30. }
  31. ~AutoLock()
  32. {
  33. mActor->Unlock();
  34. }
  35. };
  36. CacheChild();
  37. ~CacheChild();
  38. void SetListener(Cache* aListener);
  39. // Must be called by the associated Cache listener in its DestroyInternal()
  40. // method. Also, Cache must call StartDestroyFromListener() on the actor in
  41. // its destructor to trigger ActorDestroy() if it has not been called yet.
  42. void ClearListener();
  43. void
  44. ExecuteOp(nsIGlobalObject* aGlobal, Promise* aPromise,
  45. nsISupports* aParent, const CacheOpArgs& aArgs);
  46. // Our parent Listener object has gone out of scope and is being destroyed.
  47. void StartDestroyFromListener();
  48. private:
  49. // ActorChild methods
  50. // WorkerHolder is trying to destroy due to worker shutdown.
  51. virtual void StartDestroy() override;
  52. // PCacheChild methods
  53. virtual void
  54. ActorDestroy(ActorDestroyReason aReason) override;
  55. virtual PCacheOpChild*
  56. AllocPCacheOpChild(const CacheOpArgs& aOpArgs) override;
  57. virtual bool
  58. DeallocPCacheOpChild(PCacheOpChild* aActor) override;
  59. // utility methods
  60. void
  61. NoteDeletedActor();
  62. void
  63. MaybeFlushDelayedDestroy();
  64. // Methods used to temporarily force the actor alive. Only called from
  65. // AutoLock.
  66. void
  67. Lock();
  68. void
  69. Unlock();
  70. // Use a weak ref so actor does not hold DOM object alive past content use.
  71. // The Cache object must call ClearListener() to null this before its
  72. // destroyed.
  73. Cache* MOZ_NON_OWNING_REF mListener;
  74. uint32_t mNumChildActors;
  75. bool mDelayedDestroy;
  76. bool mLocked;
  77. NS_DECL_OWNINGTHREAD
  78. };
  79. } // namespace cache
  80. } // namespace dom
  81. } // namespace mozilla
  82. #endif // mozilla_dom_cache_CacheChild_h