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_
|
|
|
|
|
2013-06-23 05:03:39 -07:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsDiskCacheBinding.h"
|
|
|
|
|
|
|
|
#include "nsCache.h"
|
|
|
|
|
|
|
|
#include "nsIInputStream.h"
|
|
|
|
#include "nsIOutputStream.h"
|
|
|
|
|
2013-06-16 00:09:07 -07:00
|
|
|
#include "mozilla/Atomics.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
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:
|
2014-08-05 06:20:24 -07:00
|
|
|
explicit nsDiskCacheStreamIO(nsDiskCacheBinding * binding);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-07-18 19:24:13 -07:00
|
|
|
NS_DECL_THREADSAFE_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
|
|
|
|
2013-06-16 00:09:07 -07:00
|
|
|
void IncrementInputStreamCount() { mInStreamCount++; }
|
2007-03-22 10:30:00 -07:00
|
|
|
void DecrementInputStreamCount()
|
|
|
|
{
|
2013-06-16 00:09:07 -07:00
|
|
|
mInStreamCount--;
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ASSERTION(mInStreamCount >= 0, "mInStreamCount has gone negative");
|
|
|
|
}
|
|
|
|
|
2013-06-23 05:03:39 -07:00
|
|
|
size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf);
|
2012-11-05 10:22:33 -08:00
|
|
|
|
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:
|
2014-06-24 09:36:44 -07:00
|
|
|
virtual ~nsDiskCacheStreamIO();
|
|
|
|
|
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;
|
2013-06-16 00:09:07 -07:00
|
|
|
mozilla::Atomic<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_
|