2013-09-20 02:11:26 -07: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 CacheFileInputStream__h__
|
|
|
|
#define CacheFileInputStream__h__
|
|
|
|
|
|
|
|
#include "nsIAsyncInputStream.h"
|
|
|
|
#include "nsISeekableStream.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "CacheFileChunk.h"
|
|
|
|
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace net {
|
|
|
|
|
|
|
|
class CacheFile;
|
|
|
|
|
|
|
|
class CacheFileInputStream : public nsIAsyncInputStream
|
|
|
|
, public nsISeekableStream
|
|
|
|
, public CacheFileChunkListener
|
|
|
|
{
|
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
|
|
|
NS_DECL_NSIINPUTSTREAM
|
|
|
|
NS_DECL_NSIASYNCINPUTSTREAM
|
|
|
|
NS_DECL_NSISEEKABLESTREAM
|
|
|
|
|
|
|
|
public:
|
2014-08-05 06:20:24 -07:00
|
|
|
explicit CacheFileInputStream(CacheFile *aFile);
|
2013-09-20 02:11:26 -07:00
|
|
|
|
2015-03-21 09:28:04 -07:00
|
|
|
NS_IMETHOD OnChunkRead(nsresult aResult, CacheFileChunk *aChunk) override;
|
|
|
|
NS_IMETHOD OnChunkWritten(nsresult aResult, CacheFileChunk *aChunk) override;
|
2013-09-20 02:11:26 -07:00
|
|
|
NS_IMETHOD OnChunkAvailable(nsresult aResult, uint32_t aChunkIdx,
|
2015-03-21 09:28:04 -07:00
|
|
|
CacheFileChunk *aChunk) override;
|
|
|
|
NS_IMETHOD OnChunkUpdated(CacheFileChunk *aChunk) override;
|
2013-09-20 02:11:26 -07:00
|
|
|
|
2014-02-26 15:11:40 -08:00
|
|
|
// Memory reporting
|
|
|
|
size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const;
|
|
|
|
|
2014-05-02 11:15:14 -07:00
|
|
|
uint32_t GetPosition() const { return mPos; };
|
|
|
|
|
2013-09-20 02:11:26 -07:00
|
|
|
private:
|
|
|
|
virtual ~CacheFileInputStream();
|
|
|
|
|
2014-05-19 05:21:18 -07:00
|
|
|
nsresult CloseWithStatusLocked(nsresult aStatus);
|
2013-09-20 02:11:26 -07:00
|
|
|
void ReleaseChunk();
|
|
|
|
void EnsureCorrectChunk(bool aReleaseOnly);
|
2014-07-09 22:59:29 -07:00
|
|
|
|
|
|
|
// CanRead returns negative value when output stream truncates the data before
|
|
|
|
// the input stream's mPos.
|
2013-09-20 02:11:26 -07:00
|
|
|
void CanRead(int64_t *aCanRead, const char **aBuf);
|
|
|
|
void NotifyListener();
|
|
|
|
void MaybeNotifyListener();
|
|
|
|
|
2015-10-22 03:11:00 -07:00
|
|
|
RefPtr<CacheFile> mFile;
|
2015-10-17 22:24:48 -07:00
|
|
|
RefPtr<CacheFileChunk> mChunk;
|
2013-09-20 02:11:26 -07:00
|
|
|
int64_t mPos;
|
|
|
|
bool mClosed;
|
|
|
|
nsresult mStatus;
|
|
|
|
bool mWaitingForUpdate;
|
|
|
|
int64_t mListeningForChunk;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIInputStreamCallback> mCallback;
|
|
|
|
uint32_t mCallbackFlags;
|
|
|
|
nsCOMPtr<nsIEventTarget> mCallbackTarget;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-07-13 08:25:42 -07:00
|
|
|
} // namespace net
|
|
|
|
} // namespace mozilla
|
2013-09-20 02:11:26 -07:00
|
|
|
|
|
|
|
#endif
|