Bug 1842773 - Part 8: Implement ArrayBuffer.prototype.resize method. r=sfink
[gecko.git] / netwerk / cache2 / CacheFileInputStream.h
blob8280f9d224e6e99945dd0bab3954d11a008cbf30
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 CacheFileInputStream__h__
6 #define CacheFileInputStream__h__
8 #include "nsIAsyncInputStream.h"
9 #include "nsISeekableStream.h"
10 #include "nsCOMPtr.h"
11 #include "CacheFileChunk.h"
13 namespace mozilla {
14 namespace net {
16 class CacheFile;
18 class CacheFileInputStream : public nsIAsyncInputStream,
19 public nsISeekableStream,
20 public CacheFileChunkListener {
21 NS_DECL_THREADSAFE_ISUPPORTS
22 NS_DECL_NSIINPUTSTREAM
23 NS_DECL_NSIASYNCINPUTSTREAM
24 NS_DECL_NSISEEKABLESTREAM
25 NS_DECL_NSITELLABLESTREAM
27 public:
28 explicit CacheFileInputStream(CacheFile* aFile, nsISupports* aEntry,
29 bool aAlternativeData);
31 NS_IMETHOD OnChunkRead(nsresult aResult, CacheFileChunk* aChunk) override;
32 NS_IMETHOD OnChunkWritten(nsresult aResult, CacheFileChunk* aChunk) override;
33 NS_IMETHOD OnChunkAvailable(nsresult aResult, uint32_t aChunkIdx,
34 CacheFileChunk* aChunk) override;
35 NS_IMETHOD OnChunkUpdated(CacheFileChunk* aChunk) override;
37 // Memory reporting
38 size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const;
40 uint32_t GetPosition() const { return mPos; };
41 bool IsAlternativeData() const { return mAlternativeData; };
42 int64_t GetChunkIdx() const {
43 return mChunk ? static_cast<int64_t>(mChunk->Index()) : -1;
46 private:
47 virtual ~CacheFileInputStream();
49 void CloseWithStatusLocked(nsresult aStatus);
50 void CleanUp();
51 void ReleaseChunk();
52 void EnsureCorrectChunk(bool aReleaseOnly);
54 // CanRead returns negative value when output stream truncates the data before
55 // the input stream's mPos.
56 int64_t CanRead(CacheFileChunkReadHandle* aHandle);
57 void NotifyListener();
58 void MaybeNotifyListener();
60 RefPtr<CacheFile> mFile;
61 RefPtr<CacheFileChunk> mChunk;
62 int64_t mPos;
63 nsresult mStatus;
64 bool mClosed : 1;
65 bool mInReadSegments : 1;
66 bool mWaitingForUpdate : 1;
67 bool const mAlternativeData : 1;
68 int64_t mListeningForChunk;
70 nsCOMPtr<nsIInputStreamCallback> mCallback;
71 uint32_t mCallbackFlags;
72 nsCOMPtr<nsIEventTarget> mCallbackTarget;
73 // Held purely for referencing purposes
74 RefPtr<nsISupports> mCacheEntryHandle;
77 } // namespace net
78 } // namespace mozilla
80 #endif