|
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/. */ |
|
6 |
|
7 |
|
8 #ifndef _nsDiskCacheStreams_h_ |
|
9 #define _nsDiskCacheStreams_h_ |
|
10 |
|
11 #include "mozilla/MemoryReporting.h" |
|
12 #include "nsDiskCacheBinding.h" |
|
13 |
|
14 #include "nsCache.h" |
|
15 |
|
16 #include "nsIInputStream.h" |
|
17 #include "nsIOutputStream.h" |
|
18 |
|
19 #include "mozilla/Atomics.h" |
|
20 |
|
21 class nsDiskCacheInputStream; |
|
22 class nsDiskCacheDevice; |
|
23 |
|
24 class nsDiskCacheStreamIO : public nsIOutputStream { |
|
25 public: |
|
26 nsDiskCacheStreamIO(nsDiskCacheBinding * binding); |
|
27 virtual ~nsDiskCacheStreamIO(); |
|
28 |
|
29 NS_DECL_THREADSAFE_ISUPPORTS |
|
30 NS_DECL_NSIOUTPUTSTREAM |
|
31 |
|
32 nsresult GetInputStream(uint32_t offset, nsIInputStream ** inputStream); |
|
33 nsresult GetOutputStream(uint32_t offset, nsIOutputStream ** outputStream); |
|
34 |
|
35 nsresult ClearBinding(); |
|
36 |
|
37 void IncrementInputStreamCount() { mInStreamCount++; } |
|
38 void DecrementInputStreamCount() |
|
39 { |
|
40 mInStreamCount--; |
|
41 NS_ASSERTION(mInStreamCount >= 0, "mInStreamCount has gone negative"); |
|
42 } |
|
43 |
|
44 size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf); |
|
45 |
|
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"); } |
|
49 |
|
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); |
|
58 |
|
59 nsDiskCacheBinding * mBinding; // not an owning reference |
|
60 nsDiskCacheDevice * mDevice; |
|
61 mozilla::Atomic<int32_t> mInStreamCount; |
|
62 PRFileDesc * mFD; |
|
63 |
|
64 uint32_t mStreamEnd; // current size of data |
|
65 uint32_t mBufSize; // current end of buffer |
|
66 char * mBuffer; |
|
67 bool mOutputStreamIsOpen; |
|
68 }; |
|
69 |
|
70 #endif // _nsDiskCacheStreams_h_ |