|
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 CacheFileOutputStream__h__ |
|
6 #define CacheFileOutputStream__h__ |
|
7 |
|
8 #include "nsIAsyncOutputStream.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 class CacheOutputCloseListener; |
|
20 |
|
21 class CacheFileOutputStream : public nsIAsyncOutputStream |
|
22 , public nsISeekableStream |
|
23 , public CacheFileChunkListener |
|
24 { |
|
25 NS_DECL_THREADSAFE_ISUPPORTS |
|
26 NS_DECL_NSIOUTPUTSTREAM |
|
27 NS_DECL_NSIASYNCOUTPUTSTREAM |
|
28 NS_DECL_NSISEEKABLESTREAM |
|
29 |
|
30 public: |
|
31 CacheFileOutputStream(CacheFile *aFile, CacheOutputCloseListener *aCloseListener); |
|
32 |
|
33 NS_IMETHOD OnChunkRead(nsresult aResult, CacheFileChunk *aChunk); |
|
34 NS_IMETHOD OnChunkWritten(nsresult aResult, CacheFileChunk *aChunk); |
|
35 NS_IMETHOD OnChunkAvailable(nsresult aResult, uint32_t aChunkIdx, |
|
36 CacheFileChunk *aChunk); |
|
37 NS_IMETHOD OnChunkUpdated(CacheFileChunk *aChunk); |
|
38 |
|
39 void NotifyCloseListener(); |
|
40 |
|
41 // Memory reporting |
|
42 size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const; |
|
43 |
|
44 private: |
|
45 virtual ~CacheFileOutputStream(); |
|
46 |
|
47 void ReleaseChunk(); |
|
48 void EnsureCorrectChunk(bool aReleaseOnly); |
|
49 void FillHole(); |
|
50 void NotifyListener(); |
|
51 |
|
52 nsRefPtr<CacheFile> mFile; |
|
53 nsRefPtr<CacheFileChunk> mChunk; |
|
54 nsRefPtr<CacheOutputCloseListener> mCloseListener; |
|
55 int64_t mPos; |
|
56 bool mClosed; |
|
57 nsresult mStatus; |
|
58 |
|
59 nsCOMPtr<nsIOutputStreamCallback> mCallback; |
|
60 uint32_t mCallbackFlags; |
|
61 nsCOMPtr<nsIEventTarget> mCallbackTarget; |
|
62 }; |
|
63 |
|
64 |
|
65 } // net |
|
66 } // mozilla |
|
67 |
|
68 #endif |