Bumping manifests a=b2g-bump
[gecko.git] / netwerk / cache2 / CacheFileInputStream.h
blobd920493b85996258cebc3724e355b52d3ad30d79
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 "nsAutoPtr.h"
12 #include "CacheFileChunk.h"
15 namespace mozilla {
16 namespace net {
18 class CacheFile;
20 class CacheFileInputStream : public nsIAsyncInputStream
21 , public nsISeekableStream
22 , public CacheFileChunkListener
24 NS_DECL_THREADSAFE_ISUPPORTS
25 NS_DECL_NSIINPUTSTREAM
26 NS_DECL_NSIASYNCINPUTSTREAM
27 NS_DECL_NSISEEKABLESTREAM
29 public:
30 explicit CacheFileInputStream(CacheFile *aFile);
32 NS_IMETHOD OnChunkRead(nsresult aResult, CacheFileChunk *aChunk);
33 NS_IMETHOD OnChunkWritten(nsresult aResult, CacheFileChunk *aChunk);
34 NS_IMETHOD OnChunkAvailable(nsresult aResult, uint32_t aChunkIdx,
35 CacheFileChunk *aChunk);
36 NS_IMETHOD OnChunkUpdated(CacheFileChunk *aChunk);
38 // Memory reporting
39 size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const;
41 uint32_t GetPosition() const { return mPos; };
43 private:
44 virtual ~CacheFileInputStream();
46 nsresult CloseWithStatusLocked(nsresult aStatus);
47 void ReleaseChunk();
48 void EnsureCorrectChunk(bool aReleaseOnly);
50 // CanRead returns negative value when output stream truncates the data before
51 // the input stream's mPos.
52 void CanRead(int64_t *aCanRead, const char **aBuf);
53 void NotifyListener();
54 void MaybeNotifyListener();
56 nsRefPtr<CacheFile> mFile;
57 nsRefPtr<CacheFileChunk> mChunk;
58 int64_t mPos;
59 bool mClosed;
60 nsresult mStatus;
61 bool mWaitingForUpdate;
62 int64_t mListeningForChunk;
64 nsCOMPtr<nsIInputStreamCallback> mCallback;
65 uint32_t mCallbackFlags;
66 nsCOMPtr<nsIEventTarget> mCallbackTarget;
70 } // net
71 } // mozilla
73 #endif