Bug 1887774 convert from MediaEnginePrefs to AudioProcessing config in AudioInputProc...
[gecko.git] / netwerk / base / nsPreloadedStream.h
blob5c550b43e71c906edf4a7962a51687f3775b7afe
1 /* -*- Mode: C++; tab-width: 4; 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 /**
7 * This class allows you to prefix an existing nsIAsyncInputStream
8 * with a preloaded block of data known at construction time by wrapping the
9 * two data sources into a new nsIAsyncInputStream. Readers of the new
10 * stream initially see the preloaded data and when that has been exhausted
11 * they automatically read from the wrapped stream.
13 * It is used by nsHttpConnection when it has over buffered while reading from
14 * the HTTP input socket and accidentally consumed data that belongs to
15 * a different protocol via the HTTP Upgrade mechanism. That over-buffered
16 * data is preloaded together with the input socket to form the new input socket
17 * given to the new protocol handler.
20 #ifndef nsPreloadedStream_h__
21 #define nsPreloadedStream_h__
23 #include "nsIAsyncInputStream.h"
24 #include "nsCOMPtr.h"
25 #include "mozilla/Attributes.h"
26 #include "mozilla/DataMutex.h"
28 namespace mozilla {
29 namespace net {
31 class nsPreloadedStream final : public nsIAsyncInputStream,
32 public nsIInputStreamCallback {
33 public:
34 NS_DECL_THREADSAFE_ISUPPORTS
35 NS_DECL_NSIINPUTSTREAM
36 NS_DECL_NSIASYNCINPUTSTREAM
37 NS_DECL_NSIINPUTSTREAMCALLBACK
39 nsPreloadedStream(nsIAsyncInputStream* aStream, const char* data,
40 uint32_t datalen);
42 private:
43 ~nsPreloadedStream();
45 nsCOMPtr<nsIAsyncInputStream> mStream;
47 char* mBuf;
48 uint32_t mOffset;
49 uint32_t mLen;
51 DataMutex<nsCOMPtr<nsIInputStreamCallback>> mCallback;
54 } // namespace net
55 } // namespace mozilla
57 #endif