WebTransportEventService.h (1925B)
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_net_WebTransportEventService_h 8 #define mozilla_net_WebTransportEventService_h 9 10 #include "mozilla/AlreadyAddRefed.h" 11 #include "nsIWebTransportEventService.h" 12 #include "nsCOMPtr.h" 13 #include "nsTArray.h" 14 #include "nsIObserver.h" 15 #include "nsISupportsImpl.h" 16 #include "nsTHashMap.h" 17 #include "nsClassHashtable.h" 18 #include "nsHashKeys.h" 19 20 namespace mozilla { 21 namespace net { 22 23 class WebTransportEventService final : public nsIWebTransportEventService, 24 public nsIObserver { 25 public: 26 NS_DECL_THREADSAFE_ISUPPORTS 27 NS_DECL_NSIOBSERVER 28 NS_DECL_NSIWEBTRANSPORTEVENTSERVICE 29 30 static already_AddRefed<WebTransportEventService> GetOrCreate(); 31 32 using WebTransportEventListeners = 33 nsTArray<nsCOMPtr<nsIWebTransportEventListener>>; 34 35 void GetListeners(uint64_t aInnerWindowID, 36 WebTransportEventListeners& aListeners) const; 37 38 void WebTransportSessionCreated(uint64_t aInnerWindowID, 39 uint64_t aHttpChannelId); 40 41 void WebTransportSessionClosed(uint64_t aInnerWindowID, 42 uint64_t aHttpChannelId, uint32_t aCode, 43 const nsAString& aReason); 44 45 private: 46 WebTransportEventService(); 47 ~WebTransportEventService(); 48 49 bool HasListeners() const; 50 51 struct WindowListener { 52 WebTransportEventListeners mListeners; 53 }; 54 55 void Shutdown(); 56 57 nsClassHashtable<nsUint64HashKey, WindowListener> mWindows; 58 59 uint64_t mCountListeners; 60 }; 61 62 } // namespace net 63 } // namespace mozilla 64 65 #endif // mozilla_net_WebTransportEventService_h