No Bug, mozilla-central repo-update HSTS HPKP remote-settings tld-suffixes ct-logs...
[gecko.git] / xpcom / io / StreamBufferSource.h
blobf0a3d30eea009b413e7c674eb0d165068ad9c1a4
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
10 #include <cstddef>
11 #include "ErrorList.h"
12 #include "mozilla/MemoryReporting.h"
13 #include "mozilla/Span.h"
14 #include "nsISupportsImpl.h"
15 #include "nsString.h"
17 namespace mozilla {
19 class StreamBufferSource {
20 public:
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;
30 return NS_OK;
33 virtual bool Owning() = 0;
35 virtual size_t SizeOfExcludingThisIfUnshared(MallocSizeOf aMallocSizeOf) {
36 return SizeOfExcludingThisEvenIfShared(aMallocSizeOf);
38 size_t SizeOfIncludingThisIfUnshared(MallocSizeOf aMallocSizeOf) {
39 if (mRefCnt > 1) {
40 return 0;
42 size_t n = aMallocSizeOf(this);
43 n += SizeOfExcludingThisIfUnshared(aMallocSizeOf);
44 return n;
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);
52 return n;
55 protected:
56 virtual ~StreamBufferSource() = default;
59 } // namespace mozilla
61 #endif // mozilla_StreamBufferSource_h