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