Bumping manifests a=b2g-bump
[gecko.git] / netwerk / cache2 / CacheFileOutputStream.h
blob41968725828ebebe000fe10f8ab53c5eb2037a7c
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 CacheFileOutputStream__h__
6 #define CacheFileOutputStream__h__
8 #include "nsIAsyncOutputStream.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;
19 class CacheOutputCloseListener;
21 class CacheFileOutputStream : public nsIAsyncOutputStream
22 , public nsISeekableStream
23 , public CacheFileChunkListener
25 NS_DECL_THREADSAFE_ISUPPORTS
26 NS_DECL_NSIOUTPUTSTREAM
27 NS_DECL_NSIASYNCOUTPUTSTREAM
28 NS_DECL_NSISEEKABLESTREAM
30 public:
31 CacheFileOutputStream(CacheFile *aFile, CacheOutputCloseListener *aCloseListener);
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);
39 void NotifyCloseListener();
41 // Memory reporting
42 size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const;
44 private:
45 virtual ~CacheFileOutputStream();
47 nsresult CloseWithStatusLocked(nsresult aStatus);
48 void ReleaseChunk();
49 void EnsureCorrectChunk(bool aReleaseOnly);
50 void FillHole();
51 void NotifyListener();
53 nsRefPtr<CacheFile> mFile;
54 nsRefPtr<CacheFileChunk> mChunk;
55 nsRefPtr<CacheOutputCloseListener> mCloseListener;
56 int64_t mPos;
57 bool mClosed;
58 nsresult mStatus;
60 nsCOMPtr<nsIOutputStreamCallback> mCallback;
61 uint32_t mCallbackFlags;
62 nsCOMPtr<nsIEventTarget> mCallbackTarget;
66 } // net
67 } // mozilla
69 #endif