|
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/. */ |
|
4 |
|
5 #ifndef CacheFileInputStream__h__ |
|
6 #define CacheFileInputStream__h__ |
|
7 |
|
8 #include "nsIAsyncInputStream.h" |
|
9 #include "nsISeekableStream.h" |
|
10 #include "nsCOMPtr.h" |
|
11 #include "nsAutoPtr.h" |
|
12 #include "CacheFileChunk.h" |
|
13 |
|
14 |
|
15 namespace mozilla { |
|
16 namespace net { |
|
17 |
|
18 class CacheFile; |
|
19 |
|
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 |
|
28 |
|
29 public: |
|
30 CacheFileInputStream(CacheFile *aFile); |
|
31 |
|
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); |
|
37 |
|
38 // Memory reporting |
|
39 size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const; |
|
40 |
|
41 private: |
|
42 virtual ~CacheFileInputStream(); |
|
43 |
|
44 void ReleaseChunk(); |
|
45 void EnsureCorrectChunk(bool aReleaseOnly); |
|
46 void CanRead(int64_t *aCanRead, const char **aBuf); |
|
47 void NotifyListener(); |
|
48 void MaybeNotifyListener(); |
|
49 |
|
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; |
|
58 |
|
59 nsCOMPtr<nsIInputStreamCallback> mCallback; |
|
60 uint32_t mCallbackFlags; |
|
61 nsCOMPtr<nsIEventTarget> mCallbackTarget; |
|
62 }; |
|
63 |
|
64 |
|
65 } // net |
|
66 } // mozilla |
|
67 |
|
68 #endif |