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 CacheFileOutputStream__h__
6 #define CacheFileOutputStream__h__
8 #include "nsIAsyncOutputStream.h"
9 #include "nsISeekableStream.h"
11 #include "CacheFileChunk.h"
17 class CacheOutputCloseListener
;
19 class CacheFileOutputStream
: public nsIAsyncOutputStream
,
20 public nsISeekableStream
,
21 public CacheFileChunkListener
{
22 NS_DECL_THREADSAFE_ISUPPORTS
23 NS_DECL_NSIOUTPUTSTREAM
24 NS_DECL_NSIASYNCOUTPUTSTREAM
25 NS_DECL_NSISEEKABLESTREAM
26 NS_DECL_NSITELLABLESTREAM
29 CacheFileOutputStream(CacheFile
* aFile
,
30 CacheOutputCloseListener
* aCloseListener
,
31 bool aAlternativeData
);
33 NS_IMETHOD
OnChunkRead(nsresult aResult
, CacheFileChunk
* aChunk
) override
;
34 NS_IMETHOD
OnChunkWritten(nsresult aResult
, CacheFileChunk
* aChunk
) override
;
35 NS_IMETHOD
OnChunkAvailable(nsresult aResult
, uint32_t aChunkIdx
,
36 CacheFileChunk
* aChunk
) override
;
37 NS_IMETHOD
OnChunkUpdated(CacheFileChunk
* aChunk
) override
;
39 void NotifyCloseListener();
40 bool IsAlternativeData() const { return mAlternativeData
; };
43 size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf
) const;
46 virtual ~CacheFileOutputStream();
48 nsresult
CloseWithStatusLocked(nsresult aStatus
);
50 void EnsureCorrectChunk(bool aReleaseOnly
);
52 void NotifyListener();
54 RefPtr
<CacheFile
> mFile
;
55 RefPtr
<CacheFileChunk
> mChunk
;
56 RefPtr
<CacheOutputCloseListener
> mCloseListener
;
59 bool const mAlternativeData
: 1;
62 nsCOMPtr
<nsIOutputStreamCallback
> mCallback
;
63 uint32_t mCallbackFlags
;
64 nsCOMPtr
<nsIEventTarget
> mCallbackTarget
;
68 } // namespace mozilla