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 "nsAutoPtr.h"
12 #include "CacheFileChunk.h"
19 class CacheOutputCloseListener
;
21 class CacheFileOutputStream
: public nsIAsyncOutputStream
22 , public nsISeekableStream
23 , public CacheFileChunkListener
25 NS_DECL_THREADSAFE_ISUPPORTS
26 NS_DECL_NSIOUTPUTSTREAM
27 NS_DECL_NSIASYNCOUTPUTSTREAM
28 NS_DECL_NSISEEKABLESTREAM
31 CacheFileOutputStream(CacheFile
*aFile
, CacheOutputCloseListener
*aCloseListener
);
33 NS_IMETHOD
OnChunkRead(nsresult aResult
, CacheFileChunk
*aChunk
);
34 NS_IMETHOD
OnChunkWritten(nsresult aResult
, CacheFileChunk
*aChunk
);
35 NS_IMETHOD
OnChunkAvailable(nsresult aResult
, uint32_t aChunkIdx
,
36 CacheFileChunk
*aChunk
);
37 NS_IMETHOD
OnChunkUpdated(CacheFileChunk
*aChunk
);
39 void NotifyCloseListener();
42 size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf
) const;
45 virtual ~CacheFileOutputStream();
47 nsresult
CloseWithStatusLocked(nsresult aStatus
);
49 void EnsureCorrectChunk(bool aReleaseOnly
);
51 void NotifyListener();
53 nsRefPtr
<CacheFile
> mFile
;
54 nsRefPtr
<CacheFileChunk
> mChunk
;
55 nsRefPtr
<CacheOutputCloseListener
> mCloseListener
;
60 nsCOMPtr
<nsIOutputStreamCallback
> mCallback
;
61 uint32_t mCallbackFlags
;
62 nsCOMPtr
<nsIEventTarget
> mCallbackTarget
;