Changeset 201464 in webkit
- Timestamp:
- May 27, 2016 1:22:12 PM (8 years ago)
- Location:
- trunk
- Files:
-
- 26 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/ChangeLog
r201462 r201464 1 2016-05-27 Chris Dumez <cdumez@apple.com> 2 3 WorkQueue::dispatch() / RunLoop::dispatch() should not copy captured lambda variables 4 https://bugs.webkit.org/show_bug.cgi?id=158111 5 6 Reviewed by Darin Adler. 7 8 WorkQueue::dispatch() / RunLoop::dispatch() should not copy captured lambda variables. 9 These are often used cross-thread and copying the captured lambda variables can be 10 dangerous (e.g. we do not want to copy a String after calling isolatedCopy() upon 11 capture). 12 13 * runtime/Watchdog.cpp: 14 (JSC::Watchdog::startTimer): 15 (JSC::Watchdog::Watchdog): Deleted. 16 (JSC::Watchdog::setTimeLimit): Deleted. 17 * runtime/Watchdog.h: 18 1 19 2016-05-27 Konstantin Tokarev <annulen@yandex.ru> 2 20 -
trunk/Source/JavaScriptCore/runtime/Watchdog.cpp
r193636 r201464 51 51 , m_timerQueue(WorkQueue::create("jsc.watchdog.queue", WorkQueue::Type::Serial, WorkQueue::QOS::Utility)) 52 52 { 53 m_timerHandler = [this] {54 {55 LockHolder locker(m_lock);56 this->m_timerDidFire = true;57 }58 this->deref();59 };60 53 } 61 54 … … 178 171 m_wallClockDeadline = wallClockDeadline; 179 172 180 m_timerQueue->dispatchAfter(std::chrono::nanoseconds(timeLimit), m_timerHandler); 173 m_timerQueue->dispatchAfter(std::chrono::nanoseconds(timeLimit), [this] { 174 { 175 LockHolder locker(m_lock); 176 m_timerDidFire = true; 177 } 178 deref(); 179 }); 181 180 } 182 181 -
trunk/Source/JavaScriptCore/runtime/Watchdog.h
r193636 r201464 92 92 93 93 Ref<WorkQueue> m_timerQueue; 94 std::function<void ()> m_timerHandler;95 94 96 95 friend class LLIntOffsetsExtractor; -
trunk/Source/WTF/ChangeLog
r201433 r201464 1 2016-05-27 Chris Dumez <cdumez@apple.com> 2 3 WorkQueue::dispatch() / RunLoop::dispatch() should not copy captured lambda variables 4 https://bugs.webkit.org/show_bug.cgi?id=158111 5 6 Reviewed by Darin Adler. 7 8 WorkQueue::dispatch() / RunLoop::dispatch() should not copy captured lambda variables. 9 These are often used cross-thread and copying the captured lambda variables can be 10 dangerous (e.g. we do not want to copy a String after calling isolatedCopy() upon 11 capture). 12 13 This patch introduces a new NoncopyableFunction type that behaves similarly to 14 std::function but guarantees that the passed-in lambda (and its captured variables) 15 cannot be copied. This new NoncopyableFunction type is now used for 16 WorkQueue / RunLoop's dispatch() / dispatchAfter() which are commonly used 17 cross-thread. This should now allow us to call WorkQueue::dispatch() with a lambda 18 that captures a String like so: 19 [str = str.isolatedCopy()]() { } 20 21 Also note that even though this is not leveraged in this patch, NoncopyableFunction 22 would allow us to capture move-only types such as std::unique_ptr as so: 23 [p = WTFMove(p)]() { } 24 This does not work if we convert the lambda into an std::function because 25 std::function requires the lambda to be copyable, NoncopyableFunction does not. 26 27 * wtf/FunctionDispatcher.h: 28 (WTF::CallableWrapperBase::~CallableWrapperBase): 29 (WTF::NoncopyableFunction::NoncopyableFunction): 30 (WTF::NoncopyableFunction::operator()): 31 (WTF::NoncopyableFunction::operator bool): 32 (WTF::NoncopyableFunction::operator=): 33 * wtf/RunLoop.cpp: 34 (WTF::RunLoop::performWork): 35 (WTF::RunLoop::dispatch): 36 * wtf/RunLoop.h: 37 * wtf/WorkQueue.h: 38 * wtf/cocoa/WorkQueueCocoa.cpp: 39 (WTF::WorkQueue::dispatch): 40 (WTF::WorkQueue::dispatchAfter): 41 * wtf/efl/DispatchQueueWorkItemEfl.h: 42 (WorkItem::WorkItem): 43 (TimerWorkItem::create): 44 (TimerWorkItem::TimerWorkItem): 45 * wtf/efl/WorkQueueEfl.cpp: 46 (WTF::WorkQueue::dispatch): 47 (WTF::WorkQueue::dispatchAfter): 48 * wtf/generic/RunLoopGeneric.cpp: 49 (WTF::RunLoop::dispatchAfter): 50 * wtf/generic/WorkQueueGeneric.cpp: 51 (WorkQueue::dispatch): 52 (WorkQueue::dispatchAfter): 53 * wtf/glib/RunLoopGLib.cpp: 54 (WTF::DispatchAfterContext::DispatchAfterContext): 55 (WTF::RunLoop::dispatchAfter): 56 * wtf/win/WorkItemWin.cpp: 57 (WTF::WorkItemWin::WorkItemWin): 58 (WTF::WorkItemWin::create): 59 (WTF::HandleWorkItem::HandleWorkItem): 60 (WTF::HandleWorkItem::createByAdoptingHandle): 61 * wtf/win/WorkItemWin.h: 62 (WTF::WorkItemWin::function): 63 * wtf/win/WorkQueueWin.cpp: 64 (WTF::WorkQueue::dispatch): 65 (WTF::WorkQueue::timerCallback): 66 (WTF::WorkQueue::dispatchAfter): 67 1 68 2016-05-26 Filip Pizlo <fpizlo@apple.com> 2 69 -
trunk/Source/WTF/wtf/FunctionDispatcher.h
r174864 r201464 32 32 namespace WTF { 33 33 34 // FIXME: Move this to its own header (e.g. Functional.h). 35 // FIXME: We could make this templated to support other lambdas than void() and make this more reusable. 36 class NoncopyableFunction { 37 public: 38 NoncopyableFunction() = default; 39 40 template<typename CallableType, class = typename std::enable_if<std::is_rvalue_reference<CallableType&&>::value>::type> 41 NoncopyableFunction(CallableType&& callable) 42 : m_callableWrapper(std::make_unique<CallableWrapper<CallableType>>(WTFMove(callable))) 43 { 44 } 45 46 void operator()() const 47 { 48 if (m_callableWrapper) 49 m_callableWrapper->call(); 50 } 51 52 explicit operator bool() const { return !!m_callableWrapper; } 53 54 template<typename CallableType, class = typename std::enable_if<std::is_rvalue_reference<CallableType&&>::value>::type> 55 NoncopyableFunction& operator=(CallableType&& callable) 56 { 57 m_callableWrapper = std::make_unique<CallableWrapper<CallableType>>(WTFMove(callable)); 58 return *this; 59 } 60 61 private: 62 class CallableWrapperBase { 63 WTF_MAKE_FAST_ALLOCATED; 64 public: 65 virtual ~CallableWrapperBase() { } 66 67 virtual void call() = 0; 68 }; 69 70 template<typename CallableType> 71 class CallableWrapper final : public CallableWrapperBase { 72 public: 73 explicit CallableWrapper(CallableType&& callable) 74 : m_callable(WTFMove(callable)) 75 { 76 } 77 78 CallableWrapper(const CallableWrapper&) = delete; 79 CallableWrapper& operator=(const CallableWrapper&) = delete; 80 81 void call() final { m_callable(); } 82 83 private: 84 CallableType m_callable; 85 }; 86 87 std::unique_ptr<CallableWrapperBase> m_callableWrapper; 88 }; 89 34 90 // FunctionDispatcher is an abstract representation of something that functions can be 35 91 // dispatched to. This can for example be a run loop or a work queue. … … 39 95 WTF_EXPORT_PRIVATE virtual ~FunctionDispatcher(); 40 96 41 virtual void dispatch( std::function<void ()>) = 0;97 virtual void dispatch(NoncopyableFunction&&) = 0; 42 98 43 99 protected: … … 48 104 49 105 using WTF::FunctionDispatcher; 106 using WTF::NoncopyableFunction; 50 107 51 108 #endif // FunctionDispatcher_h -
trunk/Source/WTF/wtf/RunLoop.cpp
r194819 r201464 92 92 size_t functionsToHandle = 0; 93 93 { 94 std::function<void()>function;94 NoncopyableFunction function; 95 95 { 96 96 MutexLocker locker(m_functionQueueLock); … … 107 107 108 108 for (size_t functionsHandled = 1; functionsHandled < functionsToHandle; ++functionsHandled) { 109 std::function<void()>function;109 NoncopyableFunction function; 110 110 { 111 111 MutexLocker locker(m_functionQueueLock); … … 124 124 } 125 125 126 void RunLoop::dispatch( std::function<void ()>function)126 void RunLoop::dispatch(NoncopyableFunction&& function) 127 127 { 128 128 { -
trunk/Source/WTF/wtf/RunLoop.h
r199713 r201464 60 60 ~RunLoop(); 61 61 62 void dispatch( std::function<void()>) override;62 void dispatch(NoncopyableFunction&&) override; 63 63 64 64 WTF_EXPORT_PRIVATE static void run(); … … 80 80 81 81 #if USE(GLIB_EVENT_LOOP) || USE(GENERIC_EVENT_LOOP) 82 WTF_EXPORT_PRIVATE void dispatchAfter(std::chrono::nanoseconds, std::function<void()>);82 WTF_EXPORT_PRIVATE void dispatchAfter(std::chrono::nanoseconds, NoncopyableFunction&&); 83 83 #endif 84 84 … … 156 156 157 157 Mutex m_functionQueueLock; 158 Deque< std::function<void ()>> m_functionQueue;158 Deque<NoncopyableFunction> m_functionQueue; 159 159 160 160 #if USE(WINDOWS_EVENT_LOOP) -
trunk/Source/WTF/wtf/WorkQueue.h
r199713 r201464 69 69 Background 70 70 }; 71 71 72 72 WTF_EXPORT_PRIVATE static Ref<WorkQueue> create(const char* name, Type = Type::Serial, QOS = QOS::Default); 73 73 virtual ~WorkQueue(); 74 74 75 WTF_EXPORT_PRIVATE void dispatch( std::function<void ()>) override;76 WTF_EXPORT_PRIVATE void dispatchAfter(std::chrono::nanoseconds, std::function<void ()>);75 WTF_EXPORT_PRIVATE void dispatch(NoncopyableFunction&&) override; 76 WTF_EXPORT_PRIVATE void dispatchAfter(std::chrono::nanoseconds, NoncopyableFunction&&); 77 77 78 78 WTF_EXPORT_PRIVATE static void concurrentApply(size_t iterations, const std::function<void (size_t index)>&); -
trunk/Source/WTF/wtf/cocoa/WorkQueueCocoa.cpp
r188981 r201464 29 29 namespace WTF { 30 30 31 void WorkQueue::dispatch( std::function<void ()>function)31 void WorkQueue::dispatch(NoncopyableFunction&& function) 32 32 { 33 33 ref(); 34 auto* functionPtr = new NoncopyableFunction(WTFMove(function)); 34 35 dispatch_async(m_dispatchQueue, ^{ 35 function(); 36 (*functionPtr)(); 37 delete functionPtr; 36 38 deref(); 37 39 }); 38 40 } 39 41 40 void WorkQueue::dispatchAfter(std::chrono::nanoseconds duration, std::function<void ()>function)42 void WorkQueue::dispatchAfter(std::chrono::nanoseconds duration, NoncopyableFunction&& function) 41 43 { 42 44 ref(); 45 auto* functionPtr = new NoncopyableFunction(WTFMove(function)); 43 46 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, duration.count()), m_dispatchQueue, ^{ 44 function(); 47 (*functionPtr)(); 48 delete functionPtr; 45 49 deref(); 46 50 }); -
trunk/Source/WTF/wtf/efl/DispatchQueueWorkItemEfl.h
r194496 r201464 29 29 #include <wtf/Assertions.h> 30 30 #include <wtf/CurrentTime.h> 31 #include <wtf/FunctionDispatcher.h> 31 32 #include <wtf/RefCounted.h> 32 33 #include <wtf/WorkQueue.h> … … 34 35 class WorkItem { 35 36 public: 36 WorkItem( PassRefPtr<WorkQueue> workQueue, std::function<void ()>function)37 : m_workQueue( workQueue)37 WorkItem(Ref<WorkQueue>&& workQueue, NoncopyableFunction&& function) 38 : m_workQueue(WTFMove(workQueue)) 38 39 , m_function(WTFMove(function)) 39 40 { … … 43 44 44 45 private: 45 Ref Ptr<WorkQueue> m_workQueue;46 std::function<void ()>m_function;46 Ref<WorkQueue> m_workQueue; 47 NoncopyableFunction m_function; 47 48 }; 48 49 49 50 class TimerWorkItem : public WorkItem { 50 51 public: 51 static std::unique_ptr<TimerWorkItem> create( PassRefPtr<WorkQueue> workQueue, std::function<void ()>function, std::chrono::nanoseconds delayNanoSeconds)52 static std::unique_ptr<TimerWorkItem> create(Ref<WorkQueue>&& workQueue, NoncopyableFunction&& function, std::chrono::nanoseconds delayNanoSeconds) 52 53 { 53 54 ASSERT(delayNanoSeconds.count() >= 0); 54 return std::unique_ptr<TimerWorkItem>(new TimerWorkItem( workQueue, WTFMove(function), monotonicallyIncreasingTime() * 1000000000.0 + delayNanoSeconds.count()));55 return std::unique_ptr<TimerWorkItem>(new TimerWorkItem(WTFMove(workQueue), WTFMove(function), monotonicallyIncreasingTime() * 1000000000.0 + delayNanoSeconds.count())); 55 56 } 56 57 double expirationTimeNanoSeconds() const { return m_expirationTimeNanoSeconds; } … … 58 59 59 60 protected: 60 TimerWorkItem( PassRefPtr<WorkQueue> workQueue, std::function<void ()>function, double expirationTimeNanoSeconds)61 : WorkItem( workQueue, WTFMove(function))61 TimerWorkItem(Ref<WorkQueue>&& workQueue, NoncopyableFunction&& function, double expirationTimeNanoSeconds) 62 : WorkItem(WTFMove(workQueue), WTFMove(function)) 62 63 , m_expirationTimeNanoSeconds(expirationTimeNanoSeconds) 63 64 { -
trunk/Source/WTF/wtf/efl/WorkQueueEfl.cpp
r195094 r201464 55 55 } 56 56 57 void WorkQueue::dispatch( std::function<void ()>function)57 void WorkQueue::dispatch(NoncopyableFunction&& function) 58 58 { 59 59 if (!m_dispatchQueue) 60 60 return; 61 61 62 m_dispatchQueue->dispatch(std::make_unique<WorkItem>( this, WTFMove(function)));62 m_dispatchQueue->dispatch(std::make_unique<WorkItem>(*this, WTFMove(function))); 63 63 } 64 64 65 void WorkQueue::dispatchAfter(std::chrono::nanoseconds duration, std::function<void ()>function)65 void WorkQueue::dispatchAfter(std::chrono::nanoseconds duration, NoncopyableFunction&& function) 66 66 { 67 67 if (!m_dispatchQueue) 68 68 return; 69 69 70 m_dispatchQueue->dispatch(TimerWorkItem::create( this, WTFMove(function), duration));70 m_dispatchQueue->dispatch(TimerWorkItem::create(*this, WTFMove(function), duration)); 71 71 } 72 72 -
trunk/Source/WTF/wtf/generic/RunLoopGeneric.cpp
r199694 r201464 240 240 } 241 241 242 void RunLoop::dispatchAfter(std::chrono::nanoseconds delay, std::function<void()>function)242 void RunLoop::dispatchAfter(std::chrono::nanoseconds delay, NoncopyableFunction&& function) 243 243 { 244 244 LockHolder locker(m_loopLock); 245 245 bool repeating = false; 246 schedule(locker, TimerBase::ScheduledTask::create( function, delay.count() / 1000.0 / 1000.0 / 1000.0, repeating));246 schedule(locker, TimerBase::ScheduledTask::create(WTFMove(function), delay.count() / 1000.0 / 1000.0 / 1000.0, repeating)); 247 247 wakeUp(locker); 248 248 } -
trunk/Source/WTF/wtf/generic/WorkQueueGeneric.cpp
r199694 r201464 82 82 } 83 83 84 void WorkQueue::dispatch( std::function<void()>function)84 void WorkQueue::dispatch(NoncopyableFunction&& function) 85 85 { 86 86 RefPtr<WorkQueue> protect(this); 87 m_runLoop->dispatch([protect, function ] {87 m_runLoop->dispatch([protect, function = WTFMove(function)] { 88 88 function(); 89 89 }); 90 90 } 91 91 92 void WorkQueue::dispatchAfter(std::chrono::nanoseconds delay, std::function<void()>function)92 void WorkQueue::dispatchAfter(std::chrono::nanoseconds delay, NoncopyableFunction&& function) 93 93 { 94 94 RefPtr<WorkQueue> protect(this); 95 m_runLoop->dispatchAfter(delay, [protect, function ] {95 m_runLoop->dispatchAfter(delay, [protect, function = WTFMove(function)] { 96 96 function(); 97 97 }); -
trunk/Source/WTF/wtf/glib/RunLoopGLib.cpp
r199713 r201464 125 125 WTF_MAKE_FAST_ALLOCATED; 126 126 public: 127 DispatchAfterContext( std::function<void()>&& function)127 DispatchAfterContext(NoncopyableFunction&& function) 128 128 : m_function(WTFMove(function)) 129 129 { … … 136 136 137 137 private: 138 std::function<void()>m_function;138 NoncopyableFunction m_function; 139 139 }; 140 140 141 void RunLoop::dispatchAfter(std::chrono::nanoseconds duration, std::function<void()>function)141 void RunLoop::dispatchAfter(std::chrono::nanoseconds duration, NoncopyableFunction&& function) 142 142 { 143 143 GRefPtr<GSource> source = adoptGRef(g_timeout_source_new(std::chrono::duration_cast<std::chrono::milliseconds>(duration).count())); -
trunk/Source/WTF/wtf/win/WorkItemWin.cpp
r181220 r201464 33 33 namespace WTF { 34 34 35 WorkItemWin::WorkItemWin( std::function<void()>function, WorkQueue* queue)36 : m_function( function)35 WorkItemWin::WorkItemWin(NoncopyableFunction&& function, WorkQueue* queue) 36 : m_function(WTFMove(function)) 37 37 , m_queue(queue) 38 38 { 39 39 } 40 40 41 RefPtr<WorkItemWin> WorkItemWin::create( std::function<void()>function, WorkQueue* queue)41 RefPtr<WorkItemWin> WorkItemWin::create(NoncopyableFunction&& function, WorkQueue* queue) 42 42 { 43 return adoptRef(new WorkItemWin( function, queue));43 return adoptRef(new WorkItemWin(WTFMove(function), queue)); 44 44 } 45 45 … … 48 48 } 49 49 50 HandleWorkItem::HandleWorkItem(HANDLE handle, const std::function<void()>& function, WorkQueue* queue)51 : WorkItemWin( function, queue)50 HandleWorkItem::HandleWorkItem(HANDLE handle, NoncopyableFunction&& function, WorkQueue* queue) 51 : WorkItemWin(WTFMove(function), queue) 52 52 , m_handle(handle) 53 53 , m_waitHandle(0) … … 56 56 } 57 57 58 RefPtr<HandleWorkItem> HandleWorkItem::createByAdoptingHandle(HANDLE handle, const std::function<void()>& function, WorkQueue* queue)58 RefPtr<HandleWorkItem> HandleWorkItem::createByAdoptingHandle(HANDLE handle, NoncopyableFunction&& function, WorkQueue* queue) 59 59 { 60 return adoptRef(new HandleWorkItem(handle, function, queue));60 return adoptRef(new HandleWorkItem(handle, WTFMove(function), queue)); 61 61 } 62 62 -
trunk/Source/WTF/wtf/win/WorkItemWin.h
r181220 r201464 30 30 #include <Windows.h> 31 31 #include <functional> 32 #include <wtf/FunctionDispatcher.h> 32 33 #include <wtf/RefPtr.h> 33 34 #include <wtf/ThreadSafeRefCounted.h> … … 39 40 class WorkItemWin : public ThreadSafeRefCounted<WorkItemWin> { 40 41 public: 41 static RefPtr<WorkItemWin> create( std::function<void()>, WorkQueue*);42 static RefPtr<WorkItemWin> create(NoncopyableFunction&&, WorkQueue*); 42 43 virtual ~WorkItemWin(); 43 44 44 std::function<void()>& function() { return m_function; }45 NoncopyableFunction& function() { return m_function; } 45 46 WorkQueue* queue() const { return m_queue.get(); } 46 47 47 48 protected: 48 WorkItemWin( std::function<void()>, WorkQueue*);49 WorkItemWin(NoncopyableFunction&&, WorkQueue*); 49 50 50 51 private: 51 std::function<void()>m_function;52 NoncopyableFunction m_function; 52 53 RefPtr<WorkQueue> m_queue; 53 54 }; … … 55 56 class HandleWorkItem : public WorkItemWin { 56 57 public: 57 static RefPtr<HandleWorkItem> createByAdoptingHandle(HANDLE, const std::function<void()>&, WorkQueue*);58 static RefPtr<HandleWorkItem> createByAdoptingHandle(HANDLE, NoncopyableFunction&&, WorkQueue*); 58 59 virtual ~HandleWorkItem(); 59 60 … … 62 63 63 64 private: 64 HandleWorkItem(HANDLE, const std::function<void()>&, WorkQueue*);65 HandleWorkItem(HANDLE, NoncopyableFunction&&, WorkQueue*); 65 66 66 67 HANDLE m_handle; -
trunk/Source/WTF/wtf/win/WorkQueueWin.cpp
r188415 r201464 130 130 } 131 131 132 void WorkQueue::dispatch( std::function<void()>function)132 void WorkQueue::dispatch(NoncopyableFunction&& function) 133 133 { 134 134 MutexLocker locker(m_workItemQueueLock); 135 135 ref(); 136 m_workItemQueue.append(WorkItemWin::create( function, this));136 m_workItemQueue.append(WorkItemWin::create(WTFMove(function), this)); 137 137 138 138 // Spawn a work thread to perform the work we just added. As an optimization, we avoid … … 150 150 151 151 WorkQueue* queue; 152 std::function<void()>function;152 NoncopyableFunction function; 153 153 Mutex timerMutex; 154 154 HANDLE timer; … … 170 170 RefPtr<TimerContext> timerContext = adoptRef(static_cast<TimerContext*>(context)); 171 171 172 timerContext->queue->dispatch( timerContext->function);172 timerContext->queue->dispatch(WTFMove(timerContext->function)); 173 173 174 174 MutexLocker lock(timerContext->timerMutex); … … 181 181 } 182 182 183 void WorkQueue::dispatchAfter(std::chrono::nanoseconds duration, std::function<void()>function)183 void WorkQueue::dispatchAfter(std::chrono::nanoseconds duration, NoncopyableFunction&& function) 184 184 { 185 185 ASSERT(m_timerQueue); … … 188 188 RefPtr<TimerContext> context = TimerContext::create(); 189 189 context->queue = this; 190 context->function = function;190 context->function = WTFMove(function); 191 191 192 192 { -
trunk/Source/WebKit2/ChangeLog
r201457 r201464 1 2016-05-27 Chris Dumez <cdumez@apple.com> 2 3 WorkQueue::dispatch() / RunLoop::dispatch() should not copy captured lambda variables 4 https://bugs.webkit.org/show_bug.cgi?id=158111 5 6 Reviewed by Darin Adler. 7 8 WorkQueue::dispatch() / RunLoop::dispatch() should not copy captured lambda variables. 9 These are often used cross-thread and copying the captured lambda variables can be 10 dangerous (e.g. we do not want to copy a String after calling isolatedCopy() upon 11 capture). 12 13 * NetworkProcess/NetworkProcess.cpp: 14 (WebKit::clearDiskCacheEntries): 15 * NetworkProcess/cache/NetworkCache.cpp: 16 (WebKit::NetworkCache::Cache::clear): 17 * NetworkProcess/cache/NetworkCacheIOChannelSoup.cpp: 18 (WebKit::NetworkCache::runTaskInQueue): 19 * Platform/IPC/Connection.cpp: 20 (IPC::Connection::processIncomingMessage): 21 * UIProcess/Storage/StorageManager.cpp: 22 (WebKit::StorageManager::getSessionStorageOrigins): 23 (WebKit::StorageManager::deleteSessionStorageOrigins): 24 (WebKit::StorageManager::deleteSessionStorageEntriesForOrigins): 25 (WebKit::StorageManager::getLocalStorageOrigins): 26 (WebKit::StorageManager::getLocalStorageOriginDetails): 27 (WebKit::StorageManager::deleteLocalStorageOriginsModifiedSince): 28 (WebKit::StorageManager::deleteLocalStorageEntriesForOrigins): 29 * UIProcess/Storage/StorageManager.h: 30 1 31 2016-05-27 Alex Christensen <achristensen@webkit.org> 2 32 -
trunk/Source/WebKit2/NetworkProcess/NetworkProcess.cpp
r201333 r201464 422 422 } 423 423 424 static void clearDiskCacheEntries(const Vector<SecurityOriginData>& origins, std::function<void ()> completionHandler)424 static void clearDiskCacheEntries(const Vector<SecurityOriginData>& origins, std::function<void ()>&& completionHandler) 425 425 { 426 426 #if ENABLE(NETWORK_CACHE) … … 433 433 auto* cacheKeysToDelete = new Vector<NetworkCache::Key>; 434 434 435 NetworkCache::singleton().traverse([completionHandler , originsToDelete, cacheKeysToDelete](auto* traversalEntry){435 NetworkCache::singleton().traverse([completionHandler = WTFMove(completionHandler), originsToDelete, cacheKeysToDelete](auto* traversalEntry) mutable { 436 436 if (traversalEntry) { 437 437 if (originsToDelete->contains(SecurityOrigin::create(traversalEntry->entry.response().url()))) … … 447 447 delete cacheKeysToDelete; 448 448 449 RunLoop::main().dispatch( completionHandler);449 RunLoop::main().dispatch(WTFMove(completionHandler)); 450 450 return; 451 451 }); -
trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.cpp
r201354 r201464 633 633 634 634 if (!m_storage) { 635 RunLoop::main().dispatch( completionHandler);635 RunLoop::main().dispatch(WTFMove(completionHandler)); 636 636 return; 637 637 } -
trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheIOChannelSoup.cpp
r199875 r201464 70 70 } 71 71 72 static inline void runTaskInQueue( std::function<void ()>task, WorkQueue* queue)72 static inline void runTaskInQueue(NoncopyableFunction&& task, WorkQueue* queue) 73 73 { 74 74 if (queue) { 75 queue->dispatch( task);75 queue->dispatch(WTFMove(task)); 76 76 return; 77 77 } -
trunk/Source/WebKit2/Platform/IPC/Connection.cpp
r201246 r201464 682 682 683 683 for (auto& callback : m_incomingSyncMessageCallbacks.values()) 684 m_incomingSyncMessageCallbackQueue->dispatch( callback);684 m_incomingSyncMessageCallbackQueue->dispatch(WTFMove(callback)); 685 685 686 686 m_incomingSyncMessageCallbacks.clear(); -
trunk/Source/WebKit2/UIProcess/Storage/StorageManager.cpp
r194496 r201464 554 554 } 555 555 556 void StorageManager::getSessionStorageOrigins(std::function<void (HashSet<RefPtr<WebCore::SecurityOrigin>>&&)> completionHandler)557 { 558 RefPtr<StorageManager> storageManager(this); 559 560 m_queue->dispatch([storageManager, completionHandler ]{556 void StorageManager::getSessionStorageOrigins(std::function<void (HashSet<RefPtr<WebCore::SecurityOrigin>>&&)>&& completionHandler) 557 { 558 RefPtr<StorageManager> storageManager(this); 559 560 m_queue->dispatch([storageManager, completionHandler = WTFMove(completionHandler)]() mutable { 561 561 HashSet<RefPtr<SecurityOrigin>> origins; 562 562 … … 566 566 } 567 567 568 RunLoop::main().dispatch([origins, completionHandler ]() mutable {568 RunLoop::main().dispatch([origins, completionHandler = WTFMove(completionHandler)]() mutable { 569 569 completionHandler(WTFMove(origins)); 570 570 }); … … 572 572 } 573 573 574 void StorageManager::deleteSessionStorageOrigins(std::function<void ()> completionHandler)575 { 576 RefPtr<StorageManager> storageManager(this); 577 578 m_queue->dispatch([storageManager, completionHandler ]{574 void StorageManager::deleteSessionStorageOrigins(std::function<void ()>&& completionHandler) 575 { 576 RefPtr<StorageManager> storageManager(this); 577 578 m_queue->dispatch([storageManager, completionHandler = WTFMove(completionHandler)]() mutable { 579 579 for (auto& sessionStorageNamespace : storageManager->m_sessionStorageNamespaces.values()) 580 580 sessionStorageNamespace->clearAllStorageAreas(); 581 581 582 RunLoop::main().dispatch( completionHandler);583 }); 584 } 585 586 void StorageManager::deleteSessionStorageEntriesForOrigins(const Vector<RefPtr<WebCore::SecurityOrigin>>& origins, std::function<void ()> completionHandler)582 RunLoop::main().dispatch(WTFMove(completionHandler)); 583 }); 584 } 585 586 void StorageManager::deleteSessionStorageEntriesForOrigins(const Vector<RefPtr<WebCore::SecurityOrigin>>& origins, std::function<void ()>&& completionHandler) 587 587 { 588 588 Vector<RefPtr<WebCore::SecurityOrigin>> copiedOrigins; … … 593 593 594 594 RefPtr<StorageManager> storageManager(this); 595 m_queue->dispatch([storageManager, copiedOrigins, completionHandler ]{595 m_queue->dispatch([storageManager, copiedOrigins, completionHandler = WTFMove(completionHandler)]() mutable { 596 596 for (auto& origin : copiedOrigins) { 597 597 for (auto& sessionStorageNamespace : storageManager->m_sessionStorageNamespaces.values()) … … 599 599 } 600 600 601 RunLoop::main().dispatch( completionHandler);602 }); 603 } 604 605 void StorageManager::getLocalStorageOrigins(std::function<void (HashSet<RefPtr<WebCore::SecurityOrigin>>&&)> completionHandler)606 { 607 RefPtr<StorageManager> storageManager(this); 608 609 m_queue->dispatch([storageManager, completionHandler ]{601 RunLoop::main().dispatch(WTFMove(completionHandler)); 602 }); 603 } 604 605 void StorageManager::getLocalStorageOrigins(std::function<void (HashSet<RefPtr<WebCore::SecurityOrigin>>&&)>&& completionHandler) 606 { 607 RefPtr<StorageManager> storageManager(this); 608 609 m_queue->dispatch([storageManager, completionHandler = WTFMove(completionHandler)]() mutable { 610 610 HashSet<RefPtr<SecurityOrigin>> origins; 611 611 … … 618 618 } 619 619 620 RunLoop::main().dispatch([origins, completionHandler ]() mutable {620 RunLoop::main().dispatch([origins, completionHandler = WTFMove(completionHandler)]() mutable { 621 621 completionHandler(WTFMove(origins)); 622 622 }); … … 624 624 } 625 625 626 void StorageManager::getLocalStorageOriginDetails(std::function<void (Vector<LocalStorageDatabaseTracker::OriginDetails>)> completionHandler)627 { 628 RefPtr<StorageManager> storageManager(this); 629 630 m_queue->dispatch([storageManager, completionHandler ]{626 void StorageManager::getLocalStorageOriginDetails(std::function<void (Vector<LocalStorageDatabaseTracker::OriginDetails>)>&& completionHandler) 627 { 628 RefPtr<StorageManager> storageManager(this); 629 630 m_queue->dispatch([storageManager, completionHandler = WTFMove(completionHandler)]() mutable { 631 631 auto originDetails = storageManager->m_localStorageDatabaseTracker->originDetails(); 632 632 633 RunLoop::main().dispatch([originDetails, completionHandler ]() mutable {633 RunLoop::main().dispatch([originDetails, completionHandler = WTFMove(completionHandler)]() mutable { 634 634 completionHandler(WTFMove(originDetails)); 635 635 }); … … 653 653 } 654 654 655 void StorageManager::deleteLocalStorageOriginsModifiedSince(std::chrono::system_clock::time_point time, std::function<void ()> completionHandler)656 { 657 RefPtr<StorageManager> storageManager(this); 658 659 m_queue->dispatch([storageManager, time, completionHandler ]{655 void StorageManager::deleteLocalStorageOriginsModifiedSince(std::chrono::system_clock::time_point time, std::function<void ()>&& completionHandler) 656 { 657 RefPtr<StorageManager> storageManager(this); 658 659 m_queue->dispatch([storageManager, time, completionHandler = WTFMove(completionHandler)]() mutable { 660 660 auto deletedOrigins = storageManager->m_localStorageDatabaseTracker->deleteDatabasesModifiedSince(time); 661 661 … … 668 668 transientLocalStorageNamespace->clearAllStorageAreas(); 669 669 670 RunLoop::main().dispatch( completionHandler);671 }); 672 } 673 674 void StorageManager::deleteLocalStorageEntriesForOrigins(const Vector<RefPtr<WebCore::SecurityOrigin>>& origins, std::function<void ()> completionHandler)670 RunLoop::main().dispatch(WTFMove(completionHandler)); 671 }); 672 } 673 674 void StorageManager::deleteLocalStorageEntriesForOrigins(const Vector<RefPtr<WebCore::SecurityOrigin>>& origins, std::function<void ()>&& completionHandler) 675 675 { 676 676 Vector<RefPtr<WebCore::SecurityOrigin>> copiedOrigins; … … 681 681 682 682 RefPtr<StorageManager> storageManager(this); 683 m_queue->dispatch([storageManager, copiedOrigins, completionHandler ]{683 m_queue->dispatch([storageManager, copiedOrigins, completionHandler = WTFMove(completionHandler)]() mutable { 684 684 for (auto& origin : copiedOrigins) { 685 685 for (auto& localStorageNamespace : storageManager->m_localStorageNamespaces.values()) … … 692 692 } 693 693 694 RunLoop::main().dispatch( completionHandler);694 RunLoop::main().dispatch(WTFMove(completionHandler)); 695 695 }); 696 696 } -
trunk/Source/WebKit2/UIProcess/Storage/StorageManager.h
r197563 r201464 60 60 void applicationWillTerminate(); 61 61 62 void getSessionStorageOrigins(std::function<void (HashSet<RefPtr<WebCore::SecurityOrigin>>&&)> completionHandler);63 void deleteSessionStorageOrigins(std::function<void ()> completionHandler);64 void deleteSessionStorageEntriesForOrigins(const Vector<RefPtr<WebCore::SecurityOrigin>>&, std::function<void ()> completionHandler);62 void getSessionStorageOrigins(std::function<void (HashSet<RefPtr<WebCore::SecurityOrigin>>&&)>&& completionHandler); 63 void deleteSessionStorageOrigins(std::function<void ()>&& completionHandler); 64 void deleteSessionStorageEntriesForOrigins(const Vector<RefPtr<WebCore::SecurityOrigin>>&, std::function<void ()>&& completionHandler); 65 65 66 void getLocalStorageOrigins(std::function<void (HashSet<RefPtr<WebCore::SecurityOrigin>>&&)> completionHandler);66 void getLocalStorageOrigins(std::function<void (HashSet<RefPtr<WebCore::SecurityOrigin>>&&)>&& completionHandler); 67 67 void deleteLocalStorageEntriesForOrigin(const WebCore::SecurityOrigin&); 68 68 69 void deleteLocalStorageOriginsModifiedSince(std::chrono::system_clock::time_point, std::function<void ()> completionHandler);70 void deleteLocalStorageEntriesForOrigins(const Vector<RefPtr<WebCore::SecurityOrigin>>&, std::function<void ()> completionHandler);69 void deleteLocalStorageOriginsModifiedSince(std::chrono::system_clock::time_point, std::function<void ()>&& completionHandler); 70 void deleteLocalStorageEntriesForOrigins(const Vector<RefPtr<WebCore::SecurityOrigin>>&, std::function<void ()>&& completionHandler); 71 71 72 void getLocalStorageOriginDetails(std::function<void (Vector<LocalStorageDatabaseTracker::OriginDetails>)> completionHandler);72 void getLocalStorageOriginDetails(std::function<void (Vector<LocalStorageDatabaseTracker::OriginDetails>)>&& completionHandler); 73 73 74 74 private: -
trunk/Tools/ChangeLog
r201461 r201464 1 2016-05-27 Chris Dumez <cdumez@apple.com> 2 3 WorkQueue::dispatch() / RunLoop::dispatch() should not copy captured lambda variables 4 https://bugs.webkit.org/show_bug.cgi?id=158111 5 6 Reviewed by Darin Adler. 7 8 WorkQueue::dispatch() / RunLoop::dispatch() should not copy captured lambda variables. 9 These are often used cross-thread and copying the captured lambda variables can be 10 dangerous (e.g. we do not want to copy a String after calling isolatedCopy() upon 11 capture). 12 13 * WebKitTestRunner/TestController.cpp: 14 (WTR::TestController::decidePolicyForNavigationAction): 15 1 16 2016-05-27 Brady Eidson <beidson@apple.com> 2 17 -
trunk/Tools/WebKitTestRunner/TestController.cpp
r200945 r201464 2023 2023 WKRetainPtr<WKFramePolicyListenerRef> retainedListener { listener }; 2024 2024 const bool shouldIgnore { m_policyDelegateEnabled && !m_policyDelegatePermissive }; 2025 std::function<void()>decisionFunction = [shouldIgnore, retainedListener]() {2025 auto decisionFunction = [shouldIgnore, retainedListener]() { 2026 2026 if (shouldIgnore) 2027 2027 WKFramePolicyListenerIgnore(retainedListener.get()); … … 2031 2031 2032 2032 if (m_shouldDecideNavigationPolicyAfterDelay) 2033 RunLoop::main().dispatch( decisionFunction);2033 RunLoop::main().dispatch(WTFMove(decisionFunction)); 2034 2034 else 2035 2035 decisionFunction();
Note: See TracChangeset
for help on using the changeset viewer.