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 file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_StreamBufferSource_h
8 #define mozilla_StreamBufferSource_h
11 #include "ErrorList.h"
12 #include "mozilla/MemoryReporting.h"
13 #include "mozilla/Span.h"
14 #include "nsISupportsImpl.h"
19 class StreamBufferSource
{
21 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(StreamBufferSource
)
23 virtual Span
<const char> Data() = 0;
25 virtual nsresult
GetData(nsACString
& aString
) {
26 Span
<const char> data
= Data();
27 if (!aString
.Assign(data
.Elements(), data
.Length(), fallible
)) {
28 return NS_ERROR_OUT_OF_MEMORY
;
33 virtual bool Owning() = 0;
35 virtual size_t SizeOfExcludingThisIfUnshared(MallocSizeOf aMallocSizeOf
) {
36 return SizeOfExcludingThisEvenIfShared(aMallocSizeOf
);
38 size_t SizeOfIncludingThisIfUnshared(MallocSizeOf aMallocSizeOf
) {
42 size_t n
= aMallocSizeOf(this);
43 n
+= SizeOfExcludingThisIfUnshared(aMallocSizeOf
);
47 virtual size_t SizeOfExcludingThisEvenIfShared(
48 MallocSizeOf aMallocSizeOf
) = 0;
49 size_t SizeOfIncludingThisEvenIfShared(MallocSizeOf aMallocSizeOf
) {
50 size_t n
= aMallocSizeOf(this);
51 n
+= SizeOfExcludingThisEvenIfShared(aMallocSizeOf
);
56 virtual ~StreamBufferSource() = default;
59 } // namespace mozilla
61 #endif // mozilla_StreamBufferSource_h