Line data Source code
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,
32 : CacheOutputCloseListener *aCloseListener,
33 : bool aAlternativeData);
34 :
35 : NS_IMETHOD OnChunkRead(nsresult aResult, CacheFileChunk *aChunk) override;
36 : NS_IMETHOD OnChunkWritten(nsresult aResult, CacheFileChunk *aChunk) override;
37 : NS_IMETHOD OnChunkAvailable(nsresult aResult, uint32_t aChunkIdx,
38 : CacheFileChunk *aChunk) override;
39 : NS_IMETHOD OnChunkUpdated(CacheFileChunk *aChunk) override;
40 :
41 : void NotifyCloseListener();
42 2 : bool IsAlternativeData() const { return mAlternativeData; };
43 :
44 : // Memory reporting
45 : size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const;
46 :
47 : private:
48 : virtual ~CacheFileOutputStream();
49 :
50 : nsresult CloseWithStatusLocked(nsresult aStatus);
51 : void ReleaseChunk();
52 : void EnsureCorrectChunk(bool aReleaseOnly);
53 : void FillHole();
54 : void NotifyListener();
55 :
56 : RefPtr<CacheFile> mFile;
57 : RefPtr<CacheFileChunk> mChunk;
58 : RefPtr<CacheOutputCloseListener> mCloseListener;
59 : int64_t mPos;
60 : bool mClosed : 1;
61 : bool const mAlternativeData : 1;
62 : nsresult mStatus;
63 :
64 : nsCOMPtr<nsIOutputStreamCallback> mCallback;
65 : uint32_t mCallbackFlags;
66 : nsCOMPtr<nsIEventTarget> mCallbackTarget;
67 : };
68 :
69 :
70 : } // namespace net
71 : } // namespace mozilla
72 :
73 : #endif
|