Bug 1839316: part 5) Guard the "fetchpriority" attribute behind a pref. r=kershaw...
[gecko.git] / xpcom / io / InputStreamLengthHelper.h
blob1f44c70fe3b06ad7f0316896d373e25fbc31c42f
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_InputStreamLengthHelper_h
8 #define mozilla_InputStreamLengthHelper_h
10 #include <functional>
12 #include "nsISupportsImpl.h"
13 #include "nsIInputStreamLength.h"
14 #include "nsThreadUtils.h"
16 class nsIInputStream;
18 namespace mozilla {
20 // This class helps to retrieve the stream's length.
22 class InputStreamLengthHelper final : public Runnable,
23 public nsIInputStreamLengthCallback {
24 public:
25 NS_DECL_ISUPPORTS_INHERITED
27 // This is one of the 2 entry points of this class. It returns false if the
28 // length cannot be taken synchronously.
29 static bool GetSyncLength(nsIInputStream* aStream, int64_t* aLength);
31 // This is one of the 2 entry points of this class. The callback is executed
32 // asynchronously when the length is known.
33 static void GetAsyncLength(
34 nsIInputStream* aStream,
35 const std::function<void(int64_t aLength)>& aCallback);
37 private:
38 NS_DECL_NSIINPUTSTREAMLENGTHCALLBACK
40 InputStreamLengthHelper(
41 nsIInputStream* aStream,
42 const std::function<void(int64_t aLength)>& aCallback);
44 ~InputStreamLengthHelper();
46 NS_IMETHOD
47 Run() override;
49 void ExecCallback(int64_t aLength);
51 nsCOMPtr<nsIInputStream> mStream;
52 std::function<void(int64_t aLength)> mCallback;
55 } // namespace mozilla
57 #endif // mozilla_InputStreamLengthHelper_h