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 "nsIWeakReferenceUtils.h"
11 #include "mozilla/TimeStamp.h"
12 #include "mozilla/Attributes.h"
13 #include "mozilla/BasePrincipal.h"
15 #include "nsIDNSListener.h"
20 class nsDNSPrefetch final
: public nsIDNSListener
{
21 ~nsDNSPrefetch() = default;
24 NS_DECL_THREADSAFE_ISUPPORTS
25 NS_DECL_NSIDNSLISTENER
27 nsDNSPrefetch(nsIURI
* aURI
, mozilla::OriginAttributes
& aOriginAttributes
,
28 nsIDNSListener
* aListener
, bool storeTiming
);
29 bool TimingsValid() const {
30 return !mStartTimestamp
.IsNull() && !mEndTimestamp
.IsNull();
32 // Only use the two timings if TimingsValid() returns true
33 const mozilla::TimeStamp
& StartTimestamp() const { return mStartTimestamp
; }
34 const mozilla::TimeStamp
& EndTimestamp() const { return mEndTimestamp
; }
36 static nsresult
Initialize(nsIDNSService
* aDNSService
);
37 static nsresult
Shutdown();
39 // Call one of the following methods to start the Prefetch.
40 nsresult
PrefetchHigh(bool refreshDNS
= false);
41 nsresult
PrefetchMedium(bool refreshDNS
= false);
42 nsresult
PrefetchLow(bool refreshDNS
= false);
47 mozilla::OriginAttributes mOriginAttributes
;
49 mozilla::TimeStamp mStartTimestamp
;
50 mozilla::TimeStamp mEndTimestamp
;
53 nsresult
Prefetch(uint16_t flags
);