Stop using PassRefPtr in ShareableResource
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 22 Jun 2016 23:31:42 +0000 (23:31 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 22 Jun 2016 23:31:42 +0000 (23:31 +0000)
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:

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

Source/WebKit2/ChangeLog
Source/WebKit2/NetworkProcess/cache/NetworkCache.cpp
Source/WebKit2/NetworkProcess/cache/NetworkCacheEntry.cpp
Source/WebKit2/Shared/ShareableResource.cpp
Source/WebKit2/Shared/ShareableResource.h

index 869d2d7..228ba24 100644 (file)
@@ -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
index a930a70..b975cf9 100644 (file)
@@ -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);
         }
index 803835c..33fb53f 100644 (file)
@@ -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
index 74afd4c..d67732f 100644 (file)
@@ -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?
index e0abd7f..df879c6 100644 (file)
@@ -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 @@ public:
         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 @@ public:
     };
 
     // 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 @@ public:
     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;