Diff
Modified: trunk/Source/WebCore/ChangeLog (184619 => 184620)
--- trunk/Source/WebCore/ChangeLog 2015-05-20 06:29:13 UTC (rev 184619)
+++ trunk/Source/WebCore/ChangeLog 2015-05-20 07:04:34 UTC (rev 184620)
@@ -1,3 +1,20 @@
+2015-05-19 Carlos Garcia Campos <[email protected]>
+
+ [SOUP] Network Cache: Implement ShareableResource for Soup and enable it for GTK platform
+ https://bugs.webkit.org/show_bug.cgi?id=144380
+
+ Reviewed by Antti Koivisto.
+
+ Add a soup implementation of SharedBuffer::tryReplaceContentsWithPlatformBuffer().
+
+ Covered by http/tests/cache/disk-cache/ tests.
+
+ * loader/cache/CachedResource.cpp: Define
+ CachedResource::tryReplaceEncodedData() also for Soup.
+ * loader/cache/CachedResource.h: Ditto.
+ * platform/soup/SharedBufferSoup.cpp:
+ (WebCore::SharedBuffer::tryReplaceContentsWithPlatformBuffer):
+
2015-05-17 Sam Weinig <[email protected]>
Organize event handlers a bit
Modified: trunk/Source/WebCore/loader/cache/CachedResource.cpp (184619 => 184620)
--- trunk/Source/WebCore/loader/cache/CachedResource.cpp 2015-05-20 06:29:13 UTC (rev 184619)
+++ trunk/Source/WebCore/loader/cache/CachedResource.cpp 2015-05-20 07:04:34 UTC (rev 184620)
@@ -773,7 +773,7 @@
m_resource.didAddClient(&m_client);
}
-#if USE(FOUNDATION)
+#if USE(FOUNDATION) || USE(SOUP)
void CachedResource::tryReplaceEncodedData(SharedBuffer& newBuffer)
{
Modified: trunk/Source/WebCore/loader/cache/CachedResource.h (184619 => 184620)
--- trunk/Source/WebCore/loader/cache/CachedResource.h 2015-05-20 06:29:13 UTC (rev 184619)
+++ trunk/Source/WebCore/loader/cache/CachedResource.h 2015-05-20 07:04:34 UTC (rev 184620)
@@ -252,7 +252,7 @@
virtual bool canReuse(const ResourceRequest&) const { return true; }
-#if USE(FOUNDATION)
+#if USE(FOUNDATION) || USE(SOUP)
WEBCORE_EXPORT void tryReplaceEncodedData(SharedBuffer&);
#endif
Modified: trunk/Source/WebCore/platform/soup/SharedBufferSoup.cpp (184619 => 184620)
--- trunk/Source/WebCore/platform/soup/SharedBufferSoup.cpp 2015-05-20 06:29:13 UTC (rev 184619)
+++ trunk/Source/WebCore/platform/soup/SharedBufferSoup.cpp 2015-05-20 07:04:34 UTC (rev 184620)
@@ -78,6 +78,16 @@
return false;
}
+void SharedBuffer::tryReplaceContentsWithPlatformBuffer(SharedBuffer& newContents)
+{
+ if (!newContents.hasPlatformData())
+ return;
+
+ clear();
+ // FIXME: Use GRefPtr instead of GUniquePtr for the SoupBuffer.
+ m_soupBuffer.swap(newContents.m_soupBuffer);
+}
+
} // namespace WebCore
#endif
Modified: trunk/Source/WebKit2/ChangeLog (184619 => 184620)
--- trunk/Source/WebKit2/ChangeLog 2015-05-20 06:29:13 UTC (rev 184619)
+++ trunk/Source/WebKit2/ChangeLog 2015-05-20 07:04:34 UTC (rev 184620)
@@ -1,5 +1,60 @@
2015-05-19 Carlos Garcia Campos <[email protected]>
+ [SOUP] Network Cache: Implement ShareableResource for Soup and enable it for GTK platform
+ https://bugs.webkit.org/show_bug.cgi?id=144380
+
+ Reviewed by Antti Koivisto.
+
+ It improves the network cache performance, by mmaping big
+ resources and sending only the file descriptor to the web process
+ instead of the actual file data. It needs some changes in
+ cross-platform code, because we can't use the same approach as
+ mac (it uses a platform specific implementation not available in
+ other platforms).
+
+ * NetworkProcess/cache/NetworkCache.cpp:
+ (WebKit::NetworkCache::Cache::store): Use
+ Data::tryCreateSharedMemory() to create the shared memory used by
+ the ShareableResource. Also add an ASSERT instead of checking the
+ shareable resource created is not nullptr, because the
+ ShareableResource::create() that receives a shared memory should
+ never return nullptr.
+ * NetworkProcess/cache/NetworkCacheData.h:
+ * NetworkProcess/cache/NetworkCacheDataCocoa.mm:
+ (WebKit::NetworkCache::Data::tryCreateSharedMemory):
+ * NetworkProcess/cache/NetworkCacheDataSoup.cpp:
+ (WebKit::NetworkCache::Data::tryCreateSharedMemory): Create a
+ SharedMemory object to wrap the mapped file, but keeping the ownership.
+ * NetworkProcess/cache/NetworkCacheEntry.cpp:
+ (WebKit::NetworkCache::Entry::initializeShareableResourceHandleFromStorageRecord):
+ Use Data::tryCreateSharedMemory() to create the shared memory used
+ bythe ShareableResource. Also add an ASSERT instead of checking
+ the shareable resource created is not nullptr, because the
+ ShareableResource::create() that receives a shared memory should
+ never return nullptr.
+ * Platform/SharedMemory.h:
+ * Platform/unix/SharedMemoryUnix.cpp:
+ (WebKit::SharedMemory::map): Use wrapMap() and initialize
+ m_isWrappingMap to false.
+ (WebKit::SharedMemory::wrapMap): Create a SharedMemory object for
+ the given map, without taking its ownership.
+ (WebKit::SharedMemory::~SharedMemory): Do not unmap and close the
+ file descriptor if m_isWrappingMap is true.
+ * Shared/ShareableResource.cpp:
+ (WebKit::createShareableResourceDeallocator):
+ (WebKit::ShareableResource::wrapInSharedBuffer): Create a SharedBuffer
+ wrapping the ShareableResource data.
+ (WebKit::ShareableResource::Handle::tryWrapInSharedBuffer): Create
+ a ShareableResource for the handle and create a SharedBuffer
+ wrapping it.
+ * Shared/ShareableResource.h:
+ * WebKit2Prefix.h: Enable ENABLE_SHAREABLE_RESOURCE for GTK.
+ * WebProcess/Network/WebResourceLoader.cpp:
+ (WebKit::WebResourceLoader::didReceiveResource): Get the CFData
+ from the SharedBuffer for QuickLook instead of wrapping the handle again.
+
+2015-05-19 Carlos Garcia Campos <[email protected]>
+
[SOUP] Network Cache: Disable network cache efficacy logging
https://bugs.webkit.org/show_bug.cgi?id=145172
Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.cpp (184619 => 184620)
--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.cpp 2015-05-20 06:29:13 UTC (rev 184619)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.cpp 2015-05-20 07:04:34 UTC (rev 184620)
@@ -414,11 +414,10 @@
m_storage->store(record, [completionHandler](const Data& bodyData) {
MappedBody mappedBody;
#if ENABLE(SHAREABLE_RESOURCE)
- if (bodyData.isMap()) {
- RefPtr<SharedMemory> sharedMemory = SharedMemory::create(const_cast<uint8_t*>(bodyData.data()), bodyData.size(), SharedMemory::Protection::ReadOnly);
- mappedBody.shareableResource = sharedMemory ? ShareableResource::create(WTF::move(sharedMemory), 0, bodyData.size()) : nullptr;
- if (mappedBody.shareableResource)
- mappedBody.shareableResource->createHandle(mappedBody.shareableResourceHandle);
+ if (RefPtr<SharedMemory> sharedMemory = bodyData.tryCreateSharedMemory()) {
+ mappedBody.shareableResource = ShareableResource::create(WTF::move(sharedMemory), 0, bodyData.size());
+ ASSERT(mappedBody.shareableResource);
+ mappedBody.shareableResource->createHandle(mappedBody.shareableResourceHandle);
}
#endif
completionHandler(mappedBody);
Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheData.h (184619 => 184620)
--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheData.h 2015-05-20 06:29:13 UTC (rev 184619)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheData.h 2015-05-20 07:04:34 UTC (rev 184620)
@@ -39,6 +39,9 @@
#endif
namespace WebKit {
+
+class SharedMemory;
+
namespace NetworkCache {
#if PLATFORM(COCOA)
@@ -119,6 +122,7 @@
const uint8_t* data() const;
size_t size() const { return m_size; }
bool isMap() const { return m_isMap; }
+ RefPtr<SharedMemory> tryCreateSharedMemory() const;
Data subrange(size_t offset, size_t) const;
Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheDataCocoa.mm (184619 => 184620)
--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheDataCocoa.mm 2015-05-20 06:29:13 UTC (rev 184619)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheDataCocoa.mm 2015-05-20 07:04:34 UTC (rev 184620)
@@ -28,6 +28,7 @@
#if ENABLE(NETWORK_CACHE)
+#include "SharedMemory.h"
#include <dispatch/dispatch.h>
#include <sys/mman.h>
#include <sys/stat.h>
@@ -103,7 +104,13 @@
return { bodyMap, Data::Backing::Map };
}
+RefPtr<SharedMemory> Data::tryCreateSharedMemory() const
+{
+ if (isNull() || !isMap())
+ return nullptr;
+ return SharedMemory::create(const_cast<uint8_t*>(data()), m_size, SharedMemory::Protection::ReadOnly);
+}
}
}
Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheDataSoup.cpp (184619 => 184620)
--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheDataSoup.cpp 2015-05-20 06:29:13 UTC (rev 184619)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheDataSoup.cpp 2015-05-20 07:04:34 UTC (rev 184620)
@@ -28,6 +28,7 @@
#if ENABLE(NETWORK_CACHE)
+#include "SharedMemory.h"
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/stat.h>
@@ -127,7 +128,13 @@
return { WTF::move(buffer), fd };
}
+RefPtr<SharedMemory> Data::tryCreateSharedMemory() const
+{
+ if (isNull() || !isMap())
+ return nullptr;
+ return SharedMemory::wrapMap(const_cast<char*>(m_buffer->data), m_buffer->length, m_fileDescriptor);
+}
} // namespace NetworkCache
} // namespace WebKit
Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheEntry.cpp (184619 => 184620)
--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheEntry.cpp 2015-05-20 06:29:13 UTC (rev 184619)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheEntry.cpp 2015-05-20 07:04:34 UTC (rev 184620)
@@ -104,12 +104,13 @@
#if ENABLE(SHAREABLE_RESOURCE)
void Entry::initializeShareableResourceHandleFromStorageRecord() const
{
- auto* data = ""
- size_t size = m_sourceStorageRecord.body.size();
- RefPtr<SharedMemory> sharedMemory = m_sourceStorageRecord.body.isMap() ? SharedMemory::create(const_cast<uint8_t*>(data), size, SharedMemory::Protection::ReadOnly) : nullptr;
- RefPtr<ShareableResource> shareableResource = sharedMemory ? ShareableResource::create(sharedMemory.release(), 0, size) : nullptr;
- if (shareableResource)
- shareableResource->createHandle(m_shareableResourceHandle);
+ RefPtr<SharedMemory> sharedMemory = m_sourceStorageRecord.body.tryCreateSharedMemory();
+ if (!sharedMemory)
+ return;
+
+ RefPtr<ShareableResource> shareableResource = ShareableResource::create(sharedMemory.release(), 0, m_sourceStorageRecord.body.size());
+ ASSERT(shareableResource);
+ shareableResource->createHandle(m_shareableResourceHandle);
}
#endif
Modified: trunk/Source/WebKit2/Platform/SharedMemory.h (184619 => 184620)
--- trunk/Source/WebKit2/Platform/SharedMemory.h 2015-05-20 06:29:13 UTC (rev 184619)
+++ trunk/Source/WebKit2/Platform/SharedMemory.h 2015-05-20 07:04:34 UTC (rev 184620)
@@ -85,6 +85,9 @@
static RefPtr<SharedMemory> allocate(size_t);
static RefPtr<SharedMemory> create(void*, size_t, Protection);
static RefPtr<SharedMemory> map(const Handle&, Protection);
+#if USE(UNIX_DOMAIN_SOCKETS)
+ static RefPtr<SharedMemory> wrapMap(void*, size_t, int fileDescriptor);
+#endif
~SharedMemory();
@@ -113,6 +116,7 @@
mach_port_t m_port;
#elif USE(UNIX_DOMAIN_SOCKETS)
int m_fileDescriptor;
+ bool m_isWrappingMap { false };
#endif
};
Modified: trunk/Source/WebKit2/Platform/unix/SharedMemoryUnix.cpp (184619 => 184620)
--- trunk/Source/WebKit2/Platform/unix/SharedMemoryUnix.cpp 2015-05-20 06:29:13 UTC (rev 184619)
+++ trunk/Source/WebKit2/Platform/unix/SharedMemoryUnix.cpp 2015-05-20 07:04:34 UTC (rev 184620)
@@ -156,17 +156,27 @@
if (data == MAP_FAILED)
return nullptr;
+ RefPtr<SharedMemory> instance = wrapMap(data, handle.m_attachment.size(), handle.m_attachment.releaseFileDescriptor());
+ instance->m_isWrappingMap = false;
+ return instance;
+}
+
+RefPtr<SharedMemory> SharedMemory::wrapMap(void* data, size_t size, int fileDescriptor)
+{
RefPtr<SharedMemory> instance = adoptRef(new SharedMemory());
instance->m_data = data;
- instance->m_fileDescriptor = handle.m_attachment.releaseFileDescriptor();
- instance->m_size = handle.m_attachment.size();
+ instance->m_size = size;
+ instance->m_fileDescriptor = fileDescriptor;
+ instance->m_isWrappingMap = true;
return instance;
}
SharedMemory::~SharedMemory()
{
- munmap(m_data, m_size);
- closeWithRetry(m_fileDescriptor);
+ if (!m_isWrappingMap) {
+ munmap(m_data, m_size);
+ closeWithRetry(m_fileDescriptor);
+ }
}
bool SharedMemory::createHandle(Handle& handle, Protection)
Modified: trunk/Source/WebKit2/Shared/ShareableResource.cpp (184619 => 184620)
--- trunk/Source/WebKit2/Shared/ShareableResource.cpp 2015-05-20 06:29:13 UTC (rev 184619)
+++ trunk/Source/WebKit2/Shared/ShareableResource.cpp 2015-05-20 07:04:34 UTC (rev 184620)
@@ -57,6 +57,7 @@
return true;
}
+#if USE(CF)
static void shareableResourceDeallocate(void *ptr, void *info)
{
(static_cast<ShareableResource*>(info))->deref(); // Balanced by ref() in createShareableResourceDeallocator()
@@ -64,8 +65,6 @@
static CFAllocatorRef createShareableResourceDeallocator(ShareableResource* resource)
{
- resource->ref(); // Balanced by deref in shareableResourceDeallocate()
-
CFAllocatorContext context = { 0,
resource,
NULL, // retain
@@ -79,24 +78,35 @@
return CFAllocatorCreate(kCFAllocatorDefault, &context);
}
+#endif
-RetainPtr<CFDataRef> ShareableResource::Handle::tryWrapInCFData() const
+PassRefPtr<SharedBuffer> ShareableResource::wrapInSharedBuffer()
{
+ ref(); // Balanced by deref when SharedBuffer is deallocated.
+
+#if USE(CF)
+ RetainPtr<CFAllocatorRef> deallocator = adoptCF(createShareableResourceDeallocator(this));
+ RetainPtr<CFDataRef> cfData = adoptCF(CFDataCreateWithBytesNoCopy(kCFAllocatorDefault, reinterpret_cast<const UInt8*>(data()), static_cast<CFIndex>(size()), deallocator.get()));
+ return SharedBuffer::wrapCFData(cfData.get());
+#elif USE(SOUP)
+ return SharedBuffer::wrapSoupBuffer(soup_buffer_new_with_owner(data(), size(), this, [](void* data) { static_cast<ShareableResource*>(data)->deref(); }));
+#else
+ ASSERT_NOT_REACHED();
+ return nullptr;
+#endif
+}
+
+PassRefPtr<SharedBuffer> ShareableResource::Handle::tryWrapInSharedBuffer() const
+{
RefPtr<ShareableResource> resource = ShareableResource::create(*this);
if (!resource) {
LOG_ERROR("Failed to recreate ShareableResource from handle.");
- return 0;
+ return nullptr;
}
- RetainPtr<CFAllocatorRef> deallocator = adoptCF(createShareableResourceDeallocator(resource.get()));
- return adoptCF(CFDataCreateWithBytesNoCopy(kCFAllocatorDefault, reinterpret_cast<const UInt8*>(resource->data()), static_cast<CFIndex>(resource->size()), deallocator.get()));
+ return resource->wrapInSharedBuffer();
}
-PassRefPtr<SharedBuffer> ShareableResource::Handle::tryWrapInSharedBuffer() const
-{
- return SharedBuffer::wrapCFData(tryWrapInCFData().get());
-}
-
PassRefPtr<ShareableResource> ShareableResource::create(PassRefPtr<SharedMemory> sharedMemory, unsigned offset, unsigned size)
{
return adoptRef(new ShareableResource(sharedMemory, offset, size));
Modified: trunk/Source/WebKit2/Shared/ShareableResource.h (184619 => 184620)
--- trunk/Source/WebKit2/Shared/ShareableResource.h 2015-05-20 06:29:13 UTC (rev 184619)
+++ trunk/Source/WebKit2/Shared/ShareableResource.h 2015-05-20 07:04:34 UTC (rev 184620)
@@ -56,9 +56,6 @@
void encode(IPC::ArgumentEncoder&) const;
static bool decode(IPC::ArgumentDecoder&, Handle&);
-#if USE(CF)
- RetainPtr<CFDataRef> tryWrapInCFData() const;
-#endif
PassRefPtr<WebCore::SharedBuffer> tryWrapInSharedBuffer() const;
private:
@@ -86,6 +83,7 @@
private:
ShareableResource(PassRefPtr<SharedMemory>, unsigned offset, unsigned size);
+ PassRefPtr<WebCore::SharedBuffer> wrapInSharedBuffer();
RefPtr<SharedMemory> m_sharedMemory;
Modified: trunk/Source/WebKit2/WebKit2Prefix.h (184619 => 184620)
--- trunk/Source/WebKit2/WebKit2Prefix.h 2015-05-20 06:29:13 UTC (rev 184619)
+++ trunk/Source/WebKit2/WebKit2Prefix.h 2015-05-20 07:04:34 UTC (rev 184620)
@@ -58,6 +58,7 @@
#if PLATFORM(GTK)
#define ENABLE_NETWORK_PROCESS 1
+#define ENABLE_SHAREABLE_RESOURCE 1
#endif
/* When C++ exceptions are disabled, the C++ library defines |try| and |catch|
Modified: trunk/Source/WebKit2/WebProcess/Network/WebResourceLoader.cpp (184619 => 184620)
--- trunk/Source/WebKit2/WebProcess/Network/WebResourceLoader.cpp 2015-05-20 06:29:13 UTC (rev 184619)
+++ trunk/Source/WebKit2/WebProcess/Network/WebResourceLoader.cpp 2015-05-20 07:04:34 UTC (rev 184620)
@@ -180,11 +180,12 @@
{
LOG(Network, "(WebProcess) WebResourceLoader::didReceiveResource for '%s'", m_coreLoader->url().string().utf8().data());
+ RefPtr<SharedBuffer> buffer = handle.tryWrapInSharedBuffer();
+
#if USE(QUICK_LOOK)
if (QuickLookHandle* quickLookHandle = m_coreLoader->documentLoader()->quickLookHandle()) {
- RetainPtr<CFDataRef> cfBuffer = handle.tryWrapInCFData();
- if (cfBuffer) {
- if (quickLookHandle->didReceiveData(cfBuffer.get())) {
+ if (buffer) {
+ if (quickLookHandle->didReceiveData(buffer->existingCFData())) {
quickLookHandle->didFinishLoading();
return;
}
@@ -193,7 +194,6 @@
}
#endif
- RefPtr<SharedBuffer> buffer = handle.tryWrapInSharedBuffer();
if (!buffer) {
LOG_ERROR("Unable to create buffer from ShareableResource sent from the network process.");
m_coreLoader->didFail(internalError(m_coreLoader->request().url()));