1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/netwerk/cache/nsDiskCacheStreams.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,70 @@ 1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- 1.5 + * 1.6 + * This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 + 1.11 +#ifndef _nsDiskCacheStreams_h_ 1.12 +#define _nsDiskCacheStreams_h_ 1.13 + 1.14 +#include "mozilla/MemoryReporting.h" 1.15 +#include "nsDiskCacheBinding.h" 1.16 + 1.17 +#include "nsCache.h" 1.18 + 1.19 +#include "nsIInputStream.h" 1.20 +#include "nsIOutputStream.h" 1.21 + 1.22 +#include "mozilla/Atomics.h" 1.23 + 1.24 +class nsDiskCacheInputStream; 1.25 +class nsDiskCacheDevice; 1.26 + 1.27 +class nsDiskCacheStreamIO : public nsIOutputStream { 1.28 +public: 1.29 + nsDiskCacheStreamIO(nsDiskCacheBinding * binding); 1.30 + virtual ~nsDiskCacheStreamIO(); 1.31 + 1.32 + NS_DECL_THREADSAFE_ISUPPORTS 1.33 + NS_DECL_NSIOUTPUTSTREAM 1.34 + 1.35 + nsresult GetInputStream(uint32_t offset, nsIInputStream ** inputStream); 1.36 + nsresult GetOutputStream(uint32_t offset, nsIOutputStream ** outputStream); 1.37 + 1.38 + nsresult ClearBinding(); 1.39 + 1.40 + void IncrementInputStreamCount() { mInStreamCount++; } 1.41 + void DecrementInputStreamCount() 1.42 + { 1.43 + mInStreamCount--; 1.44 + NS_ASSERTION(mInStreamCount >= 0, "mInStreamCount has gone negative"); 1.45 + } 1.46 + 1.47 + size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf); 1.48 + 1.49 + // GCC 2.95.2 requires this to be defined, although we never call it. 1.50 + // and OS/2 requires that it not be private 1.51 + nsDiskCacheStreamIO() { NS_NOTREACHED("oops"); } 1.52 + 1.53 +private: 1.54 + nsresult OpenCacheFile(int flags, PRFileDesc ** fd); 1.55 + nsresult ReadCacheBlocks(uint32_t bufferSize); 1.56 + nsresult FlushBufferToFile(); 1.57 + void UpdateFileSize(); 1.58 + void DeleteBuffer(); 1.59 + nsresult CloseOutputStream(); 1.60 + nsresult SeekAndTruncate(uint32_t offset); 1.61 + 1.62 + nsDiskCacheBinding * mBinding; // not an owning reference 1.63 + nsDiskCacheDevice * mDevice; 1.64 + mozilla::Atomic<int32_t> mInStreamCount; 1.65 + PRFileDesc * mFD; 1.66 + 1.67 + uint32_t mStreamEnd; // current size of data 1.68 + uint32_t mBufSize; // current end of buffer 1.69 + char * mBuffer; 1.70 + bool mOutputStreamIsOpen; 1.71 +}; 1.72 + 1.73 +#endif // _nsDiskCacheStreams_h_