Bug 1337672 - Part 1: Reduce the priority of prefetch network requests. r?mayhemer draft
authorChris Peterson <cpeterson@mozilla.com>
Wed, 18 Jan 2017 00:55:58 -0800
changeset 480447 cf0306d33ea0dbe51bfc957eb39ad2e37565c51a
parent 480238 f4f374622111022d41dd8d5eb9220624135c534a
child 480448 8c6a57080737a44506339b8c6fbda5f8ea496189
push id44544
push usercpeterson@mozilla.com
push dateWed, 08 Feb 2017 08:10:53 +0000
reviewersmayhemer
bugs1337672
milestone54.0a1
Bug 1337672 - Part 1: Reduce the priority of prefetch network requests. r?mayhemer Reduce the priority of <link rel="prefetch"> network requests from PRIORITY_NORMAL to PRIORITY_LOWEST, the same as favicons. These prefetch requests are already deferred until the browser is idle using nsIWebProgressListener, but we can also adjust the network request priority to reflect their lower importance. https://developer.mozilla.org/docs/Web/HTTP/Link_prefetching_FAQ#How_is_browser_idle_time_determined.3F MozReview-Commit-ID: 2PjGRGOgKUU
uriloader/prefetch/nsPrefetchService.cpp
--- a/uriloader/prefetch/nsPrefetchService.cpp
+++ b/uriloader/prefetch/nsPrefetchService.cpp
@@ -9,16 +9,17 @@
 #include "nsICategoryManager.h"
 #include "nsIObserverService.h"
 #include "nsIWebProgress.h"
 #include "nsCURILoader.h"
 #include "nsICacheInfoChannel.h"
 #include "nsIHttpChannel.h"
 #include "nsIURL.h"
 #include "nsISimpleEnumerator.h"
+#include "nsISupportsPriority.h"
 #include "nsNetUtil.h"
 #include "nsString.h"
 #include "nsXPIDLString.h"
 #include "nsReadableUtils.h"
 #include "nsStreamUtils.h"
 #include "nsAutoPtr.h"
 #include "prtime.h"
 #include "mozilla/Logging.h"
@@ -151,16 +152,22 @@ nsPrefetchNode::OpenChannel()
     if (httpChannel) {
         httpChannel->SetReferrerWithPolicy(mReferrerURI, referrerPolicy);
         httpChannel->SetRequestHeader(
             NS_LITERAL_CSTRING("X-Moz"),
             NS_LITERAL_CSTRING("prefetch"),
             false);
     }
 
+    // Reduce the priority of prefetch network requests.
+    nsCOMPtr<nsISupportsPriority> priorityChannel = do_QueryInterface(mChannel);
+    if (priorityChannel) {
+      priorityChannel->AdjustPriority(nsISupportsPriority::PRIORITY_LOWEST);
+    }
+
     rv = mChannel->AsyncOpen2(this);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       // Drop the ref to the channel, because we don't want to end up with
       // cycles through it.
       mChannel = nullptr;
     }
     return rv;
 }