Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
michael@0 | 2 | * |
michael@0 | 3 | * This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | |
michael@0 | 8 | #ifndef _nsDiskCacheStreams_h_ |
michael@0 | 9 | #define _nsDiskCacheStreams_h_ |
michael@0 | 10 | |
michael@0 | 11 | #include "mozilla/MemoryReporting.h" |
michael@0 | 12 | #include "nsDiskCacheBinding.h" |
michael@0 | 13 | |
michael@0 | 14 | #include "nsCache.h" |
michael@0 | 15 | |
michael@0 | 16 | #include "nsIInputStream.h" |
michael@0 | 17 | #include "nsIOutputStream.h" |
michael@0 | 18 | |
michael@0 | 19 | #include "mozilla/Atomics.h" |
michael@0 | 20 | |
michael@0 | 21 | class nsDiskCacheInputStream; |
michael@0 | 22 | class nsDiskCacheDevice; |
michael@0 | 23 | |
michael@0 | 24 | class nsDiskCacheStreamIO : public nsIOutputStream { |
michael@0 | 25 | public: |
michael@0 | 26 | nsDiskCacheStreamIO(nsDiskCacheBinding * binding); |
michael@0 | 27 | virtual ~nsDiskCacheStreamIO(); |
michael@0 | 28 | |
michael@0 | 29 | NS_DECL_THREADSAFE_ISUPPORTS |
michael@0 | 30 | NS_DECL_NSIOUTPUTSTREAM |
michael@0 | 31 | |
michael@0 | 32 | nsresult GetInputStream(uint32_t offset, nsIInputStream ** inputStream); |
michael@0 | 33 | nsresult GetOutputStream(uint32_t offset, nsIOutputStream ** outputStream); |
michael@0 | 34 | |
michael@0 | 35 | nsresult ClearBinding(); |
michael@0 | 36 | |
michael@0 | 37 | void IncrementInputStreamCount() { mInStreamCount++; } |
michael@0 | 38 | void DecrementInputStreamCount() |
michael@0 | 39 | { |
michael@0 | 40 | mInStreamCount--; |
michael@0 | 41 | NS_ASSERTION(mInStreamCount >= 0, "mInStreamCount has gone negative"); |
michael@0 | 42 | } |
michael@0 | 43 | |
michael@0 | 44 | size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf); |
michael@0 | 45 | |
michael@0 | 46 | // GCC 2.95.2 requires this to be defined, although we never call it. |
michael@0 | 47 | // and OS/2 requires that it not be private |
michael@0 | 48 | nsDiskCacheStreamIO() { NS_NOTREACHED("oops"); } |
michael@0 | 49 | |
michael@0 | 50 | private: |
michael@0 | 51 | nsresult OpenCacheFile(int flags, PRFileDesc ** fd); |
michael@0 | 52 | nsresult ReadCacheBlocks(uint32_t bufferSize); |
michael@0 | 53 | nsresult FlushBufferToFile(); |
michael@0 | 54 | void UpdateFileSize(); |
michael@0 | 55 | void DeleteBuffer(); |
michael@0 | 56 | nsresult CloseOutputStream(); |
michael@0 | 57 | nsresult SeekAndTruncate(uint32_t offset); |
michael@0 | 58 | |
michael@0 | 59 | nsDiskCacheBinding * mBinding; // not an owning reference |
michael@0 | 60 | nsDiskCacheDevice * mDevice; |
michael@0 | 61 | mozilla::Atomic<int32_t> mInStreamCount; |
michael@0 | 62 | PRFileDesc * mFD; |
michael@0 | 63 | |
michael@0 | 64 | uint32_t mStreamEnd; // current size of data |
michael@0 | 65 | uint32_t mBufSize; // current end of buffer |
michael@0 | 66 | char * mBuffer; |
michael@0 | 67 | bool mOutputStreamIsOpen; |
michael@0 | 68 | }; |
michael@0 | 69 | |
michael@0 | 70 | #endif // _nsDiskCacheStreams_h_ |