netwerk/base/src/nsAsyncStreamCopier.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 #ifndef nsAsyncStreamCopier_h__
michael@0 6 #define nsAsyncStreamCopier_h__
michael@0 7
michael@0 8 #include "nsIAsyncStreamCopier.h"
michael@0 9 #include "nsIAsyncStreamCopier2.h"
michael@0 10 #include "mozilla/Mutex.h"
michael@0 11 #include "nsStreamUtils.h"
michael@0 12 #include "nsCOMPtr.h"
michael@0 13
michael@0 14 class nsIRequestObserver;
michael@0 15
michael@0 16 //-----------------------------------------------------------------------------
michael@0 17
michael@0 18 class nsAsyncStreamCopier : public nsIAsyncStreamCopier, nsIAsyncStreamCopier2
michael@0 19 {
michael@0 20 public:
michael@0 21 NS_DECL_THREADSAFE_ISUPPORTS
michael@0 22 NS_DECL_NSIREQUEST
michael@0 23 NS_DECL_NSIASYNCSTREAMCOPIER
michael@0 24
michael@0 25 // nsIAsyncStreamCopier2
michael@0 26 // We declare it by hand instead of NS_DECL_NSIASYNCSTREAMCOPIER2
michael@0 27 // as nsIAsyncStreamCopier2 duplicates methods of nsIAsyncStreamCopier
michael@0 28 NS_IMETHOD Init(nsIInputStream *aSource,
michael@0 29 nsIOutputStream *aSink,
michael@0 30 nsIEventTarget *aTarget,
michael@0 31 uint32_t aChunkSize,
michael@0 32 bool aCloseSource,
michael@0 33 bool aCloseSink);
michael@0 34
michael@0 35 nsAsyncStreamCopier();
michael@0 36 virtual ~nsAsyncStreamCopier();
michael@0 37
michael@0 38 //-------------------------------------------------------------------------
michael@0 39 // these methods may be called on any thread
michael@0 40
michael@0 41 bool IsComplete(nsresult *status = nullptr);
michael@0 42 void Complete(nsresult status);
michael@0 43
michael@0 44 private:
michael@0 45 nsresult InitInternal(nsIInputStream *source,
michael@0 46 nsIOutputStream *sink,
michael@0 47 nsIEventTarget *target,
michael@0 48 uint32_t chunkSize,
michael@0 49 bool closeSource,
michael@0 50 bool closeSink);
michael@0 51
michael@0 52 static void OnAsyncCopyComplete(void *, nsresult);
michael@0 53
michael@0 54 void AsyncCopyInternal();
michael@0 55 nsresult ApplyBufferingPolicy();
michael@0 56 nsIRequest* AsRequest();
michael@0 57
michael@0 58 nsCOMPtr<nsIInputStream> mSource;
michael@0 59 nsCOMPtr<nsIOutputStream> mSink;
michael@0 60
michael@0 61 nsCOMPtr<nsIRequestObserver> mObserver;
michael@0 62
michael@0 63 nsCOMPtr<nsIEventTarget> mTarget;
michael@0 64
michael@0 65 nsCOMPtr<nsISupports> mCopierCtx;
michael@0 66
michael@0 67 mozilla::Mutex mLock;
michael@0 68
michael@0 69 nsAsyncCopyMode mMode;
michael@0 70 uint32_t mChunkSize;
michael@0 71 nsresult mStatus;
michael@0 72 bool mIsPending;
michael@0 73 bool mCloseSource;
michael@0 74 bool mCloseSink;
michael@0 75 bool mShouldSniffBuffering;
michael@0 76
michael@0 77 friend class ProceedWithAsyncCopy;
michael@0 78 friend class AsyncApplyBufferingPolicyEvent;
michael@0 79 };
michael@0 80
michael@0 81 #endif // !nsAsyncStreamCopier_h__

mercurial