nsDNSPrefetch.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
  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 nsDNSPrefetch_h___
  6. #define nsDNSPrefetch_h___
  7. #include "nsWeakReference.h"
  8. #include "nsString.h"
  9. #include "mozilla/TimeStamp.h"
  10. #include "mozilla/Attributes.h"
  11. #include "nsIDNSListener.h"
  12. class nsIURI;
  13. class nsIDNSService;
  14. class nsDNSPrefetch final : public nsIDNSListener
  15. {
  16. ~nsDNSPrefetch() {}
  17. public:
  18. NS_DECL_THREADSAFE_ISUPPORTS
  19. NS_DECL_NSIDNSLISTENER
  20. nsDNSPrefetch(nsIURI *aURI, nsIDNSListener *aListener, bool storeTiming);
  21. bool TimingsValid() const {
  22. return !mStartTimestamp.IsNull() && !mEndTimestamp.IsNull();
  23. }
  24. // Only use the two timings if TimingsValid() returns true
  25. const mozilla::TimeStamp& StartTimestamp() const { return mStartTimestamp; }
  26. const mozilla::TimeStamp& EndTimestamp() const { return mEndTimestamp; }
  27. static nsresult Initialize(nsIDNSService *aDNSService);
  28. static nsresult Shutdown();
  29. // Call one of the following methods to start the Prefetch.
  30. nsresult PrefetchHigh(bool refreshDNS = false);
  31. nsresult PrefetchMedium(bool refreshDNS = false);
  32. nsresult PrefetchLow(bool refreshDNS = false);
  33. private:
  34. nsCString mHostname;
  35. bool mStoreTiming;
  36. mozilla::TimeStamp mStartTimestamp;
  37. mozilla::TimeStamp mEndTimestamp;
  38. nsWeakPtr mListener;
  39. nsresult Prefetch(uint16_t flags);
  40. };
  41. #endif