1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/netwerk/base/src/nsAsyncStreamCopier.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,81 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +#ifndef nsAsyncStreamCopier_h__ 1.9 +#define nsAsyncStreamCopier_h__ 1.10 + 1.11 +#include "nsIAsyncStreamCopier.h" 1.12 +#include "nsIAsyncStreamCopier2.h" 1.13 +#include "mozilla/Mutex.h" 1.14 +#include "nsStreamUtils.h" 1.15 +#include "nsCOMPtr.h" 1.16 + 1.17 +class nsIRequestObserver; 1.18 + 1.19 +//----------------------------------------------------------------------------- 1.20 + 1.21 +class nsAsyncStreamCopier : public nsIAsyncStreamCopier, nsIAsyncStreamCopier2 1.22 +{ 1.23 +public: 1.24 + NS_DECL_THREADSAFE_ISUPPORTS 1.25 + NS_DECL_NSIREQUEST 1.26 + NS_DECL_NSIASYNCSTREAMCOPIER 1.27 + 1.28 + // nsIAsyncStreamCopier2 1.29 + // We declare it by hand instead of NS_DECL_NSIASYNCSTREAMCOPIER2 1.30 + // as nsIAsyncStreamCopier2 duplicates methods of nsIAsyncStreamCopier 1.31 + NS_IMETHOD Init(nsIInputStream *aSource, 1.32 + nsIOutputStream *aSink, 1.33 + nsIEventTarget *aTarget, 1.34 + uint32_t aChunkSize, 1.35 + bool aCloseSource, 1.36 + bool aCloseSink); 1.37 + 1.38 + nsAsyncStreamCopier(); 1.39 + virtual ~nsAsyncStreamCopier(); 1.40 + 1.41 + //------------------------------------------------------------------------- 1.42 + // these methods may be called on any thread 1.43 + 1.44 + bool IsComplete(nsresult *status = nullptr); 1.45 + void Complete(nsresult status); 1.46 + 1.47 +private: 1.48 + nsresult InitInternal(nsIInputStream *source, 1.49 + nsIOutputStream *sink, 1.50 + nsIEventTarget *target, 1.51 + uint32_t chunkSize, 1.52 + bool closeSource, 1.53 + bool closeSink); 1.54 + 1.55 + static void OnAsyncCopyComplete(void *, nsresult); 1.56 + 1.57 + void AsyncCopyInternal(); 1.58 + nsresult ApplyBufferingPolicy(); 1.59 + nsIRequest* AsRequest(); 1.60 + 1.61 + nsCOMPtr<nsIInputStream> mSource; 1.62 + nsCOMPtr<nsIOutputStream> mSink; 1.63 + 1.64 + nsCOMPtr<nsIRequestObserver> mObserver; 1.65 + 1.66 + nsCOMPtr<nsIEventTarget> mTarget; 1.67 + 1.68 + nsCOMPtr<nsISupports> mCopierCtx; 1.69 + 1.70 + mozilla::Mutex mLock; 1.71 + 1.72 + nsAsyncCopyMode mMode; 1.73 + uint32_t mChunkSize; 1.74 + nsresult mStatus; 1.75 + bool mIsPending; 1.76 + bool mCloseSource; 1.77 + bool mCloseSink; 1.78 + bool mShouldSniffBuffering; 1.79 + 1.80 + friend class ProceedWithAsyncCopy; 1.81 + friend class AsyncApplyBufferingPolicyEvent; 1.82 +}; 1.83 + 1.84 +#endif // !nsAsyncStreamCopier_h__