StreamList.h (2051B)
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/. */ 6 7 #ifndef mozilla_dom_cache_StreamList_h 8 #define mozilla_dom_cache_StreamList_h 9 10 #include "mozilla/dom/SafeRefPtr.h" 11 #include "mozilla/dom/cache/Context.h" 12 #include "mozilla/dom/cache/Types.h" 13 #include "nsTArray.h" 14 15 class nsIInputStream; 16 17 namespace mozilla::dom::cache { 18 19 class CacheStreamControlParent; 20 class Manager; 21 22 class StreamList final : public Context::Activity, 23 public SafeRefCounted<StreamList> { 24 public: 25 StreamList(SafeRefPtr<Manager> aManager, SafeRefPtr<Context> aContext); 26 27 Manager& GetManager() const; 28 bool ShouldOpenStreamFor(const nsID& aId) const; 29 30 void SetStreamControl(CacheStreamControlParent* aStreamControl); 31 void RemoveStreamControl(CacheStreamControlParent* aStreamControl); 32 33 void Activate(CacheId aCacheId); 34 35 void Add(const nsID& aId, nsCOMPtr<nsIInputStream>&& aStream); 36 already_AddRefed<nsIInputStream> Extract(const nsID& aId); 37 38 void NoteClosed(const nsID& aId); 39 void NoteClosedAll(); 40 void CloseAll(); 41 42 // Context::Activity methods 43 virtual void Cancel() override; 44 virtual bool MatchesCacheId(CacheId aCacheId) const override; 45 46 private: 47 void DoStringify(nsACString& aData) override; 48 49 struct Entry { 50 explicit Entry(const nsID& aId, nsCOMPtr<nsIInputStream>&& aStream) 51 : mId(aId), mStream(std::move(aStream)) {} 52 53 nsID mId; 54 nsCOMPtr<nsIInputStream> mStream; 55 }; 56 SafeRefPtr<Manager> mManager; 57 SafeRefPtr<Context> mContext; 58 CacheId mCacheId; 59 CacheStreamControlParent* mStreamControl; 60 nsTArray<Entry> mList; 61 bool mActivated; 62 63 public: 64 ~StreamList(); 65 66 NS_DECL_OWNINGTHREAD 67 MOZ_DECLARE_REFCOUNTED_TYPENAME(cache::StreamList) 68 }; 69 70 } // namespace mozilla::dom::cache 71 72 #endif // mozilla_dom_cache_StreamList_h