Bug 1526591 - Remove devtools.inspector.shapesHighlighter.enabled pref. r=rcaliman
[gecko.git] / netwerk / base / PartiallySeekableInputStream.h
blob92ad4114c52271fee33c158b87e1cad2549ef508
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/. */
6 #ifndef PartiallySeekableInputStream_h
7 #define PartiallySeekableInputStream_h
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"
18 namespace mozilla {
19 namespace net {
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.
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 public:
33 NS_DECL_THREADSAFE_ISUPPORTS
34 NS_DECL_NSIINPUTSTREAM
35 NS_DECL_NSISEEKABLESTREAM
36 NS_DECL_NSITELLABLESTREAM
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
45 explicit PartiallySeekableInputStream(
46 already_AddRefed<nsIInputStream> aInputStream,
47 uint64_t aBufferSize = 4096);
49 private:
50 PartiallySeekableInputStream(
51 already_AddRefed<nsIInputStream> aClonedBaseStream,
52 PartiallySeekableInputStream* aClonedFrom);
54 ~PartiallySeekableInputStream() = default;
56 void Init();
58 template <typename M>
59 void SerializeInternal(mozilla::ipc::InputStreamParams& aParams,
60 FileDescriptorArray& aFileDescriptors,
61 bool aDelayedStart, uint32_t aMaxSize,
62 uint32_t* aSizeUsed, M* aManager);
64 nsCOMPtr<nsIInputStream> mInputStream;
66 // Raw pointers because these are just QI of mInputStream.
67 nsICloneableInputStream* mWeakCloneableInputStream;
68 nsIIPCSerializableInputStream* mWeakIPCSerializableInputStream;
69 nsIAsyncInputStream* mWeakAsyncInputStream;
70 nsIInputStreamLength* mWeakInputStreamLength;
71 nsIAsyncInputStreamLength* mWeakAsyncInputStreamLength;
73 // Protected by mutex.
74 nsCOMPtr<nsIInputStreamCallback> mAsyncWaitCallback;
76 // Protected by mutex.
77 nsCOMPtr<nsIInputStreamLengthCallback> mAsyncInputStreamLengthCallback;
79 nsTArray<char> mCachedBuffer;
81 uint64_t mBufferSize;
82 uint64_t mPos;
83 bool mClosed;
85 Mutex mMutex;
88 } // namespace net
89 } // namespace mozilla
91 #endif // PartiallySeekableInputStream_h