Bug 1552176 - Pass TRRMode to nsDNSPrefetch r=dragana
☠☠ backed out by 4fb5404dcbef ☠ ☠
authorValentin Gosu <valentin.gosu@gmail.com>
Sun, 10 Nov 2019 17:12:06 +0000
changeset 501428 de7aa0eaf4c8a01b0caa4249a8af80c5e36f5e33
parent 501427 c8e692a40cd34db3a29a4238257c61da2825f397
child 501429 4b970cc771cab1cd4424b7ffa5f1a5d72563a09f
push id114170
push usermalexandru@mozilla.com
push dateTue, 12 Nov 2019 21:58:32 +0000
treeherdermozilla-inbound@9e3f44e87a1a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdragana
bugs1552176
milestone72.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1552176 - Pass TRRMode to nsDNSPrefetch r=dragana Differential Revision: https://phabricator.services.mozilla.com/D49158
netwerk/base/nsDNSPrefetch.cpp
netwerk/base/nsDNSPrefetch.h
netwerk/protocol/http/nsHttpChannel.cpp
--- a/netwerk/base/nsDNSPrefetch.cpp
+++ b/netwerk/base/nsDNSPrefetch.cpp
@@ -28,25 +28,27 @@ nsresult nsDNSPrefetch::Initialize(nsIDN
 
 nsresult nsDNSPrefetch::Shutdown() {
   NS_IF_RELEASE(sDNSService);
   return NS_OK;
 }
 
 nsDNSPrefetch::nsDNSPrefetch(nsIURI* aURI,
                              mozilla::OriginAttributes& aOriginAttributes,
+                             nsIRequest::TRRMode aTRRMode,
                              nsIDNSListener* aListener, bool storeTiming)
     : mOriginAttributes(aOriginAttributes),
       mStoreTiming(storeTiming),
+      mTRRMode(aTRRMode),
       mListener(do_GetWeakReference(aListener)) {
   aURI->GetAsciiHost(mHostname);
   mIsHttps = aURI->SchemeIs("https");
 }
 
-nsresult nsDNSPrefetch::Prefetch(uint16_t flags) {
+nsresult nsDNSPrefetch::Prefetch(uint32_t flags) {
   // This can work properly only if this call is on the main thread.
   // Curenlty we use nsDNSPrefetch only in nsHttpChannel which will call
   // PrefetchHigh() from the main thread. Let's add assertion to catch
   // if things change.
   MOZ_ASSERT(NS_IsMainThread(), "Expecting DNS callback on main thread.");
 
   if (mHostname.IsEmpty()) return NS_ERROR_NOT_AVAILABLE;
 
@@ -56,16 +58,18 @@ nsresult nsDNSPrefetch::Prefetch(uint16_
 
   if (mStoreTiming) mStartTimestamp = mozilla::TimeStamp::Now();
   // If AsyncResolve fails, for example because prefetching is disabled,
   // then our timing will be useless. However, in such a case,
   // mEndTimestamp will be a null timestamp and callers should check
   // TimingsValid() before using the timing.
   nsCOMPtr<nsIEventTarget> main = mozilla::GetMainThreadEventTarget();
 
+  flags |= nsIDNSService::GetFlagsFromTRRMode(mTRRMode);
+
   nsresult rv = sDNSService->AsyncResolveNative(
       mHostname, flags | nsIDNSService::RESOLVE_SPECULATE, this, main,
       mOriginAttributes, getter_AddRefs(tmpOutstanding));
   if (NS_FAILED(rv)) {
     return rv;
   }
 
   // Fetch esni keys if needed.
--- a/netwerk/base/nsDNSPrefetch.h
+++ b/netwerk/base/nsDNSPrefetch.h
@@ -20,17 +20,18 @@ class nsIDNSService;
 class nsDNSPrefetch final : public nsIDNSListener {
   ~nsDNSPrefetch() = default;
 
  public:
   NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSIDNSLISTENER
 
   nsDNSPrefetch(nsIURI* aURI, mozilla::OriginAttributes& aOriginAttributes,
-                nsIDNSListener* aListener, bool storeTiming);
+                nsIRequest::TRRMode aTRRMode, nsIDNSListener* aListener,
+                bool storeTiming);
   bool TimingsValid() const {
     return !mStartTimestamp.IsNull() && !mEndTimestamp.IsNull();
   }
   // Only use the two timings if TimingsValid() returns true
   const mozilla::TimeStamp& StartTimestamp() const { return mStartTimestamp; }
   const mozilla::TimeStamp& EndTimestamp() const { return mEndTimestamp; }
 
   static nsresult Initialize(nsIDNSService* aDNSService);
@@ -41,16 +42,17 @@ class nsDNSPrefetch final : public nsIDN
   nsresult PrefetchMedium(bool refreshDNS = false);
   nsresult PrefetchLow(bool refreshDNS = false);
 
  private:
   nsCString mHostname;
   bool mIsHttps;
   mozilla::OriginAttributes mOriginAttributes;
   bool mStoreTiming;
+  nsIRequest::TRRMode mTRRMode;
   mozilla::TimeStamp mStartTimestamp;
   mozilla::TimeStamp mEndTimestamp;
   nsWeakPtr mListener;
 
-  nsresult Prefetch(uint16_t flags);
+  nsresult Prefetch(uint32_t flags);
 };
 
 #endif
--- a/netwerk/protocol/http/nsHttpChannel.cpp
+++ b/netwerk/protocol/http/nsHttpChannel.cpp
@@ -6834,18 +6834,18 @@ void nsHttpChannel::MaybeStartDNSPrefetc
     // this data around for 3 minutes by default, this should almost always
     // be correct, and even when it isn't, the timing still represents _a_
     // valid DNS lookup timing for the site, even if it is not _the_
     // timing we used.
     LOG(("nsHttpChannel::MaybeStartDNSPrefetch [this=%p] prefetching%s\n", this,
          mCaps & NS_HTTP_REFRESH_DNS ? ", refresh requested" : ""));
     OriginAttributes originAttributes;
     NS_GetOriginAttributes(this, originAttributes);
-    mDNSPrefetch =
-        new nsDNSPrefetch(mURI, originAttributes, this, mTimingEnabled);
+    mDNSPrefetch = new nsDNSPrefetch(
+        mURI, originAttributes, nsIRequest::GetTRRMode(), this, mTimingEnabled);
     mDNSPrefetch->PrefetchHigh(mCaps & NS_HTTP_REFRESH_DNS);
   }
 }
 
 NS_IMETHODIMP
 nsHttpChannel::GetEncodedBodySize(uint64_t* aEncodedBodySize) {
   if (mCacheEntry && !mCacheEntryIsWriteOnly) {
     int64_t dataSize = 0;