Bug 1348050 - Part 1: Mark channel as urgent-start when the Fetch and XHR are triggered by user input events. r=mayhemer, baku draft
authorTom Tung <shes050117@gmail.com>
Fri, 21 Apr 2017 13:29:31 +0800
changeset 574689 329af890ee06f4c6d8df550fe4313a17c8a43b60
parent 574519 b21b974d60d3075ae24f6fb1bae75d0f122f28fc
child 574690 a96e0409608c594eae0aa39feb4f5a2d294b1ad9
push id57804
push userttung@mozilla.com
push dateTue, 09 May 2017 09:59:40 +0000
reviewersmayhemer, baku
bugs1348050
milestone55.0a1
Bug 1348050 - Part 1: Mark channel as urgent-start when the Fetch and XHR are triggered by user input events. r=mayhemer, baku Raise the urgent-start flag in the ClassOfService when the Fetch and XHR are triggered by user input events. The urgent-start classification will tell the network requests scheduler to perform it with the highest priority and also ignoring any parallelism or overall connection limits. MozReview-Commit-ID: 2YavWbuFaln
dom/fetch/FetchDriver.cpp
dom/xhr/XMLHttpRequestMainThread.cpp
--- a/dom/fetch/FetchDriver.cpp
+++ b/dom/fetch/FetchDriver.cpp
@@ -25,16 +25,17 @@
 #include "nsNetUtil.h"
 #include "nsPrintfCString.h"
 #include "nsStreamUtils.h"
 #include "nsStringStream.h"
 #include "nsHttpChannel.h"
 
 #include "mozilla/dom/File.h"
 #include "mozilla/dom/workers/Workers.h"
+#include "mozilla/EventStateManager.h"
 #include "mozilla/ipc/PBackgroundSharedTypes.h"
 #include "mozilla/Unused.h"
 
 #include "Fetch.h"
 #include "FetchUtil.h"
 #include "InternalRequest.h"
 #include "InternalResponse.h"
 
@@ -250,16 +251,23 @@ FetchDriver::HttpFetch()
   {
     nsCOMPtr<nsIInterfaceRequestor> notificationCallbacks;
     chan->GetNotificationCallbacks(getter_AddRefs(notificationCallbacks));
     MOZ_ASSERT(!notificationCallbacks);
   }
 #endif
   chan->SetNotificationCallbacks(this);
 
+  nsCOMPtr<nsIClassOfService> cos(do_QueryInterface(chan));
+  // Mark channel as urgent-start if the Fetch is triggered by user input
+  // events.
+  if (cos && EventStateManager::IsHandlingUserInput()) {
+    cos->AddClassFlags(nsIClassOfService::UrgentStart);
+  }
+
   // Step 3.5 begins "HTTP network or cache fetch".
   // HTTP network or cache fetch
   // ---------------------------
   // Step 1 "Let HTTPRequest..." The channel is the HTTPRequest.
   nsCOMPtr<nsIHttpChannel> httpChan = do_QueryInterface(chan);
   if (httpChan) {
     // Copy the method.
     nsAutoCString method;
--- a/dom/xhr/XMLHttpRequestMainThread.cpp
+++ b/dom/xhr/XMLHttpRequestMainThread.cpp
@@ -22,16 +22,17 @@
 #include "mozilla/dom/FetchUtil.h"
 #include "mozilla/dom/FormData.h"
 #include "mozilla/dom/MutableBlobStorage.h"
 #include "mozilla/dom/XMLDocument.h"
 #include "mozilla/dom/URLSearchParams.h"
 #include "mozilla/dom/PromiseNativeHandler.h"
 #include "mozilla/EventDispatcher.h"
 #include "mozilla/EventListenerManager.h"
+#include "mozilla/EventStateManager.h"
 #include "mozilla/LoadInfo.h"
 #include "mozilla/LoadContext.h"
 #include "mozilla/MemoryReporting.h"
 #include "nsIDOMDocument.h"
 #include "mozilla/dom/ProgressEvent.h"
 #include "nsIJARChannel.h"
 #include "nsIJARURI.h"
 #include "nsLayoutCID.h"
@@ -2647,16 +2648,22 @@ XMLHttpRequestMainThread::InitiateFetch(
     }
   }
 
   // We never let XHR be blocked by head CSS/JS loads to avoid potential
   // deadlock where server generation of CSS/JS requires an XHR signal.
   nsCOMPtr<nsIClassOfService> cos(do_QueryInterface(mChannel));
   if (cos) {
     cos->AddClassFlags(nsIClassOfService::Unblocked);
+
+    // Mark channel as urgent-start if the XHR is triggered by user input
+    // events.
+    if (EventStateManager::IsHandlingUserInput()) {
+      cos->AddClassFlags(nsIClassOfService::UrgentStart);
+    }
   }
 
   // Disable Necko-internal response timeouts.
   nsCOMPtr<nsIHttpChannelInternal>
     internalHttpChannel(do_QueryInterface(mChannel));
   if (internalHttpChannel) {
     rv = internalHttpChannel->SetResponseTimeoutEnabled(false);
     MOZ_ASSERT(NS_SUCCEEDED(rv));