Factor NetworkResourceLoader code for storing a cache entry into a function
authorantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 21 Dec 2015 20:01:35 +0000 (20:01 +0000)
committerantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 21 Dec 2015 20:01:35 +0000 (20:01 +0000)
https://bugs.webkit.org/show_bug.cgi?id=152467

Reviewed by Andreas Kling.

* NetworkProcess/NetworkResourceLoader.cpp:
(WebKit::NetworkResourceLoader::didFinishLoading):

    Having m_cacheEntryForValidation already implies canUseCache() so remove the test from this path.
    Move storing to the end of the function so we don't delay DidFinishResourceLoad message on it.

(WebKit::NetworkResourceLoader::sendBufferMaybeAborting):
(WebKit::NetworkResourceLoader::tryStoreAsCacheEntry):

    Factor to a function.
    Remove m_response.isHTTP() test as it is covered by NetworkCache::store().
    Remove !isPrivateSession test as it is covered by NetworkResourceLoader::canUseCache().

(WebKit::NetworkResourceLoader::didRetrieveCacheEntry):
* NetworkProcess/NetworkResourceLoader.h:

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

Source/WebKit2/ChangeLog
Source/WebKit2/NetworkProcess/NetworkResourceLoader.cpp
Source/WebKit2/NetworkProcess/NetworkResourceLoader.h

index cd91e84..0e3d425 100644 (file)
@@ -1,5 +1,28 @@
 2015-12-21  Antti Koivisto  <antti@apple.com>
 
+        Factor NetworkResourceLoader code for storing a cache entry into a function
+        https://bugs.webkit.org/show_bug.cgi?id=152467
+
+        Reviewed by Andreas Kling.
+
+        * NetworkProcess/NetworkResourceLoader.cpp:
+        (WebKit::NetworkResourceLoader::didFinishLoading):
+
+            Having m_cacheEntryForValidation already implies canUseCache() so remove the test from this path.
+            Move storing to the end of the function so we don't delay DidFinishResourceLoad message on it.
+
+        (WebKit::NetworkResourceLoader::sendBufferMaybeAborting):
+        (WebKit::NetworkResourceLoader::tryStoreAsCacheEntry):
+
+            Factor to a function.
+            Remove m_response.isHTTP() test as it is covered by NetworkCache::store().
+            Remove !isPrivateSession test as it is covered by NetworkResourceLoader::canUseCache().
+
+        (WebKit::NetworkResourceLoader::didRetrieveCacheEntry):
+        * NetworkProcess/NetworkResourceLoader.h:
+
+2015-12-21  Antti Koivisto  <antti@apple.com>
+
         Limit cached redirect chain length
         https://bugs.webkit.org/show_bug.cgi?id=152477
 
index e8fe1dd..07a5510 100644 (file)
@@ -338,29 +338,12 @@ void NetworkResourceLoader::didReceiveBuffer(RefPtr<SharedBuffer>&& buffer, int
 void NetworkResourceLoader::didFinishLoading(double finishTime)
 {
 #if ENABLE(NETWORK_CACHE)
-    if (canUseCache(m_networkLoad->currentRequest())) {
-        if (m_cacheEntryForValidation) {
-            // 304 Not Modified
-            ASSERT(m_response.httpStatusCode() == 304);
-            LOG(NetworkCache, "(NetworkProcess) revalidated");
-            didRetrieveCacheEntry(WTF::move(m_cacheEntryForValidation));
-            return;
-        }
-
-        bool isPrivateSession = sessionID().isEphemeral();
-        if (m_bufferedDataForCache && m_response.isHTTP() && !isPrivateSession) {
-            // Keep the connection alive.
-            RefPtr<NetworkConnectionToWebProcess> connection(&connectionToWebProcess());
-            RefPtr<NetworkResourceLoader> loader(this);
-            NetworkCache::singleton().store(m_networkLoad->currentRequest(), m_response, WTF::move(m_bufferedDataForCache), [loader, connection](NetworkCache::MappedBody& mappedBody) {
-#if ENABLE(SHAREABLE_RESOURCE)
-                if (mappedBody.shareableResourceHandle.isNull())
-                    return;
-                LOG(NetworkCache, "(NetworkProcess) sending DidCacheResource");
-                loader->send(Messages::NetworkProcessConnection::DidCacheResource(loader->originalRequest(), mappedBody.shareableResourceHandle, loader->sessionID()));
-#endif
-            });
-        }
+    if (m_cacheEntryForValidation) {
+        // 304 Not Modified
+        ASSERT(m_response.httpStatusCode() == 304);
+        LOG(NetworkCache, "(NetworkProcess) revalidated");
+        didRetrieveCacheEntry(WTF::move(m_cacheEntryForValidation));
+        return;
     }
 #endif
 
@@ -376,6 +359,10 @@ void NetworkResourceLoader::didFinishLoading(double finishTime)
         send(Messages::WebResourceLoader::DidFinishResourceLoad(finishTime));
     }
 
+#if ENABLE(NETWORK_CACHE)
+    tryStoreAsCacheEntry();
+#endif
+
     cleanup();
 }
 
@@ -500,6 +487,26 @@ bool NetworkResourceLoader::sendBufferMaybeAborting(SharedBuffer& buffer, size_t
 }
 
 #if ENABLE(NETWORK_CACHE)
+void NetworkResourceLoader::tryStoreAsCacheEntry()
+{
+    if (!canUseCache(m_networkLoad->currentRequest()))
+        return;
+    if (!m_bufferedDataForCache)
+        return;
+
+    // Keep the connection alive.
+    RefPtr<NetworkConnectionToWebProcess> connection(&connectionToWebProcess());
+    RefPtr<NetworkResourceLoader> loader(this);
+    NetworkCache::singleton().store(m_networkLoad->currentRequest(), m_response, WTF::move(m_bufferedDataForCache), [loader, connection](NetworkCache::MappedBody& mappedBody) {
+#if ENABLE(SHAREABLE_RESOURCE)
+        if (mappedBody.shareableResourceHandle.isNull())
+            return;
+        LOG(NetworkCache, "(NetworkProcess) sending DidCacheResource");
+        loader->send(Messages::NetworkProcessConnection::DidCacheResource(loader->originalRequest(), mappedBody.shareableResourceHandle, loader->sessionID()));
+#endif
+    });
+}
+
 void NetworkResourceLoader::didRetrieveCacheEntry(std::unique_ptr<NetworkCache::Entry> entry)
 {
     if (isSynchronous()) {
index ca430cf..8d9e03f 100644 (file)
@@ -115,6 +115,7 @@ private:
     bool canUseCache(const WebCore::ResourceRequest&) const;
     bool canUseCachedRedirect(const WebCore::ResourceRequest&) const;
 
+    void tryStoreAsCacheEntry();
     void retrieveCacheEntry(const WebCore::ResourceRequest&);
     void didRetrieveCacheEntry(std::unique_ptr<NetworkCache::Entry>);
     void validateCacheEntry(std::unique_ptr<NetworkCache::Entry>);