nsAsyncStreamCopier.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. #ifndef nsAsyncStreamCopier_h__
  5. #define nsAsyncStreamCopier_h__
  6. #include "nsIAsyncStreamCopier.h"
  7. #include "nsIAsyncStreamCopier2.h"
  8. #include "mozilla/Mutex.h"
  9. #include "nsStreamUtils.h"
  10. #include "nsCOMPtr.h"
  11. class nsIRequestObserver;
  12. //-----------------------------------------------------------------------------
  13. class nsAsyncStreamCopier final : public nsIAsyncStreamCopier,
  14. nsIAsyncStreamCopier2
  15. {
  16. public:
  17. NS_DECL_THREADSAFE_ISUPPORTS
  18. NS_DECL_NSIREQUEST
  19. NS_DECL_NSIASYNCSTREAMCOPIER
  20. // nsIAsyncStreamCopier2
  21. // We declare it by hand instead of NS_DECL_NSIASYNCSTREAMCOPIER2
  22. // as nsIAsyncStreamCopier2 duplicates methods of nsIAsyncStreamCopier
  23. NS_IMETHOD Init(nsIInputStream *aSource,
  24. nsIOutputStream *aSink,
  25. nsIEventTarget *aTarget,
  26. uint32_t aChunkSize,
  27. bool aCloseSource,
  28. bool aCloseSink) override;
  29. nsAsyncStreamCopier();
  30. //-------------------------------------------------------------------------
  31. // these methods may be called on any thread
  32. bool IsComplete(nsresult *status = nullptr);
  33. void Complete(nsresult status);
  34. private:
  35. virtual ~nsAsyncStreamCopier();
  36. nsresult InitInternal(nsIInputStream *source,
  37. nsIOutputStream *sink,
  38. nsIEventTarget *target,
  39. uint32_t chunkSize,
  40. bool closeSource,
  41. bool closeSink);
  42. static void OnAsyncCopyComplete(void *, nsresult);
  43. void AsyncCopyInternal();
  44. nsresult ApplyBufferingPolicy();
  45. nsIRequest* AsRequest();
  46. nsCOMPtr<nsIInputStream> mSource;
  47. nsCOMPtr<nsIOutputStream> mSink;
  48. nsCOMPtr<nsIRequestObserver> mObserver;
  49. nsCOMPtr<nsIEventTarget> mTarget;
  50. nsCOMPtr<nsISupports> mCopierCtx;
  51. mozilla::Mutex mLock;
  52. nsAsyncCopyMode mMode;
  53. uint32_t mChunkSize;
  54. nsresult mStatus;
  55. bool mIsPending;
  56. bool mCloseSource;
  57. bool mCloseSink;
  58. bool mShouldSniffBuffering;
  59. friend class ProceedWithAsyncCopy;
  60. friend class AsyncApplyBufferingPolicyEvent;
  61. };
  62. #endif // !nsAsyncStreamCopier_h__