Skip to content
Permalink
Browse files
Stop using PassRefPtr in ShareableResource
https://bugs.webkit.org/show_bug.cgi?id=159043

Reviewed by Alex Christensen.

Stop using PassRefPtr in ShareableResource.

* NetworkProcess/cache/NetworkCache.cpp:
(WebKit::NetworkCache::Cache::store):
* NetworkProcess/cache/NetworkCacheEntry.cpp:
(WebKit::NetworkCache::Entry::initializeShareableResourceHandleFromStorageRecord):
* Shared/ShareableResource.cpp:
(WebKit::shareableResourceDeallocate):
(WebKit::ShareableResource::wrapInSharedBuffer):
(WebKit::ShareableResource::Handle::tryWrapInSharedBuffer):
(WebKit::ShareableResource::create):
(WebKit::ShareableResource::map):
(WebKit::ShareableResource::ShareableResource):
* Shared/ShareableResource.h:


Canonical link: https://commits.webkit.org/177124@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@202357 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
cdumez committed Jun 22, 2016
1 parent a0527b9 commit e60a44cc29036cebd34025efa7fd2da95105a6dd
@@ -1,3 +1,25 @@
2016-06-22 Chris Dumez <cdumez@apple.com>

Stop using PassRefPtr in ShareableResource
https://bugs.webkit.org/show_bug.cgi?id=159043

Reviewed by Alex Christensen.

Stop using PassRefPtr in ShareableResource.

* NetworkProcess/cache/NetworkCache.cpp:
(WebKit::NetworkCache::Cache::store):
* NetworkProcess/cache/NetworkCacheEntry.cpp:
(WebKit::NetworkCache::Entry::initializeShareableResourceHandleFromStorageRecord):
* Shared/ShareableResource.cpp:
(WebKit::shareableResourceDeallocate):
(WebKit::ShareableResource::wrapInSharedBuffer):
(WebKit::ShareableResource::Handle::tryWrapInSharedBuffer):
(WebKit::ShareableResource::create):
(WebKit::ShareableResource::map):
(WebKit::ShareableResource::ShareableResource):
* Shared/ShareableResource.h:

2016-06-17 Dean Jackson <dino@apple.com>

REGRESSION: Double tap to zoom does not work on yahoo finance
@@ -412,8 +412,8 @@ std::unique_ptr<Entry> Cache::store(const WebCore::ResourceRequest& request, con
m_storage->store(record, [completionHandler = WTFMove(completionHandler)](const Data& bodyData) {
MappedBody mappedBody;
#if ENABLE(SHAREABLE_RESOURCE)
if (RefPtr<SharedMemory> sharedMemory = bodyData.tryCreateSharedMemory()) {
mappedBody.shareableResource = ShareableResource::create(WTFMove(sharedMemory), 0, bodyData.size());
if (auto sharedMemory = bodyData.tryCreateSharedMemory()) {
mappedBody.shareableResource = ShareableResource::create(sharedMemory.releaseNonNull(), 0, bodyData.size());
ASSERT(mappedBody.shareableResource);
mappedBody.shareableResource->createHandle(mappedBody.shareableResourceHandle);
}
@@ -149,7 +149,7 @@ void Entry::initializeShareableResourceHandleFromStorageRecord() const
if (!sharedMemory)
return;

auto shareableResource = ShareableResource::create(WTFMove(sharedMemory), 0, m_sourceStorageRecord.body.size());
auto shareableResource = ShareableResource::create(sharedMemory.releaseNonNull(), 0, m_sourceStorageRecord.body.size());
shareableResource->createHandle(m_shareableResourceHandle);
}
#endif
@@ -60,7 +60,7 @@ bool ShareableResource::Handle::decode(IPC::ArgumentDecoder& decoder, Handle& ha
#if USE(CF)
static void shareableResourceDeallocate(void *ptr, void *info)
{
(static_cast<ShareableResource*>(info))->deref(); // Balanced by ref() in createShareableResourceDeallocator()
static_cast<ShareableResource*>(info)->deref(); // Balanced by ref() in createShareableResourceDeallocator()
}

static CFAllocatorRef createShareableResourceDeallocator(ShareableResource* resource)
@@ -80,7 +80,7 @@ static CFAllocatorRef createShareableResourceDeallocator(ShareableResource* reso
}
#endif

PassRefPtr<SharedBuffer> ShareableResource::wrapInSharedBuffer()
RefPtr<SharedBuffer> ShareableResource::wrapInSharedBuffer()
{
ref(); // Balanced by deref when SharedBuffer is deallocated.

@@ -96,7 +96,7 @@ PassRefPtr<SharedBuffer> ShareableResource::wrapInSharedBuffer()
#endif
}

PassRefPtr<SharedBuffer> ShareableResource::Handle::tryWrapInSharedBuffer() const
RefPtr<SharedBuffer> ShareableResource::Handle::tryWrapInSharedBuffer() const
{
RefPtr<ShareableResource> resource = ShareableResource::map(*this);
if (!resource) {
@@ -107,26 +107,25 @@ PassRefPtr<SharedBuffer> ShareableResource::Handle::tryWrapInSharedBuffer() cons
return resource->wrapInSharedBuffer();
}

Ref<ShareableResource> ShareableResource::create(PassRefPtr<SharedMemory> sharedMemory, unsigned offset, unsigned size)
Ref<ShareableResource> ShareableResource::create(Ref<SharedMemory>&& sharedMemory, unsigned offset, unsigned size)
{
return adoptRef(*new ShareableResource(sharedMemory, offset, size));
return adoptRef(*new ShareableResource(WTFMove(sharedMemory), offset, size));
}

PassRefPtr<ShareableResource> ShareableResource::map(const Handle& handle)
RefPtr<ShareableResource> ShareableResource::map(const Handle& handle)
{
auto sharedMemory = SharedMemory::map(handle.m_handle, SharedMemory::Protection::ReadOnly);
if (!sharedMemory)
return 0;
return nullptr;

return create(WTFMove(sharedMemory), handle.m_offset, handle.m_size);
return create(sharedMemory.releaseNonNull(), handle.m_offset, handle.m_size);
}

ShareableResource::ShareableResource(PassRefPtr<SharedMemory> sharedMemory, unsigned offset, unsigned size)
: m_sharedMemory(sharedMemory)
ShareableResource::ShareableResource(Ref<SharedMemory>&& sharedMemory, unsigned offset, unsigned size)
: m_sharedMemory(WTFMove(sharedMemory))
, m_offset(offset)
, m_size(size)
{
ASSERT(m_sharedMemory);
ASSERT(m_offset + m_size <= m_sharedMemory->size());

// FIXME (NetworkProcess): This data was received from another process. If it is bogus, should we assume that process is compromised and we should kill it?
@@ -30,7 +30,6 @@

#include "SharedMemory.h"

#include <wtf/PassRefPtr.h>
#include <wtf/RefCounted.h>
#include <wtf/RefPtr.h>
#include <wtf/RetainPtr.h>
@@ -56,7 +55,7 @@ class ShareableResource : public RefCounted<ShareableResource> {
void encode(IPC::ArgumentEncoder&) const;
static bool decode(IPC::ArgumentDecoder&, Handle&);

PassRefPtr<WebCore::SharedBuffer> tryWrapInSharedBuffer() const;
RefPtr<WebCore::SharedBuffer> tryWrapInSharedBuffer() const;

private:
friend class ShareableResource;
@@ -67,10 +66,10 @@ class ShareableResource : public RefCounted<ShareableResource> {
};

// Create a shareable resource that uses malloced memory.
static Ref<ShareableResource> create(PassRefPtr<SharedMemory>, unsigned offset, unsigned size);
static Ref<ShareableResource> create(Ref<SharedMemory>&&, unsigned offset, unsigned size);

// Create a shareable resource from a handle.
static PassRefPtr<ShareableResource> map(const Handle&);
static RefPtr<ShareableResource> map(const Handle&);

// Create a handle.
bool createHandle(Handle&);
@@ -81,10 +80,10 @@ class ShareableResource : public RefCounted<ShareableResource> {
unsigned size() const;

private:
ShareableResource(PassRefPtr<SharedMemory>, unsigned offset, unsigned size);
PassRefPtr<WebCore::SharedBuffer> wrapInSharedBuffer();
ShareableResource(Ref<SharedMemory>&&, unsigned offset, unsigned size);
RefPtr<WebCore::SharedBuffer> wrapInSharedBuffer();

RefPtr<SharedMemory> m_sharedMemory;
Ref<SharedMemory> m_sharedMemory;

unsigned m_offset;
unsigned m_size;

0 comments on commit e60a44c

Please sign in to comment.