Title: [147006] trunk/Source/WebKit2
Revision
147006
Author
beid...@apple.com
Date
2013-03-27 13:38:24 -0700 (Wed, 27 Mar 2013)

Log Message

Mem mapped resource data improvements.
<rdar://problem/13196481> and https://bugs.webkit.org/show_bug.cgi?id=113422

Reviewed by Alexey Proskuryakov (and looked over by Geoff Garen).

Remove timer-based approach support code:
* NetworkProcess/NetworkResourceLoader.cpp:
(WebKit::NetworkResourceLoader::NetworkResourceLoader):
(WebKit::NetworkResourceLoader::abortInProgressLoad):
(WebKit::NetworkResourceLoader::didFinishLoading):
* NetworkProcess/NetworkResourceLoader.h:

Add an object to encapsulate monitoring a resource going in to the disk cache.
It listens for a callback on the cached response indicating it is disk backed
and also sets a timeout so we don't keep the monitor alive and waiting forever.
* NetworkProcess/mac/DiskCacheMonitor.h: Added.
(WebKit::DiskCacheMonitor::destinationID):
(WebKit::DiskCacheMonitor::connectionToWebProcess):
(WebKit::DiskCacheMonitor::resourceRequest):
* NetworkProcess/mac/DiskCacheMonitor.mm: Added.
(CFCachedURLResponseSetBecameFileBackedCallBackBlock):
(WebKit::monitorFileBackingStoreCreation):
(WebKit::DiskCacheMonitor::DiskCachingMonitor):
(WebKit::DiskCacheMonitor::connection):

Refactoring and monitor certain cached responses:
* NetworkProcess/mac/NetworkResourceLoaderMac.mm:
(CFCachedURLResponseGetMemMappedData):
(WebKit::NetworkResourceLoader::tryGetShareableHandleFromCFURLCachedResponse): Use CFCachedURLResponseGetMemMappedData
  to explicitly get an mem-mapped data object.
(WebKit::NetworkResourceLoader::tryGetShareableHandleForResource):
(WebKit::NetworkResourceLoader::willCacheResponseAsync): If the resource is over the minimum
  size then set up a disk caching monitor.

* WebKit2.xcodeproj/project.pbxproj:

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (147005 => 147006)


--- trunk/Source/WebKit2/ChangeLog	2013-03-27 20:35:23 UTC (rev 147005)
+++ trunk/Source/WebKit2/ChangeLog	2013-03-27 20:38:24 UTC (rev 147006)
@@ -1,3 +1,41 @@
+2013-03-27  Brady Eidson  <beid...@apple.com>
+
+        Mem mapped resource data improvements.
+        <rdar://problem/13196481> and https://bugs.webkit.org/show_bug.cgi?id=113422
+
+        Reviewed by Alexey Proskuryakov (and looked over by Geoff Garen).
+
+        Remove timer-based approach support code:
+        * NetworkProcess/NetworkResourceLoader.cpp:
+        (WebKit::NetworkResourceLoader::NetworkResourceLoader):
+        (WebKit::NetworkResourceLoader::abortInProgressLoad):
+        (WebKit::NetworkResourceLoader::didFinishLoading):
+        * NetworkProcess/NetworkResourceLoader.h:
+
+        Add an object to encapsulate monitoring a resource going in to the disk cache.
+        It listens for a callback on the cached response indicating it is disk backed
+        and also sets a timeout so we don't keep the monitor alive and waiting forever.
+        * NetworkProcess/mac/DiskCacheMonitor.h: Added.
+        (WebKit::DiskCacheMonitor::destinationID):
+        (WebKit::DiskCacheMonitor::connectionToWebProcess):
+        (WebKit::DiskCacheMonitor::resourceRequest):
+        * NetworkProcess/mac/DiskCacheMonitor.mm: Added.
+        (CFCachedURLResponseSetBecameFileBackedCallBackBlock):
+        (WebKit::monitorFileBackingStoreCreation):
+        (WebKit::DiskCacheMonitor::DiskCachingMonitor):
+        (WebKit::DiskCacheMonitor::connection):
+
+        Refactoring and monitor certain cached responses:
+        * NetworkProcess/mac/NetworkResourceLoaderMac.mm:
+        (CFCachedURLResponseGetMemMappedData):
+        (WebKit::NetworkResourceLoader::tryGetShareableHandleFromCFURLCachedResponse): Use CFCachedURLResponseGetMemMappedData
+          to explicitly get an mem-mapped data object.
+        (WebKit::NetworkResourceLoader::tryGetShareableHandleForResource):
+        (WebKit::NetworkResourceLoader::willCacheResponseAsync): If the resource is over the minimum
+          size then set up a disk caching monitor.
+
+        * WebKit2.xcodeproj/project.pbxproj:
+
 2013-03-26  Timothy Hatcher  <timo...@apple.com>
 
         Add support for dock-to-right of the Web Inspector in the Mac port.

Modified: trunk/Source/WebKit2/NetworkProcess/NetworkResourceLoader.cpp (147005 => 147006)


--- trunk/Source/WebKit2/NetworkProcess/NetworkResourceLoader.cpp	2013-03-27 20:35:23 UTC (rev 147005)
+++ trunk/Source/WebKit2/NetworkProcess/NetworkResourceLoader.cpp	2013-03-27 20:38:24 UTC (rev 147006)
@@ -54,9 +54,6 @@
 NetworkResourceLoader::NetworkResourceLoader(const NetworkResourceLoadParameters& loadParameters, NetworkConnectionToWebProcess* connection)
     : SchedulableLoader(loadParameters, connection)
     , m_bytesReceived(0)
-#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
-    , m_diskCacheTimer(RunLoop::main(), this, &NetworkResourceLoader::diskCacheTimerFired)
-#endif // __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
 {
     ASSERT(isMainThread());
 }
@@ -174,21 +171,6 @@
     cleanup();
 }
 
-#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
-void NetworkResourceLoader::diskCacheTimerFired()
-{
-    ASSERT(isMainThread());
-    RefPtr<NetworkResourceLoader> adoptedRef = adoptRef(this); // Balance out the ref() when setting the timer.
-
-    ShareableResource::Handle handle;
-    tryGetShareableHandleForResource(handle);
-    if (handle.isNull())
-        return;
-
-    send(Messages::NetworkProcessConnection::DidCacheResource(request(), handle));
-}
-#endif // #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
-
 template<typename U> bool NetworkResourceLoader::sendAbortingOnFailure(const U& message)
 {
     bool result = send(message);
@@ -208,8 +190,8 @@
 void NetworkResourceLoader::abortInProgressLoad()
 {
     ASSERT(m_handle);
-    ASSERT(!isMainThread());
- 
+    ASSERT(isMainThread());
+
     m_handle->cancel();
 
     scheduleCleanupOnMainThread();
@@ -254,16 +236,6 @@
     // Such bookkeeping will need to be thread safe, as this callback is happening on a background thread.
     invalidateSandboxExtensions();
     send(Messages::WebResourceLoader::DidFinishResourceLoad(finishTime));
-
-#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
-    // If this resource was large enough that it should be cached to disk as a separate file,
-    // then we should try to re-deliver the resource to the WebProcess once it *is* saved as a separate file.    
-    if (m_bytesReceived >= fileBackedResourceMinimumSize()) {
-        // FIXME: Once a notification API exists that obliviates this timer, use that instead.
-        ref(); // Balanced by an adoptRef() in diskCacheTimerFired().
-        m_diskCacheTimer.startOneShot(10);
-    }
-#endif // __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
     
     scheduleCleanupOnMainThread();
 }
@@ -373,12 +345,6 @@
 #endif
 
 #if PLATFORM(MAC)
-void NetworkResourceLoader::willCacheResponseAsync(ResourceHandle* handle, NSCachedURLResponse* response)
-{
-    notImplemented();
-    handle->continueWillCacheResponse(response);
-}
-
 void NetworkResourceLoader::willStopBufferingData(ResourceHandle*, const char*, int)
 {
     notImplemented();

Modified: trunk/Source/WebKit2/NetworkProcess/NetworkResourceLoader.h (147005 => 147006)


--- trunk/Source/WebKit2/NetworkProcess/NetworkResourceLoader.h	2013-03-27 20:35:23 UTC (rev 147005)
+++ trunk/Source/WebKit2/NetworkProcess/NetworkResourceLoader.h	2013-03-27 20:38:24 UTC (rev 147006)
@@ -35,6 +35,8 @@
 #include <WebCore/ResourceLoaderOptions.h>
 #include <WebCore/RunLoop.h>
 
+typedef const struct _CFCachedURLResponse* CFCachedURLResponseRef;
+
 namespace WebCore {
 class ResourceBuffer;
 class ResourceHandle;
@@ -95,6 +97,10 @@
     // Message handlers.
     void didReceiveNetworkResourceLoaderMessage(CoreIPC::Connection*, CoreIPC::MessageDecoder&);
 
+#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
+    static void tryGetShareableHandleFromCFURLCachedResponse(ShareableResource::Handle&, CFCachedURLResponseRef);
+#endif
+
 private:
     NetworkResourceLoader(const NetworkResourceLoadParameters&, NetworkConnectionToWebProcess*);
 
@@ -113,8 +119,6 @@
     template<typename U> bool sendSyncAbortingOnFailure(const U& message, const typename U::Reply& reply);
     void abortInProgressLoad();
 
-    void tryGetShareableHandleForResource(ShareableResource::Handle&);
-
     RefPtr<RemoteNetworkingContext> m_networkingContext;
     RefPtr<WebCore::ResourceHandle> m_handle;
 
@@ -124,8 +128,7 @@
     uint64_t m_bytesReceived;
 
 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
-    void diskCacheTimerFired();
-    WebCore::RunLoop::Timer<NetworkResourceLoader> m_diskCacheTimer;
+    void tryGetShareableHandleForResource(ShareableResource::Handle&);
 #endif
 };
 

Added: trunk/Source/WebKit2/NetworkProcess/mac/DiskCacheMonitor.h (0 => 147006)


--- trunk/Source/WebKit2/NetworkProcess/mac/DiskCacheMonitor.h	                        (rev 0)
+++ trunk/Source/WebKit2/NetworkProcess/mac/DiskCacheMonitor.h	2013-03-27 20:38:24 UTC (rev 147006)
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef DiskCacheMonitor_h
+#define DiskCacheMonitor_h
+
+#include "MessageSender.h"
+#include <WebCore/ResourceRequest.h>
+#include <WebCore/RunLoop.h>
+
+typedef const struct _CFCachedURLResponse* CFCachedURLResponseRef;
+
+namespace WebKit {
+
+class NetworkConnectionToWebProcess;
+class NetworkResourceLoader;
+
+class DiskCacheMonitor : public CoreIPC::MessageSender<DiskCacheMonitor> {
+public:
+    static void monitorFileBackingStoreCreation(CFCachedURLResponseRef, NetworkResourceLoader*);
+
+    // Used by MessageSender.
+    CoreIPC::Connection* connection() const;
+    uint64_t destinationID() const { return 0; }
+    
+    const WebCore::ResourceRequest& resourceRequest() const { return m_resourceRequest; }
+
+private:
+    DiskCacheMonitor(CFCachedURLResponseRef, NetworkResourceLoader*);
+    
+    RefPtr<NetworkConnectionToWebProcess> m_connectionToWebProcess;
+    WebCore::ResourceRequest m_resourceRequest;
+};
+
+
+} // namespace WebKit
+
+#endif // DiskCacheMonitor_h

Added: trunk/Source/WebKit2/NetworkProcess/mac/DiskCacheMonitor.mm (0 => 147006)


--- trunk/Source/WebKit2/NetworkProcess/mac/DiskCacheMonitor.mm	                        (rev 0)
+++ trunk/Source/WebKit2/NetworkProcess/mac/DiskCacheMonitor.mm	2013-03-27 20:38:24 UTC (rev 147006)
@@ -0,0 +1,107 @@
+/*
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+#import "DiskCacheMonitor.h"
+
+#import "NetworkConnectionToWebProcess.h"
+#import "NetworkProcessConnectionMessages.h"
+#import "NetworkResourceLoader.h"
+#import "WebCoreArgumentCoders.h"
+#import <WebCore/SoftLinking.h>
+
+#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
+
+SOFT_LINK_FRAMEWORK(CFNetwork)
+
+typedef void (^CFCachedURLResponseCallBackBlock)(CFCachedURLResponseRef);
+static void CFCachedURLResponseSetBecameFileBackedCallBackBlock(CFCachedURLResponseRef response, CFCachedURLResponseCallBackBlock callback, dispatch_queue_t queue)
+{
+    typedef void (*SetCallbackFunctionType)(CFCachedURLResponseRef, CFCachedURLResponseCallBackBlock, dispatch_queue_t);
+    static SetCallbackFunctionType softResponseSetBecameFileBackedCallBackBlock = (SetCallbackFunctionType) dlsym(CFNetworkLibrary(), "_CFCachedURLResponseSetBecameFileBackedCallBackBlock");
+    if (softResponseSetBecameFileBackedCallBackBlock)
+        return softResponseSetBecameFileBackedCallBackBlock(response, callback, queue);
+}
+
+using namespace WebCore;
+
+namespace WebKit {
+
+// The maximum number of seconds we'll try to wait for a resource to be disk cached before we forget the request.
+static const double diskCacheMonitorTimeout = 20;
+
+void DiskCacheMonitor::monitorFileBackingStoreCreation(CFCachedURLResponseRef cachedResponse, NetworkResourceLoader* loader)
+{
+    if (!cachedResponse)
+        return;
+
+    ASSERT(loader);
+
+    new DiskCacheMonitor(cachedResponse, loader); // Balanced by adoptPtr in the blocks setup in the constructor, one of which is guaranteed to run.
+}
+
+DiskCacheMonitor::DiskCacheMonitor(CFCachedURLResponseRef cachedResponse, NetworkResourceLoader* loader)
+    : m_connectionToWebProcess(loader->connectionToWebProcess())
+    , m_resourceRequest(loader->request())
+{
+    ASSERT(isMainThread());
+
+    // Set up a delayed callback to cancel this monitor if the resource hasn't been cached yet.
+    __block DiskCacheMonitor* rawMonitor = this;
+
+    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_SEC * diskCacheMonitorTimeout), dispatch_get_main_queue(), ^{
+        adoptPtr(rawMonitor); // Balanced by `new DiskCacheMonitor` in monitorFileBackingStoreCreation.
+        rawMonitor = 0;
+    });
+
+    // Set up the disk caching callback to create the ShareableResource and send it to the WebProcess.
+    CFCachedURLResponseCallBackBlock block = ^(CFCachedURLResponseRef cachedResponse)
+    {
+        // If the monitor isn't there then it timed out before this resource was cached to disk.
+        if (!rawMonitor)
+            return;
+
+        OwnPtr<DiskCacheMonitor> monitor = adoptPtr(rawMonitor); // Balanced by `new DiskCacheMonitor` in monitorFileBackingStoreCreation.
+        rawMonitor = 0;
+        
+        ShareableResource::Handle handle;
+        NetworkResourceLoader::tryGetShareableHandleFromCFURLCachedResponse(handle, cachedResponse);
+        if (handle.isNull())
+            return;
+
+        monitor->send(Messages::NetworkProcessConnection::DidCacheResource(monitor->resourceRequest(), handle));
+    };
+
+    CFCachedURLResponseSetBecameFileBackedCallBackBlock(cachedResponse, block, dispatch_get_main_queue());
+}
+
+CoreIPC::Connection* DiskCacheMonitor::connection() const
+{
+    return m_connectionToWebProcess->connection();
+}
+
+} // namespace WebKit
+
+#endif // #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090

Modified: trunk/Source/WebKit2/NetworkProcess/mac/NetworkResourceLoaderMac.mm (147005 => 147006)


--- trunk/Source/WebKit2/NetworkProcess/mac/NetworkResourceLoaderMac.mm	2013-03-27 20:35:23 UTC (rev 147005)
+++ trunk/Source/WebKit2/NetworkProcess/mac/NetworkResourceLoaderMac.mm	2013-03-27 20:38:24 UTC (rev 147006)
@@ -26,81 +26,86 @@
 #import "config.h"
 #import "NetworkResourceLoader.h"
 
-#include "ShareableResource.h"
-#include "SharedMemory.h"
-#include "WebResourceLoaderMessages.h"
-#include <WebCore/SoftLinking.h>
+#import "DiskCacheMonitor.h"
+#import "ShareableResource.h"
+#import <WebCore/ResourceHandle.h>
+#import <WebCore/SoftLinking.h>
 
 using namespace WebCore;
 
 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
-typedef struct _CFURLCache* CFURLCacheRef;
-typedef struct _CFCachedURLResponse* CFCachedURLResponseRef;
+typedef const struct _CFURLCache* CFURLCacheRef;
+typedef const struct _CFCachedURLResponse* CFCachedURLResponseRef;
 extern "C" CFURLCacheRef CFURLCacheCopySharedURLCache();
 extern "C" CFCachedURLResponseRef CFURLCacheCopyResponseForRequest(CFURLCacheRef, CFURLRequestRef);
-extern "C" CFArrayRef CFCachedURLResponseCopyReceiverDataArray(CFCachedURLResponseRef);
 
 SOFT_LINK_FRAMEWORK(CFNetwork)
-static bool CFURLCacheIsMemMappedData(CFURLCacheRef cache, CFDataRef data)
+static CFDataRef CFCachedURLResponseGetMemMappedData(CFCachedURLResponseRef response)
 {
-    static CFBooleanRef (*softLinkIsCacheMMAPedData)(CFURLCacheRef cache, CFDataRef data) = (CFBooleanRef (*)(CFURLCacheRef cache, CFDataRef data)) dlsym(CFNetworkLibrary(), "_CFURLCacheIsResponseDataMemMapped");
+    static CFDataRef (*softGetMemMappedData)(CFCachedURLResponseRef) = (CFDataRef (*)(CFCachedURLResponseRef)) dlsym(CFNetworkLibrary(), "_CFCachedURLResponseGetMemMappedData");
     
-    if (softLinkIsCacheMMAPedData)
-        return softLinkIsCacheMMAPedData(cache, data) == kCFBooleanTrue;
-    return false;
+    if (softGetMemMappedData)
+        return softGetMemMappedData(response);
+    return NULL;
 }
 #endif
 
+@interface NSCachedURLResponse (NSCachedURLResponseDetails)
+-(CFCachedURLResponseRef)_CFCachedURLResponse;
+@end
+
 namespace WebKit {
 
-void NetworkResourceLoader::tryGetShareableHandleForResource(ShareableResource::Handle& handle)
+#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
+void NetworkResourceLoader::tryGetShareableHandleFromCFURLCachedResponse(ShareableResource::Handle& handle, CFCachedURLResponseRef cachedResponse)
 {
-#if __MAC_OS_X_VERSION_MIN_REQUIRED < 1090
-    return;
-#else
+    CFDataRef data = ""
 
-    // Check the cache to see if we can vm_copy a filesystem-backed resource buffer.   
-    RetainPtr<CFURLCacheRef> cache = adoptCF(CFURLCacheCopySharedURLCache());
-    if (!cache)
+    if (!data || CFDataGetLength(data) < (CFIndex)NetworkResourceLoader::fileBackedResourceMinimumSize())
         return;
 
-    CFURLRequestRef cfRequest = request().cfURLRequest(DoNotUpdateHTTPBody);
-    RetainPtr<CFCachedURLResponseRef> cachedResponse = adoptCF(CFURLCacheCopyResponseForRequest(cache.get(), cfRequest));
-    if (!cachedResponse)
-        return;
-
-    RetainPtr<CFArrayRef> array = adoptCF(CFCachedURLResponseCopyReceiverDataArray(cachedResponse.get()));
-    if (!array || CFArrayGetCount(array.get()) != 1)
-        return;
-    
-    CFTypeRef value = CFArrayGetValueAtIndex(array.get(), 0);
-    if (CFGetTypeID(value) != CFDataGetTypeID())
-        return;
-    CFDataRef data = ""
-
-    // We only care about the vm_copy optimization for resources that should be file backed.
-    // FIXME: If there were an API available to guarantee that a buffer was file backed, we should use it here.
-    if (CFDataGetLength(data) < (CFIndex)fileBackedResourceMinimumSize())
-        return;
-    
-    if (!CFURLCacheIsMemMappedData(cache.get(), data))
-        return;
-
     RefPtr<SharedMemory> sharedMemory = SharedMemory::createFromVMBuffer((void*)CFDataGetBytePtr(data), CFDataGetLength(data));
     if (!sharedMemory) {
-        LOG_ERROR("Failed to create VMCopied shared memory for cached resource.");
+        LOG_ERROR("Failed to create VM shared memory for cached resource.");
         return;
     }
 
     size_t size = sharedMemory->size();
     RefPtr<ShareableResource> resource = ShareableResource::create(sharedMemory.release(), 0, size);
     resource->createHandle(handle);
-#endif // __MAC_OS_X_VERSION_MIN_REQUIRED < 1090
 }
 
+void NetworkResourceLoader::tryGetShareableHandleForResource(ShareableResource::Handle& handle)
+{
+    // Check the cache to see if we can vm_copy a filesystem-backed resource buffer.
+    RetainPtr<CFURLCacheRef> cache = adoptCF(CFURLCacheCopySharedURLCache());
+    if (!cache)
+        return;
+
+    CFURLRequestRef cfRequest = request().cfURLRequest(DoNotUpdateHTTPBody);
+    RetainPtr<CFCachedURLResponseRef> cachedResponse = adoptCF(CFURLCacheCopyResponseForRequest(cache.get(), cfRequest));
+    if (!cachedResponse)
+        return;
+
+    tryGetShareableHandleFromCFURLCachedResponse(handle, cachedResponse.get());
+}
+#endif // __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
+
 size_t NetworkResourceLoader::fileBackedResourceMinimumSize()
 {
     return SharedMemory::systemPageSize();
 }
 
+void NetworkResourceLoader::willCacheResponseAsync(ResourceHandle* handle, NSCachedURLResponse *nsResponse)
+{
+    ASSERT(handle == m_handle);
+
+#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
+    if (m_bytesReceived >= fileBackedResourceMinimumSize())
+        DiskCacheMonitor::monitorFileBackingStoreCreation([nsResponse _CFCachedURLResponse], this);
+#endif
+
+    m_handle->continueWillCacheResponse(nsResponse);
+}
+
 } // namespace WebKit

Modified: trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj (147005 => 147006)


--- trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj	2013-03-27 20:35:23 UTC (rev 147005)
+++ trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj	2013-03-27 20:38:24 UTC (rev 147006)
@@ -468,6 +468,8 @@
 		516319921628980A00E22F00 /* NetworkProcessProxyMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 516319911628980A00E22F00 /* NetworkProcessProxyMac.mm */; };
 		5163199416289A6000E22F00 /* NetworkProcessMessageReceiver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51ACC9341628064800342550 /* NetworkProcessMessageReceiver.cpp */; };
 		5163199516289A6300E22F00 /* NetworkProcessMessages.h in Headers */ = {isa = PBXBuildFile; fileRef = 51ACC9351628064800342550 /* NetworkProcessMessages.h */; };
+		5167EEA0170377BF007681CA /* DiskCacheMonitor.h in Headers */ = {isa = PBXBuildFile; fileRef = 5167EE9E170377BF007681CA /* DiskCacheMonitor.h */; };
+		5167EEA1170377BF007681CA /* DiskCacheMonitor.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5167EE9F170377BF007681CA /* DiskCacheMonitor.mm */; };
 		516A4A5D120A2CCD00C05B7F /* WebError.h in Headers */ = {isa = PBXBuildFile; fileRef = 516A4A5B120A2CCD00C05B7F /* WebError.h */; };
 		51795567162876CB00FA43B6 /* NetworkProcessMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 51A8A6151627F3F9000D90E9 /* NetworkProcessMac.mm */; };
 		51795568162876CF00FA43B6 /* NetworkProcess.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 510CC7DF16138E2900D03ED3 /* NetworkProcess.cpp */; };
@@ -1874,6 +1876,8 @@
 		51578B821209ECEF00A37C4A /* WebData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebData.h; sourceTree = "<group>"; };
 		5160BFE013381DF900918999 /* Logging.mac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = Logging.mac.mm; sourceTree = "<group>"; };
 		516319911628980A00E22F00 /* NetworkProcessProxyMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = NetworkProcessProxyMac.mm; path = mac/NetworkProcessProxyMac.mm; sourceTree = "<group>"; };
+		5167EE9E170377BF007681CA /* DiskCacheMonitor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DiskCacheMonitor.h; sourceTree = "<group>"; };
+		5167EE9F170377BF007681CA /* DiskCacheMonitor.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DiskCacheMonitor.mm; sourceTree = "<group>"; };
 		516A4A5B120A2CCD00C05B7F /* WebError.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebError.h; sourceTree = "<group>"; };
 		517A33B3130B308C00F80CB5 /* WKApplicationCacheManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WKApplicationCacheManager.cpp; sourceTree = "<group>"; };
 		517A33B4130B308C00F80CB5 /* WKApplicationCacheManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKApplicationCacheManager.h; sourceTree = "<group>"; };
@@ -3521,6 +3525,8 @@
 			isa = PBXGroup;
 			children = (
 				E17AE2C116B9C139001C42F1 /* com.apple.WebKit.NetworkProcess.sb.in */,
+				5167EE9E170377BF007681CA /* DiskCacheMonitor.h */,
+				5167EE9F170377BF007681CA /* DiskCacheMonitor.mm */,
 				51A8A6151627F3F9000D90E9 /* NetworkProcessMac.mm */,
 				512C068F16390E6900ABB911 /* NetworkResourceLoadSchedulerMac.mm */,
 				51E3B67E16F266B3009968DC /* NetworkResourceLoaderMac.mm */,
@@ -5493,6 +5499,7 @@
 				512F58F612A88A5400629530 /* WKAuthenticationChallenge.h in Headers */,
 				512F58F812A88A5400629530 /* WKAuthenticationDecisionListener.h in Headers */,
 				BC646C1B11DD399F006455B0 /* WKBackForwardList.h in Headers */,
+				5167EEA0170377BF007681CA /* DiskCacheMonitor.h in Headers */,
 				BC646C1D11DD399F006455B0 /* WKBackForwardListItem.h in Headers */,
 				BCDDB317124EBD130048D13C /* WKBase.h in Headers */,
 				BCBAAC73144E619E0053F82F /* WKBrowsingContextController.h in Headers */,
@@ -6814,6 +6821,7 @@
 				E134F01A12EA5D99004EC58D /* WKPrintingView.mm in Sources */,
 				BCBAACEC145225E30053F82F /* WKProcessGroup.mm in Sources */,
 				512F58FB12A88A5400629530 /* WKProtectionSpace.cpp in Sources */,
+				5167EEA1170377BF007681CA /* DiskCacheMonitor.mm in Sources */,
 				37948408150C4B9700E52CE9 /* WKRenderLayer.cpp in Sources */,
 				37608822150414F700FC82C7 /* WKRenderObject.cpp in Sources */,
 				3336763A130C99DC006C9DE2 /* WKResourceCacheManager.cpp in Sources */,
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to