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;
|
2012-11-19 15:02:21 -08:00
|
|
|
class nsDiskCacheOutputStream;
|
2007-03-22 10:30:00 -07:00
|
|
|
class nsDiskCacheDevice;
|
|
|
|
|
2012-11-19 15:02:21 -08:00
|
|
|
class nsDiskCacheStreamIO : public nsISupports {
|
2007-03-22 10:30:00 -07:00
|
|
|
public:
|
|
|
|
nsDiskCacheStreamIO(nsDiskCacheBinding * binding);
|
|
|
|
virtual ~nsDiskCacheStreamIO();
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
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-11-19 15:02:21 -08:00
|
|
|
nsresult CloseOutputStream(nsDiskCacheOutputStream * outputStream);
|
|
|
|
nsresult CloseOutputStreamInternal(nsDiskCacheOutputStream * outputStream);
|
|
|
|
|
|
|
|
nsresult Write( const char * buffer,
|
|
|
|
uint32_t count,
|
|
|
|
uint32_t * bytesWritten);
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
nsresult Seek(int32_t whence, int32_t offset);
|
|
|
|
nsresult Tell(uint32_t * position);
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult SetEOF();
|
|
|
|
|
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"); }
|
|
|
|
private:
|
2012-11-19 15:02:21 -08:00
|
|
|
|
|
|
|
|
|
|
|
void Close();
|
2012-08-09 00:09:40 -07:00
|
|
|
nsresult OpenCacheFile(int flags, PRFileDesc ** fd);
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult ReadCacheBlocks();
|
|
|
|
nsresult FlushBufferToFile();
|
|
|
|
void UpdateFileSize();
|
|
|
|
void DeleteBuffer();
|
2012-11-19 15:02:21 -08:00
|
|
|
nsresult Flush();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsDiskCacheBinding * mBinding; // not an owning reference
|
|
|
|
nsDiskCacheDevice * mDevice;
|
2012-11-19 15:02:21 -08:00
|
|
|
nsDiskCacheOutputStream * mOutStream; // not an owning reference
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t mInStreamCount;
|
2012-06-05 19:08:30 -07:00
|
|
|
nsCOMPtr<nsIFile> mLocalFile;
|
2007-03-22 10:30:00 -07:00
|
|
|
PRFileDesc * mFD;
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mStreamPos; // for Output Streams
|
|
|
|
uint32_t mStreamEnd;
|
|
|
|
uint32_t mBufPos; // current mark in buffer
|
|
|
|
uint32_t mBufEnd; // current end of data in buffer
|
|
|
|
uint32_t mBufSize; // current end of buffer
|
2012-11-19 15:02:21 -08:00
|
|
|
bool mBufDirty;
|
2007-03-22 10:30:00 -07:00
|
|
|
char * mBuffer;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // _nsDiskCacheStreams_h_
|