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 // CoderMixer2MT.h
3 #ifndef __CODER_MIXER2_MT_H
4 #define __CODER_MIXER2_MT_H
6 #include "CoderMixer2.h"
7 #include "../../../Common/MyCom.h"
8 #include "../../../Windows/Thread.h"
9 #include "../../Common/StreamBinder.h"
11 namespace NCoderMixer2 {
13 // CreateEvents();
14 // {
15 // SetCoderInfo()
16 // Init Streams
17 // set CompressEvent()
18 // wait CompressionCompletedEvent
19 // }
21 struct CThreadCoderInfo: public CCoderInfo
22 {
23 NWindows::NSynchronization::CAutoResetEvent *CompressEvent;
24 HANDLE ExitEvent;
25 NWindows::NSynchronization::CAutoResetEvent *CompressionCompletedEvent;
27 CObjectVector< CMyComPtr<ISequentialInStream> > InStreams;
28 CObjectVector< CMyComPtr<ISequentialOutStream> > OutStreams;
29 CRecordVector<ISequentialInStream *> InStreamPointers;
30 CRecordVector<ISequentialOutStream *> OutStreamPointers;
32 CMyComPtr<ICompressProgressInfo> Progress; // CMyComPtr
33 HRESULT Result;
35 CThreadCoderInfo(UInt32 numInStreams, UInt32 numOutStreams);
36 void SetCoderInfo(const UInt64 **inSizes,
37 const UInt64 **outSizes, ICompressProgressInfo *progress);
38 ~CThreadCoderInfo();
39 bool WaitAndCode();
40 void CreateEvents();
41 };
44 // SetBindInfo()
45 // for each coder
46 // {
47 // AddCoder[2]()
48 // }
49 //
50 // for each file
51 // {
52 // ReInit()
53 // for each coder
54 // {
55 // SetCoderInfo
56 // }
57 // SetProgressIndex(UInt32 coderIndex);
58 // Code
59 // }
62 class CCoderMixer2MT:
63 public ICompressCoder2,
64 public CCoderMixer2,
65 public CMyUnknownImp
66 {
67 MY_UNKNOWN_IMP
69 public:
70 STDMETHOD(Init)(ISequentialInStream **inStreams,
71 ISequentialOutStream **outStreams);
73 STDMETHOD(Code)(ISequentialInStream **inStreams,
74 const UInt64 **inSizes,
75 UInt32 numInStreams,
76 ISequentialOutStream **outStreams,
77 const UInt64 **outSizes,
78 UInt32 numOutStreams,
79 ICompressProgressInfo *progress);
82 CCoderMixer2MT();
83 ~CCoderMixer2MT();
84 void AddCoderCommon();
85 void AddCoder(ICompressCoder *coder);
86 void AddCoder2(ICompressCoder2 *coder);
88 void ReInit();
89 void SetCoderInfo(UInt32 coderIndex, const UInt64 **inSizes, const UInt64 **outSizes)
90 { _coderInfoVector[coderIndex].SetCoderInfo(inSizes, outSizes, NULL); }
91 void SetProgressCoderIndex(UInt32 coderIndex)
92 { _progressCoderIndex = coderIndex; }
95 UInt64 GetWriteProcessedSize(UInt32 binderIndex) const;
98 bool MyCode();
100 private:
101 CBindInfo _bindInfo;
102 CObjectVector<CStreamBinder> _streamBinders;
103 CObjectVector<CThreadCoderInfo> _coderInfoVector;
104 CRecordVector<NWindows::CThread> _threads;
105 NWindows::CThread _mainThread;
107 NWindows::NSynchronization::CAutoResetEvent _startCompressingEvent;
108 CRecordVector<HANDLE> _compressingCompletedEvents;
109 NWindows::NSynchronization::CAutoResetEvent _compressingFinishedEvent;
111 NWindows::NSynchronization::CManualResetEvent _exitEvent;
112 UInt32 _progressCoderIndex;
114 public:
115 void SetBindInfo(const CBindInfo &bindInfo);
117 };
119 }
120 #endif