Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; 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 | #ifndef nsBufferedStreams_h__ |
michael@0 | 7 | #define nsBufferedStreams_h__ |
michael@0 | 8 | |
michael@0 | 9 | #include "nsIBufferedStreams.h" |
michael@0 | 10 | #include "nsIInputStream.h" |
michael@0 | 11 | #include "nsIOutputStream.h" |
michael@0 | 12 | #include "nsISafeOutputStream.h" |
michael@0 | 13 | #include "nsISeekableStream.h" |
michael@0 | 14 | #include "nsIStreamBufferAccess.h" |
michael@0 | 15 | #include "nsCOMPtr.h" |
michael@0 | 16 | #include "nsIIPCSerializableInputStream.h" |
michael@0 | 17 | |
michael@0 | 18 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 19 | |
michael@0 | 20 | class nsBufferedStream : public nsISeekableStream |
michael@0 | 21 | { |
michael@0 | 22 | public: |
michael@0 | 23 | NS_DECL_THREADSAFE_ISUPPORTS |
michael@0 | 24 | NS_DECL_NSISEEKABLESTREAM |
michael@0 | 25 | |
michael@0 | 26 | nsBufferedStream(); |
michael@0 | 27 | virtual ~nsBufferedStream(); |
michael@0 | 28 | |
michael@0 | 29 | nsresult Close(); |
michael@0 | 30 | |
michael@0 | 31 | protected: |
michael@0 | 32 | nsresult Init(nsISupports* stream, uint32_t bufferSize); |
michael@0 | 33 | NS_IMETHOD Fill() = 0; |
michael@0 | 34 | NS_IMETHOD Flush() = 0; |
michael@0 | 35 | |
michael@0 | 36 | uint32_t mBufferSize; |
michael@0 | 37 | char* mBuffer; |
michael@0 | 38 | |
michael@0 | 39 | // mBufferStartOffset is the offset relative to the start of mStream. |
michael@0 | 40 | int64_t mBufferStartOffset; |
michael@0 | 41 | |
michael@0 | 42 | // mCursor is the read cursor for input streams, or write cursor for |
michael@0 | 43 | // output streams, and is relative to mBufferStartOffset. |
michael@0 | 44 | uint32_t mCursor; |
michael@0 | 45 | |
michael@0 | 46 | // mFillPoint is the amount available in the buffer for input streams, |
michael@0 | 47 | // or the high watermark of bytes written into the buffer, and therefore |
michael@0 | 48 | // is relative to mBufferStartOffset. |
michael@0 | 49 | uint32_t mFillPoint; |
michael@0 | 50 | |
michael@0 | 51 | nsISupports* mStream; // cast to appropriate subclass |
michael@0 | 52 | |
michael@0 | 53 | bool mBufferDisabled; |
michael@0 | 54 | bool mEOF; // True if mStream is at EOF |
michael@0 | 55 | uint8_t mGetBufferCount; |
michael@0 | 56 | }; |
michael@0 | 57 | |
michael@0 | 58 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 59 | |
michael@0 | 60 | class nsBufferedInputStream : public nsBufferedStream, |
michael@0 | 61 | public nsIBufferedInputStream, |
michael@0 | 62 | public nsIStreamBufferAccess, |
michael@0 | 63 | public nsIIPCSerializableInputStream |
michael@0 | 64 | { |
michael@0 | 65 | public: |
michael@0 | 66 | NS_DECL_ISUPPORTS_INHERITED |
michael@0 | 67 | NS_DECL_NSIINPUTSTREAM |
michael@0 | 68 | NS_DECL_NSIBUFFEREDINPUTSTREAM |
michael@0 | 69 | NS_DECL_NSISTREAMBUFFERACCESS |
michael@0 | 70 | NS_DECL_NSIIPCSERIALIZABLEINPUTSTREAM |
michael@0 | 71 | |
michael@0 | 72 | nsBufferedInputStream() : nsBufferedStream() {} |
michael@0 | 73 | virtual ~nsBufferedInputStream() {} |
michael@0 | 74 | |
michael@0 | 75 | static nsresult |
michael@0 | 76 | Create(nsISupports *aOuter, REFNSIID aIID, void **aResult); |
michael@0 | 77 | |
michael@0 | 78 | nsIInputStream* Source() { |
michael@0 | 79 | return (nsIInputStream*)mStream; |
michael@0 | 80 | } |
michael@0 | 81 | |
michael@0 | 82 | protected: |
michael@0 | 83 | NS_IMETHOD Fill(); |
michael@0 | 84 | NS_IMETHOD Flush() { return NS_OK; } // no-op for input streams |
michael@0 | 85 | }; |
michael@0 | 86 | |
michael@0 | 87 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 88 | |
michael@0 | 89 | class nsBufferedOutputStream : public nsBufferedStream, |
michael@0 | 90 | public nsISafeOutputStream, |
michael@0 | 91 | public nsIBufferedOutputStream, |
michael@0 | 92 | public nsIStreamBufferAccess |
michael@0 | 93 | { |
michael@0 | 94 | public: |
michael@0 | 95 | NS_DECL_ISUPPORTS_INHERITED |
michael@0 | 96 | NS_DECL_NSIOUTPUTSTREAM |
michael@0 | 97 | NS_DECL_NSISAFEOUTPUTSTREAM |
michael@0 | 98 | NS_DECL_NSIBUFFEREDOUTPUTSTREAM |
michael@0 | 99 | NS_DECL_NSISTREAMBUFFERACCESS |
michael@0 | 100 | |
michael@0 | 101 | nsBufferedOutputStream() : nsBufferedStream() {} |
michael@0 | 102 | virtual ~nsBufferedOutputStream() { nsBufferedOutputStream::Close(); } |
michael@0 | 103 | |
michael@0 | 104 | static nsresult |
michael@0 | 105 | Create(nsISupports *aOuter, REFNSIID aIID, void **aResult); |
michael@0 | 106 | |
michael@0 | 107 | nsIOutputStream* Sink() { |
michael@0 | 108 | return (nsIOutputStream*)mStream; |
michael@0 | 109 | } |
michael@0 | 110 | |
michael@0 | 111 | protected: |
michael@0 | 112 | NS_IMETHOD Fill() { return NS_OK; } // no-op for input streams |
michael@0 | 113 | |
michael@0 | 114 | nsCOMPtr<nsISafeOutputStream> mSafeStream; // QI'd from mStream |
michael@0 | 115 | }; |
michael@0 | 116 | |
michael@0 | 117 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 118 | |
michael@0 | 119 | #endif // nsBufferedStreams_h__ |