no bug - Bumping Firefox l10n changesets r=release a=l10n-bump DONTBUILD CLOSED TREE
[gecko.git] / dom / cache / StreamControl.h
blob4a5cdfc309f55fff05bd53b531f692e29ebd9214
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_dom_cache_StreamControl_h
8 #define mozilla_dom_cache_StreamControl_h
10 #include "mozilla/dom/cache/ReadStream.h"
11 #include "mozilla/dom/cache/Types.h"
12 #include "mozilla/RefPtr.h"
13 #include "nsTObserverArray.h"
15 struct nsID;
17 namespace mozilla::dom::cache {
19 class CacheReadStream;
21 // Abstract class to help implement the stream control Child and Parent actors.
22 // This provides an interface to partly help with serialization of IPC types,
23 // but also an implementation for tracking ReadStream objects.
24 class StreamControl {
25 public:
26 // abstract interface that must be implemented by child class
27 virtual void SerializeControl(CacheReadStream* aReadStreamOut) = 0;
29 virtual void SerializeStream(CacheReadStream* aReadStreamOut,
30 nsIInputStream* aStream) = 0;
32 virtual void OpenStream(const nsID& aId, InputStreamResolver&& aResolver) = 0;
34 // inherited implementation of the ReadStream::Controllable list
36 // Begin controlling the given ReadStream. This causes a strong ref to
37 // be held by the control. The ReadStream must call NoteClosed() or
38 // ForgetReadStream() to release this ref.
39 void AddReadStream(SafeRefPtr<ReadStream::Controllable> aReadStream);
41 // Forget the ReadStream without notifying the actor.
42 void ForgetReadStream(SafeRefPtr<ReadStream::Controllable> aReadStream);
44 // Forget the ReadStream and then notify the actor the stream is closed.
45 void NoteClosed(SafeRefPtr<ReadStream::Controllable> aReadStream,
46 const nsID& aId);
48 protected:
49 ~StreamControl();
51 void CloseAllReadStreams();
53 void CloseAllReadStreamsWithoutReporting();
55 bool HasEverBeenRead() const;
57 // protected parts of the abstract interface
58 virtual void NoteClosedAfterForget(const nsID& aId) = 0;
60 #ifdef DEBUG
61 virtual void AssertOwningThread() = 0;
62 #else
63 void AssertOwningThread() {}
64 #endif
66 private:
67 // Hold strong references to ReadStream object. When the stream is closed
68 // it should call NoteClosed() or ForgetReadStream() to release this ref.
69 using ReadStreamList = nsTObserverArray<SafeRefPtr<ReadStream::Controllable>>;
70 ReadStreamList mReadStreamList;
73 } // namespace mozilla::dom::cache
75 #endif // mozilla_dom_cache_StreamControl_h