tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

nsDNSPrefetch.h (2296B)


      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 <functional>
     10 
     11 #include "nsIWeakReferenceUtils.h"
     12 #include "nsString.h"
     13 #include "mozilla/TimeStamp.h"
     14 #include "mozilla/BasePrincipal.h"
     15 
     16 #include "nsIDNSListener.h"
     17 #include "nsIRequest.h"
     18 #include "nsIDNSService.h"
     19 
     20 class nsIURI;
     21 class nsIDNSHTTPSSVCRecord;
     22 
     23 class nsDNSPrefetch final : public nsIDNSListener {
     24  ~nsDNSPrefetch() = default;
     25 
     26 public:
     27  NS_DECL_THREADSAFE_ISUPPORTS
     28  NS_DECL_NSIDNSLISTENER
     29 
     30  nsDNSPrefetch(nsIURI* aURI, mozilla::OriginAttributes& aOriginAttributes,
     31                nsIRequest::TRRMode aTRRMode, nsIDNSListener* aListener,
     32                bool storeTiming);
     33  // For fetching HTTPS RR.
     34  nsDNSPrefetch(nsIURI* aURI, mozilla::OriginAttributes& aOriginAttributes,
     35                nsIRequest::TRRMode aTRRMode);
     36  bool TimingsValid() const {
     37    return !mStartTimestamp.IsNull() && !mEndTimestamp.IsNull();
     38  }
     39  // Only use the two timings if TimingsValid() returns true
     40  const mozilla::TimeStamp& StartTimestamp() const { return mStartTimestamp; }
     41  const mozilla::TimeStamp& EndTimestamp() const { return mEndTimestamp; }
     42 
     43  static nsresult Initialize(nsIDNSService* aDNSService);
     44  static nsresult Shutdown();
     45 
     46  // Call one of the following methods to start the Prefetch.
     47  nsresult PrefetchHigh(
     48      nsIDNSService::DNSFlags = nsIDNSService::RESOLVE_DEFAULT_FLAGS);
     49  nsresult PrefetchMedium(
     50      nsIDNSService::DNSFlags = nsIDNSService::RESOLVE_DEFAULT_FLAGS);
     51  nsresult PrefetchLow(
     52      nsIDNSService::DNSFlags = nsIDNSService::RESOLVE_DEFAULT_FLAGS);
     53 
     54  nsresult FetchHTTPSSVC(
     55      bool aRefreshDNS, bool aPrefetch,
     56      std::function<void(nsIDNSHTTPSSVCRecord*)>&& aCallback);
     57 
     58 private:
     59  nsCString mHostname;
     60  int32_t mPort{-1};
     61  mozilla::OriginAttributes mOriginAttributes;
     62  bool mStoreTiming;
     63  nsIRequest::TRRMode mTRRMode;
     64  mozilla::TimeStamp mStartTimestamp;
     65  mozilla::TimeStamp mEndTimestamp;
     66  nsWeakPtr mListener;
     67 
     68  nsresult Prefetch(nsIDNSService::DNSFlags flags);
     69 };
     70 
     71 #endif