StreamControl.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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_StreamControl_h
  6. #define mozilla_dom_cache_StreamControl_h
  7. #include "mozilla/dom/cache/ReadStream.h"
  8. #include "mozilla/RefPtr.h"
  9. #include "nsTObserverArray.h"
  10. struct nsID;
  11. namespace mozilla {
  12. namespace ipc {
  13. class AutoIPCStream;
  14. } // namespace ipc
  15. namespace dom {
  16. namespace cache {
  17. class CacheReadStream;
  18. // Abstract class to help implement the stream control Child and Parent actors.
  19. // This provides an interface to partly help with serialization of IPC types,
  20. // but also an implementation for tracking ReadStream objects.
  21. class StreamControl
  22. {
  23. public:
  24. // abstract interface that must be implemented by child class
  25. virtual void
  26. SerializeControl(CacheReadStream* aReadStreamOut) = 0;
  27. virtual void
  28. SerializeStream(CacheReadStream* aReadStreamOut, nsIInputStream* aStream,
  29. nsTArray<UniquePtr<mozilla::ipc::AutoIPCStream>>& aStreamCleanupList) = 0;
  30. // inherited implementation of the ReadStream::Controllable list
  31. // Begin controlling the given ReadStream. This causes a strong ref to
  32. // be held by the control. The ReadStream must call NoteClosed() or
  33. // ForgetReadStream() to release this ref.
  34. void
  35. AddReadStream(ReadStream::Controllable* aReadStream);
  36. // Forget the ReadStream without notifying the actor.
  37. void
  38. ForgetReadStream(ReadStream::Controllable* aReadStream);
  39. // Forget the ReadStream and then notify the actor the stream is closed.
  40. void
  41. NoteClosed(ReadStream::Controllable* aReadStream, const nsID& aId);
  42. protected:
  43. ~StreamControl();
  44. void
  45. CloseReadStreams(const nsID& aId);
  46. void
  47. CloseAllReadStreams();
  48. void
  49. CloseAllReadStreamsWithoutReporting();
  50. bool
  51. HasEverBeenRead() const;
  52. // protected parts of the abstract interface
  53. virtual void
  54. NoteClosedAfterForget(const nsID& aId) = 0;
  55. #ifdef DEBUG
  56. virtual void
  57. AssertOwningThread() = 0;
  58. #else
  59. void AssertOwningThread() { }
  60. #endif
  61. private:
  62. // Hold strong references to ReadStream object. When the stream is closed
  63. // it should call NoteClosed() or ForgetReadStream() to release this ref.
  64. typedef nsTObserverArray<RefPtr<ReadStream::Controllable>> ReadStreamList;
  65. ReadStreamList mReadStreamList;
  66. };
  67. } // namespace cache
  68. } // namespace dom
  69. } // namespace mozilla
  70. #endif // mozilla_dom_cache_StreamControl_h