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