From dd7c87fd1f04bfe296ecc194a35e4c7eea52daeb Mon Sep 17 00:00:00 2001 From: Dragana Damjanovic Date: Tue, 30 Oct 2018 10:27:28 +0000 Subject: [PATCH] Bug 1503011 - Make sure DNSPrefetch is called. r=mayhemer Differential Revision: https://phabricator.services.mozilla.com/D10118 --HG-- extra : moz-landing-system : lando --- netwerk/protocol/http/nsHttpChannel.cpp | 37 +++++++++++++++---------- netwerk/protocol/http/nsHttpChannel.h | 1 + 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/netwerk/protocol/http/nsHttpChannel.cpp b/netwerk/protocol/http/nsHttpChannel.cpp index 9a721d8eb059..08cb0ecd1c64 100644 --- a/netwerk/protocol/http/nsHttpChannel.cpp +++ b/netwerk/protocol/http/nsHttpChannel.cpp @@ -6687,6 +6687,7 @@ nsHttpChannel::BeginConnect() } if (!(mLoadFlags & LOAD_CLASSIFY_URI)) { + MaybeStartDNSPrefetch(); return ContinueBeginConnectWithResult(); } @@ -6721,21 +6722,9 @@ nsHttpChannel::BeginConnect() return NS_OK; } -nsresult -nsHttpChannel::BeginConnectActual() +void +nsHttpChannel::MaybeStartDNSPrefetch() { - 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; - } - 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 @@ -6751,7 +6740,7 @@ nsHttpChannel::BeginConnectActual() // 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); @@ -6759,6 +6748,24 @@ nsHttpChannel::BeginConnectActual() 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)) { diff --git a/netwerk/protocol/http/nsHttpChannel.h b/netwerk/protocol/http/nsHttpChannel.h index ba8198a26a4a..f4c12e8c632a 100644 --- a/netwerk/protocol/http/nsHttpChannel.h +++ b/netwerk/protocol/http/nsHttpChannel.h @@ -300,6 +300,7 @@ private: // 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