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