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