Source code

Revision control

Other Tools

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