Bug 1503011 - Make sure DNSPrefetch is called. r=mayhemer
authorDragana Damjanovic <dd.mozilla@gmail.com>
Tue, 30 Oct 2018 10:27:28 +0000
changeset 499954 80f9ac0ab7dcea7a28ff9b12bd8e9fcda8977a84
parent 499953 8a0dc33b66dcdec911d03733682372fff745fd27
child 499955 5d017b5af700c51b674a32933074b11cddb5a5cb
push id10290
push userffxbld-merge
push dateMon, 03 Dec 2018 16:23:23 +0000
treeherdermozilla-beta@700bed2445e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmayhemer
bugs1503011
milestone65.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 1503011 - Make sure DNSPrefetch is called. r=mayhemer Differential Revision: https://phabricator.services.mozilla.com/D10118
netwerk/protocol/http/nsHttpChannel.cpp
netwerk/protocol/http/nsHttpChannel.h
--- a/netwerk/protocol/http/nsHttpChannel.cpp
+++ b/netwerk/protocol/http/nsHttpChannel.cpp
@@ -6682,16 +6682,17 @@ nsHttpChannel::BeginConnect()
     // We may have been cancelled already, either by on-modify-request
     // listeners or load group observers; in that case, we should not send the
     // request to the server
     if (mCanceled) {
         return mStatus;
     }
 
     if (!(mLoadFlags & LOAD_CLASSIFY_URI)) {
+        MaybeStartDNSPrefetch();
         return ContinueBeginConnectWithResult();
     }
 
     // We are about to do a sync lookup to check if the URI is a
     // tracker. If yes, this channel will be canceled by channel classifier.
     // Chances are the lookup is not needed so CheckIsTrackerWithLocalTable()
     // will return an error and then we can BeginConnectActual() right away.
     RefPtr<nsChannelClassifier> channelClassifier =
@@ -6716,54 +6717,60 @@ nsHttpChannel::BeginConnect()
         // BeginConnect() will return synchronously and the caller will be responsible
         // for handling it.
         return BeginConnectActual();
     }
 
     return NS_OK;
 }
 
-nsresult
-nsHttpChannel::BeginConnectActual()
-{
-    if (mCanceled) {
-        return mStatus;
-    }
-
-    if (mTrackingProtectionCancellationPending) {
-        LOG(("Waiting for tracking protection cancellation in BeginConnectActual [this=%p]\n", this));
-        MOZ_ASSERT(!mCallOnResume ||
-                   mCallOnResume == &nsHttpChannel::HandleContinueCancelledByTrackingProtection,
-                   "We should be paused waiting for cancellation from tracking protection");
-        return NS_OK;
-    }
-
+void
+nsHttpChannel::MaybeStartDNSPrefetch()
+{
     if (!mConnectionInfo->UsingHttpProxy() &&
         !(mLoadFlags & (LOAD_NO_NETWORK_IO | LOAD_ONLY_FROM_CACHE))) {
         // Start a DNS lookup very early in case the real open is queued the DNS can
         // happen in parallel. Do not do so in the presence of an HTTP proxy as
         // all lookups other than for the proxy itself are done by the proxy.
         // Also we don't do a lookup if the LOAD_NO_NETWORK_IO or
         // LOAD_ONLY_FROM_CACHE flags are set.
         //
         // We keep the DNS prefetch object around so that we can retrieve
         // timing information from it. There is no guarantee that we actually
         // use the DNS prefetch data for the real connection, but as we keep
         // 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::BeginConnect [this=%p] prefetching%s\n",
+        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->PrefetchHigh(mCaps & NS_HTTP_REFRESH_DNS);
     }
+}
+
+nsresult
+nsHttpChannel::BeginConnectActual()
+{
+    if (mCanceled) {
+        return mStatus;
+    }
+
+    if (mTrackingProtectionCancellationPending) {
+        LOG(("Waiting for tracking protection cancellation in BeginConnectActual [this=%p]\n", this));
+        MOZ_ASSERT(!mCallOnResume ||
+                   mCallOnResume == &nsHttpChannel::HandleContinueCancelledByTrackingProtection,
+                   "We should be paused waiting for cancellation from tracking protection");
+        return NS_OK;
+    }
+
+    MaybeStartDNSPrefetch();
 
     nsresult rv = ContinueBeginConnectWithResult();
     if (NS_FAILED(rv)) {
         return rv;
     }
 
     // Start nsChannelClassifier to catch phishing and malware URIs.
     RefPtr<nsChannelClassifier> channelClassifier =
--- a/netwerk/protocol/http/nsHttpChannel.h
+++ b/netwerk/protocol/http/nsHttpChannel.h
@@ -295,16 +295,17 @@ private:
     bool     RequestIsConditional();
     void HandleContinueCancelledByTrackingProtection();
     nsresult CancelInternal(nsresult status);
     void ContinueCancelledByTrackingProtection();
 
     // Connections will only be established in this function.
     // (including DNS prefetch and speculative connection.)
     nsresult BeginConnectActual();
+    void MaybeStartDNSPrefetch();
 
     // We might synchronously or asynchronously call BeginConnectActual,
     // which includes DNS prefetch and speculative connection, according to
     // whether an async tracker lookup is required. If the tracker lookup
     // is required, this funciton will just return NS_OK and BeginConnectActual()
     // will be called when callback. See Bug 1325054 for more information.
     nsresult BeginConnect();
     MOZ_MUST_USE nsresult ContinueBeginConnectWithResult();