Dashboard.h (2566B)
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 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 #ifndef nsDashboard_h__ 6 #define nsDashboard_h__ 7 8 #include "mozilla/Mutex.h" 9 #include "mozilla/net/DashboardTypes.h" 10 #include "nsIDashboard.h" 11 #include "nsIDashboardEventNotifier.h" 12 13 class nsIDNSService; 14 15 namespace mozilla { 16 namespace net { 17 18 class SocketData; 19 class HttpData; 20 class Http3ConnectionStatsData; 21 class DnsData; 22 class WebSocketRequest; 23 class ConnectionData; 24 class RcwnData; 25 26 class Dashboard final : public nsIDashboard, public nsIDashboardEventNotifier { 27 public: 28 NS_DECL_THREADSAFE_ISUPPORTS 29 NS_DECL_NSIDASHBOARD 30 NS_DECL_NSIDASHBOARDEVENTNOTIFIER 31 32 Dashboard(); 33 static const char* GetErrorString(nsresult rv); 34 nsresult GetConnectionStatus(ConnectionData* aConnectionData); 35 36 private: 37 struct LogData { 38 LogData(nsCString host, uint32_t serial, bool encryption) 39 : mHost(host), 40 mSerial(serial), 41 mMsgSent(0), 42 mMsgReceived(0), 43 mSizeSent(0), 44 mSizeReceived(0), 45 mEncrypted(encryption) {} 46 nsCString mHost; 47 uint32_t mSerial; 48 uint32_t mMsgSent; 49 uint32_t mMsgReceived; 50 uint64_t mSizeSent; 51 uint64_t mSizeReceived; 52 bool mEncrypted; 53 bool operator==(const LogData& a) const { 54 return mHost.Equals(a.mHost) && (mSerial == a.mSerial); 55 } 56 }; 57 58 struct WebSocketData { 59 WebSocketData() : lock("Dashboard.webSocketData") {} 60 uint32_t IndexOf(const nsCString& hostname, uint32_t mSerial) { 61 LogData temp(hostname, mSerial, false); 62 return data.IndexOf(temp); 63 } 64 nsTArray<LogData> data; 65 mozilla::Mutex lock MOZ_UNANNOTATED; 66 }; 67 68 bool mEnableLogging; 69 WebSocketData mWs; 70 71 private: 72 virtual ~Dashboard() = default; 73 74 nsresult GetSocketsDispatch(SocketData*); 75 nsresult GetHttpDispatch(HttpData*); 76 nsresult GetHttp3ConnectionStatsDispatch(Http3ConnectionStatsData*); 77 nsresult GetDnsInfoDispatch(DnsData*); 78 nsresult TestNewConnection(ConnectionData*); 79 80 /* Helper methods that pass the JSON to the callback function. */ 81 nsresult GetSockets(SocketData*); 82 nsresult GetHttpConnections(HttpData*); 83 nsresult GetHttp3ConnectionStats(Http3ConnectionStatsData*); 84 nsresult GetDNSCacheEntries(DnsData*); 85 nsresult GetWebSocketConnections(WebSocketRequest*); 86 nsresult GetRcwnData(RcwnData*); 87 88 nsCOMPtr<nsIDNSService> mDnsService; 89 }; 90 91 } // namespace net 92 } // namespace mozilla 93 94 #endif // nsDashboard_h__