Disable all network caching for HLS streams.
authorjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 11 Jul 2018 19:29:58 +0000 (19:29 +0000)
committerjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 11 Jul 2018 19:29:58 +0000 (19:29 +0000)
https://bugs.webkit.org/show_bug.cgi?id=187544
<rdar://problem/41863600>

Reviewed by Chris Dumez.

Source/WebKit:

Revert the behavior added in r215263 where Media responses are cached if they are from
a resource whose expected content length is <4MB.

* NetworkProcess/cache/NetworkCache.cpp:
(WebKit::NetworkCache::makeStoreDecision):
(WebKit::NetworkCache::expectedTotalResourceSizeFromContentRange): Deleted.

LayoutTests:

* http/tests/cache/disk-cache/disk-cache-media-small-expected.txt:
* http/tests/cache/disk-cache/disk-cache-media-small.html:

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

LayoutTests/ChangeLog
LayoutTests/http/tests/cache/disk-cache/disk-cache-media-small-expected.txt
LayoutTests/http/tests/cache/disk-cache/disk-cache-media-small.html
Source/WebKit/ChangeLog
Source/WebKit/NetworkProcess/cache/NetworkCache.cpp

index 38ad4b9..5e0c4b2 100644 (file)
@@ -1,3 +1,14 @@
+2018-07-11  Jer Noble  <jer.noble@apple.com>
+
+        Disable all network caching for HLS streams.
+        https://bugs.webkit.org/show_bug.cgi?id=187544
+        <rdar://problem/41863600>
+
+        Reviewed by Chris Dumez.
+
+        * http/tests/cache/disk-cache/disk-cache-media-small-expected.txt:
+        * http/tests/cache/disk-cache/disk-cache-media-small.html:
+
 2018-07-11  Ms2ger  <Ms2ger@igalia.com>
 
         [GTK] Unreviewed test gardening
index ac7a79a..cebdd15 100644 (file)
@@ -1,5 +1,5 @@
 First load
 PASS: All response ranges from: Network
 Second Load
-PASS: All response ranges from: Disk cache
+PASS: All response ranges from: Network
  
index f45e249..d1d053a 100644 (file)
@@ -43,7 +43,7 @@ async function test() {
     logResponses(await loadTestMedia(), "Network");
 
     logdiv.innerHTML += "Second Load<br>";
-    logResponses(await loadTestMedia(), "Disk cache");
+    logResponses(await loadTestMedia(), "Network");
 
     testRunner.notifyDone();
 }
index 3f12d4b..bf15bb0 100644 (file)
@@ -1,3 +1,18 @@
+2018-07-11  Jer Noble  <jer.noble@apple.com>
+
+        Disable all network caching for HLS streams.
+        https://bugs.webkit.org/show_bug.cgi?id=187544
+        <rdar://problem/41863600>
+
+        Reviewed by Chris Dumez.
+
+        Revert the behavior added in r215263 where Media responses are cached if they are from
+        a resource whose expected content length is <4MB.
+
+        * NetworkProcess/cache/NetworkCache.cpp:
+        (WebKit::NetworkCache::makeStoreDecision):
+        (WebKit::NetworkCache::expectedTotalResourceSizeFromContentRange): Deleted.
+
 2018-07-11  Zan Dobersek  <zdobersek@igalia.com>
 
         [WPE] AC for fixed-position elements is not enabled
index 989469b..b72dc15 100644 (file)
@@ -225,33 +225,6 @@ static bool isMediaMIMEType(const String& type)
     return startsWithLettersIgnoringASCIICase(type, "video/") || startsWithLettersIgnoringASCIICase(type, "audio/");
 }
 
-static std::optional<size_t> expectedTotalResourceSizeFromContentRange(const WebCore::ResourceResponse& response)
-{
-    ASSERT(response.httpStatusCode() == 206);
-
-    auto contentRange = response.httpHeaderField(WebCore::HTTPHeaderName::ContentRange);
-    if (contentRange.isNull())
-        return { };
-
-    if (!contentRange.startsWith("bytes "))
-        return { };
-
-    auto slashPosition = contentRange.find('/');
-    if (slashPosition == notFound)
-        return { };
-
-    auto sizeStringLength = contentRange.length() - slashPosition - 1;
-    if (!sizeStringLength)
-        return { };
-
-    bool isValid;
-    auto size = StringView(contentRange).right(sizeStringLength).toIntStrict(isValid);
-    if (!isValid)
-        return { };
-
-    return size;
-}
-
 static StoreDecision makeStoreDecision(const WebCore::ResourceRequest& originalRequest, const WebCore::ResourceResponse& response, size_t bodySize)
 {
     if (!originalRequest.url().protocolIsInHTTPFamily() || !response.isHTTP())
@@ -286,25 +259,15 @@ static StoreDecision makeStoreDecision(const WebCore::ResourceRequest& originalR
             return StoreDecision::NoDueToUnlikelyToReuse;
     }
 
+    // Media loaded via XHR is likely being used for MSE streaming (YouTube and Netflix for example).
     // Streaming media fills the cache quickly and is unlikely to be reused.
     // FIXME: We should introduce a separate media cache partition that doesn't affect other resources.
     // FIXME: We should also make sure make the MSE paths are copy-free so we can use mapped buffers from disk effectively.
     auto requester = originalRequest.requester();
-    bool isDefinitelyMedia = requester == WebCore::ResourceRequest::Requester::Media;
-    if (isDefinitelyMedia) {
-        // Allow caching of smaller media files if we know the total size.
-        const size_t maximumCacheableMediaSize = 5 * 1024 * 1024;
-        auto totalSize = response.httpStatusCode() == 206 ? expectedTotalResourceSizeFromContentRange(response) : bodySize;
-        if (!totalSize || *totalSize > maximumCacheableMediaSize)
-            return StoreDecision::NoDueToStreamingMedia;
-    }
-
+    bool isDefinitelyStreamingMedia = requester == WebCore::ResourceRequest::Requester::Media;
     bool isLikelyStreamingMedia = requester == WebCore::ResourceRequest::Requester::XHR && isMediaMIMEType(response.mimeType());
-    if (isLikelyStreamingMedia) {
-        // Media loaded via XHR is likely being used for MSE streaming (YouTube and Netflix for example).
-        // We have no way of knowing the total media size so disallow caching.
+    if (isLikelyStreamingMedia || isDefinitelyStreamingMedia)
         return StoreDecision::NoDueToStreamingMedia;
-    }
 
     return StoreDecision::Yes;
 }