Title: [147179] trunk/Source/WebKit2
Revision
147179
Author
beid...@apple.com
Date
2013-03-28 16:09:03 -0700 (Thu, 28 Mar 2013)

Log Message

Resources are never revalidated/reloaded if a cached response exists on disk.
<rdar://problem/13479890> and https://bugs.webkit.org/show_bug.cgi?id=113542

Reviewed by Alexey Proskuryakov.

Trying to get a cached resource in didReceiveResponse and then aborting the load
meant we never performed any new loads.

We can check and see if the data is cached data inside didReceiveBuffer, instead.

* NetworkProcess/NetworkResourceLoader.cpp:
(WebKit::NetworkResourceLoader::didReceiveResponse): Don't try for cached resources here.
(WebKit::NetworkResourceLoader::didReceiveData): This callback should never be used.
(WebKit::NetworkResourceLoader::didReceiveBuffer): Try to see if this data objected represents
  a file based mmaped buffer.
* NetworkProcess/NetworkResourceLoader.h:

Refactor these utility functions to start from either a CFURLCachedResponse or a SharedBuffer:
* NetworkProcess/mac/NetworkResourceLoaderMac.mm:
(CFCachedURLResponseGetMemMappedData):
(CFURLCacheIsMemMappedData):
(WebKit::tryGetShareableHandleFromCFData):
(WebKit::NetworkResourceLoader::tryGetShareableHandleFromCFURLCachedResponse):
(WebKit::NetworkResourceLoader::tryGetShareableHandleFromSharedBuffer):

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (147178 => 147179)


--- trunk/Source/WebKit2/ChangeLog	2013-03-28 23:08:43 UTC (rev 147178)
+++ trunk/Source/WebKit2/ChangeLog	2013-03-28 23:09:03 UTC (rev 147179)
@@ -1,3 +1,30 @@
+2013-03-28  Brady Eidson  <beid...@apple.com>
+
+        Resources are never revalidated/reloaded if a cached response exists on disk.
+        <rdar://problem/13479890> and https://bugs.webkit.org/show_bug.cgi?id=113542
+
+        Reviewed by Alexey Proskuryakov.
+
+        Trying to get a cached resource in didReceiveResponse and then aborting the load
+        meant we never performed any new loads.
+
+        We can check and see if the data is cached data inside didReceiveBuffer, instead.
+
+        * NetworkProcess/NetworkResourceLoader.cpp:
+        (WebKit::NetworkResourceLoader::didReceiveResponse): Don't try for cached resources here.
+        (WebKit::NetworkResourceLoader::didReceiveData): This callback should never be used.
+        (WebKit::NetworkResourceLoader::didReceiveBuffer): Try to see if this data objected represents
+          a file based mmaped buffer.
+        * NetworkProcess/NetworkResourceLoader.h:
+
+        Refactor these utility functions to start from either a CFURLCachedResponse or a SharedBuffer:
+        * NetworkProcess/mac/NetworkResourceLoaderMac.mm:
+        (CFCachedURLResponseGetMemMappedData):
+        (CFURLCacheIsMemMappedData):
+        (WebKit::tryGetShareableHandleFromCFData):
+        (WebKit::NetworkResourceLoader::tryGetShareableHandleFromCFURLCachedResponse):
+        (WebKit::NetworkResourceLoader::tryGetShareableHandleFromSharedBuffer):
+
 2013-03-28  Tim Horton  <timothy_hor...@apple.com>
 
         [wk2] REGRESSION (r125500): WebFrameLoaderClient's active m_pluginView can be zeroed by PluginDocuments leaving the page cache

Modified: trunk/Source/WebKit2/NetworkProcess/NetworkResourceLoader.cpp (147178 => 147179)


--- trunk/Source/WebKit2/NetworkProcess/NetworkResourceLoader.cpp	2013-03-28 23:08:43 UTC (rev 147178)
+++ trunk/Source/WebKit2/NetworkProcess/NetworkResourceLoader.cpp	2013-03-28 23:09:03 UTC (rev 147179)
@@ -203,30 +203,35 @@
     if (FormData* formData = request().httpBody())
         formData->removeGeneratedFilesIfNeeded();
 
-    if (!sendAbortingOnFailure(Messages::WebResourceLoader::DidReceiveResponseWithCertificateInfo(response, PlatformCertificateInfo(response))))
-        return;
-
-#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
-    ShareableResource::Handle handle;
-    tryGetShareableHandleForResource(handle);
-    if (handle.isNull())
-        return;
-
-    // Since we're delivering this resource by ourselves all at once, we'll abort the resource handle since we don't need anymore callbacks from ResourceHandle.
-    abortInProgressLoad();
-    
-    send(Messages::WebResourceLoader::DidReceiveResource(handle, currentTime()));
-#endif // __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
+    sendAbortingOnFailure(Messages::WebResourceLoader::DidReceiveResponseWithCertificateInfo(response, PlatformCertificateInfo(response)));
 }
 
 void NetworkResourceLoader::didReceiveData(ResourceHandle*, const char* data, int length, int encodedDataLength)
 {
+    // The NetworkProcess should never get a didReceiveData callback.
+    // We should always be using didReceiveBuffer.
+    ASSERT_NOT_REACHED();
+}
+
+void NetworkResourceLoader::didReceiveBuffer(WebCore::ResourceHandle*, PassRefPtr<WebCore::SharedBuffer> buffer, int encodedDataLength)
+{
     // FIXME (NetworkProcess): For the memory cache we'll also need to cache the response data here.
     // Such buffering will need to be thread safe, as this callback is happening on a background thread.
     
-    m_bytesReceived += length;
+    m_bytesReceived += buffer->size();
+    
+#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
+    ShareableResource::Handle handle;
+    tryGetShareableHandleFromSharedBuffer(handle, buffer.get());
+    if (!handle.isNull()) {
+        // Since we're delivering this resource by ourselves all at once, we'll abort the resource handle since we don't need anymore callbacks from ResourceHandle.
+        abortInProgressLoad();
+        send(Messages::WebResourceLoader::DidReceiveResource(handle, currentTime()));
+        return;
+    }
+#endif // __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
 
-    CoreIPC::DataReference dataReference(reinterpret_cast<const uint8_t*>(data), length);
+    CoreIPC::DataReference dataReference(reinterpret_cast<const uint8_t*>(buffer->data()), buffer->size());
     sendAbortingOnFailure(Messages::WebResourceLoader::DidReceiveData(dataReference, encodedDataLength));
 }
 

Modified: trunk/Source/WebKit2/NetworkProcess/NetworkResourceLoader.h (147178 => 147179)


--- trunk/Source/WebKit2/NetworkProcess/NetworkResourceLoader.h	2013-03-28 23:08:43 UTC (rev 147178)
+++ trunk/Source/WebKit2/NetworkProcess/NetworkResourceLoader.h	2013-03-28 23:09:03 UTC (rev 147179)
@@ -69,6 +69,7 @@
     virtual void didSendData(WebCore::ResourceHandle*, unsigned long long bytesSent, unsigned long long totalBytesToBeSent) OVERRIDE;
     virtual void didReceiveResponse(WebCore::ResourceHandle*, const WebCore::ResourceResponse&) OVERRIDE;
     virtual void didReceiveData(WebCore::ResourceHandle*, const char*, int, int encodedDataLength) OVERRIDE;
+    virtual void didReceiveBuffer(WebCore::ResourceHandle*, PassRefPtr<WebCore::SharedBuffer>, int encodedDataLength) OVERRIDE;
     virtual void didReceiveCachedMetadata(WebCore::ResourceHandle*, const char*, int) OVERRIDE;
     virtual void didFinishLoading(WebCore::ResourceHandle*, double finishTime) OVERRIDE;
     virtual void didFail(WebCore::ResourceHandle*, const WebCore::ResourceError&) OVERRIDE;
@@ -128,7 +129,7 @@
     uint64_t m_bytesReceived;
 
 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
-    void tryGetShareableHandleForResource(ShareableResource::Handle&);
+    static void tryGetShareableHandleFromSharedBuffer(ShareableResource::Handle&, WebCore::SharedBuffer*);
 #endif
 };
 

Modified: trunk/Source/WebKit2/NetworkProcess/mac/NetworkResourceLoaderMac.mm (147178 => 147179)


--- trunk/Source/WebKit2/NetworkProcess/mac/NetworkResourceLoaderMac.mm	2013-03-28 23:08:43 UTC (rev 147178)
+++ trunk/Source/WebKit2/NetworkProcess/mac/NetworkResourceLoaderMac.mm	2013-03-28 23:09:03 UTC (rev 147179)
@@ -29,6 +29,7 @@
 #import "DiskCacheMonitor.h"
 #import "ShareableResource.h"
 #import <WebCore/ResourceHandle.h>
+#import <WebCore/SharedBuffer.h>
 #import <WebCore/SoftLinking.h>
 
 using namespace WebCore;
@@ -42,12 +43,23 @@
 SOFT_LINK_FRAMEWORK(CFNetwork)
 static CFDataRef CFCachedURLResponseGetMemMappedData(CFCachedURLResponseRef response)
 {
-    static CFDataRef (*softGetMemMappedData)(CFCachedURLResponseRef) = (CFDataRef (*)(CFCachedURLResponseRef)) dlsym(CFNetworkLibrary(), "_CFCachedURLResponseGetMemMappedData");
+    typedef CFDataRef (*functionType)(CFCachedURLResponseRef);
+    static functionType softGetMemMappedData = (functionType) dlsym(CFNetworkLibrary(), "_CFCachedURLResponseGetMemMappedData");
     
     if (softGetMemMappedData)
         return softGetMemMappedData(response);
     return NULL;
 }
+
+static bool CFURLCacheIsMemMappedData(CFURLCacheRef cache, CFDataRef data)
+{
+    typedef CFBooleanRef (*functionType)(CFURLCacheRef cache, CFDataRef data);
+    static functionType softLinkIsCacheMMAPedData = (functionType) dlsym(CFNetworkLibrary(), "_CFURLCacheIsResponseDataMemMapped");
+   
+    if (softLinkIsCacheMMAPedData)
+        return softLinkIsCacheMMAPedData(cache, data) == kCFBooleanTrue;
+    return false;
+}
 #endif
 
 @interface NSCachedURLResponse (NSCachedURLResponseDetails)
@@ -57,10 +69,9 @@
 namespace WebKit {
 
 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
-void NetworkResourceLoader::tryGetShareableHandleFromCFURLCachedResponse(ShareableResource::Handle& handle, CFCachedURLResponseRef cachedResponse)
+
+static void tryGetShareableHandleFromCFData(ShareableResource::Handle& handle, CFDataRef data)
 {
-    CFDataRef data = ""
-
     if (!data || CFDataGetLength(data) < (CFIndex)NetworkResourceLoader::fileBackedResourceMinimumSize())
         return;
 
@@ -75,19 +86,24 @@
     resource->createHandle(handle);
 }
 
-void NetworkResourceLoader::tryGetShareableHandleForResource(ShareableResource::Handle& handle)
+void NetworkResourceLoader::tryGetShareableHandleFromCFURLCachedResponse(ShareableResource::Handle& handle, CFCachedURLResponseRef cachedResponse)
 {
-    // Check the cache to see if we can vm_copy a filesystem-backed resource buffer.
+    CFDataRef data = ""
+
+    tryGetShareableHandleFromCFData(handle, data);
+}
+
+void NetworkResourceLoader::tryGetShareableHandleFromSharedBuffer(ShareableResource::Handle& handle, SharedBuffer* buffer)
+{
     RetainPtr<CFURLCacheRef> cache = adoptCF(CFURLCacheCopySharedURLCache());
     if (!cache)
         return;
 
-    CFURLRequestRef cfRequest = request().cfURLRequest(DoNotUpdateHTTPBody);
-    RetainPtr<CFCachedURLResponseRef> cachedResponse = adoptCF(CFURLCacheCopyResponseForRequest(cache.get(), cfRequest));
-    if (!cachedResponse)
+    RetainPtr<CFDataRef> data = ""
+    if (!CFURLCacheIsMemMappedData(cache.get(), data.get()))
         return;
 
-    tryGetShareableHandleFromCFURLCachedResponse(handle, cachedResponse.get());
+    tryGetShareableHandleFromCFData(handle, data.get());
 }
 #endif // __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to