CacheStreamControlParent.h (2591B)
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_CacheStreamControlParent_h 8 #define mozilla_dom_cache_CacheStreamControlParent_h 9 10 #include "mozilla/dom/cache/Manager.h" 11 #include "mozilla/dom/cache/PCacheStreamControlParent.h" 12 #include "mozilla/dom/cache/StreamControl.h" 13 #include "nsTObserverArray.h" 14 15 namespace mozilla::dom::cache { 16 17 class StreamList; 18 19 class CacheStreamControlParent final : public PCacheStreamControlParent, 20 public StreamControl, 21 Manager::Listener { 22 friend class PCacheStreamControlParent; 23 24 public: 25 CacheStreamControlParent(); 26 27 void SetStreamList(SafeRefPtr<StreamList> aStreamList); 28 29 // Will close all streams. May synchronously free our this, see 30 // inherited StreamControl::CloseAllReadStreams. 31 void CloseAll(); 32 33 // Implicitly called when the last stream goes away. 34 void Shutdown(); 35 36 // StreamControl methods 37 virtual void SerializeControl(CacheReadStream* aReadStreamOut) override; 38 39 virtual void SerializeStream(CacheReadStream* aReadStreamOut, 40 nsIInputStream* aStream) override; 41 42 virtual void OpenStream(const nsID& aId, 43 InputStreamResolver&& aResolver) override; 44 45 void AssertWillDelete(); 46 47 void LostIPCCleanup(SafeRefPtr<StreamList> aStreamList); 48 49 private: 50 ~CacheStreamControlParent(); 51 virtual void NoteClosedAfterForget(const nsID& aId) override; 52 53 #ifdef DEBUG 54 virtual void AssertOwningThread() override; 55 #endif 56 57 // PCacheStreamControlParent methods 58 virtual void ActorDestroy(ActorDestroyReason aReason) override; 59 60 mozilla::ipc::IPCResult RecvOpenStream(const nsID& aStreamId, 61 OpenStreamResolver&& aResolve); 62 63 mozilla::ipc::IPCResult RecvNoteClosed(const nsID& aId); 64 65 void NotifyCloseAll(); 66 67 // Cycle with StreamList via a weak-ref to us. Cleanup occurs when the actor 68 // is deleted by the PBackground manager. ActorDestroy() then calls 69 // StreamList::RemoveStreamControl() to clear the weak ref. 70 SafeRefPtr<StreamList> mStreamList; 71 72 NS_DECL_OWNINGTHREAD 73 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(CacheStreamControlParent, override) 74 }; 75 76 } // namespace mozilla::dom::cache 77 78 #endif // mozilla_dom_cache_CacheStreamControlParent_h