netwerk/base/src/nsAsyncStreamCopier.h

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:25ca980dd0c4
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
5 #ifndef nsAsyncStreamCopier_h__
6 #define nsAsyncStreamCopier_h__
7
8 #include "nsIAsyncStreamCopier.h"
9 #include "nsIAsyncStreamCopier2.h"
10 #include "mozilla/Mutex.h"
11 #include "nsStreamUtils.h"
12 #include "nsCOMPtr.h"
13
14 class nsIRequestObserver;
15
16 //-----------------------------------------------------------------------------
17
18 class nsAsyncStreamCopier : public nsIAsyncStreamCopier, nsIAsyncStreamCopier2
19 {
20 public:
21 NS_DECL_THREADSAFE_ISUPPORTS
22 NS_DECL_NSIREQUEST
23 NS_DECL_NSIASYNCSTREAMCOPIER
24
25 // nsIAsyncStreamCopier2
26 // We declare it by hand instead of NS_DECL_NSIASYNCSTREAMCOPIER2
27 // as nsIAsyncStreamCopier2 duplicates methods of nsIAsyncStreamCopier
28 NS_IMETHOD Init(nsIInputStream *aSource,
29 nsIOutputStream *aSink,
30 nsIEventTarget *aTarget,
31 uint32_t aChunkSize,
32 bool aCloseSource,
33 bool aCloseSink);
34
35 nsAsyncStreamCopier();
36 virtual ~nsAsyncStreamCopier();
37
38 //-------------------------------------------------------------------------
39 // these methods may be called on any thread
40
41 bool IsComplete(nsresult *status = nullptr);
42 void Complete(nsresult status);
43
44 private:
45 nsresult InitInternal(nsIInputStream *source,
46 nsIOutputStream *sink,
47 nsIEventTarget *target,
48 uint32_t chunkSize,
49 bool closeSource,
50 bool closeSink);
51
52 static void OnAsyncCopyComplete(void *, nsresult);
53
54 void AsyncCopyInternal();
55 nsresult ApplyBufferingPolicy();
56 nsIRequest* AsRequest();
57
58 nsCOMPtr<nsIInputStream> mSource;
59 nsCOMPtr<nsIOutputStream> mSink;
60
61 nsCOMPtr<nsIRequestObserver> mObserver;
62
63 nsCOMPtr<nsIEventTarget> mTarget;
64
65 nsCOMPtr<nsISupports> mCopierCtx;
66
67 mozilla::Mutex mLock;
68
69 nsAsyncCopyMode mMode;
70 uint32_t mChunkSize;
71 nsresult mStatus;
72 bool mIsPending;
73 bool mCloseSource;
74 bool mCloseSink;
75 bool mShouldSniffBuffering;
76
77 friend class ProceedWithAsyncCopy;
78 friend class AsyncApplyBufferingPolicyEvent;
79 };
80
81 #endif // !nsAsyncStreamCopier_h__

mercurial