Source code

Revision control

Other Tools

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/. */
5
6
#ifndef nsDNSPrefetch_h___
7
#define nsDNSPrefetch_h___
8
9
#include "nsIWeakReferenceUtils.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
~nsDNSPrefetch() = default;
22
23
public:
24
NS_DECL_THREADSAFE_ISUPPORTS
25
NS_DECL_NSIDNSLISTENER
26
27
nsDNSPrefetch(nsIURI* aURI, mozilla::OriginAttributes& aOriginAttributes,
28
nsIDNSListener* aListener, bool storeTiming);
29
bool TimingsValid() const {
30
return !mStartTimestamp.IsNull() && !mEndTimestamp.IsNull();
31
}
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; }
35
36
static nsresult Initialize(nsIDNSService* aDNSService);
37
static nsresult Shutdown();
38
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);
43
44
private:
45
nsCString mHostname;
46
bool mIsHttps;
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