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___
11 #include "nsIWeakReferenceUtils.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"
22 class nsIDNSHTTPSSVCRecord
;
24 class nsDNSPrefetch final
: public nsIDNSListener
{
25 ~nsDNSPrefetch() = default;
28 NS_DECL_THREADSAFE_ISUPPORTS
29 NS_DECL_NSIDNSLISTENER
31 nsDNSPrefetch(nsIURI
* aURI
, mozilla::OriginAttributes
& aOriginAttributes
,
32 nsIRequest::TRRMode aTRRMode
, nsIDNSListener
* aListener
,
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
);
53 nsIDNSService::DNSFlags
= nsIDNSService::RESOLVE_DEFAULT_FLAGS
);
55 nsresult
FetchHTTPSSVC(
56 bool aRefreshDNS
, bool aPrefetch
,
57 std::function
<void(nsIDNSHTTPSSVCRecord
*)>&& aCallback
);
62 mozilla::OriginAttributes mOriginAttributes
;
64 nsIRequest::TRRMode mTRRMode
;
65 mozilla::TimeStamp mStartTimestamp
;
66 mozilla::TimeStamp mEndTimestamp
;
69 nsresult
Prefetch(nsIDNSService::DNSFlags flags
);