NetworkConnectivityService.h (2572B)
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 NetworkConnectivityService_h_ 6 #define NetworkConnectivityService_h_ 7 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" 15 16 namespace mozilla { 17 namespace net { 18 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 30 31 already_AddRefed<AddrInfo> MapNAT64IPs(AddrInfo* aNewRRSet); 32 33 static already_AddRefed<NetworkConnectivityService> GetSingleton(); 34 35 private: 36 NetworkConnectivityService() = default; 37 virtual ~NetworkConnectivityService() = default; 38 39 nsresult Init(); 40 // Calls all the check methods 41 void PerformChecks(); 42 43 void SaveNAT64Prefixes(nsIDNSRecord* aRecord); 44 45 already_AddRefed<nsIChannel> SetupIPCheckChannel(bool ipv4); 46 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{ConnectivityState::UNKNOWN}; 51 Atomic<ConnectivityState, Relaxed> mDNSv6{ConnectivityState::UNKNOWN}; 52 Atomic<ConnectivityState, Relaxed> mDNS_HTTPS{ConnectivityState::UNKNOWN}; 53 54 Atomic<ConnectivityState, Relaxed> mIPv4{ConnectivityState::UNKNOWN}; 55 Atomic<ConnectivityState, Relaxed> mIPv6{ConnectivityState::UNKNOWN}; 56 57 Atomic<ConnectivityState, Relaxed> mNAT64{ConnectivityState::UNKNOWN}; 58 59 nsTArray<NetAddr> mNAT64Prefixes{ConnectivityState::UNKNOWN}; 60 61 nsCOMPtr<nsICancelable> mDNSv4Request; 62 nsCOMPtr<nsICancelable> mDNSv6Request; 63 nsCOMPtr<nsICancelable> mDNS_HTTPSRequest; 64 nsCOMPtr<nsICancelable> mNAT64Request; 65 66 nsCOMPtr<nsIChannel> mIPv4Channel; 67 nsCOMPtr<nsIChannel> mIPv6Channel; 68 69 bool mCheckedNetworkId = false; 70 bool mHasNetworkId = false; 71 bool mIdleStartupDone{false}; 72 73 Mutex mLock MOZ_UNANNOTATED{"nat64prefixes"}; 74 }; 75 76 } // namespace net 77 } // namespace mozilla 78 79 #endif // NetworkConnectivityService_h_