2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
*
|
2012-05-21 04:12:37 -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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
|
|
|
|
#ifndef _nsDiskCacheStreams_h_
|
|
|
|
#define _nsDiskCacheStreams_h_
|
|
|
|
|
|
|
|
#include "nsDiskCacheBinding.h"
|
|
|
|
|
|
|
|
#include "nsCache.h"
|
|
|
|
|
|
|
|
#include "nsIInputStream.h"
|
|
|
|
#include "nsIOutputStream.h"
|
|
|
|
|
|
|
|
#include "pratom.h"
|
|
|
|
|
|
|
|
class nsDiskCacheInputStream;
|
|
|
|
class nsDiskCacheDevice;
|
|
|
|
|
2013-02-16 06:50:09 -08:00
|
|
|
class nsDiskCacheStreamIO : public nsIOutputStream {
|
2007-03-22 10:30:00 -07:00
|
|
|
public:
|
|
|
|
nsDiskCacheStreamIO(nsDiskCacheBinding * binding);
|
|
|
|
virtual ~nsDiskCacheStreamIO();
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
2013-02-16 06:50:09 -08:00
|
|
|
NS_DECL_NSIOUTPUTSTREAM
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
nsresult GetInputStream(uint32_t offset, nsIInputStream ** inputStream);
|
|
|
|
nsresult GetOutputStream(uint32_t offset, nsIOutputStream ** outputStream);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-01-26 03:23:45 -08:00
|
|
|
nsresult ClearBinding();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-03-28 12:58:49 -07:00
|
|
|
void IncrementInputStreamCount() { PR_ATOMIC_INCREMENT(&mInStreamCount); }
|
2007-03-22 10:30:00 -07:00
|
|
|
void DecrementInputStreamCount()
|
|
|
|
{
|
2011-03-28 12:58:49 -07:00
|
|
|
PR_ATOMIC_DECREMENT(&mInStreamCount);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ASSERTION(mInStreamCount >= 0, "mInStreamCount has gone negative");
|
|
|
|
}
|
|
|
|
|
2012-11-05 10:22:33 -08:00
|
|
|
size_t SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// GCC 2.95.2 requires this to be defined, although we never call it.
|
|
|
|
// and OS/2 requires that it not be private
|
|
|
|
nsDiskCacheStreamIO() { NS_NOTREACHED("oops"); }
|
2012-11-19 15:02:21 -08:00
|
|
|
|
2013-01-06 05:51:12 -08:00
|
|
|
private:
|
2012-08-09 00:09:40 -07:00
|
|
|
nsresult OpenCacheFile(int flags, PRFileDesc ** fd);
|
2013-01-06 05:51:12 -08:00
|
|
|
nsresult ReadCacheBlocks(uint32_t bufferSize);
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult FlushBufferToFile();
|
|
|
|
void UpdateFileSize();
|
|
|
|
void DeleteBuffer();
|
2013-02-16 06:50:09 -08:00
|
|
|
nsresult CloseOutputStream();
|
2013-01-06 05:51:12 -08:00
|
|
|
nsresult SeekAndTruncate(uint32_t offset);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsDiskCacheBinding * mBinding; // not an owning reference
|
|
|
|
nsDiskCacheDevice * mDevice;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t mInStreamCount;
|
2007-03-22 10:30:00 -07:00
|
|
|
PRFileDesc * mFD;
|
|
|
|
|
2013-01-06 05:51:12 -08:00
|
|
|
uint32_t mStreamEnd; // current size of data
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mBufSize; // current end of buffer
|
2007-03-22 10:30:00 -07:00
|
|
|
char * mBuffer;
|
2013-02-16 06:50:09 -08:00
|
|
|
bool mOutputStreamIsOpen;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // _nsDiskCacheStreams_h_
|