2013-09-20 13:11:26 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef CacheFileOutputStream__h__
|
|
|
|
#define CacheFileOutputStream__h__
|
|
|
|
|
|
|
|
#include "nsIAsyncOutputStream.h"
|
|
|
|
#include "nsISeekableStream.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "CacheFileChunk.h"
|
|
|
|
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace net {
|
|
|
|
|
|
|
|
class CacheFile;
|
2013-11-21 02:20:17 +04:00
|
|
|
class CacheOutputCloseListener;
|
2013-09-20 13:11:26 +04:00
|
|
|
|
|
|
|
class CacheFileOutputStream : public nsIAsyncOutputStream
|
|
|
|
, public nsISeekableStream
|
|
|
|
, public CacheFileChunkListener
|
|
|
|
{
|
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
|
|
|
NS_DECL_NSIOUTPUTSTREAM
|
|
|
|
NS_DECL_NSIASYNCOUTPUTSTREAM
|
|
|
|
NS_DECL_NSISEEKABLESTREAM
|
|
|
|
|
|
|
|
public:
|
2016-08-17 13:58:44 +03:00
|
|
|
CacheFileOutputStream(CacheFile *aFile,
|
|
|
|
CacheOutputCloseListener *aCloseListener,
|
|
|
|
bool aAlternativeData);
|
2013-09-20 13:11:26 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
NS_IMETHOD OnChunkRead(nsresult aResult, CacheFileChunk *aChunk) override;
|
|
|
|
NS_IMETHOD OnChunkWritten(nsresult aResult, CacheFileChunk *aChunk) override;
|
2013-09-20 13:11:26 +04:00
|
|
|
NS_IMETHOD OnChunkAvailable(nsresult aResult, uint32_t aChunkIdx,
|
2015-03-21 19:28:04 +03:00
|
|
|
CacheFileChunk *aChunk) override;
|
|
|
|
NS_IMETHOD OnChunkUpdated(CacheFileChunk *aChunk) override;
|
2013-09-20 13:11:26 +04:00
|
|
|
|
2013-11-21 02:20:17 +04:00
|
|
|
void NotifyCloseListener();
|
2016-08-17 13:58:44 +03:00
|
|
|
bool IsAlternativeData() const { return mAlternativeData; };
|
2013-11-21 02:20:17 +04:00
|
|
|
|
2014-02-27 03:11:40 +04:00
|
|
|
// Memory reporting
|
|
|
|
size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const;
|
|
|
|
|
2013-09-20 13:11:26 +04:00
|
|
|
private:
|
|
|
|
virtual ~CacheFileOutputStream();
|
|
|
|
|
2014-05-19 16:21:18 +04:00
|
|
|
nsresult CloseWithStatusLocked(nsresult aStatus);
|
2013-09-20 13:11:26 +04:00
|
|
|
void ReleaseChunk();
|
|
|
|
void EnsureCorrectChunk(bool aReleaseOnly);
|
|
|
|
void FillHole();
|
|
|
|
void NotifyListener();
|
|
|
|
|
2015-10-22 13:11:00 +03:00
|
|
|
RefPtr<CacheFile> mFile;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<CacheFileChunk> mChunk;
|
|
|
|
RefPtr<CacheOutputCloseListener> mCloseListener;
|
2013-09-20 13:11:26 +04:00
|
|
|
int64_t mPos;
|
2016-08-17 13:58:44 +03:00
|
|
|
bool mClosed : 1;
|
|
|
|
bool const mAlternativeData : 1;
|
2013-09-20 13:11:26 +04:00
|
|
|
nsresult mStatus;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIOutputStreamCallback> mCallback;
|
|
|
|
uint32_t mCallbackFlags;
|
|
|
|
nsCOMPtr<nsIEventTarget> mCallbackTarget;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace net
|
|
|
|
} // namespace mozilla
|
2013-09-20 13:11:26 +04:00
|
|
|
|
|
|
|
#endif
|