ChildDNSService.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #ifndef mozilla_net_ChildDNSService_h
  6. #define mozilla_net_ChildDNSService_h
  7. #include "nsPIDNSService.h"
  8. #include "nsIObserver.h"
  9. #include "mozilla/Attributes.h"
  10. #include "mozilla/Mutex.h"
  11. #include "DNSRequestChild.h"
  12. #include "nsHashKeys.h"
  13. #include "nsClassHashtable.h"
  14. namespace mozilla {
  15. namespace net {
  16. class ChildDNSService final
  17. : public nsPIDNSService
  18. , public nsIObserver
  19. {
  20. public:
  21. // AsyncResolve (and CancelAsyncResolve) can be called off-main
  22. NS_DECL_THREADSAFE_ISUPPORTS
  23. NS_DECL_NSPIDNSSERVICE
  24. NS_DECL_NSIDNSSERVICE
  25. NS_DECL_NSIOBSERVER
  26. ChildDNSService();
  27. static ChildDNSService* GetSingleton();
  28. void NotifyRequestDone(DNSRequestChild *aDnsRequest);
  29. bool GetOffline() const;
  30. private:
  31. virtual ~ChildDNSService();
  32. void MOZ_ALWAYS_INLINE GetDNSRecordHashKey(const nsACString &aHost,
  33. uint32_t aFlags,
  34. const nsACString &aNetworkInterface,
  35. nsIDNSListener* aListener,
  36. nsACString &aHashKey);
  37. bool mFirstTime;
  38. bool mDisablePrefetch;
  39. // We need to remember pending dns requests to be able to cancel them.
  40. nsClassHashtable<nsCStringHashKey, nsTArray<RefPtr<DNSRequestChild>>> mPendingRequests;
  41. Mutex mPendingRequestsLock;
  42. };
  43. } // namespace net
  44. } // namespace mozilla
  45. #endif // mozilla_net_ChildDNSService_h