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