Diff
Modified: trunk/Source/WebKit2/ChangeLog (218023 => 218024)
--- trunk/Source/WebKit2/ChangeLog 2017-06-09 22:35:01 UTC (rev 218023)
+++ trunk/Source/WebKit2/ChangeLog 2017-06-09 22:38:40 UTC (rev 218024)
@@ -1,3 +1,30 @@
+2017-06-09 Chris Dumez <[email protected]>
+
+ Use WTF::Function instead of std::function in NetworkProcess code
+ https://bugs.webkit.org/show_bug.cgi?id=173182
+
+ Reviewed by Alex Christensen.
+
+ Use WTF::Function instead of std::function in NetworkProcess code to avoid
+ unnecessary copying.
+
+ * NetworkProcess/NetworkProcess.h:
+ * NetworkProcess/cache/NetworkCacheIOChannel.h:
+ * NetworkProcess/cache/NetworkCacheIOChannelCocoa.mm:
+ (WebKit::NetworkCache::IOChannel::read):
+ (WebKit::NetworkCache::IOChannel::write):
+ * NetworkProcess/cache/NetworkCacheIOChannelSoup.cpp:
+ (WebKit::NetworkCache::IOChannel::read):
+ (WebKit::NetworkCache::IOChannel::readSyncInThread):
+ (WebKit::NetworkCache::IOChannel::write):
+ * NetworkProcess/cache/NetworkCacheSpeculativeLoad.h:
+ * NetworkProcess/cache/NetworkCacheStatistics.h:
+ * NetworkProcess/cocoa/NetworkProcessCocoa.mm:
+ (WebKit::clearNSURLCache):
+ (WebKit::NetworkProcess::clearDiskCache):
+ * NetworkProcess/soup/NetworkProcessSoup.cpp:
+ (WebKit::NetworkProcess::clearDiskCache):
+
2017-06-09 Tim Horton <[email protected]>
REGRESSION (r213584): WeChat app can not switch to next text field
Modified: trunk/Source/WebKit2/NetworkProcess/NetworkProcess.h (218023 => 218024)
--- trunk/Source/WebKit2/NetworkProcess/NetworkProcess.h 2017-06-09 22:35:01 UTC (rev 218023)
+++ trunk/Source/WebKit2/NetworkProcess/NetworkProcess.h 2017-06-09 22:38:40 UTC (rev 218024)
@@ -170,7 +170,7 @@
void clearCachedCredentials();
// FIXME: This should take a session ID so we can identify which disk cache to delete.
- void clearDiskCache(std::chrono::system_clock::time_point modifiedSince, std::function<void ()> completionHandler);
+ void clearDiskCache(std::chrono::system_clock::time_point modifiedSince, Function<void ()>&& completionHandler);
void downloadRequest(WebCore::SessionID, DownloadID, const WebCore::ResourceRequest&, const String& suggestedFilename);
void resumeDownload(WebCore::SessionID, DownloadID, const IPC::DataReference& resumeData, const String& path, const SandboxExtension::Handle&);
Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheIOChannel.h (218023 => 218024)
--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheIOChannel.h 2017-06-09 22:35:01 UTC (rev 218023)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheIOChannel.h 2017-06-09 22:38:40 UTC (rev 218024)
@@ -29,7 +29,7 @@
#if ENABLE(NETWORK_CACHE)
#include "NetworkCacheData.h"
-#include <functional>
+#include <wtf/Function.h>
#include <wtf/ThreadSafeRefCounted.h>
#include <wtf/WorkQueue.h>
#include <wtf/text/WTFString.h>
@@ -48,8 +48,8 @@
// Using nullptr as queue submits the result to the main queue.
// FIXME: We should add WorkQueue::main() instead.
- void read(size_t offset, size_t, WorkQueue*, std::function<void (Data&, int error)>);
- void write(size_t offset, const Data&, WorkQueue*, std::function<void (int error)>);
+ void read(size_t offset, size_t, WorkQueue*, Function<void (Data&, int error)>&&);
+ void write(size_t offset, const Data&, WorkQueue*, Function<void (int error)>&&);
const String& path() const { return m_path; }
Type type() const { return m_type; }
@@ -62,7 +62,7 @@
IOChannel(const String& filePath, IOChannel::Type);
#if USE(SOUP)
- void readSyncInThread(size_t offset, size_t, WorkQueue*, std::function<void (Data&, int error)>);
+ void readSyncInThread(size_t offset, size_t, WorkQueue*, Function<void (Data&, int error)>&&);
#endif
String m_path;
Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheIOChannelCocoa.mm (218023 => 218024)
--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheIOChannelCocoa.mm 2017-06-09 22:35:01 UTC (rev 218023)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheIOChannelCocoa.mm 2017-06-09 22:38:40 UTC (rev 218024)
@@ -33,6 +33,7 @@
#include <mach/vm_param.h>
#include <sys/mman.h>
#include <sys/stat.h>
+#include <wtf/BlockPtr.h>
#include <wtf/text/CString.h>
namespace WebKit {
@@ -92,12 +93,12 @@
return adoptRef(*new IOChannel(filePath, type));
}
-void IOChannel::read(size_t offset, size_t size, WorkQueue* queue, std::function<void (Data&, int error)> completionHandler)
+void IOChannel::read(size_t offset, size_t size, WorkQueue* queue, Function<void (Data&, int error)>&& completionHandler)
{
RefPtr<IOChannel> channel(this);
bool didCallCompletionHandler = false;
auto dispatchQueue = queue ? queue->dispatchQueue() : dispatch_get_main_queue();
- dispatch_io_read(m_dispatchIO.get(), offset, size, dispatchQueue, [channel, completionHandler, didCallCompletionHandler](bool done, dispatch_data_t fileData, int error) mutable {
+ dispatch_io_read(m_dispatchIO.get(), offset, size, dispatchQueue, BlockPtr<void(bool, dispatch_data_t, int)>::fromCallable([channel, completionHandler = WTFMove(completionHandler), didCallCompletionHandler](bool done, dispatch_data_t fileData, int error) mutable {
ASSERT_UNUSED(done, done || !didCallCompletionHandler);
if (didCallCompletionHandler)
return;
@@ -105,18 +106,18 @@
Data data(fileDataPtr);
completionHandler(data, error);
didCallCompletionHandler = true;
- });
+ }).get());
}
-void IOChannel::write(size_t offset, const Data& data, WorkQueue* queue, std::function<void (int error)> completionHandler)
+void IOChannel::write(size_t offset, const Data& data, WorkQueue* queue, Function<void (int error)>&& completionHandler)
{
RefPtr<IOChannel> channel(this);
auto dispatchData = data.dispatchData();
auto dispatchQueue = queue ? queue->dispatchQueue() : dispatch_get_main_queue();
- dispatch_io_write(m_dispatchIO.get(), offset, dispatchData, dispatchQueue, [channel, completionHandler](bool done, dispatch_data_t fileData, int error) {
+ dispatch_io_write(m_dispatchIO.get(), offset, dispatchData, dispatchQueue, BlockPtr<void(bool, dispatch_data_t, int)>::fromCallable([channel, completionHandler = WTFMove(completionHandler)](bool done, dispatch_data_t fileData, int error) {
ASSERT_UNUSED(done, done);
completionHandler(error);
- });
+ }).get());
}
}
Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheIOChannelSoup.cpp (218023 => 218024)
--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheIOChannelSoup.cpp 2017-06-09 22:35:01 UTC (rev 218023)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheIOChannelSoup.cpp 2017-06-09 22:38:40 UTC (rev 218024)
@@ -110,7 +110,7 @@
GRefPtr<SoupBuffer> buffer;
RefPtr<WorkQueue> queue;
size_t bytesToRead;
- std::function<void (Data&, int error)> completionHandler;
+ Function<void (Data&, int error)> completionHandler;
Data data;
};
@@ -153,11 +153,11 @@
reinterpret_cast<GAsyncReadyCallback>(inputStreamReadReadyCallback), asyncData.release());
}
-void IOChannel::read(size_t offset, size_t size, WorkQueue* queue, std::function<void (Data&, int error)> completionHandler)
+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] {
+ runTaskInQueue([channel, completionHandler = WTFMove(completionHandler)] {
Data data;
completionHandler(data, -1);
}, queue);
@@ -165,7 +165,7 @@
}
if (!isMainThread()) {
- readSyncInThread(offset, size, queue, completionHandler);
+ readSyncInThread(offset, size, queue, WTFMove(completionHandler));
return;
}
@@ -172,7 +172,7 @@
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, completionHandler, { } };
+ 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,
@@ -179,12 +179,12 @@
reinterpret_cast<GAsyncReadyCallback>(inputStreamReadReadyCallback), asyncData);
}
-void IOChannel::readSyncInThread(size_t offset, size_t size, WorkQueue* queue, std::function<void (Data&, int error)> completionHandler)
+void IOChannel::readSyncInThread(size_t offset, size_t size, WorkQueue* queue, Function<void (Data&, int error)>&& completionHandler)
{
ASSERT(!isMainThread());
RefPtr<IOChannel> channel(this);
- Thread::create("IOChannel::readSync", [channel, size, queue, completionHandler] {
+ 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));
@@ -195,7 +195,7 @@
// 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] {
+ runTaskInQueue([channel, completionHandler = WTFMove(completionHandler)] {
Data data;
completionHandler(data, -1);
}, queue);
@@ -213,7 +213,7 @@
} while (pendingBytesToRead);
GRefPtr<SoupBuffer> bufferCapture = data.soupBuffer();
- runTaskInQueue([channel, bufferCapture, completionHandler] {
+ runTaskInQueue([channel, bufferCapture, completionHandler = WTFMove(completionHandler)] {
GRefPtr<SoupBuffer> buffer = bufferCapture;
Data data = { WTFMove(buffer) };
completionHandler(data, 0);
@@ -225,7 +225,7 @@
RefPtr<IOChannel> channel;
GRefPtr<SoupBuffer> buffer;
RefPtr<WorkQueue> queue;
- std::function<void (int error)> completionHandler;
+ Function<void (int error)> completionHandler;
};
static void outputStreamWriteReadyCallback(GOutputStream* stream, GAsyncResult* result, gpointer userData)
@@ -256,11 +256,11 @@
reinterpret_cast<GAsyncReadyCallback>(outputStreamWriteReadyCallback), asyncData.release());
}
-void IOChannel::write(size_t offset, const Data& data, WorkQueue* queue, std::function<void (int error)> completionHandler)
+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] {
+ runTaskInQueue([channel, completionHandler = WTFMove(completionHandler)] {
completionHandler(-1);
}, queue);
return;
@@ -268,13 +268,13 @@
GOutputStream* stream = m_outputStream ? m_outputStream.get() : g_io_stream_get_output_stream(G_IO_STREAM(m_ioStream.get()));
if (!stream) {
- runTaskInQueue([channel, completionHandler] {
+ runTaskInQueue([channel, completionHandler = WTFMove(completionHandler)] {
completionHandler(-1);
}, queue);
return;
}
- WriteAsyncData* asyncData = new WriteAsyncData { this, data.soupBuffer(), queue, completionHandler };
+ 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);
Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheSpeculativeLoad.h (218023 => 218024)
--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheSpeculativeLoad.h 2017-06-09 22:35:01 UTC (rev 218023)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheSpeculativeLoad.h 2017-06-09 22:38:40 UTC (rev 218024)
@@ -44,7 +44,7 @@
class SpeculativeLoad final : public NetworkLoadClient {
WTF_MAKE_FAST_ALLOCATED;
public:
- typedef std::function<void (std::unique_ptr<NetworkCache::Entry>)> RevalidationCompletionHandler;
+ typedef Function<void (std::unique_ptr<NetworkCache::Entry>)> RevalidationCompletionHandler;
SpeculativeLoad(const GlobalFrameID&, const WebCore::ResourceRequest&, std::unique_ptr<NetworkCache::Entry>, RevalidationCompletionHandler&&);
virtual ~SpeculativeLoad();
Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStatistics.h (218023 => 218024)
--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStatistics.h 2017-06-09 22:35:01 UTC (rev 218023)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStatistics.h 2017-06-09 22:38:40 UTC (rev 218024)
@@ -66,7 +66,7 @@
void addStoreDecisionsToDatabase(const HashMap<String, NetworkCache::StoreDecision>&);
void writeTimerFired();
- typedef std::function<void (bool wasEverRequested, const std::optional<StoreDecision>&)> RequestedCompletionHandler;
+ typedef Function<void (bool wasEverRequested, const std::optional<StoreDecision>&)> RequestedCompletionHandler;
enum class NeedUncachedReason { No, Yes };
void queryWasEverRequested(const String&, NeedUncachedReason, RequestedCompletionHandler&&);
void markAsRequested(const String& hash);
Modified: trunk/Source/WebKit2/NetworkProcess/cocoa/NetworkProcessCocoa.mm (218023 => 218024)
--- trunk/Source/WebKit2/NetworkProcess/cocoa/NetworkProcessCocoa.mm 2017-06-09 22:35:01 UTC (rev 218023)
+++ trunk/Source/WebKit2/NetworkProcess/cocoa/NetworkProcessCocoa.mm 2017-06-09 22:38:40 UTC (rev 218024)
@@ -40,6 +40,7 @@
#import <WebCore/SecurityOrigin.h>
#import <WebCore/SecurityOriginData.h>
#import <WebKitSystemInterface.h>
+#import <wtf/BlockPtr.h>
namespace WebKit {
@@ -167,9 +168,9 @@
_CFNetworkResetHSTSHostsSinceDate(session.platformSession(), (__bridge CFDateRef)date);
}
-static void clearNSURLCache(dispatch_group_t group, std::chrono::system_clock::time_point modifiedSince, const std::function<void ()>& completionHandler)
+static void clearNSURLCache(dispatch_group_t group, std::chrono::system_clock::time_point modifiedSince, Function<void ()>&& completionHandler)
{
- dispatch_group_async(group, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), [modifiedSince, completionHandler] {
+ dispatch_group_async(group, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), BlockPtr<void()>::fromCallable([modifiedSince, completionHandler = WTFMove(completionHandler)] () mutable {
NSURLCache *cache = [NSURLCache sharedURLCache];
NSTimeInterval timeInterval = std::chrono::duration_cast<std::chrono::duration<double>>(modifiedSince.time_since_epoch()).count();
@@ -176,13 +177,13 @@
NSDate *date = [NSDate dateWithTimeIntervalSince1970:timeInterval];
[cache removeCachedResponsesSinceDate:date];
- dispatch_async(dispatch_get_main_queue(), [completionHandler] {
+ dispatch_async(dispatch_get_main_queue(), BlockPtr<void()>::fromCallable([completionHandler = WTFMove(completionHandler)] {
completionHandler();
- });
- });
+ }).get());
+ }).get());
}
-void NetworkProcess::clearDiskCache(std::chrono::system_clock::time_point modifiedSince, std::function<void ()> completionHandler)
+void NetworkProcess::clearDiskCache(std::chrono::system_clock::time_point modifiedSince, Function<void ()>&& completionHandler)
{
if (!m_clearCacheDispatchGroup)
m_clearCacheDispatchGroup = dispatch_group_create();
@@ -189,14 +190,14 @@
#if ENABLE(NETWORK_CACHE)
auto group = m_clearCacheDispatchGroup;
- dispatch_group_async(group, dispatch_get_main_queue(), [group, modifiedSince, completionHandler] {
- NetworkCache::singleton().clear(modifiedSince, [group, modifiedSince, completionHandler] {
+ dispatch_group_async(group, dispatch_get_main_queue(), BlockPtr<void()>::fromCallable([group, modifiedSince, completionHandler = WTFMove(completionHandler)] () mutable {
+ NetworkCache::singleton().clear(modifiedSince, [group, modifiedSince, completionHandler = WTFMove(completionHandler)] () mutable {
// FIXME: Probably not necessary.
- clearNSURLCache(group, modifiedSince, completionHandler);
+ clearNSURLCache(group, modifiedSince, WTFMove(completionHandler));
});
- });
+ }).get());
#else
- clearNSURLCache(m_clearCacheDispatchGroup, modifiedSince, completionHandler);
+ clearNSURLCache(m_clearCacheDispatchGroup, modifiedSince, WTFMove(completionHandler));
#endif
}
Modified: trunk/Source/WebKit2/NetworkProcess/soup/NetworkProcessSoup.cpp (218023 => 218024)
--- trunk/Source/WebKit2/NetworkProcess/soup/NetworkProcessSoup.cpp 2017-06-09 22:35:01 UTC (rev 218023)
+++ trunk/Source/WebKit2/NetworkProcess/soup/NetworkProcessSoup.cpp 2017-06-09 22:38:40 UTC (rev 218024)
@@ -156,7 +156,7 @@
clearDiskCache(std::chrono::system_clock::time_point::min(), [] { });
}
-void NetworkProcess::clearDiskCache(std::chrono::system_clock::time_point modifiedSince, std::function<void ()> completionHandler)
+void NetworkProcess::clearDiskCache(std::chrono::system_clock::time_point modifiedSince, Function<void ()>&& completionHandler)
{
NetworkCache::singleton().clear(modifiedSince, WTFMove(completionHandler));
}