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