Line data Source code
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 :
6 : #ifndef nsDNSPrefetch_h___
7 : #define nsDNSPrefetch_h___
8 :
9 : #include "nsWeakReference.h"
10 : #include "nsString.h"
11 : #include "mozilla/TimeStamp.h"
12 : #include "mozilla/Attributes.h"
13 : #include "mozilla/BasePrincipal.h"
14 :
15 : #include "nsIDNSListener.h"
16 :
17 : class nsIURI;
18 : class nsIDNSService;
19 :
20 : class nsDNSPrefetch final : public nsIDNSListener
21 : {
22 4 : ~nsDNSPrefetch() {}
23 :
24 : public:
25 : NS_DECL_THREADSAFE_ISUPPORTS
26 : NS_DECL_NSIDNSLISTENER
27 :
28 : nsDNSPrefetch(nsIURI *aURI, mozilla::OriginAttributes& aOriginAttributes,
29 : nsIDNSListener *aListener, bool storeTiming);
30 1 : bool TimingsValid() const {
31 1 : return !mStartTimestamp.IsNull() && !mEndTimestamp.IsNull();
32 : }
33 : // Only use the two timings if TimingsValid() returns true
34 0 : const mozilla::TimeStamp& StartTimestamp() const { return mStartTimestamp; }
35 0 : const mozilla::TimeStamp& EndTimestamp() const { return mEndTimestamp; }
36 :
37 : static nsresult Initialize(nsIDNSService *aDNSService);
38 : static nsresult Shutdown();
39 :
40 : // Call one of the following methods to start the Prefetch.
41 : nsresult PrefetchHigh(bool refreshDNS = false);
42 : nsresult PrefetchMedium(bool refreshDNS = false);
43 : nsresult PrefetchLow(bool refreshDNS = false);
44 :
45 : private:
46 : nsCString mHostname;
47 : mozilla::OriginAttributes mOriginAttributes;
48 : bool mStoreTiming;
49 : mozilla::TimeStamp mStartTimestamp;
50 : mozilla::TimeStamp mEndTimestamp;
51 : nsWeakPtr mListener;
52 :
53 : nsresult Prefetch(uint16_t flags);
54 : };
55 :
56 : #endif
|