/src/mozilla-central/netwerk/base/PartiallySeekableInputStream.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
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/. */ |
5 | | |
6 | | #ifndef PartiallySeekableInputStream_h |
7 | | #define PartiallySeekableInputStream_h |
8 | | |
9 | | #include "mozilla/Attributes.h" |
10 | | #include "mozilla/Mutex.h" |
11 | | #include "nsCOMPtr.h" |
12 | | #include "nsIAsyncInputStream.h" |
13 | | #include "nsICloneableInputStream.h" |
14 | | #include "nsIInputStreamLength.h" |
15 | | #include "nsIIPCSerializableInputStream.h" |
16 | | #include "nsISeekableStream.h" |
17 | | |
18 | | namespace mozilla { |
19 | | namespace net { |
20 | | |
21 | | // A wrapper for making a stream seekable for the first |aBufferSize| bytes. |
22 | | // Note that this object takes the ownership of the underlying stream. |
23 | | |
24 | | class PartiallySeekableInputStream final : public nsISeekableStream |
25 | | , public nsIAsyncInputStream |
26 | | , public nsICloneableInputStream |
27 | | , public nsIIPCSerializableInputStream |
28 | | , public nsIInputStreamCallback |
29 | | , public nsIInputStreamLength |
30 | | , public nsIAsyncInputStreamLength |
31 | | , public nsIInputStreamLengthCallback |
32 | | { |
33 | | public: |
34 | | NS_DECL_THREADSAFE_ISUPPORTS |
35 | | NS_DECL_NSIINPUTSTREAM |
36 | | NS_DECL_NSISEEKABLESTREAM |
37 | | NS_DECL_NSIASYNCINPUTSTREAM |
38 | | NS_DECL_NSICLONEABLEINPUTSTREAM |
39 | | NS_DECL_NSIIPCSERIALIZABLEINPUTSTREAM |
40 | | NS_DECL_NSIINPUTSTREAMCALLBACK |
41 | | NS_DECL_NSIINPUTSTREAMLENGTH |
42 | | NS_DECL_NSIASYNCINPUTSTREAMLENGTH |
43 | | NS_DECL_NSIINPUTSTREAMLENGTHCALLBACK |
44 | | |
45 | | explicit PartiallySeekableInputStream(already_AddRefed<nsIInputStream> aInputStream, |
46 | | uint64_t aBufferSize = 4096); |
47 | | |
48 | | private: |
49 | | PartiallySeekableInputStream(already_AddRefed<nsIInputStream> aClonedBaseStream, |
50 | | PartiallySeekableInputStream* aClonedFrom); |
51 | | |
52 | 0 | ~PartiallySeekableInputStream() = default; |
53 | | |
54 | | void |
55 | | Init(); |
56 | | |
57 | | nsCOMPtr<nsIInputStream> mInputStream; |
58 | | |
59 | | // Raw pointers because these are just QI of mInputStream. |
60 | | nsICloneableInputStream* mWeakCloneableInputStream; |
61 | | nsIIPCSerializableInputStream* mWeakIPCSerializableInputStream; |
62 | | nsIAsyncInputStream* mWeakAsyncInputStream; |
63 | | nsIInputStreamLength* mWeakInputStreamLength; |
64 | | nsIAsyncInputStreamLength* mWeakAsyncInputStreamLength; |
65 | | |
66 | | // Protected by mutex. |
67 | | nsCOMPtr<nsIInputStreamCallback> mAsyncWaitCallback; |
68 | | |
69 | | // Protected by mutex. |
70 | | nsCOMPtr<nsIInputStreamLengthCallback> mAsyncInputStreamLengthCallback; |
71 | | |
72 | | nsTArray<char> mCachedBuffer; |
73 | | |
74 | | uint64_t mBufferSize; |
75 | | uint64_t mPos; |
76 | | bool mClosed; |
77 | | |
78 | | Mutex mMutex; |
79 | | }; |
80 | | |
81 | | } // net namespace |
82 | | } // mozilla namespace |
83 | | |
84 | | #endif // PartiallySeekableInputStream_h |