Bug 1845134 - Part 4: Update existing ui-icons to use the latest source from acorn...
[gecko.git] / netwerk / base / nsAsyncStreamCopier.h
blob120218c3c760b8250e3cbc142d99eef2c075c9c6
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/. */
5 #ifndef nsAsyncStreamCopier_h__
6 #define nsAsyncStreamCopier_h__
8 #include "nsIAsyncStreamCopier.h"
9 #include "nsIAsyncStreamCopier2.h"
10 #include "mozilla/Mutex.h"
11 #include "nsStreamUtils.h"
12 #include "nsCOMPtr.h"
14 class nsIRequestObserver;
16 //-----------------------------------------------------------------------------
18 class nsAsyncStreamCopier final : public nsIAsyncStreamCopier,
19 nsIAsyncStreamCopier2 {
20 public:
21 NS_DECL_THREADSAFE_ISUPPORTS
22 NS_DECL_NSIREQUEST
23 NS_DECL_NSIASYNCSTREAMCOPIER
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, nsIOutputStream* aSink,
29 nsIEventTarget* aTarget, uint32_t aChunkSize,
30 bool aCloseSource, bool aCloseSink) override;
32 nsAsyncStreamCopier();
34 //-------------------------------------------------------------------------
35 // these methods may be called on any thread
37 bool IsComplete(nsresult* status = nullptr);
38 void Complete(nsresult status);
40 private:
41 virtual ~nsAsyncStreamCopier();
43 nsresult InitInternal(nsIInputStream* source, nsIOutputStream* sink,
44 nsIEventTarget* target, uint32_t chunkSize,
45 bool closeSource, bool closeSink);
47 static void OnAsyncCopyComplete(void*, nsresult);
49 void AsyncCopyInternal();
50 nsresult ApplyBufferingPolicy();
51 nsIRequest* AsRequest();
53 nsCOMPtr<nsIInputStream> mSource;
54 nsCOMPtr<nsIOutputStream> mSink;
56 nsCOMPtr<nsIRequestObserver> mObserver;
58 nsCOMPtr<nsIEventTarget> mTarget;
60 nsCOMPtr<nsISupports> mCopierCtx MOZ_GUARDED_BY(mLock);
62 mozilla::Mutex mLock{"nsAsyncStreamCopier.mLock"};
64 nsAsyncCopyMode mMode{NS_ASYNCCOPY_VIA_READSEGMENTS};
65 uint32_t mChunkSize; // only modified in Init
66 nsresult mStatus MOZ_GUARDED_BY(mLock){NS_OK};
67 bool mIsPending MOZ_GUARDED_BY(mLock){false};
68 bool mCloseSource MOZ_GUARDED_BY(mLock){false};
69 bool mCloseSink MOZ_GUARDED_BY(mLock){false};
70 bool mShouldSniffBuffering{false}; // only modified in Init
72 friend class ProceedWithAsyncCopy;
73 friend class AsyncApplyBufferingPolicyEvent;
76 #endif // !nsAsyncStreamCopier_h__