Title: [202154] trunk/Source
Revision
202154
Author
[email protected]
Date
2016-06-16 19:50:30 -0700 (Thu, 16 Jun 2016)

Log Message

No need to ref connection in lambda inside NetworkResourceLoader::tryStoreAsCacheEntry()
https://bugs.webkit.org/show_bug.cgi?id=158862

Reviewed by Darin Adler.

Source/WebKit2:

No need to ref connection in lambda inside NetworkResourceLoader::tryStoreAsCacheEntry().
We already ref the NetworkResourceLoader which hold a ref to the connection. Also update
the lambda capture to use Ref<> for the NetworkResourceLoader instead of RefPtr<>.
Switch callback type from std::function to WTF::NoncopyableFunction so we can capture a
Ref<>.

* NetworkProcess/NetworkResourceLoader.cpp:
(WebKit::NetworkResourceLoader::tryStoreAsCacheEntry):
* NetworkProcess/cache/NetworkCache.cpp:
(WebKit::NetworkCache::Cache::store):
* NetworkProcess/cache/NetworkCache.h:
* NetworkProcess/cache/NetworkCacheStorage.cpp:
(WebKit::NetworkCache::Storage::WriteOperation::WriteOperation):
* NetworkProcess/cache/NetworkCacheStorage.h:

Source/WTF:

Add NoncopyableFunction constructor that takes a nullptr_t in, in order
to match the std::function API and make porting from one to the other
easier.

* wtf/NoncopyableFunction.h:

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (202153 => 202154)


--- trunk/Source/WTF/ChangeLog	2016-06-17 02:30:43 UTC (rev 202153)
+++ trunk/Source/WTF/ChangeLog	2016-06-17 02:50:30 UTC (rev 202154)
@@ -1,5 +1,18 @@
 2016-06-16  Chris Dumez  <[email protected]>
 
+        No need to ref connection in lambda inside NetworkResourceLoader::tryStoreAsCacheEntry()
+        https://bugs.webkit.org/show_bug.cgi?id=158862
+
+        Reviewed by Darin Adler.
+
+        Add NoncopyableFunction constructor that takes a nullptr_t in, in order
+        to match the std::function API and make porting from one to the other
+        easier.
+
+        * wtf/NoncopyableFunction.h:
+
+2016-06-16  Chris Dumez  <[email protected]>
+
         Unreviewed, rolling out r202002 and r202111.
 
         Ryosuke says this was a JSBench regression on iOS

Modified: trunk/Source/WTF/wtf/NoncopyableFunction.h (202153 => 202154)


--- trunk/Source/WTF/wtf/NoncopyableFunction.h	2016-06-17 02:30:43 UTC (rev 202153)
+++ trunk/Source/WTF/wtf/NoncopyableFunction.h	2016-06-17 02:50:30 UTC (rev 202154)
@@ -36,6 +36,7 @@
 class NoncopyableFunction<Out(In...)> {
 public:
     NoncopyableFunction() = default;
+    NoncopyableFunction(std::nullptr_t) { }
 
     template<typename CallableType, class = typename std::enable_if<std::is_rvalue_reference<CallableType&&>::value>::type>
     NoncopyableFunction(CallableType&& callable)

Modified: trunk/Source/WebKit2/ChangeLog (202153 => 202154)


--- trunk/Source/WebKit2/ChangeLog	2016-06-17 02:30:43 UTC (rev 202153)
+++ trunk/Source/WebKit2/ChangeLog	2016-06-17 02:50:30 UTC (rev 202154)
@@ -1,5 +1,27 @@
 2016-06-16  Chris Dumez  <[email protected]>
 
+        No need to ref connection in lambda inside NetworkResourceLoader::tryStoreAsCacheEntry()
+        https://bugs.webkit.org/show_bug.cgi?id=158862
+
+        Reviewed by Darin Adler.
+
+        No need to ref connection in lambda inside NetworkResourceLoader::tryStoreAsCacheEntry().
+        We already ref the NetworkResourceLoader which hold a ref to the connection. Also update
+        the lambda capture to use Ref<> for the NetworkResourceLoader instead of RefPtr<>.
+        Switch callback type from std::function to WTF::NoncopyableFunction so we can capture a
+        Ref<>.
+
+        * NetworkProcess/NetworkResourceLoader.cpp:
+        (WebKit::NetworkResourceLoader::tryStoreAsCacheEntry):
+        * NetworkProcess/cache/NetworkCache.cpp:
+        (WebKit::NetworkCache::Cache::store):
+        * NetworkProcess/cache/NetworkCache.h:
+        * NetworkProcess/cache/NetworkCacheStorage.cpp:
+        (WebKit::NetworkCache::Storage::WriteOperation::WriteOperation):
+        * NetworkProcess/cache/NetworkCacheStorage.h:
+
+2016-06-16  Chris Dumez  <[email protected]>
+
         [WK2] Improve serialization of SubresourcesEntry to network disk cache
         https://bugs.webkit.org/show_bug.cgi?id=158851
 

Modified: trunk/Source/WebKit2/NetworkProcess/NetworkResourceLoader.cpp (202153 => 202154)


--- trunk/Source/WebKit2/NetworkProcess/NetworkResourceLoader.cpp	2016-06-17 02:30:43 UTC (rev 202153)
+++ trunk/Source/WebKit2/NetworkProcess/NetworkResourceLoader.cpp	2016-06-17 02:50:30 UTC (rev 202154)
@@ -515,10 +515,7 @@
     if (!m_bufferedDataForCache)
         return;
 
-    // Keep the connection alive.
-    RefPtr<NetworkConnectionToWebProcess> connection(&connectionToWebProcess());
-    RefPtr<NetworkResourceLoader> loader(this);
-    NetworkCache::singleton().store(m_networkLoad->currentRequest(), m_response, WTFMove(m_bufferedDataForCache), [loader, connection](auto& mappedBody) {
+    NetworkCache::singleton().store(m_networkLoad->currentRequest(), m_response, WTFMove(m_bufferedDataForCache), [loader = Ref<NetworkResourceLoader>(*this)](auto& mappedBody) mutable {
 #if ENABLE(SHAREABLE_RESOURCE)
         if (mappedBody.shareableResourceHandle.isNull())
             return;

Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.cpp (202153 => 202154)


--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.cpp	2016-06-17 02:30:43 UTC (rev 202153)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.cpp	2016-06-17 02:50:30 UTC (rev 202154)
@@ -382,7 +382,7 @@
     });
 }
 
-std::unique_ptr<Entry> Cache::store(const WebCore::ResourceRequest& request, const WebCore::ResourceResponse& response, RefPtr<WebCore::SharedBuffer>&& responseData, std::function<void (MappedBody&)>&& completionHandler)
+std::unique_ptr<Entry> Cache::store(const WebCore::ResourceRequest& request, const WebCore::ResourceResponse& response, RefPtr<WebCore::SharedBuffer>&& responseData, NoncopyableFunction<void (MappedBody&)>&& completionHandler)
 {
     ASSERT(isEnabled());
     ASSERT(responseData);

Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.h (202153 => 202154)


--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.h	2016-06-17 02:30:43 UTC (rev 202153)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.h	2016-06-17 02:50:30 UTC (rev 202154)
@@ -106,7 +106,7 @@
 
     // Completion handler may get called back synchronously on failure.
     void retrieve(const WebCore::ResourceRequest&, const GlobalFrameID&, std::function<void (std::unique_ptr<Entry>)>&&);
-    std::unique_ptr<Entry> store(const WebCore::ResourceRequest&, const WebCore::ResourceResponse&, RefPtr<WebCore::SharedBuffer>&&, std::function<void (MappedBody&)>&&);
+    std::unique_ptr<Entry> store(const WebCore::ResourceRequest&, const WebCore::ResourceResponse&, RefPtr<WebCore::SharedBuffer>&&, NoncopyableFunction<void (MappedBody&)>&&);
     std::unique_ptr<Entry> storeRedirect(const WebCore::ResourceRequest&, const WebCore::ResourceResponse&, const WebCore::ResourceRequest& redirectRequest);
     std::unique_ptr<Entry> update(const WebCore::ResourceRequest&, const GlobalFrameID&, const Entry&, const WebCore::ResourceResponse& validatingResponse);
 

Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.cpp (202153 => 202154)


--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.cpp	2016-06-17 02:30:43 UTC (rev 202153)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.cpp	2016-06-17 02:50:30 UTC (rev 202154)
@@ -99,9 +99,9 @@
 struct Storage::WriteOperation {
     WTF_MAKE_FAST_ALLOCATED;
 public:
-    WriteOperation(const Record& record, const MappedBodyHandler& mappedBodyHandler)
+    WriteOperation(const Record& record, MappedBodyHandler&& mappedBodyHandler)
         : record(record)
-        , mappedBodyHandler(mappedBodyHandler)
+        , mappedBodyHandler(WTFMove(mappedBodyHandler))
     { }
     
     const Record record;

Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.h (202153 => 202154)


--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.h	2016-06-17 02:30:43 UTC (rev 202153)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.h	2016-06-17 02:50:30 UTC (rev 202154)
@@ -62,7 +62,7 @@
     typedef std::function<bool (std::unique_ptr<Record>)> RetrieveCompletionHandler;
     void retrieve(const Key&, unsigned priority, RetrieveCompletionHandler&&);
 
-    typedef std::function<void (const Data& mappedBody)> MappedBodyHandler;
+    typedef NoncopyableFunction<void (const Data& mappedBody)> MappedBodyHandler;
     void store(const Record&, MappedBodyHandler&&);
 
     void remove(const Key&);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to