Bug 1845134 - Part 4: Update existing ui-icons to use the latest source from acorn...
[gecko.git] / netwerk / base / nsDNSPrefetch.h
blob7cad00b58852f340b8b945ecf70b8ac1a3ab5c49
1 /* -*- Mode: C++; tab-width: 4; 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/. */
6 #ifndef nsDNSPrefetch_h___
7 #define nsDNSPrefetch_h___
9 #include <functional>
11 #include "nsIWeakReferenceUtils.h"
12 #include "nsString.h"
13 #include "mozilla/TimeStamp.h"
14 #include "mozilla/Attributes.h"
15 #include "mozilla/BasePrincipal.h"
17 #include "nsIDNSListener.h"
18 #include "nsIRequest.h"
19 #include "nsIDNSService.h"
21 class nsIURI;
22 class nsIDNSHTTPSSVCRecord;
24 class nsDNSPrefetch final : public nsIDNSListener {
25 ~nsDNSPrefetch() = default;
27 public:
28 NS_DECL_THREADSAFE_ISUPPORTS
29 NS_DECL_NSIDNSLISTENER
31 nsDNSPrefetch(nsIURI* aURI, mozilla::OriginAttributes& aOriginAttributes,
32 nsIRequest::TRRMode aTRRMode, nsIDNSListener* aListener,
33 bool storeTiming);
34 // For fetching HTTPS RR.
35 nsDNSPrefetch(nsIURI* aURI, mozilla::OriginAttributes& aOriginAttributes,
36 nsIRequest::TRRMode aTRRMode);
37 bool TimingsValid() const {
38 return !mStartTimestamp.IsNull() && !mEndTimestamp.IsNull();
40 // Only use the two timings if TimingsValid() returns true
41 const mozilla::TimeStamp& StartTimestamp() const { return mStartTimestamp; }
42 const mozilla::TimeStamp& EndTimestamp() const { return mEndTimestamp; }
44 static nsresult Initialize(nsIDNSService* aDNSService);
45 static nsresult Shutdown();
47 // Call one of the following methods to start the Prefetch.
48 nsresult PrefetchHigh(
49 nsIDNSService::DNSFlags = nsIDNSService::RESOLVE_DEFAULT_FLAGS);
50 nsresult PrefetchMedium(
51 nsIDNSService::DNSFlags = nsIDNSService::RESOLVE_DEFAULT_FLAGS);
52 nsresult PrefetchLow(
53 nsIDNSService::DNSFlags = nsIDNSService::RESOLVE_DEFAULT_FLAGS);
55 nsresult FetchHTTPSSVC(
56 bool aRefreshDNS, bool aPrefetch,
57 std::function<void(nsIDNSHTTPSSVCRecord*)>&& aCallback);
59 private:
60 nsCString mHostname;
61 int32_t mPort{-1};
62 mozilla::OriginAttributes mOriginAttributes;
63 bool mStoreTiming;
64 nsIRequest::TRRMode mTRRMode;
65 mozilla::TimeStamp mStartTimestamp;
66 mozilla::TimeStamp mEndTimestamp;
67 nsWeakPtr mListener;
69 nsresult Prefetch(nsIDNSService::DNSFlags flags);
72 #endif