ActorsChild.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  3. * You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. #ifndef mozilla_dom_filehandle_ActorsChild_h
  5. #define mozilla_dom_filehandle_ActorsChild_h
  6. #include "js/RootingAPI.h"
  7. #include "mozilla/Attributes.h"
  8. #include "mozilla/dom/FileHandleCommon.h"
  9. #include "mozilla/dom/PBackgroundFileHandleChild.h"
  10. #include "mozilla/dom/PBackgroundFileRequestChild.h"
  11. #include "mozilla/dom/PBackgroundMutableFileChild.h"
  12. class nsCString;
  13. namespace mozilla {
  14. namespace dom {
  15. class FileHandleBase;
  16. class FileRequestBase;
  17. class MutableFileBase;
  18. class BackgroundMutableFileChildBase
  19. : public ThreadObject
  20. , public PBackgroundMutableFileChild
  21. {
  22. protected:
  23. friend class MutableFileBase;
  24. RefPtr<MutableFileBase> mTemporaryStrongMutableFile;
  25. MutableFileBase* mMutableFile;
  26. public:
  27. void
  28. EnsureDOMObject();
  29. MutableFileBase*
  30. GetDOMObject() const
  31. {
  32. AssertIsOnOwningThread();
  33. return mMutableFile;
  34. }
  35. void
  36. ReleaseDOMObject();
  37. protected:
  38. BackgroundMutableFileChildBase(DEBUGONLY(PRThread* aOwningThread));
  39. ~BackgroundMutableFileChildBase();
  40. void
  41. SendDeleteMeInternal();
  42. virtual already_AddRefed<MutableFileBase>
  43. CreateMutableFile() = 0;
  44. // IPDL methods are only called by IPDL.
  45. virtual void
  46. ActorDestroy(ActorDestroyReason aWhy) override;
  47. virtual PBackgroundFileHandleChild*
  48. AllocPBackgroundFileHandleChild(const FileMode& aMode) override;
  49. virtual bool
  50. DeallocPBackgroundFileHandleChild(PBackgroundFileHandleChild* aActor)
  51. override;
  52. bool
  53. SendDeleteMe() = delete;
  54. };
  55. class BackgroundFileHandleChild
  56. : public ThreadObject
  57. , public PBackgroundFileHandleChild
  58. {
  59. friend class BackgroundMutableFileChildBase;
  60. friend class MutableFileBase;
  61. // mTemporaryStrongFileHandle is strong and is only valid until the end of
  62. // NoteComplete() member function or until the NoteActorDestroyed() member
  63. // function is called.
  64. RefPtr<FileHandleBase> mTemporaryStrongFileHandle;
  65. // mFileHandle is weak and is valid until the NoteActorDestroyed() member
  66. // function is called.
  67. FileHandleBase* mFileHandle;
  68. public:
  69. explicit BackgroundFileHandleChild(DEBUGONLY(PRThread* aOwningThread,)
  70. FileHandleBase* aFileHandle);
  71. void
  72. SendDeleteMeInternal();
  73. private:
  74. ~BackgroundFileHandleChild();
  75. void
  76. NoteActorDestroyed();
  77. void
  78. NoteComplete();
  79. // IPDL methods are only called by IPDL.
  80. virtual void
  81. ActorDestroy(ActorDestroyReason aWhy) override;
  82. bool
  83. RecvComplete(const bool& aAborted) override;
  84. virtual PBackgroundFileRequestChild*
  85. AllocPBackgroundFileRequestChild(const FileRequestParams& aParams)
  86. override;
  87. virtual bool
  88. DeallocPBackgroundFileRequestChild(PBackgroundFileRequestChild* aActor)
  89. override;
  90. bool
  91. SendDeleteMe() = delete;
  92. };
  93. class BackgroundFileRequestChild final
  94. : public ThreadObject
  95. , public PBackgroundFileRequestChild
  96. {
  97. friend class BackgroundFileHandleChild;
  98. friend class FileHandleBase;
  99. RefPtr<FileRequestBase> mFileRequest;
  100. RefPtr<FileHandleBase> mFileHandle;
  101. bool mActorDestroyed;
  102. private:
  103. // Only created by FileHandleBase.
  104. explicit BackgroundFileRequestChild(DEBUGONLY(PRThread* aOwningThread,)
  105. FileRequestBase* aFileRequest);
  106. // Only destroyed by BackgroundFileHandleChild.
  107. ~BackgroundFileRequestChild();
  108. void
  109. HandleResponse(nsresult aResponse);
  110. void
  111. HandleResponse(const FileRequestGetFileResponse& aResponse);
  112. void
  113. HandleResponse(const nsCString& aResponse);
  114. void
  115. HandleResponse(const FileRequestMetadata& aResponse);
  116. void
  117. HandleResponse(JS::Handle<JS::Value> aResponse);
  118. // IPDL methods are only called by IPDL.
  119. virtual void
  120. ActorDestroy(ActorDestroyReason aWhy) override;
  121. virtual bool
  122. Recv__delete__(const FileRequestResponse& aResponse) override;
  123. virtual bool
  124. RecvProgress(const uint64_t& aProgress,
  125. const uint64_t& aProgressMax) override;
  126. };
  127. } // namespace dom
  128. } // namespace mozilla
  129. #endif // mozilla_dom_filehandle_ActorsChild_h