michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef CacheFileOutputStream__h__ michael@0: #define CacheFileOutputStream__h__ michael@0: michael@0: #include "nsIAsyncOutputStream.h" michael@0: #include "nsISeekableStream.h" michael@0: #include "nsCOMPtr.h" michael@0: #include "nsAutoPtr.h" michael@0: #include "CacheFileChunk.h" michael@0: michael@0: michael@0: namespace mozilla { michael@0: namespace net { michael@0: michael@0: class CacheFile; michael@0: class CacheOutputCloseListener; michael@0: michael@0: class CacheFileOutputStream : public nsIAsyncOutputStream michael@0: , public nsISeekableStream michael@0: , public CacheFileChunkListener michael@0: { michael@0: NS_DECL_THREADSAFE_ISUPPORTS michael@0: NS_DECL_NSIOUTPUTSTREAM michael@0: NS_DECL_NSIASYNCOUTPUTSTREAM michael@0: NS_DECL_NSISEEKABLESTREAM michael@0: michael@0: public: michael@0: CacheFileOutputStream(CacheFile *aFile, CacheOutputCloseListener *aCloseListener); michael@0: michael@0: NS_IMETHOD OnChunkRead(nsresult aResult, CacheFileChunk *aChunk); michael@0: NS_IMETHOD OnChunkWritten(nsresult aResult, CacheFileChunk *aChunk); michael@0: NS_IMETHOD OnChunkAvailable(nsresult aResult, uint32_t aChunkIdx, michael@0: CacheFileChunk *aChunk); michael@0: NS_IMETHOD OnChunkUpdated(CacheFileChunk *aChunk); michael@0: michael@0: void NotifyCloseListener(); michael@0: michael@0: // Memory reporting michael@0: size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const; michael@0: michael@0: private: michael@0: virtual ~CacheFileOutputStream(); michael@0: michael@0: void ReleaseChunk(); michael@0: void EnsureCorrectChunk(bool aReleaseOnly); michael@0: void FillHole(); michael@0: void NotifyListener(); michael@0: michael@0: nsRefPtr mFile; michael@0: nsRefPtr mChunk; michael@0: nsRefPtr mCloseListener; michael@0: int64_t mPos; michael@0: bool mClosed; michael@0: nsresult mStatus; michael@0: michael@0: nsCOMPtr mCallback; michael@0: uint32_t mCallbackFlags; michael@0: nsCOMPtr mCallbackTarget; michael@0: }; michael@0: michael@0: michael@0: } // net michael@0: } // mozilla michael@0: michael@0: #endif