Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / dom / cache / StreamList.h
blob52d7691c023a1283ede65b3575efcd90959a284e
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_StreamList_h
8 #define mozilla_dom_cache_StreamList_h
10 #include "mozilla/dom/SafeRefPtr.h"
11 #include "mozilla/dom/cache/Context.h"
12 #include "mozilla/dom/cache/Types.h"
13 #include "nsTArray.h"
15 class nsIInputStream;
17 namespace mozilla::dom::cache {
19 class CacheStreamControlParent;
20 class Manager;
22 class StreamList final : public Context::Activity,
23 public SafeRefCounted<StreamList> {
24 public:
25 StreamList(SafeRefPtr<Manager> aManager, SafeRefPtr<Context> aContext);
27 Manager& GetManager() const;
28 bool ShouldOpenStreamFor(const nsID& aId) const;
30 void SetStreamControl(CacheStreamControlParent* aStreamControl);
31 void RemoveStreamControl(CacheStreamControlParent* aStreamControl);
33 void Activate(CacheId aCacheId);
35 void Add(const nsID& aId, nsCOMPtr<nsIInputStream>&& aStream);
36 already_AddRefed<nsIInputStream> Extract(const nsID& aId);
38 void NoteClosed(const nsID& aId);
39 void NoteClosedAll();
40 void CloseAll();
42 // Context::Activity methods
43 virtual void Cancel() override;
44 virtual bool MatchesCacheId(CacheId aCacheId) const override;
46 private:
47 void DoStringify(nsACString& aData) override;
49 struct Entry {
50 explicit Entry(const nsID& aId, nsCOMPtr<nsIInputStream>&& aStream)
51 : mId(aId), mStream(std::move(aStream)) {}
53 nsID mId;
54 nsCOMPtr<nsIInputStream> mStream;
56 SafeRefPtr<Manager> mManager;
57 SafeRefPtr<Context> mContext;
58 CacheId mCacheId;
59 CacheStreamControlParent* mStreamControl;
60 nsTArray<Entry> mList;
61 bool mActivated;
63 public:
64 ~StreamList();
66 NS_DECL_OWNINGTHREAD
67 MOZ_DECLARE_REFCOUNTED_TYPENAME(cache::StreamList)
70 } // namespace mozilla::dom::cache
72 #endif // mozilla_dom_cache_StreamList_h