Dashboard.h 2.6 KB

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