Bug 1842773 - Part 8: Implement ArrayBuffer.prototype.resize method. r=sfink
[gecko.git] / netwerk / cache2 / CacheFileOutputStream.h
blob4d1fc5e4b77de3a4821754febac5ed884ad066b4
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"
10 #include "nsCOMPtr.h"
11 #include "CacheFileChunk.h"
13 namespace mozilla {
14 namespace net {
16 class CacheFile;
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
28 public:
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; };
42 // Memory reporting
43 size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const;
45 private:
46 virtual ~CacheFileOutputStream();
48 nsresult CloseWithStatusLocked(nsresult aStatus);
49 void ReleaseChunk();
50 void EnsureCorrectChunk(bool aReleaseOnly);
51 void FillHole();
52 void NotifyListener();
54 RefPtr<CacheFile> mFile;
55 RefPtr<CacheFileChunk> mChunk;
56 RefPtr<CacheOutputCloseListener> mCloseListener;
57 int64_t mPos;
58 bool mClosed : 1;
59 bool const mAlternativeData : 1;
60 nsresult mStatus;
62 nsCOMPtr<nsIOutputStreamCallback> mCallback;
63 uint32_t mCallbackFlags;
64 nsCOMPtr<nsIEventTarget> mCallbackTarget;
67 } // namespace net
68 } // namespace mozilla
70 #endif