tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

WebrtcGlobalStatsHistory.h (3020B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
      3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 #pragma once
      6 
      7 #include "domstubs.h"
      8 #include "mozilla/LinkedList.h"
      9 #include "mozilla/UniquePtr.h"
     10 #include "mozilla/dom/BindingDeclarations.h"
     11 #include "mozilla/dom/RTCStatsReportBinding.h"
     12 #include "nsDOMNavigationTiming.h"
     13 #include "nsHashKeys.h"
     14 
     15 namespace mozilla::dom {
     16 class WebrtcGlobalStatisticsHistoryCallback;
     17 struct RTCStatsReportInternal;
     18 
     19 struct WebrtcGlobalStatsHistory {
     20  // History preferences
     21  struct Pref {
     22    static auto Enabled() -> bool;
     23    static auto PollIntervalMs() -> uint32_t;
     24    static auto StorageWindowS() -> uint32_t;
     25    static auto PruneAfterM() -> uint32_t;
     26    static auto ClosedStatsToRetain() -> uint32_t;
     27    Pref() = delete;
     28    ~Pref() = delete;
     29  };
     30 
     31  struct Entry {
     32    NS_INLINE_DECL_THREADSAFE_REFCOUNTING(Entry)
     33    // We need to wrap the report in an element
     34    struct ReportElement : public LinkedListElement<ReportElement> {
     35      UniquePtr<RTCStatsReportInternal> report;
     36      auto Timestamp() const -> DOMHighResTimeStamp;
     37      virtual ~ReportElement() = default;
     38    };
     39    // And likewise for the SDP history
     40    struct SdpElement : public LinkedListElement<SdpElement> {
     41      RTCSdpHistoryEntryInternal sdp;
     42      auto Timestamp() const -> DOMHighResTimeStamp;
     43      virtual ~SdpElement() = default;
     44    };
     45 
     46    explicit Entry(const nsString& aPcid, const bool aIsLongTermStatsDisabled)
     47        : mPcid(aPcid), mIsLongTermStatsDisabled(aIsLongTermStatsDisabled) {}
     48 
     49    nsString mPcid;
     50    AutoCleanLinkedList<ReportElement> mReports;
     51    AutoCleanLinkedList<SdpElement> mSdp;
     52    bool mIsLongTermStatsDisabled;
     53    bool mIsClosed = false;
     54 
     55    auto Since(const Maybe<DOMHighResTimeStamp>& aAfter) const
     56        -> nsTArray<RTCStatsReportInternal>;
     57    auto SdpSince(const Maybe<DOMHighResTimeStamp>& aAfter) const
     58        -> RTCSdpHistoryInternal;
     59 
     60    static auto MakeReportElement(UniquePtr<RTCStatsReportInternal> aReport)
     61        -> ReportElement*;
     62    static auto MakeSdpElementsSince(
     63        Sequence<RTCSdpHistoryEntryInternal>&& aSdpHistory,
     64        const Maybe<DOMHighResTimeStamp>& aSdpAfter)
     65        -> AutoCleanLinkedList<SdpElement>;
     66    auto Prune(const DOMHighResTimeStamp aBefore) -> void;
     67 
     68   private:
     69    virtual ~Entry() = default;
     70  };
     71  using StatsMap = nsTHashMap<nsStringHashKey, RefPtr<Entry> >;
     72  static auto InitHistory(const nsAString& aPcId,
     73                          const bool aIsLongTermStatsDisabled) -> void;
     74  static auto Record(UniquePtr<RTCStatsReportInternal> aReport) -> void;
     75  static auto CloseHistory(const nsAString& aPcId) -> void;
     76  static auto GetHistory(const nsAString& aPcId) -> Maybe<RefPtr<Entry> >;
     77  static auto Clear() -> void;
     78  static auto PcIds() -> dom::Sequence<nsString>;
     79 
     80  WebrtcGlobalStatsHistory() = delete;
     81 
     82 private:
     83  static auto Get() -> StatsMap&;
     84 };
     85 }  // namespace mozilla::dom