michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nsAsyncStreamCopier_h__ michael@0: #define nsAsyncStreamCopier_h__ michael@0: michael@0: #include "nsIAsyncStreamCopier.h" michael@0: #include "nsIAsyncStreamCopier2.h" michael@0: #include "mozilla/Mutex.h" michael@0: #include "nsStreamUtils.h" michael@0: #include "nsCOMPtr.h" michael@0: michael@0: class nsIRequestObserver; michael@0: michael@0: //----------------------------------------------------------------------------- michael@0: michael@0: class nsAsyncStreamCopier : public nsIAsyncStreamCopier, nsIAsyncStreamCopier2 michael@0: { michael@0: public: michael@0: NS_DECL_THREADSAFE_ISUPPORTS michael@0: NS_DECL_NSIREQUEST michael@0: NS_DECL_NSIASYNCSTREAMCOPIER michael@0: michael@0: // nsIAsyncStreamCopier2 michael@0: // We declare it by hand instead of NS_DECL_NSIASYNCSTREAMCOPIER2 michael@0: // as nsIAsyncStreamCopier2 duplicates methods of nsIAsyncStreamCopier michael@0: NS_IMETHOD Init(nsIInputStream *aSource, michael@0: nsIOutputStream *aSink, michael@0: nsIEventTarget *aTarget, michael@0: uint32_t aChunkSize, michael@0: bool aCloseSource, michael@0: bool aCloseSink); michael@0: michael@0: nsAsyncStreamCopier(); michael@0: virtual ~nsAsyncStreamCopier(); michael@0: michael@0: //------------------------------------------------------------------------- michael@0: // these methods may be called on any thread michael@0: michael@0: bool IsComplete(nsresult *status = nullptr); michael@0: void Complete(nsresult status); michael@0: michael@0: private: michael@0: nsresult InitInternal(nsIInputStream *source, michael@0: nsIOutputStream *sink, michael@0: nsIEventTarget *target, michael@0: uint32_t chunkSize, michael@0: bool closeSource, michael@0: bool closeSink); michael@0: michael@0: static void OnAsyncCopyComplete(void *, nsresult); michael@0: michael@0: void AsyncCopyInternal(); michael@0: nsresult ApplyBufferingPolicy(); michael@0: nsIRequest* AsRequest(); michael@0: michael@0: nsCOMPtr mSource; michael@0: nsCOMPtr mSink; michael@0: michael@0: nsCOMPtr mObserver; michael@0: michael@0: nsCOMPtr mTarget; michael@0: michael@0: nsCOMPtr mCopierCtx; michael@0: michael@0: mozilla::Mutex mLock; michael@0: michael@0: nsAsyncCopyMode mMode; michael@0: uint32_t mChunkSize; michael@0: nsresult mStatus; michael@0: bool mIsPending; michael@0: bool mCloseSource; michael@0: bool mCloseSink; michael@0: bool mShouldSniffBuffering; michael@0: michael@0: friend class ProceedWithAsyncCopy; michael@0: friend class AsyncApplyBufferingPolicyEvent; michael@0: }; michael@0: michael@0: #endif // !nsAsyncStreamCopier_h__