Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 /*
7 * The storage stream provides an internal buffer that can be filled by a
8 * client using a single output stream. One or more independent input streams
9 * can be created to read the data out non-destructively. The implementation
10 * uses a segmented buffer internally to avoid realloc'ing of large buffers,
11 * with the attendant performance loss and heap fragmentation.
12 */
14 #ifndef _nsStorageStream_h_
15 #define _nsStorageStream_h_
17 #include "nsIStorageStream.h"
18 #include "nsIOutputStream.h"
19 #include "nsMemory.h"
20 #include "mozilla/Attributes.h"
22 #define NS_STORAGESTREAM_CID \
23 { /* 669a9795-6ff7-4ed4-9150-c34ce2971b63 */ \
24 0x669a9795, \
25 0x6ff7, \
26 0x4ed4, \
27 {0x91, 0x50, 0xc3, 0x4c, 0xe2, 0x97, 0x1b, 0x63} \
28 }
30 #define NS_STORAGESTREAM_CONTRACTID "@mozilla.org/storagestream;1"
32 class nsSegmentedBuffer;
34 class nsStorageStream MOZ_FINAL : public nsIStorageStream,
35 public nsIOutputStream
36 {
37 public:
38 nsStorageStream();
40 NS_DECL_THREADSAFE_ISUPPORTS
41 NS_DECL_NSISTORAGESTREAM
42 NS_DECL_NSIOUTPUTSTREAM
44 friend class nsStorageInputStream;
46 private:
47 ~nsStorageStream();
49 nsSegmentedBuffer* mSegmentedBuffer;
50 uint32_t mSegmentSize; // All segments, except possibly the last, are of this size
51 // Must be power-of-2
52 uint32_t mSegmentSizeLog2; // log2(mSegmentSize)
53 bool mWriteInProgress; // true, if an un-Close'ed output stream exists
54 int32_t mLastSegmentNum; // Last segment # in use, -1 initially
55 char* mWriteCursor; // Pointer to next byte to be written
56 char* mSegmentEnd; // Pointer to one byte after end of segment
57 // containing the write cursor
58 uint32_t mLogicalLength; // Number of bytes written to stream
60 NS_METHOD Seek(int32_t aPosition);
61 uint32_t SegNum(uint32_t aPosition) {return aPosition >> mSegmentSizeLog2;}
62 uint32_t SegOffset(uint32_t aPosition) {return aPosition & (mSegmentSize - 1);}
63 };
65 #endif // _nsStorageStream_h_