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 | // OffsetStream.cpp |
michael@0 | 2 | |
michael@0 | 3 | #include "StdAfx.h" |
michael@0 | 4 | |
michael@0 | 5 | #include "Common/Defs.h" |
michael@0 | 6 | #include "OffsetStream.h" |
michael@0 | 7 | |
michael@0 | 8 | HRESULT COffsetOutStream::Init(IOutStream *stream, UInt64 offset) |
michael@0 | 9 | { |
michael@0 | 10 | _offset = offset; |
michael@0 | 11 | _stream = stream; |
michael@0 | 12 | return _stream->Seek(offset, STREAM_SEEK_SET, NULL); |
michael@0 | 13 | } |
michael@0 | 14 | |
michael@0 | 15 | STDMETHODIMP COffsetOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize) |
michael@0 | 16 | { |
michael@0 | 17 | return _stream->Write(data, size, processedSize); |
michael@0 | 18 | } |
michael@0 | 19 | |
michael@0 | 20 | STDMETHODIMP COffsetOutStream::Seek(Int64 offset, UInt32 seekOrigin, |
michael@0 | 21 | UInt64 *newPosition) |
michael@0 | 22 | { |
michael@0 | 23 | UInt64 absoluteNewPosition; |
michael@0 | 24 | if (seekOrigin == STREAM_SEEK_SET) |
michael@0 | 25 | offset += _offset; |
michael@0 | 26 | HRESULT result = _stream->Seek(offset, seekOrigin, &absoluteNewPosition); |
michael@0 | 27 | if (newPosition != NULL) |
michael@0 | 28 | *newPosition = absoluteNewPosition - _offset; |
michael@0 | 29 | return result; |
michael@0 | 30 | } |
michael@0 | 31 | |
michael@0 | 32 | STDMETHODIMP COffsetOutStream::SetSize(Int64 newSize) |
michael@0 | 33 | { |
michael@0 | 34 | return _stream->SetSize(_offset + newSize); |
michael@0 | 35 | } |