Title: [272196] trunk/Source
Revision
272196
Author
[email protected]
Date
2021-02-02 00:52:42 -0800 (Tue, 02 Feb 2021)

Log Message

[SOUP] Stop using SoupBuffer in preparation for libsoup3
https://bugs.webkit.org/show_bug.cgi?id=221206

Reviewed by Sergio Villar Senin.

Source/WebCore:

Remove use of SoupBuffer from platform since it's now unused.

* platform/SharedBuffer.cpp:
(WebCore::SharedBuffer::DataSegment::data const):
(WebCore::SharedBuffer::DataSegment::size const):
* platform/SharedBuffer.h:
* platform/Soup.cmake:
* platform/SourcesSoup.txt:
* platform/network/soup/GRefPtrSoup.cpp: Removed.
* platform/network/soup/GRefPtrSoup.h: Removed.
* platform/network/soup/GUniquePtrSoup.h:
* platform/network/soup/ResourceRequestSoup.cpp:
(WebCore::ResourceRequest::updateSoupMessageBody const):
* platform/soup/SharedBufferSoup.cpp: Removed.

Source/WebKit:

Use GBytes instead of SoupBuffer.

* NetworkProcess/cache/NetworkCacheData.h:
(WebKit::NetworkCache::Data::bytes const):
* NetworkProcess/cache/NetworkCacheDataGLib.cpp: Renamed from Source/WebKit/NetworkProcess/cache/NetworkCacheDataSoup.cpp.
(WebKit::NetworkCache::Data::Data):
(WebKit::NetworkCache::Data::empty):
(WebKit::NetworkCache::Data::data const):
(WebKit::NetworkCache::Data::apply const):
(WebKit::NetworkCache::Data::subrange const):
(WebKit::NetworkCache::concatenate):
(WebKit::NetworkCache::Data::adoptMap):
(WebKit::NetworkCache::Data::tryCreateSharedMemory const):
* NetworkProcess/cache/NetworkCacheIOChannel.h:
* NetworkProcess/cache/NetworkCacheIOChannelGLib.cpp: Renamed from Source/WebKit/NetworkProcess/cache/NetworkCacheIOChannelSoup.cpp.
(WebKit::NetworkCache::runTaskInQueue):
(WebKit::NetworkCache::fillDataFromReadBuffer):
(WebKit::NetworkCache::inputStreamReadReadyCallback):
(WebKit::NetworkCache::IOChannel::read):
(WebKit::NetworkCache::IOChannel::readSyncInThread):
(WebKit::NetworkCache::outputStreamWriteReadyCallback):
(WebKit::NetworkCache::IOChannel::write):
* Shared/ShareableResource.cpp:
(WebKit::ShareableResource::wrapInSharedBuffer):
* SourcesGTK.txt:
* SourcesWPE.txt:

Modified Paths

Added Paths

Removed Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (272195 => 272196)


--- trunk/Source/WebCore/ChangeLog	2021-02-02 08:50:27 UTC (rev 272195)
+++ trunk/Source/WebCore/ChangeLog	2021-02-02 08:52:42 UTC (rev 272196)
@@ -1,3 +1,25 @@
+2021-02-02  Carlos Garcia Campos  <[email protected]>
+
+        [SOUP] Stop using SoupBuffer in preparation for libsoup3
+        https://bugs.webkit.org/show_bug.cgi?id=221206
+
+        Reviewed by Sergio Villar Senin.
+
+        Remove use of SoupBuffer from platform since it's now unused.
+
+        * platform/SharedBuffer.cpp:
+        (WebCore::SharedBuffer::DataSegment::data const):
+        (WebCore::SharedBuffer::DataSegment::size const):
+        * platform/SharedBuffer.h:
+        * platform/Soup.cmake:
+        * platform/SourcesSoup.txt:
+        * platform/network/soup/GRefPtrSoup.cpp: Removed.
+        * platform/network/soup/GRefPtrSoup.h: Removed.
+        * platform/network/soup/GUniquePtrSoup.h:
+        * platform/network/soup/ResourceRequestSoup.cpp:
+        (WebCore::ResourceRequest::updateSoupMessageBody const):
+        * platform/soup/SharedBufferSoup.cpp: Removed.
+
 2021-02-02  Adrian Perez de Castro  <[email protected]>
 
         Non-unified build fixes, late January 2021 edition

Modified: trunk/Source/WebCore/platform/SharedBuffer.cpp (272195 => 272196)


--- trunk/Source/WebCore/platform/SharedBuffer.cpp	2021-02-02 08:50:27 UTC (rev 272195)
+++ trunk/Source/WebCore/platform/SharedBuffer.cpp	2021-02-02 08:52:42 UTC (rev 272196)
@@ -236,9 +236,6 @@
 #if USE(CF)
         [](const RetainPtr<CFDataRef>& data) { return reinterpret_cast<const char*>(CFDataGetBytePtr(data.get())); },
 #endif
-#if USE(SOUP)
-        [](const GUniquePtr<SoupBuffer>& data) { return data->data; },
-#endif
 #if USE(GLIB)
         [](const GRefPtr<GBytes>& data) { return reinterpret_cast<const char*>(g_bytes_get_data(data.get(), nullptr)); },
 #endif
@@ -317,9 +314,6 @@
 #if USE(CF)
         [](const RetainPtr<CFDataRef>& data) { return CFDataGetLength(data.get()); },
 #endif
-#if USE(SOUP)
-        [](const GUniquePtr<SoupBuffer>& data) { return static_cast<size_t>(data->length); },
-#endif
 #if USE(GLIB)
         [](const GRefPtr<GBytes>& data) { return g_bytes_get_size(data.get()); },
 #endif

Modified: trunk/Source/WebCore/platform/SharedBuffer.h (272195 => 272196)


--- trunk/Source/WebCore/platform/SharedBuffer.h	2021-02-02 08:50:27 UTC (rev 272195)
+++ trunk/Source/WebCore/platform/SharedBuffer.h	2021-02-02 08:52:42 UTC (rev 272196)
@@ -39,10 +39,6 @@
 #include <wtf/RetainPtr.h>
 #endif
 
-#if USE(SOUP)
-#include "GUniquePtrSoup.h"
-#endif
-
 #if USE(GLIB)
 #include <wtf/glib/GRefPtr.h>
 typedef struct _GBytes GBytes;
@@ -89,11 +85,6 @@
     void append(CFDataRef);
 #endif
 
-#if USE(SOUP)
-    GUniquePtr<SoupBuffer> createSoupBuffer(unsigned offset = 0, unsigned size = 0);
-    static Ref<SharedBuffer> wrapSoupBuffer(SoupBuffer*);
-#endif
-
 #if USE(GLIB)
     static Ref<SharedBuffer> create(GBytes*);
     GRefPtr<GBytes> createGBytes() const;
@@ -140,9 +131,6 @@
 #if USE(CF)
         static Ref<DataSegment> create(RetainPtr<CFDataRef>&& data) { return adoptRef(*new DataSegment(WTFMove(data))); }
 #endif
-#if USE(SOUP)
-        static Ref<DataSegment> create(GUniquePtr<SoupBuffer>&& data) { return adoptRef(*new DataSegment(WTFMove(data))); }
-#endif
 #if USE(GLIB)
         static Ref<DataSegment> create(GRefPtr<GBytes>&& data) { return adoptRef(*new DataSegment(WTFMove(data))); }
 #endif
@@ -162,10 +150,6 @@
         DataSegment(RetainPtr<CFDataRef>&& data)
             : m_immutableData(WTFMove(data)) { }
 #endif
-#if USE(SOUP)
-        DataSegment(GUniquePtr<SoupBuffer>&& data)
-            : m_immutableData(WTFMove(data)) { }
-#endif
 #if USE(GLIB)
         DataSegment(GRefPtr<GBytes>&& data)
             : m_immutableData(WTFMove(data)) { }
@@ -181,9 +165,6 @@
 #if USE(CF)
             RetainPtr<CFDataRef>,
 #endif
-#if USE(SOUP)
-            GUniquePtr<SoupBuffer>,
-#endif
 #if USE(GLIB)
             GRefPtr<GBytes>,
 #endif
@@ -223,9 +204,6 @@
 #if USE(CF)
     explicit SharedBuffer(CFDataRef);
 #endif
-#if USE(SOUP)
-    explicit SharedBuffer(SoupBuffer*);
-#endif
 #if USE(GLIB)
     explicit SharedBuffer(GBytes*);
 #endif

Modified: trunk/Source/WebCore/platform/Soup.cmake (272195 => 272196)


--- trunk/Source/WebCore/platform/Soup.cmake	2021-02-02 08:50:27 UTC (rev 272195)
+++ trunk/Source/WebCore/platform/Soup.cmake	2021-02-02 08:52:42 UTC (rev 272196)
@@ -9,7 +9,6 @@
 list(APPEND WebCore_PRIVATE_FRAMEWORK_HEADERS
     platform/network/soup/AuthenticationChallenge.h
     platform/network/soup/CertificateInfo.h
-    platform/network/soup/GRefPtrSoup.h
     platform/network/soup/GUniquePtrSoup.h
     platform/network/soup/ResourceError.h
     platform/network/soup/ResourceRequest.h

Modified: trunk/Source/WebCore/platform/SourcesSoup.txt (272195 => 272196)


--- trunk/Source/WebCore/platform/SourcesSoup.txt	2021-02-02 08:50:27 UTC (rev 272195)
+++ trunk/Source/WebCore/platform/SourcesSoup.txt	2021-02-02 08:52:42 UTC (rev 272196)
@@ -26,7 +26,6 @@
 platform/network/soup/CookieSoup.cpp
 platform/network/soup/CookieStorageSoup.cpp
 platform/network/soup/CredentialStorageSoup.cpp
-platform/network/soup/GRefPtrSoup.cpp
 platform/network/soup/NetworkStorageSessionSoup.cpp
 platform/network/soup/ProxyServerSoup.cpp
 platform/network/soup/ResourceErrorSoup.cpp
@@ -39,4 +38,3 @@
 platform/network/soup/WebKitFormDataInputStream.cpp @no-unify
 
 platform/soup/PublicSuffixSoup.cpp
-platform/soup/SharedBufferSoup.cpp

Deleted: trunk/Source/WebCore/platform/network/soup/GRefPtrSoup.cpp (272195 => 272196)


--- trunk/Source/WebCore/platform/network/soup/GRefPtrSoup.cpp	2021-02-02 08:50:27 UTC (rev 272195)
+++ trunk/Source/WebCore/platform/network/soup/GRefPtrSoup.cpp	2021-02-02 08:52:42 UTC (rev 272196)
@@ -1,35 +0,0 @@
-/*
- *  Copyright (C) 2015 Igalia S.L.
- *
- *  This library is free software; you can redistribute it and/or
- *  modify it under the terms of the GNU Lesser General Public
- *  License as published by the Free Software Foundation; either
- *  version 2 of the License, or (at your option) any later version.
- *
- *  This library is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- *  Lesser General Public License for more details.
- *
- *  You should have received a copy of the GNU Lesser General Public
- *  License along with this library; if not, write to the Free Software
- *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- */
-
-#include "config.h"
-#include "GRefPtrSoup.h"
-
-namespace WTF {
-
-template <> SoupBuffer* refGPtr(SoupBuffer* ptr)
-{
-    return ptr ? soup_buffer_copy(ptr) : nullptr;
-}
-
-template <> void derefGPtr(SoupBuffer* ptr)
-{
-    if (ptr)
-        soup_buffer_free(ptr);
-}
-
-} // namespace WTF

Deleted: trunk/Source/WebCore/platform/network/soup/GRefPtrSoup.h (272195 => 272196)


--- trunk/Source/WebCore/platform/network/soup/GRefPtrSoup.h	2021-02-02 08:50:27 UTC (rev 272195)
+++ trunk/Source/WebCore/platform/network/soup/GRefPtrSoup.h	2021-02-02 08:52:42 UTC (rev 272196)
@@ -1,37 +0,0 @@
-/*
- *  Copyright (C) 2015 Igalia S.L.
- *
- *  This library is free software; you can redistribute it and/or
- *  modify it under the terms of the GNU Library General Public
- *  License as published by the Free Software Foundation; either
- *  version 2 of the License, or (at your option) any later version.
- *
- *  This library is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- *  Library General Public License for more details.
- *
- *  You should have received a copy of the GNU Library General Public License
- *  along with this library; see the file COPYING.LIB.  If not, write to
- *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- *  Boston, MA 02110-1301, USA.
- */
-
-#ifndef GRefPtrSoup_h
-#define GRefPtrSoup_h
-
-#if USE(SOUP)
-
-#include <libsoup/soup.h>
-#include <wtf/glib/GRefPtr.h>
-
-namespace WTF {
-
-template <> SoupBuffer* refGPtr(SoupBuffer*);
-template <> void derefGPtr(SoupBuffer*);
-
-} // namespace WTF
-
-#endif // USE(SOUP)
-
-#endif

Modified: trunk/Source/WebCore/platform/network/soup/GUniquePtrSoup.h (272195 => 272196)


--- trunk/Source/WebCore/platform/network/soup/GUniquePtrSoup.h	2021-02-02 08:50:27 UTC (rev 272195)
+++ trunk/Source/WebCore/platform/network/soup/GUniquePtrSoup.h	2021-02-02 08:52:42 UTC (rev 272196)
@@ -31,7 +31,6 @@
 WTF_DEFINE_GPTR_DELETER(SoupURI, soup_uri_free)
 WTF_DEFINE_GPTR_DELETER(SoupCookie, soup_cookie_free)
 WTF_DEFINE_GPTR_DELETER(SoupMessageHeaders, soup_message_headers_free)
-WTF_DEFINE_GPTR_DELETER(SoupBuffer, soup_buffer_free)
 #if SOUP_CHECK_VERSION(2, 67, 1)
 WTF_DEFINE_GPTR_DELETER(SoupHSTSPolicy, soup_hsts_policy_free)
 #endif

Modified: trunk/Source/WebCore/platform/network/soup/ResourceRequestSoup.cpp (272195 => 272196)


--- trunk/Source/WebCore/platform/network/soup/ResourceRequestSoup.cpp	2021-02-02 08:50:27 UTC (rev 272195)
+++ trunk/Source/WebCore/platform/network/soup/ResourceRequestSoup.cpp	2021-02-02 08:52:42 UTC (rev 272196)
@@ -66,9 +66,10 @@
     GRefPtr<GInputStream> stream = webkitFormDataInputStreamNew(WTFMove(resolvedFormData));
     if (GBytes* data = "" {
         soup_message_body_set_accumulate(soupMessage->request_body, FALSE);
-        GUniquePtr<SoupBuffer> soupBuffer(soup_buffer_new_with_owner(g_bytes_get_data(data, nullptr),
-            g_bytes_get_size(data), data, reinterpret_cast<GDestroyNotify>(g_bytes_unref)));
-        soup_message_body_append_buffer(soupMessage->request_body, soupBuffer.get());
+        auto* soupBuffer = soup_buffer_new_with_owner(g_bytes_get_data(data, nullptr),
+            g_bytes_get_size(data), data, reinterpret_cast<GDestroyNotify>(g_bytes_unref));
+        soup_message_body_append_buffer(soupMessage->request_body, soupBuffer);
+        soup_buffer_free(soupBuffer);
     }
 
     ASSERT(length == static_cast<uint64_t>(soupMessage->request_body->length));

Deleted: trunk/Source/WebCore/platform/soup/SharedBufferSoup.cpp (272195 => 272196)


--- trunk/Source/WebCore/platform/soup/SharedBufferSoup.cpp	2021-02-02 08:50:27 UTC (rev 272195)
+++ trunk/Source/WebCore/platform/soup/SharedBufferSoup.cpp	2021-02-02 08:52:42 UTC (rev 272196)
@@ -1,52 +0,0 @@
-/*
- * Copyright (C) 2013 Company 100 Inc.
- *
- *  This library is free software; you can redistribute it and/or
- *  modify it under the terms of the GNU Lesser General Public
- *  License as published by the Free Software Foundation; either
- *  version 2 of the License, or (at your option) any later version.
- *
- *  This library is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- *  Lesser General Public License for more details.
- *
- *  You should have received a copy of the GNU Lesser General Public
- *  License along with this library; if not, write to the Free Software
- *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- */
-
-#include "config.h"
-
-#if USE(SOUP)
-
-#include "SharedBuffer.h"
-
-#include <libsoup/soup.h>
-
-namespace WebCore {
-
-SharedBuffer::SharedBuffer(SoupBuffer* soupBuffer)
-{
-    ASSERT(soupBuffer);
-    m_size = soupBuffer->length;
-    m_segments.append({0, DataSegment::create(GUniquePtr<SoupBuffer>(soupBuffer))});
-}
-
-Ref<SharedBuffer> SharedBuffer::wrapSoupBuffer(SoupBuffer* soupBuffer)
-{
-    return adoptRef(*new SharedBuffer(soupBuffer));
-}
-
-GUniquePtr<SoupBuffer> SharedBuffer::createSoupBuffer(unsigned offset, unsigned size)
-{
-    ref();
-    GUniquePtr<SoupBuffer> buffer(soup_buffer_new_with_owner(data() + offset, size ? size : this->size(), this, [](void* data) {
-        static_cast<SharedBuffer*>(data)->deref();
-    }));
-    return buffer;
-}
-
-} // namespace WebCore
-
-#endif

Modified: trunk/Source/WebKit/ChangeLog (272195 => 272196)


--- trunk/Source/WebKit/ChangeLog	2021-02-02 08:50:27 UTC (rev 272195)
+++ trunk/Source/WebKit/ChangeLog	2021-02-02 08:52:42 UTC (rev 272196)
@@ -1,3 +1,37 @@
+2021-02-02  Carlos Garcia Campos  <[email protected]>
+
+        [SOUP] Stop using SoupBuffer in preparation for libsoup3
+        https://bugs.webkit.org/show_bug.cgi?id=221206
+
+        Reviewed by Sergio Villar Senin.
+
+        Use GBytes instead of SoupBuffer.
+
+        * NetworkProcess/cache/NetworkCacheData.h:
+        (WebKit::NetworkCache::Data::bytes const):
+        * NetworkProcess/cache/NetworkCacheDataGLib.cpp: Renamed from Source/WebKit/NetworkProcess/cache/NetworkCacheDataSoup.cpp.
+        (WebKit::NetworkCache::Data::Data):
+        (WebKit::NetworkCache::Data::empty):
+        (WebKit::NetworkCache::Data::data const):
+        (WebKit::NetworkCache::Data::apply const):
+        (WebKit::NetworkCache::Data::subrange const):
+        (WebKit::NetworkCache::concatenate):
+        (WebKit::NetworkCache::Data::adoptMap):
+        (WebKit::NetworkCache::Data::tryCreateSharedMemory const):
+        * NetworkProcess/cache/NetworkCacheIOChannel.h:
+        * NetworkProcess/cache/NetworkCacheIOChannelGLib.cpp: Renamed from Source/WebKit/NetworkProcess/cache/NetworkCacheIOChannelSoup.cpp.
+        (WebKit::NetworkCache::runTaskInQueue):
+        (WebKit::NetworkCache::fillDataFromReadBuffer):
+        (WebKit::NetworkCache::inputStreamReadReadyCallback):
+        (WebKit::NetworkCache::IOChannel::read):
+        (WebKit::NetworkCache::IOChannel::readSyncInThread):
+        (WebKit::NetworkCache::outputStreamWriteReadyCallback):
+        (WebKit::NetworkCache::IOChannel::write):
+        * Shared/ShareableResource.cpp:
+        (WebKit::ShareableResource::wrapInSharedBuffer):
+        * SourcesGTK.txt:
+        * SourcesWPE.txt:
+
 2021-02-02  Adrian Perez de Castro  <[email protected]>
 
         Non-unified build fixes, late January 2021 edition

Modified: trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheData.h (272195 => 272196)


--- trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheData.h	2021-02-02 08:50:27 UTC (rev 272195)
+++ trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheData.h	2021-02-02 08:52:42 UTC (rev 272196)
@@ -35,8 +35,8 @@
 #include <wtf/OSObjectPtr.h>
 #endif
 
-#if USE(SOUP)
-#include <WebCore/GRefPtrSoup.h>
+#if USE(GLIB)
+#include <wtf/glib/GRefPtr.h>
 #endif
 
 #if USE(CURL)
@@ -64,8 +64,8 @@
     enum class Backing { Buffer, Map };
     Data(OSObjectPtr<dispatch_data_t>&&, Backing = Backing::Buffer);
 #endif
-#if USE(SOUP)
-    Data(GRefPtr<SoupBuffer>&&, FileSystem::PlatformFileHandle fd = FileSystem::invalidPlatformFileHandle);
+#if USE(GLIB)
+    Data(GRefPtr<GBytes>&&, FileSystem::PlatformFileHandle fd = FileSystem::invalidPlatformFileHandle);
 #elif USE(CURL)
     Data(Variant<Vector<uint8_t>, FileSystem::MappedFileData>&&);
 #endif
@@ -87,15 +87,15 @@
     dispatch_data_t dispatchData() const { return m_dispatchData.get(); }
 #endif
 
-#if USE(SOUP)
-    SoupBuffer* soupBuffer() const { return m_buffer.get(); }
+#if USE(GLIB)
+    GBytes* bytes() const { return m_buffer.get(); }
 #endif
 private:
 #if PLATFORM(COCOA)
     mutable OSObjectPtr<dispatch_data_t> m_dispatchData;
 #endif
-#if USE(SOUP)
-    mutable GRefPtr<SoupBuffer> m_buffer;
+#if USE(GLIB)
+    mutable GRefPtr<GBytes> m_buffer;
     FileSystem::PlatformFileHandle m_fileDescriptor { FileSystem::invalidPlatformFileHandle };
 #endif
 #if USE(CURL)

Copied: trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheDataGLib.cpp (from rev 272195, trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheDataSoup.cpp) (0 => 272196)


--- trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheDataGLib.cpp	                        (rev 0)
+++ trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheDataGLib.cpp	2021-02-02 08:52:42 UTC (rev 272196)
@@ -0,0 +1,157 @@
+/*
+ * Copyright (C) 2015 Igalia S.L
+ *
+ * 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.
+ */
+
+#include "config.h"
+#include "NetworkCacheData.h"
+
+#if USE(GLIB)
+
+#include "SharedMemory.h"
+#include <fcntl.h>
+#include <sys/mman.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#if !PLATFORM(WIN)
+#include <gio/gfiledescriptorbased.h>
+#endif
+
+namespace WebKit {
+namespace NetworkCache {
+
+Data::Data(const uint8_t* data, size_t size)
+    : m_size(size)
+{
+    uint8_t* copiedData = static_cast<uint8_t*>(fastMalloc(size));
+    memcpy(copiedData, data, size);
+    m_buffer = adoptGRef(g_bytes_new_with_free_func(copiedData, size, fastFree, copiedData));
+}
+
+Data::Data(GRefPtr<GBytes>&& buffer, FileSystem::PlatformFileHandle fd)
+    : m_buffer(WTFMove(buffer))
+    , m_fileDescriptor(fd)
+    , m_size(m_buffer ? g_bytes_get_size(m_buffer.get()) : 0)
+    , m_isMap(m_size && FileSystem::isHandleValid(fd))
+{
+}
+
+Data Data::empty()
+{
+    return { adoptGRef(g_bytes_new(nullptr, 0)) };
+}
+
+const uint8_t* Data::data() const
+{
+    return m_buffer ? reinterpret_cast<const uint8_t*>(g_bytes_get_data(m_buffer.get(), nullptr)) : nullptr;
+}
+
+bool Data::isNull() const
+{
+    return !m_buffer;
+}
+
+bool Data::apply(const Function<bool(const uint8_t*, size_t)>& applier) const
+{
+    if (!m_size)
+        return false;
+
+    gsize length;
+    const auto* data = "" &length);
+    return applier(reinterpret_cast<const uint8_t*>(data), length);
+}
+
+Data Data::subrange(size_t offset, size_t size) const
+{
+    if (!m_buffer)
+        return { };
+
+    return { adoptGRef(g_bytes_new_from_bytes(m_buffer.get(), offset, size)) };
+}
+
+Data concatenate(const Data& a, const Data& b)
+{
+    if (a.isNull())
+        return b;
+    if (b.isNull())
+        return a;
+
+    size_t size = a.size() + b.size();
+    uint8_t* data = ""
+    gsize aLength;
+    const auto* aData = g_bytes_get_data(a.bytes(), &aLength);
+    memcpy(data, aData, aLength);
+    gsize bLength;
+    const auto* bData = g_bytes_get_data(b.bytes(), &bLength);
+    memcpy(data + aLength, bData, bLength);
+
+    return { adoptGRef(g_bytes_new_with_free_func(data, size, fastFree, data)) };
+}
+
+struct MapWrapper {
+    WTF_MAKE_STRUCT_FAST_ALLOCATED;
+
+    ~MapWrapper()
+    {
+        munmap(map, size);
+        FileSystem::closeFile(fileDescriptor);
+    }
+
+    void* map;
+    size_t size;
+    FileSystem::PlatformFileHandle fileDescriptor;
+};
+
+static void deleteMapWrapper(MapWrapper* wrapper)
+{
+    delete wrapper;
+}
+
+Data Data::adoptMap(FileSystem::MappedFileData&& mappedFile, FileSystem::PlatformFileHandle fd)
+{
+    size_t size = mappedFile.size();
+    void* map = mappedFile.leakHandle();
+    ASSERT(map);
+    ASSERT(map != MAP_FAILED);
+    MapWrapper* wrapper = new MapWrapper { map, size, fd };
+    return { adoptGRef(g_bytes_new_with_free_func(map, size, reinterpret_cast<GDestroyNotify>(deleteMapWrapper), wrapper)), fd };
+}
+
+RefPtr<SharedMemory> Data::tryCreateSharedMemory() const
+{
+    if (isNull() || !isMap())
+        return nullptr;
+
+    GInputStream* inputStream = g_io_stream_get_input_stream(G_IO_STREAM(m_fileDescriptor));
+    int fd = g_file_descriptor_based_get_fd(G_FILE_DESCRIPTOR_BASED(inputStream));
+    gsize length;
+    const auto* data = "" &length);
+    return SharedMemory::wrapMap(const_cast<void*>(data), length, fd);
+}
+
+} // namespace NetworkCache
+} // namespace WebKit
+
+#endif // USE(GLIB)

Deleted: trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheDataSoup.cpp (272195 => 272196)


--- trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheDataSoup.cpp	2021-02-02 08:50:27 UTC (rev 272195)
+++ trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheDataSoup.cpp	2021-02-02 08:52:42 UTC (rev 272196)
@@ -1,146 +0,0 @@
-/*
- * Copyright (C) 2015 Igalia S.L
- *
- * 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.
- */
-
-#include "config.h"
-#include "NetworkCacheData.h"
-
-#include "SharedMemory.h"
-#include <fcntl.h>
-#include <sys/mman.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <unistd.h>
-
-#if USE(GLIB) && !PLATFORM(WIN)
-#include <gio/gfiledescriptorbased.h>
-#endif
-
-namespace WebKit {
-namespace NetworkCache {
-
-Data::Data(const uint8_t* data, size_t size)
-    : m_size(size)
-{
-    uint8_t* copiedData = static_cast<uint8_t*>(fastMalloc(size));
-    memcpy(copiedData, data, size);
-    m_buffer = adoptGRef(soup_buffer_new_with_owner(copiedData, size, copiedData, fastFree));
-}
-
-Data::Data(GRefPtr<SoupBuffer>&& buffer, FileSystem::PlatformFileHandle fd)
-    : m_buffer(buffer)
-    , m_fileDescriptor(fd)
-    , m_size(buffer ? buffer->length : 0)
-    , m_isMap(m_size && FileSystem::isHandleValid(fd))
-{
-}
-
-Data Data::empty()
-{
-    GRefPtr<SoupBuffer> buffer = adoptGRef(soup_buffer_new(SOUP_MEMORY_TAKE, nullptr, 0));
-    return { WTFMove(buffer) };
-}
-
-const uint8_t* Data::data() const
-{
-    return m_buffer ? reinterpret_cast<const uint8_t*>(m_buffer->data) : nullptr;
-}
-
-bool Data::isNull() const
-{
-    return !m_buffer;
-}
-
-bool Data::apply(const Function<bool (const uint8_t*, size_t)>& applier) const
-{
-    if (!m_size)
-        return false;
-
-    return applier(reinterpret_cast<const uint8_t*>(m_buffer->data), m_buffer->length);
-}
-
-Data Data::subrange(size_t offset, size_t size) const
-{
-    if (!m_buffer)
-        return { };
-
-    GRefPtr<SoupBuffer> subBuffer = adoptGRef(soup_buffer_new_subbuffer(m_buffer.get(), offset, size));
-    return { WTFMove(subBuffer) };
-}
-
-Data concatenate(const Data& a, const Data& b)
-{
-    if (a.isNull())
-        return b;
-    if (b.isNull())
-        return a;
-
-    size_t size = a.size() + b.size();
-    uint8_t* data = ""
-    memcpy(data, a.soupBuffer()->data, a.soupBuffer()->length);
-    memcpy(data + a.soupBuffer()->length, b.soupBuffer()->data, b.soupBuffer()->length);
-    GRefPtr<SoupBuffer> buffer = adoptGRef(soup_buffer_new_with_owner(data, size, data, fastFree));
-    return { WTFMove(buffer) };
-}
-
-struct MapWrapper {
-    ~MapWrapper()
-    {
-        munmap(map, size);
-        FileSystem::closeFile(fileDescriptor);
-    }
-
-    void* map;
-    size_t size;
-    FileSystem::PlatformFileHandle fileDescriptor;
-};
-
-static void deleteMapWrapper(MapWrapper* wrapper)
-{
-    delete wrapper;
-}
-
-Data Data::adoptMap(FileSystem::MappedFileData&& mappedFile, FileSystem::PlatformFileHandle fd)
-{
-    size_t size = mappedFile.size();
-    void* map = mappedFile.leakHandle();
-    ASSERT(map);
-    ASSERT(map != MAP_FAILED);
-    MapWrapper* wrapper = new MapWrapper { map, size, fd };
-    GRefPtr<SoupBuffer> buffer = adoptGRef(soup_buffer_new_with_owner(map, size, wrapper, reinterpret_cast<GDestroyNotify>(deleteMapWrapper)));
-    return { WTFMove(buffer), fd };
-}
-
-RefPtr<SharedMemory> Data::tryCreateSharedMemory() const
-{
-    if (isNull() || !isMap())
-        return nullptr;
-
-    GInputStream* inputStream = g_io_stream_get_input_stream(G_IO_STREAM(m_fileDescriptor));
-    int fd = g_file_descriptor_based_get_fd(G_FILE_DESCRIPTOR_BASED(inputStream));
-    return SharedMemory::wrapMap(const_cast<char*>(m_buffer->data), m_buffer->length, fd);
-}
-
-} // namespace NetworkCache
-} // namespace WebKit

Modified: trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheIOChannel.h (272195 => 272196)


--- trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheIOChannel.h	2021-02-02 08:50:27 UTC (rev 272195)
+++ trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheIOChannel.h	2021-02-02 08:52:42 UTC (rev 272196)
@@ -32,8 +32,12 @@
 #include <wtf/WorkQueue.h>
 #include <wtf/text/WTFString.h>
 
-#if USE(SOUP)
+#if USE(GLIB)
 #include <wtf/glib/GRefPtr.h>
+
+typedef struct _GFileIOStream GFileIOStream;
+typedef struct _GInputStream GInputStream;
+typedef struct _GOutputStream GOutputStream;
 #endif
 
 namespace WebKit {
@@ -52,7 +56,7 @@
     const String& path() const { return m_path; }
     Type type() const { return m_type; }
 
-#if !USE(SOUP)
+#if !USE(GLIB)
     bool isOpened() const { return FileSystem::isHandleValid(m_fileDescriptor); }
 #else
     bool isOpened() const { return true; }
@@ -63,7 +67,7 @@
 private:
     IOChannel(const String& filePath, IOChannel::Type, Optional<WorkQueue::QOS>);
 
-#if USE(SOUP)
+#if USE(GLIB)
     void readSyncInThread(size_t offset, size_t, WorkQueue*, Function<void (Data&, int error)>&&);
 #endif
 
@@ -70,7 +74,7 @@
     String m_path;
     Type m_type;
 
-#if !USE(SOUP)
+#if !USE(GLIB)
     FileSystem::PlatformFileHandle m_fileDescriptor { FileSystem::invalidPlatformFileHandle };
 #endif
     std::atomic<bool> m_wasDeleted { false }; // Try to narrow down a crash, https://bugs.webkit.org/show_bug.cgi?id=165659
@@ -77,7 +81,7 @@
 #if PLATFORM(COCOA)
     OSObjectPtr<dispatch_io_t> m_dispatchIO;
 #endif
-#if USE(SOUP)
+#if USE(GLIB)
     GRefPtr<GInputStream> m_inputStream;
     GRefPtr<GOutputStream> m_outputStream;
     GRefPtr<GFileIOStream> m_ioStream;

Copied: trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheIOChannelGLib.cpp (from rev 272195, trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheIOChannelSoup.cpp) (0 => 272196)


--- trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheIOChannelGLib.cpp	                        (rev 0)
+++ trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheIOChannelGLib.cpp	2021-02-02 08:52:42 UTC (rev 272196)
@@ -0,0 +1,278 @@
+/*
+ * Copyright (C) 2015 Igalia S.L.
+ *
+ * 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.
+ */
+
+#include "config.h"
+#include "NetworkCacheIOChannel.h"
+
+#include "NetworkCacheFileSystem.h"
+#include <wtf/MainThread.h>
+#include <wtf/RunLoop.h>
+#include <wtf/glib/GUniquePtr.h>
+#include <wtf/glib/RunLoopSourcePriority.h>
+
+namespace WebKit {
+namespace NetworkCache {
+
+static const size_t gDefaultReadBufferSize = 4096;
+
+IOChannel::IOChannel(const String& filePath, Type type, Optional<WorkQueue::QOS>)
+    : m_path(filePath)
+    , m_type(type)
+{
+    auto path = FileSystem::fileSystemRepresentation(filePath);
+    GRefPtr<GFile> file = adoptGRef(g_file_new_for_path(path.data()));
+    switch (m_type) {
+    case Type::Create: {
+        g_file_delete(file.get(), nullptr, nullptr);
+        m_outputStream = adoptGRef(G_OUTPUT_STREAM(g_file_create(file.get(), static_cast<GFileCreateFlags>(G_FILE_CREATE_PRIVATE), nullptr, nullptr)));
+#if !HAVE(STAT_BIRTHTIME)
+        GUniquePtr<char> birthtimeString(g_strdup_printf("%" G_GUINT64_FORMAT, WallTime::now().secondsSinceEpoch().secondsAs<uint64_t>()));
+        g_file_set_attribute_string(file.get(), "xattr::birthtime", birthtimeString.get(), G_FILE_QUERY_INFO_NONE, nullptr, nullptr);
+#endif
+        break;
+    }
+    case Type::Write: {
+        m_ioStream = adoptGRef(g_file_open_readwrite(file.get(), nullptr, nullptr));
+        break;
+    }
+    case Type::Read:
+        m_inputStream = adoptGRef(G_INPUT_STREAM(g_file_read(file.get(), nullptr, nullptr)));
+        break;
+    }
+}
+
+IOChannel::~IOChannel()
+{
+    RELEASE_ASSERT(!m_wasDeleted.exchange(true));
+}
+
+static inline void runTaskInQueue(Function<void()>&& task, WorkQueue* queue)
+{
+    if (queue) {
+        queue->dispatch(WTFMove(task));
+        return;
+    }
+
+    // Using nullptr as queue submits the result to the main context.
+    RunLoop::main().dispatch(WTFMove(task));
+}
+
+static void fillDataFromReadBuffer(GBytes* readBuffer, size_t size, Data& data)
+{
+    GRefPtr<GBytes> buffer;
+    if (size != g_bytes_get_size(readBuffer)) {
+        // The subbuffer does not copy the data.
+        buffer = adoptGRef(g_bytes_new_from_bytes(readBuffer, 0, size));
+    } else
+        buffer = readBuffer;
+
+    if (data.isNull()) {
+        // First chunk, we need to force the data to be copied.
+        data = { reinterpret_cast<const uint8_t*>(g_bytes_get_data(buffer.get(), nullptr)), size };
+    } else {
+        Data dataRead(WTFMove(buffer));
+        // Concatenate will copy the data.
+        data = "" dataRead);
+    }
+}
+
+struct ReadAsyncData {
+    WTF_MAKE_STRUCT_FAST_ALLOCATED;
+
+    RefPtr<IOChannel> channel;
+    GRefPtr<GBytes> buffer;
+    RefPtr<WorkQueue> queue;
+    size_t bytesToRead;
+    Function<void(Data&, int error)> completionHandler;
+    Data data;
+};
+
+static void inputStreamReadReadyCallback(GInputStream* stream, GAsyncResult* result, gpointer userData)
+{
+    std::unique_ptr<ReadAsyncData> asyncData(static_cast<ReadAsyncData*>(userData));
+    gssize bytesRead = g_input_stream_read_finish(stream, result, nullptr);
+    if (bytesRead == -1) {
+        WorkQueue* queue = asyncData->queue.get();
+        runTaskInQueue([asyncData = WTFMove(asyncData)] {
+            asyncData->completionHandler(asyncData->data, -1);
+        }, queue);
+        return;
+    }
+
+    if (!bytesRead) {
+        WorkQueue* queue = asyncData->queue.get();
+        runTaskInQueue([asyncData = WTFMove(asyncData)] {
+            asyncData->completionHandler(asyncData->data, 0);
+        }, queue);
+        return;
+    }
+
+    ASSERT(bytesRead > 0);
+    fillDataFromReadBuffer(asyncData->buffer.get(), static_cast<size_t>(bytesRead), asyncData->data);
+
+    size_t pendingBytesToRead = asyncData->bytesToRead - asyncData->data.size();
+    if (!pendingBytesToRead) {
+        WorkQueue* queue = asyncData->queue.get();
+        runTaskInQueue([asyncData = WTFMove(asyncData)] {
+            asyncData->completionHandler(asyncData->data, 0);
+        }, queue);
+        return;
+    }
+
+    size_t bytesToRead = std::min(pendingBytesToRead, g_bytes_get_size(asyncData->buffer.get()));
+    // Use a local variable for the data buffer to pass it to g_input_stream_read_async(), because ReadAsyncData is released.
+    auto* data = "" nullptr));
+    g_input_stream_read_async(stream, data, bytesToRead, RunLoopSourcePriority::DiskCacheRead, nullptr,
+        reinterpret_cast<GAsyncReadyCallback>(inputStreamReadReadyCallback), asyncData.release());
+}
+
+void IOChannel::read(size_t offset, size_t size, WorkQueue* queue, Function<void(Data&, int error)>&& completionHandler)
+{
+    RefPtr<IOChannel> protectedThis(this);
+    if (!m_inputStream) {
+        runTaskInQueue([protectedThis = WTFMove(protectedThis), completionHandler = WTFMove(completionHandler)] {
+            Data data;
+            completionHandler(data, -1);
+        }, queue);
+        return;
+    }
+
+    if (!RunLoop::isMain()) {
+        readSyncInThread(offset, size, queue, WTFMove(completionHandler));
+        return;
+    }
+
+    size_t bufferSize = std::min(size, gDefaultReadBufferSize);
+    uint8_t* bufferData = static_cast<uint8_t*>(fastMalloc(bufferSize));
+    GRefPtr<GBytes> buffer = adoptGRef(g_bytes_new_with_free_func(bufferData, bufferSize, fastFree, bufferData));
+    ReadAsyncData* asyncData = new ReadAsyncData { this, buffer.get(), queue, size, WTFMove(completionHandler), { } };
+
+    // FIXME: implement offset.
+    g_input_stream_read_async(m_inputStream.get(), bufferData, bufferSize, RunLoopSourcePriority::DiskCacheRead, nullptr,
+        reinterpret_cast<GAsyncReadyCallback>(inputStreamReadReadyCallback), asyncData);
+}
+
+void IOChannel::readSyncInThread(size_t offset, size_t size, WorkQueue* queue, Function<void(Data&, int error)>&& completionHandler)
+{
+    ASSERT(!RunLoop::isMain());
+
+    Thread::create("IOChannel::readSync", [this, protectedThis = makeRef(*this), size, queue, completionHandler = WTFMove(completionHandler)] () mutable {
+        size_t bufferSize = std::min(size, gDefaultReadBufferSize);
+        uint8_t* bufferData = static_cast<uint8_t*>(fastMalloc(bufferSize));
+        GRefPtr<GBytes> readBuffer = adoptGRef(g_bytes_new_with_free_func(bufferData, bufferSize, fastFree, bufferData));
+        Data data;
+        size_t pendingBytesToRead = size;
+        size_t bytesToRead = bufferSize;
+        do {
+            // FIXME: implement offset.
+            gssize bytesRead = g_input_stream_read(m_inputStream.get(), const_cast<void*>(g_bytes_get_data(readBuffer.get(), nullptr)), bytesToRead, nullptr, nullptr);
+            if (bytesRead == -1) {
+                runTaskInQueue([protectedThis = WTFMove(protectedThis), completionHandler = WTFMove(completionHandler)] {
+                    Data data;
+                    completionHandler(data, -1);
+                }, queue);
+                return;
+            }
+
+            if (!bytesRead)
+                break;
+
+            ASSERT(bytesRead > 0);
+            fillDataFromReadBuffer(readBuffer.get(), static_cast<size_t>(bytesRead), data);
+
+            pendingBytesToRead = size - data.size();
+            bytesToRead = std::min(pendingBytesToRead, g_bytes_get_size(readBuffer.get()));
+        } while (pendingBytesToRead);
+
+        runTaskInQueue([protectedThis = WTFMove(protectedThis), buffer = GRefPtr<GBytes>(data.bytes()), completionHandler = WTFMove(completionHandler)]() mutable {
+            Data data = { WTFMove(buffer) };
+            completionHandler(data, 0);
+        }, queue);
+    })->detach();
+}
+
+struct WriteAsyncData {
+    WTF_MAKE_STRUCT_FAST_ALLOCATED;
+
+    RefPtr<IOChannel> channel;
+    GRefPtr<GBytes> buffer;
+    RefPtr<WorkQueue> queue;
+    Function<void(int error)> completionHandler;
+};
+
+static void outputStreamWriteReadyCallback(GOutputStream* stream, GAsyncResult* result, gpointer userData)
+{
+    std::unique_ptr<WriteAsyncData> asyncData(static_cast<WriteAsyncData*>(userData));
+    gssize bytesWritten = g_output_stream_write_finish(stream, result, nullptr);
+    if (bytesWritten == -1) {
+        WorkQueue* queue = asyncData->queue.get();
+        runTaskInQueue([asyncData = WTFMove(asyncData)] {
+            asyncData->completionHandler(-1);
+        }, queue);
+        return;
+    }
+
+    gssize pendingBytesToWrite = g_bytes_get_size(asyncData->buffer.get()) - bytesWritten;
+    if (!pendingBytesToWrite) {
+        WorkQueue* queue = asyncData->queue.get();
+        runTaskInQueue([asyncData = WTFMove(asyncData)] {
+            asyncData->completionHandler(0);
+        }, queue);
+        return;
+    }
+
+    asyncData->buffer = adoptGRef(g_bytes_new_from_bytes(asyncData->buffer.get(), bytesWritten, pendingBytesToWrite));
+    // Use a local variable for the data buffer to pass it to g_output_stream_write_async(), because WriteAsyncData is released.
+    const auto* data = "" nullptr);
+    g_output_stream_write_async(stream, data, pendingBytesToWrite, RunLoopSourcePriority::DiskCacheWrite, nullptr,
+        reinterpret_cast<GAsyncReadyCallback>(outputStreamWriteReadyCallback), asyncData.release());
+}
+
+void IOChannel::write(size_t offset, const Data& data, WorkQueue* queue, Function<void(int error)>&& completionHandler)
+{
+    RefPtr<IOChannel> protectedThis(this);
+    if (!m_outputStream && !m_ioStream) {
+        runTaskInQueue([protectedThis = WTFMove(protectedThis), completionHandler = WTFMove(completionHandler)] {
+            completionHandler(-1);
+        }, queue);
+        return;
+    }
+
+    GOutputStream* stream = m_outputStream ? m_outputStream.get() : g_io_stream_get_output_stream(G_IO_STREAM(m_ioStream.get()));
+    if (!stream) {
+        runTaskInQueue([protectedThis = WTFMove(protectedThis), completionHandler = WTFMove(completionHandler)] {
+            completionHandler(-1);
+        }, queue);
+        return;
+    }
+
+    WriteAsyncData* asyncData = new WriteAsyncData { this, data.bytes(), queue, WTFMove(completionHandler) };
+    // FIXME: implement offset.
+    g_output_stream_write_async(stream, g_bytes_get_data(asyncData->buffer.get(), nullptr), data.size(), RunLoopSourcePriority::DiskCacheWrite, nullptr,
+        reinterpret_cast<GAsyncReadyCallback>(outputStreamWriteReadyCallback), asyncData);
+}
+
+} // namespace NetworkCache
+} // namespace WebKit

Deleted: trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheIOChannelSoup.cpp (272195 => 272196)


--- trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheIOChannelSoup.cpp	2021-02-02 08:50:27 UTC (rev 272195)
+++ trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheIOChannelSoup.cpp	2021-02-02 08:52:42 UTC (rev 272196)
@@ -1,277 +0,0 @@
-/*
- * Copyright (C) 2015 Igalia S.L.
- *
- * 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.
- */
-
-#include "config.h"
-#include "NetworkCacheIOChannel.h"
-
-#include "NetworkCacheFileSystem.h"
-#include <wtf/MainThread.h>
-#include <wtf/RunLoop.h>
-#include <wtf/glib/GUniquePtr.h>
-#include <wtf/glib/RunLoopSourcePriority.h>
-
-namespace WebKit {
-namespace NetworkCache {
-
-static const size_t gDefaultReadBufferSize = 4096;
-
-IOChannel::IOChannel(const String& filePath, Type type, Optional<WorkQueue::QOS>)
-    : m_path(filePath)
-    , m_type(type)
-{
-    auto path = FileSystem::fileSystemRepresentation(filePath);
-    GRefPtr<GFile> file = adoptGRef(g_file_new_for_path(path.data()));
-    switch (m_type) {
-    case Type::Create: {
-        g_file_delete(file.get(), nullptr, nullptr);
-        m_outputStream = adoptGRef(G_OUTPUT_STREAM(g_file_create(file.get(), static_cast<GFileCreateFlags>(G_FILE_CREATE_PRIVATE), nullptr, nullptr)));
-#if !HAVE(STAT_BIRTHTIME)
-        GUniquePtr<char> birthtimeString(g_strdup_printf("%" G_GUINT64_FORMAT, WallTime::now().secondsSinceEpoch().secondsAs<uint64_t>()));
-        g_file_set_attribute_string(file.get(), "xattr::birthtime", birthtimeString.get(), G_FILE_QUERY_INFO_NONE, nullptr, nullptr);
-#endif
-        break;
-    }
-    case Type::Write: {
-        m_ioStream = adoptGRef(g_file_open_readwrite(file.get(), nullptr, nullptr));
-        break;
-    }
-    case Type::Read:
-        m_inputStream = adoptGRef(G_INPUT_STREAM(g_file_read(file.get(), nullptr, nullptr)));
-        break;
-    }
-}
-
-IOChannel::~IOChannel()
-{
-    RELEASE_ASSERT(!m_wasDeleted.exchange(true));
-}
-
-static inline void runTaskInQueue(Function<void ()>&& task, WorkQueue* queue)
-{
-    if (queue) {
-        queue->dispatch(WTFMove(task));
-        return;
-    }
-
-    // Using nullptr as queue submits the result to the main context.
-    RunLoop::main().dispatch(WTFMove(task));
-}
-
-static void fillDataFromReadBuffer(SoupBuffer* readBuffer, size_t size, Data& data)
-{
-    GRefPtr<SoupBuffer> buffer;
-    if (size != readBuffer->length) {
-        // The subbuffer does not copy the data.
-        buffer = adoptGRef(soup_buffer_new_subbuffer(readBuffer, 0, size));
-    } else
-        buffer = readBuffer;
-
-    if (data.isNull()) {
-        // First chunk, we need to force the data to be copied.
-        data = { reinterpret_cast<const uint8_t*>(buffer->data), size };
-    } else {
-        Data dataRead(WTFMove(buffer));
-        // Concatenate will copy the data.
-        data = "" dataRead);
-    }
-}
-
-struct ReadAsyncData {
-    RefPtr<IOChannel> channel;
-    GRefPtr<SoupBuffer> buffer;
-    RefPtr<WorkQueue> queue;
-    size_t bytesToRead;
-    Function<void (Data&, int error)> completionHandler;
-    Data data;
-};
-
-static void inputStreamReadReadyCallback(GInputStream* stream, GAsyncResult* result, gpointer userData)
-{
-    std::unique_ptr<ReadAsyncData> asyncData(static_cast<ReadAsyncData*>(userData));
-    gssize bytesRead = g_input_stream_read_finish(stream, result, nullptr);
-    if (bytesRead == -1) {
-        WorkQueue* queue = asyncData->queue.get();
-        runTaskInQueue([asyncData = WTFMove(asyncData)] {
-            asyncData->completionHandler(asyncData->data, -1);
-        }, queue);
-        return;
-    }
-
-    if (!bytesRead) {
-        WorkQueue* queue = asyncData->queue.get();
-        runTaskInQueue([asyncData = WTFMove(asyncData)] {
-            asyncData->completionHandler(asyncData->data, 0);
-        }, queue);
-        return;
-    }
-
-    ASSERT(bytesRead > 0);
-    fillDataFromReadBuffer(asyncData->buffer.get(), static_cast<size_t>(bytesRead), asyncData->data);
-
-    size_t pendingBytesToRead = asyncData->bytesToRead - asyncData->data.size();
-    if (!pendingBytesToRead) {
-        WorkQueue* queue = asyncData->queue.get();
-        runTaskInQueue([asyncData = WTFMove(asyncData)] {
-            asyncData->completionHandler(asyncData->data, 0);
-        }, queue);
-        return;
-    }
-
-    size_t bytesToRead = std::min(pendingBytesToRead, asyncData->buffer->length);
-    // Use a local variable for the data buffer to pass it to g_input_stream_read_async(), because ReadAsyncData is released.
-    auto data = ""
-    g_input_stream_read_async(stream, data, bytesToRead, RunLoopSourcePriority::DiskCacheRead, nullptr,
-        reinterpret_cast<GAsyncReadyCallback>(inputStreamReadReadyCallback), asyncData.release());
-}
-
-void IOChannel::read(size_t offset, size_t size, WorkQueue* queue, Function<void (Data&, int error)>&& completionHandler)
-{
-    RefPtr<IOChannel> channel(this);
-    if (!m_inputStream) {
-        runTaskInQueue([channel, completionHandler = WTFMove(completionHandler)] {
-            Data data;
-            completionHandler(data, -1);
-        }, queue);
-        return;
-    }
-
-    if (!RunLoop::isMain()) {
-        readSyncInThread(offset, size, queue, WTFMove(completionHandler));
-        return;
-    }
-
-    size_t bufferSize = std::min(size, gDefaultReadBufferSize);
-    uint8_t* bufferData = static_cast<uint8_t*>(fastMalloc(bufferSize));
-    GRefPtr<SoupBuffer> buffer = adoptGRef(soup_buffer_new_with_owner(bufferData, bufferSize, bufferData, fastFree));
-    ReadAsyncData* asyncData = new ReadAsyncData { this, buffer.get(), queue, size, WTFMove(completionHandler), { } };
-
-    // FIXME: implement offset.
-    g_input_stream_read_async(m_inputStream.get(), const_cast<char*>(buffer->data), bufferSize, RunLoopSourcePriority::DiskCacheRead, nullptr,
-        reinterpret_cast<GAsyncReadyCallback>(inputStreamReadReadyCallback), asyncData);
-}
-
-void IOChannel::readSyncInThread(size_t offset, size_t size, WorkQueue* queue, Function<void (Data&, int error)>&& completionHandler)
-{
-    ASSERT(!RunLoop::isMain());
-
-    RefPtr<IOChannel> channel(this);
-    Thread::create("IOChannel::readSync", [channel, size, queue, completionHandler = WTFMove(completionHandler)] () mutable {
-        size_t bufferSize = std::min(size, gDefaultReadBufferSize);
-        uint8_t* bufferData = static_cast<uint8_t*>(fastMalloc(bufferSize));
-        GRefPtr<SoupBuffer> readBuffer = adoptGRef(soup_buffer_new_with_owner(bufferData, bufferSize, bufferData, fastFree));
-        Data data;
-        size_t pendingBytesToRead = size;
-        size_t bytesToRead = bufferSize;
-        do {
-            // FIXME: implement offset.
-            gssize bytesRead = g_input_stream_read(channel->m_inputStream.get(), const_cast<char*>(readBuffer->data), bytesToRead, nullptr, nullptr);
-            if (bytesRead == -1) {
-                runTaskInQueue([channel, completionHandler = WTFMove(completionHandler)] {
-                    Data data;
-                    completionHandler(data, -1);
-                }, queue);
-                return;
-            }
-
-            if (!bytesRead)
-                break;
-
-            ASSERT(bytesRead > 0);
-            fillDataFromReadBuffer(readBuffer.get(), static_cast<size_t>(bytesRead), data);
-
-            pendingBytesToRead = size - data.size();
-            bytesToRead = std::min(pendingBytesToRead, readBuffer->length);
-        } while (pendingBytesToRead);
-
-        GRefPtr<SoupBuffer> bufferCapture = data.soupBuffer();
-        runTaskInQueue([channel, bufferCapture, completionHandler = WTFMove(completionHandler)] {
-            GRefPtr<SoupBuffer> buffer = bufferCapture;
-            Data data = { WTFMove(buffer) };
-            completionHandler(data, 0);
-        }, queue);
-    })->detach();
-}
-
-struct WriteAsyncData {
-    RefPtr<IOChannel> channel;
-    GRefPtr<SoupBuffer> buffer;
-    RefPtr<WorkQueue> queue;
-    Function<void (int error)> completionHandler;
-};
-
-static void outputStreamWriteReadyCallback(GOutputStream* stream, GAsyncResult* result, gpointer userData)
-{
-    std::unique_ptr<WriteAsyncData> asyncData(static_cast<WriteAsyncData*>(userData));
-    gssize bytesWritten = g_output_stream_write_finish(stream, result, nullptr);
-    if (bytesWritten == -1) {
-        WorkQueue* queue = asyncData->queue.get();
-        runTaskInQueue([asyncData = WTFMove(asyncData)] {
-            asyncData->completionHandler(-1);
-        }, queue);
-        return;
-    }
-
-    gssize pendingBytesToWrite = asyncData->buffer->length - bytesWritten;
-    if (!pendingBytesToWrite) {
-        WorkQueue* queue = asyncData->queue.get();
-        runTaskInQueue([asyncData = WTFMove(asyncData)] {
-            asyncData->completionHandler(0);
-        }, queue);
-        return;
-    }
-
-    asyncData->buffer = adoptGRef(soup_buffer_new_subbuffer(asyncData->buffer.get(), bytesWritten, pendingBytesToWrite));
-    // Use a local variable for the data buffer to pass it to g_output_stream_write_async(), because WriteAsyncData is released.
-    auto data = ""
-    g_output_stream_write_async(stream, data, pendingBytesToWrite, RunLoopSourcePriority::DiskCacheWrite, nullptr,
-        reinterpret_cast<GAsyncReadyCallback>(outputStreamWriteReadyCallback), asyncData.release());
-}
-
-void IOChannel::write(size_t offset, const Data& data, WorkQueue* queue, Function<void (int error)>&& completionHandler)
-{
-    RefPtr<IOChannel> channel(this);
-    if (!m_outputStream && !m_ioStream) {
-        runTaskInQueue([channel, completionHandler = WTFMove(completionHandler)] {
-            completionHandler(-1);
-        }, queue);
-        return;
-    }
-
-    GOutputStream* stream = m_outputStream ? m_outputStream.get() : g_io_stream_get_output_stream(G_IO_STREAM(m_ioStream.get()));
-    if (!stream) {
-        runTaskInQueue([channel, completionHandler = WTFMove(completionHandler)] {
-            completionHandler(-1);
-        }, queue);
-        return;
-    }
-
-    WriteAsyncData* asyncData = new WriteAsyncData { this, data.soupBuffer(), queue, WTFMove(completionHandler) };
-    // FIXME: implement offset.
-    g_output_stream_write_async(stream, asyncData->buffer->data, data.size(), RunLoopSourcePriority::DiskCacheWrite, nullptr,
-        reinterpret_cast<GAsyncReadyCallback>(outputStreamWriteReadyCallback), asyncData);
-}
-
-} // namespace NetworkCache
-} // namespace WebKit

Modified: trunk/Source/WebKit/Shared/ShareableResource.cpp (272195 => 272196)


--- trunk/Source/WebKit/Shared/ShareableResource.cpp	2021-02-02 08:50:27 UTC (rev 272195)
+++ trunk/Source/WebKit/Shared/ShareableResource.cpp	2021-02-02 08:52:42 UTC (rev 272196)
@@ -88,8 +88,11 @@
     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::create(cfData.get());
-#elif USE(SOUP)
-    return SharedBuffer::wrapSoupBuffer(soup_buffer_new_with_owner(data(), size(), this, [](void* data) { static_cast<ShareableResource*>(data)->deref(); }));
+#elif USE(GLIB)
+    GRefPtr<GBytes> bytes = adoptGRef(g_bytes_new_with_free_func(data(), size(), [](void* data) {
+        static_cast<ShareableResource*>(data)->deref();
+    }, this));
+    return SharedBuffer::create(bytes.get());
 #else
     ASSERT_NOT_REACHED();
     return nullptr;

Modified: trunk/Source/WebKit/SourcesGTK.txt (272195 => 272196)


--- trunk/Source/WebKit/SourcesGTK.txt	2021-02-02 08:50:27 UTC (rev 272195)
+++ trunk/Source/WebKit/SourcesGTK.txt	2021-02-02 08:52:42 UTC (rev 272196)
@@ -32,8 +32,8 @@
 
 NetworkProcess/Cookies/soup/WebCookieManagerSoup.cpp
 
-NetworkProcess/cache/NetworkCacheDataSoup.cpp
-NetworkProcess/cache/NetworkCacheIOChannelSoup.cpp
+NetworkProcess/cache/NetworkCacheDataGLib.cpp
+NetworkProcess/cache/NetworkCacheIOChannelGLib.cpp
 
 NetworkProcess/glib/DNSCache.cpp
 NetworkProcess/glib/WebKitCachedResolver.cpp

Modified: trunk/Source/WebKit/SourcesWPE.txt (272195 => 272196)


--- trunk/Source/WebKit/SourcesWPE.txt	2021-02-02 08:50:27 UTC (rev 272195)
+++ trunk/Source/WebKit/SourcesWPE.txt	2021-02-02 08:52:42 UTC (rev 272196)
@@ -32,8 +32,8 @@
 
 NetworkProcess/Cookies/soup/WebCookieManagerSoup.cpp
 
-NetworkProcess/cache/NetworkCacheDataSoup.cpp
-NetworkProcess/cache/NetworkCacheIOChannelSoup.cpp
+NetworkProcess/cache/NetworkCacheDataGLib.cpp
+NetworkProcess/cache/NetworkCacheIOChannelGLib.cpp
 
 NetworkProcess/glib/DNSCache.cpp
 NetworkProcess/glib/WebKitCachedResolver.cpp
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to