Merge mozilla-central to autoland. CLOSED TREE
[gecko.git] / netwerk / base / NetworkConnectivityService.h
blob6315fb192b483efee5822d823ade8ee45536f045
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/. */
5 #ifndef NetworkConnectivityService_h_
6 #define NetworkConnectivityService_h_
8 #include "nsINetworkConnectivityService.h"
9 #include "nsCOMPtr.h"
10 #include "nsIObserver.h"
11 #include "nsIDNSListener.h"
12 #include "nsIStreamListener.h"
13 #include "mozilla/net/DNS.h"
14 #include "mozilla/Mutex.h"
16 namespace mozilla {
17 namespace net {
19 class NetworkConnectivityService : public nsINetworkConnectivityService,
20 public nsIObserver,
21 public nsIDNSListener,
22 public nsIStreamListener {
23 public:
24 NS_DECL_ISUPPORTS
25 NS_DECL_NSINETWORKCONNECTIVITYSERVICE
26 NS_DECL_NSIOBSERVER
27 NS_DECL_NSIDNSLISTENER
28 NS_DECL_NSISTREAMLISTENER
29 NS_DECL_NSIREQUESTOBSERVER
31 already_AddRefed<AddrInfo> MapNAT64IPs(AddrInfo* aNewRRSet);
33 static already_AddRefed<NetworkConnectivityService> GetSingleton();
35 private:
36 NetworkConnectivityService();
37 virtual ~NetworkConnectivityService() = default;
39 nsresult Init();
40 // Calls all the check methods
41 void PerformChecks();
43 void SaveNAT64Prefixes(nsIDNSRecord* aRecord);
45 already_AddRefed<nsIChannel> SetupIPCheckChannel(bool ipv4);
47 // Will be set to OK if the DNS request returned in IP of this type,
48 // NOT_AVAILABLE if that type of resolution is not available
49 // UNKNOWN if the check wasn't performed
50 Atomic<ConnectivityState, Relaxed> mDNSv4;
51 Atomic<ConnectivityState, Relaxed> mDNSv6;
53 Atomic<ConnectivityState, Relaxed> mIPv4;
54 Atomic<ConnectivityState, Relaxed> mIPv6;
56 Atomic<ConnectivityState, Relaxed> mNAT64;
58 nsTArray<NetAddr> mNAT64Prefixes;
60 nsCOMPtr<nsICancelable> mDNSv4Request;
61 nsCOMPtr<nsICancelable> mDNSv6Request;
62 nsCOMPtr<nsICancelable> mNAT64Request;
64 nsCOMPtr<nsIChannel> mIPv4Channel;
65 nsCOMPtr<nsIChannel> mIPv6Channel;
67 bool mCheckedNetworkId = false;
68 bool mHasNetworkId = false;
70 Mutex mLock MOZ_UNANNOTATED;
73 } // namespace net
74 } // namespace mozilla
76 #endif // NetworkConnectivityService_h_