[Mac] Set the NSURLSessionTask priority to match the request's priority
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 3 Mar 2017 06:10:27 +0000 (06:10 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 3 Mar 2017 06:10:27 +0000 (06:10 +0000)
https://bugs.webkit.org/show_bug.cgi?id=169115
<rdar://problem/28881392>

Patch by Joseph Pecoraro <pecoraro@apple.com> on 2017-03-02
Reviewed by Alex Christensen.

* NetworkProcess/cocoa/NetworkDataTaskCocoa.mm:
(WebKit::toNSURLSessionTaskPriority):
(WebKit::NetworkDataTaskCocoa::NetworkDataTaskCocoa):
Set the priority on the task based on the ResourceRequest's priority.
This is used for HTTP/2 request prioritization.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@213354 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit2/ChangeLog
Source/WebKit2/NetworkProcess/cocoa/NetworkDataTaskCocoa.mm

index de1f222..225908f 100644 (file)
@@ -1,3 +1,17 @@
+2017-03-02  Joseph Pecoraro  <pecoraro@apple.com>
+
+        [Mac] Set the NSURLSessionTask priority to match the request's priority
+        https://bugs.webkit.org/show_bug.cgi?id=169115
+        <rdar://problem/28881392>
+
+        Reviewed by Alex Christensen.
+
+        * NetworkProcess/cocoa/NetworkDataTaskCocoa.mm:
+        (WebKit::toNSURLSessionTaskPriority):
+        (WebKit::NetworkDataTaskCocoa::NetworkDataTaskCocoa):
+        Set the priority on the task based on the ResourceRequest's priority.
+        This is used for HTTP/2 request prioritization.
+
 2017-03-02  Mark Lam  <mark.lam@apple.com>
 
         Add WebKit2 hooks to notify the VM that the user has requested a debugger break.
index d447ea2..32cb6cf 100644 (file)
@@ -46,6 +46,7 @@
 #import <wtf/text/Base64.h>
 
 namespace WebKit {
+
 #if USE(CREDENTIAL_STORAGE_WITH_NETWORK_SESSION)
 static void applyBasicAuthorizationHeader(WebCore::ResourceRequest& request, const WebCore::Credential& credential)
 {
@@ -54,6 +55,25 @@ static void applyBasicAuthorizationHeader(WebCore::ResourceRequest& request, con
 }
 #endif
 
+static float toNSURLSessionTaskPriority(WebCore::ResourceLoadPriority priority)
+{
+    switch (priority) {
+    case WebCore::ResourceLoadPriority::VeryLow:
+        return 0;
+    case WebCore::ResourceLoadPriority::Low:
+        return 0.25;
+    case WebCore::ResourceLoadPriority::Medium:
+        return 0.5;
+    case WebCore::ResourceLoadPriority::High:
+        return 0.75;
+    case WebCore::ResourceLoadPriority::VeryHigh:
+        return 1;
+    }
+
+    ASSERT_NOT_REACHED();
+    return NSURLSessionTaskPriorityDefault;
+}
+
 NetworkDataTaskCocoa::NetworkDataTaskCocoa(NetworkSession& session, NetworkDataTaskClient& client, const WebCore::ResourceRequest& requestWithCredentials, WebCore::StoredCredentials storedCredentials, WebCore::ContentSniffingPolicy shouldContentSniff, bool shouldClearReferrerOnHTTPSToHTTPRedirect)
     : NetworkDataTask(session, client, requestWithCredentials, storedCredentials, shouldClearReferrerOnHTTPSToHTTPRedirect)
 {
@@ -107,6 +127,9 @@ NetworkDataTaskCocoa::NetworkDataTaskCocoa(NetworkSession& session, NetworkDataT
     if (!storagePartition.isEmpty())
         m_task.get()._storagePartitionIdentifier = storagePartition;
 #endif
+
+    if (WebCore::ResourceRequest::resourcePrioritiesEnabled())
+        m_task.get().priority = toNSURLSessionTaskPriority(request.priority());
 }
 
 NetworkDataTaskCocoa::~NetworkDataTaskCocoa()