Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
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
23 {
24 NS_DECL_THREADSAFE_ISUPPORTS
25 NS_DECL_NSIINPUTSTREAM
26 NS_DECL_NSIASYNCINPUTSTREAM
27 NS_DECL_NSISEEKABLESTREAM
29 public:
30 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 private:
42 virtual ~CacheFileInputStream();
44 void ReleaseChunk();
45 void EnsureCorrectChunk(bool aReleaseOnly);
46 void CanRead(int64_t *aCanRead, const char **aBuf);
47 void NotifyListener();
48 void MaybeNotifyListener();
50 nsRefPtr<CacheFile> mFile;
51 nsRefPtr<CacheFileChunk> mChunk;
52 int64_t mPos;
53 bool mClosed;
54 nsresult mStatus;
55 bool mWaitingForUpdate;
56 int64_t mListeningForChunk;
57 bool mInReadSegments;
59 nsCOMPtr<nsIInputStreamCallback> mCallback;
60 uint32_t mCallbackFlags;
61 nsCOMPtr<nsIEventTarget> mCallbackTarget;
62 };
65 } // net
66 } // mozilla
68 #endif