Source code

Revision control

Other Tools

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 final : public nsIAsyncStreamCopier,
19
nsIAsyncStreamCopier2 {
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, nsIOutputStream* aSink,
29
nsIEventTarget* aTarget, uint32_t aChunkSize,
30
bool aCloseSource, bool aCloseSink) override;
31
32
nsAsyncStreamCopier();
33
34
//-------------------------------------------------------------------------
35
// these methods may be called on any thread
36
37
bool IsComplete(nsresult* status = nullptr);
38
void Complete(nsresult status);
39
40
private:
41
virtual ~nsAsyncStreamCopier();
42
43
nsresult InitInternal(nsIInputStream* source, nsIOutputStream* sink,
44
nsIEventTarget* target, uint32_t chunkSize,
45
bool closeSource, bool closeSink);
46
47
static void OnAsyncCopyComplete(void*, nsresult);
48
49
void AsyncCopyInternal();
50
nsresult ApplyBufferingPolicy();
51
nsIRequest* AsRequest();
52
53
nsCOMPtr<nsIInputStream> mSource;
54
nsCOMPtr<nsIOutputStream> mSink;
55
56
nsCOMPtr<nsIRequestObserver> mObserver;
57
58
nsCOMPtr<nsIEventTarget> mTarget;
59
60
nsCOMPtr<nsISupports> mCopierCtx;
61
62
mozilla::Mutex mLock;
63
64
nsAsyncCopyMode mMode;
65
uint32_t mChunkSize;
66
nsresult mStatus;
67
bool mIsPending;
68
bool mCloseSource;
69
bool mCloseSink;
70
bool mShouldSniffBuffering;
71
72
friend class ProceedWithAsyncCopy;
73
friend class AsyncApplyBufferingPolicyEvent;
74
};
75
76
#endif // !nsAsyncStreamCopier_h__