Diff
Modified: trunk/Source/WebCore/ChangeLog (201496 => 201497)
--- trunk/Source/WebCore/ChangeLog 2016-05-30 04:30:22 UTC (rev 201496)
+++ trunk/Source/WebCore/ChangeLog 2016-05-30 06:53:36 UTC (rev 201497)
@@ -1,5 +1,39 @@
2016-05-29 Brady Eidson <beid...@apple.com>
+ Transition various Task/Function queues from std::function to NoncopyableFunction.
+ https://bugs.webkit.org/show_bug.cgi?id=158196
+
+ Reviewed by Chris Dumez.
+
+ No new tests (Refactor, no behavior change).
+
+ * dom/ActiveDOMCallbackMicrotask.cpp:
+ (WebCore::ActiveDOMCallbackMicrotask::ActiveDOMCallbackMicrotask):
+ * dom/ActiveDOMCallbackMicrotask.h:
+
+ * html/HTMLMediaElement.cpp:
+ (WebCore::HTMLMediaElement::layoutSizeChanged):
+
+ * page/FrameView.cpp:
+ (WebCore::FrameView::queuePostLayoutCallback):
+ (WebCore::FrameView::flushPostLayoutTasksQueue):
+ * page/FrameView.h:
+
+ * platform/GenericTaskQueue.cpp:
+ (WebCore::TaskDispatcher<Timer>::postTask):
+ (WebCore::TaskDispatcher<Timer>::dispatchOneTask):
+ * platform/GenericTaskQueue.h:
+ (WebCore::TaskDispatcher::postTask):
+ (WebCore::GenericTaskQueue::enqueueTask):
+
+ * style/StyleTreeResolver.cpp:
+ (WebCore::Style::postResolutionCallbackQueue):
+ (WebCore::Style::queuePostResolutionCallback):
+ (WebCore::Style::suspendMemoryCacheClientCalls):
+ * style/StyleTreeResolver.h:
+
+2016-05-29 Brady Eidson <beid...@apple.com>
+
Make ScriptExecutionContext::Task work in terms of wtf::NoncopyableFunction instead of std::function.
https://bugs.webkit.org/show_bug.cgi?id=158187
Modified: trunk/Source/WebCore/dom/ActiveDOMCallbackMicrotask.cpp (201496 => 201497)
--- trunk/Source/WebCore/dom/ActiveDOMCallbackMicrotask.cpp 2016-05-30 04:30:22 UTC (rev 201496)
+++ trunk/Source/WebCore/dom/ActiveDOMCallbackMicrotask.cpp 2016-05-30 06:53:36 UTC (rev 201497)
@@ -28,7 +28,7 @@
namespace WebCore {
-ActiveDOMCallbackMicrotask::ActiveDOMCallbackMicrotask(MicrotaskQueue& queue, ScriptExecutionContext& scriptExecutionContext, std::function<void()>&& task)
+ActiveDOMCallbackMicrotask::ActiveDOMCallbackMicrotask(MicrotaskQueue& queue, ScriptExecutionContext& scriptExecutionContext, NoncopyableFunction<void()>&& task)
: ActiveDOMCallback(&scriptExecutionContext)
, m_queue(queue)
, m_task(WTFMove(task))
Modified: trunk/Source/WebCore/dom/ActiveDOMCallbackMicrotask.h (201496 => 201497)
--- trunk/Source/WebCore/dom/ActiveDOMCallbackMicrotask.h 2016-05-30 04:30:22 UTC (rev 201496)
+++ trunk/Source/WebCore/dom/ActiveDOMCallbackMicrotask.h 2016-05-30 06:53:36 UTC (rev 201497)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2015 Apple Inc. All rights reserved.
+ * Copyright (C) 2015, 2016 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -23,19 +23,18 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef ActiveDOMCallbackMicrotask_h
-#define ActiveDOMCallbackMicrotask_h
+#pragma once
#include "ActiveDOMCallback.h"
#include "Microtasks.h"
-#include <functional>
+#include <wtf/NoncopyableFunction.h>
namespace WebCore {
class ActiveDOMCallbackMicrotask final : public Microtask, public ActiveDOMCallback {
WTF_MAKE_FAST_ALLOCATED;
public:
- WEBCORE_EXPORT ActiveDOMCallbackMicrotask(MicrotaskQueue&, ScriptExecutionContext&, std::function<void()>&&);
+ WEBCORE_EXPORT ActiveDOMCallbackMicrotask(MicrotaskQueue&, ScriptExecutionContext&, NoncopyableFunction<void()>&&);
WEBCORE_EXPORT virtual ~ActiveDOMCallbackMicrotask();
Result run() override;
@@ -47,9 +46,7 @@
// be accessed via the ScriptExecutionContext, which should hold a reference to the relevent
// queue.
MicrotaskQueue& m_queue;
- std::function<void()> m_task;
+ NoncopyableFunction<void()> m_task;
};
} // namespace WebCore
-
-#endif // ActiveDOMCallbackMicrotask_h
Modified: trunk/Source/WebCore/html/HTMLMediaElement.cpp (201496 => 201497)
--- trunk/Source/WebCore/html/HTMLMediaElement.cpp 2016-05-30 04:30:22 UTC (rev 201496)
+++ trunk/Source/WebCore/html/HTMLMediaElement.cpp 2016-05-30 06:53:36 UTC (rev 201497)
@@ -3994,12 +3994,11 @@
void HTMLMediaElement::layoutSizeChanged()
{
#if ENABLE(MEDIA_CONTROLS_SCRIPT)
- RefPtr<HTMLMediaElement> strongThis = this;
- std::function<void()> task = [strongThis] {
- if (ShadowRoot* root = strongThis->userAgentShadowRoot())
+ auto task = [this, protectedThis = Ref<Element>(*this)] {
+ if (ShadowRoot* root = userAgentShadowRoot())
root->dispatchEvent(Event::create("resize", false, false));
};
- m_resizeTaskQueue.enqueueTask(task);
+ m_resizeTaskQueue.enqueueTask(WTFMove(task));
#endif
}
Modified: trunk/Source/WebCore/page/FrameView.cpp (201496 => 201497)
--- trunk/Source/WebCore/page/FrameView.cpp 2016-05-30 04:30:22 UTC (rev 201496)
+++ trunk/Source/WebCore/page/FrameView.cpp 2016-05-30 06:53:36 UTC (rev 201497)
@@ -3133,9 +3133,9 @@
updateEmbeddedObjectsTimerFired();
}
-void FrameView::queuePostLayoutCallback(std::function<void()> callback)
+void FrameView::queuePostLayoutCallback(NoncopyableFunction<void()>&& callback)
{
- m_postLayoutCallbackQueue.append(callback);
+ m_postLayoutCallbackQueue.append(WTFMove(callback));
}
void FrameView::flushPostLayoutTasksQueue()
@@ -3146,10 +3146,9 @@
if (!m_postLayoutCallbackQueue.size())
return;
- const auto queue = m_postLayoutCallbackQueue;
- m_postLayoutCallbackQueue.clear();
- for (size_t i = 0; i < queue.size(); ++i)
- queue[i]();
+ Vector<NoncopyableFunction<void()>> queue = WTFMove(m_postLayoutCallbackQueue);
+ for (auto& task : queue)
+ task();
}
void FrameView::performPostLayoutTasks()
Modified: trunk/Source/WebCore/page/FrameView.h (201496 => 201497)
--- trunk/Source/WebCore/page/FrameView.h 2016-05-30 04:30:22 UTC (rev 201496)
+++ trunk/Source/WebCore/page/FrameView.h 2016-05-30 06:53:36 UTC (rev 201497)
@@ -4,7 +4,7 @@
(C) 1998, 1999 Torben Weis (w...@kde.org)
(C) 1999 Lars Knoll (kn...@kde.org)
(C) 1999 Antti Koivisto (koivi...@kde.org)
- Copyright (C) 2004-2009, 2014-2015 Apple Inc. All rights reserved.
+ Copyright (C) 2004-2009, 2014-2016 Apple Inc. All rights reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
@@ -22,8 +22,7 @@
Boston, MA 02110-1301, USA.
*/
-#ifndef FrameView_h
-#define FrameView_h
+#pragma once
#include "AdjustViewSizeOrNot.h"
#include "Color.h"
@@ -38,6 +37,7 @@
#include <wtf/Forward.h>
#include <wtf/HashSet.h>
#include <wtf/ListHashSet.h>
+#include <wtf/NoncopyableFunction.h>
#include <wtf/text/WTFString.h>
namespace WebCore {
@@ -111,7 +111,7 @@
void scheduleRelayout();
void scheduleRelayoutOfSubtree(RenderElement&);
void unscheduleRelayout();
- void queuePostLayoutCallback(std::function<void()>);
+ void queuePostLayoutCallback(NoncopyableFunction<void()>&&);
bool layoutPending() const;
bool isInLayout() const { return m_layoutPhase != OutsideLayout; }
bool isInRenderTreeLayout() const { return m_layoutPhase == InRenderTreeLayout; }
@@ -828,7 +828,7 @@
ScrollPinningBehavior m_scrollPinningBehavior;
IntRect* m_cachedWindowClipRect { nullptr };
- Vector<std::function<void()>> m_postLayoutCallbackQueue;
+ Vector<NoncopyableFunction<void()>> m_postLayoutCallbackQueue;
};
inline void FrameView::incrementVisuallyNonEmptyCharacterCount(unsigned count)
@@ -854,5 +854,3 @@
} // namespace WebCore
SPECIALIZE_TYPE_TRAITS_WIDGET(FrameView, isFrameView())
-
-#endif // FrameView_h
Modified: trunk/Source/WebCore/platform/GenericTaskQueue.cpp (201496 => 201497)
--- trunk/Source/WebCore/platform/GenericTaskQueue.cpp 2016-05-30 04:30:22 UTC (rev 201496)
+++ trunk/Source/WebCore/platform/GenericTaskQueue.cpp 2016-05-30 06:53:36 UTC (rev 201497)
@@ -36,7 +36,7 @@
{
}
-void TaskDispatcher<Timer>::postTask(std::function<void()> function)
+void TaskDispatcher<Timer>::postTask(NoncopyableFunction<void()>&& function)
{
m_pendingTasks.append(WTFMove(function));
pendingDispatchers().append(m_weakPtrFactory.createWeakPtr());
@@ -77,7 +77,7 @@
void TaskDispatcher<Timer>::dispatchOneTask()
{
ASSERT(!m_pendingTasks.isEmpty());
- std::function<void()> task = m_pendingTasks.takeFirst();
+ auto task = m_pendingTasks.takeFirst();
task();
}
Modified: trunk/Source/WebCore/platform/GenericTaskQueue.h (201496 => 201497)
--- trunk/Source/WebCore/platform/GenericTaskQueue.h 2016-05-30 04:30:22 UTC (rev 201496)
+++ trunk/Source/WebCore/platform/GenericTaskQueue.h 2016-05-30 06:53:36 UTC (rev 201497)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2015 Apple Inc. All rights reserved.
+ * Copyright (C) 2015, 2016 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -23,11 +23,11 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef GenericTaskQueue_h
-#define GenericTaskQueue_h
+#pragma once
#include "Timer.h"
#include <wtf/Deque.h>
+#include <wtf/NoncopyableFunction.h>
#include <wtf/WeakPtr.h>
namespace WebCore {
@@ -40,9 +40,9 @@
{
}
- void postTask(std::function<void()> f)
+ void postTask(NoncopyableFunction<void()>&& f)
{
- m_context.postTask(f);
+ m_context.postTask(WTFMove(f));
}
private:
@@ -53,7 +53,7 @@
class TaskDispatcher<Timer> {
public:
TaskDispatcher();
- void postTask(std::function<void()>);
+ void postTask(NoncopyableFunction<void()>&&);
private:
static Timer& sharedTimer();
@@ -63,7 +63,7 @@
void dispatchOneTask();
WeakPtrFactory<TaskDispatcher> m_weakPtrFactory;
- Deque<std::function<void()>> m_pendingTasks;
+ Deque<NoncopyableFunction<void()>> m_pendingTasks;
};
template <typename T>
@@ -81,16 +81,16 @@
{
}
- typedef std::function<void()> TaskFunction;
+ typedef NoncopyableFunction<void()> TaskFunction;
- void enqueueTask(TaskFunction task)
+ void enqueueTask(TaskFunction&& task)
{
if (m_isClosed)
return;
++m_pendingTasks;
auto weakThis = m_weakPtrFactory.createWeakPtr();
- m_dispatcher.postTask([weakThis, task] {
+ m_dispatcher.postTask([weakThis, task = WTFMove(task)] {
if (!weakThis)
return;
ASSERT(weakThis->m_pendingTasks);
@@ -120,5 +120,3 @@
};
}
-
-#endif
Modified: trunk/Source/WebCore/style/StyleTreeResolver.cpp (201496 => 201497)
--- trunk/Source/WebCore/style/StyleTreeResolver.cpp 2016-05-30 04:30:22 UTC (rev 201496)
+++ trunk/Source/WebCore/style/StyleTreeResolver.cpp 2016-05-30 06:53:36 UTC (rev 201497)
@@ -521,15 +521,15 @@
return WTFMove(m_update);
}
-static Vector<std::function<void ()>>& postResolutionCallbackQueue()
+static Vector<NoncopyableFunction<void ()>>& postResolutionCallbackQueue()
{
- static NeverDestroyed<Vector<std::function<void ()>>> vector;
+ static NeverDestroyed<Vector<NoncopyableFunction<void ()>>> vector;
return vector;
}
-void queuePostResolutionCallback(std::function<void ()> callback)
+void queuePostResolutionCallback(NoncopyableFunction<void ()>&& callback)
{
- postResolutionCallbackQueue().append(callback);
+ postResolutionCallbackQueue().append(WTFMove(callback));
}
static void suspendMemoryCacheClientCalls(Document& document)
@@ -540,8 +540,7 @@
page->setMemoryCacheClientCallsEnabled(false);
- RefPtr<MainFrame> protectedMainFrame = &page->mainFrame();
- postResolutionCallbackQueue().append([protectedMainFrame]{
+ postResolutionCallbackQueue().append([protectedMainFrame = Ref<MainFrame>(page->mainFrame())] {
if (Page* page = protectedMainFrame->page())
page->setMemoryCacheClientCallsEnabled(true);
});
Modified: trunk/Source/WebCore/style/StyleTreeResolver.h (201496 => 201497)
--- trunk/Source/WebCore/style/StyleTreeResolver.h 2016-05-30 04:30:22 UTC (rev 201496)
+++ trunk/Source/WebCore/style/StyleTreeResolver.h 2016-05-30 06:53:36 UTC (rev 201497)
@@ -23,8 +23,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef StyleTreeResolver_h
-#define StyleTreeResolver_h
+#pragma once
#include "RenderStyleConstants.h"
#include "RenderTreePosition.h"
@@ -35,6 +34,7 @@
#include "StyleUpdate.h"
#include <functional>
#include <wtf/HashMap.h>
+#include <wtf/NoncopyableFunction.h>
#include <wtf/RefPtr.h>
namespace WebCore {
@@ -110,7 +110,7 @@
std::unique_ptr<Update> m_update;
};
-void queuePostResolutionCallback(std::function<void ()>);
+void queuePostResolutionCallback(NoncopyableFunction<void ()>&&);
bool postResolutionCallbacksAreSuspended();
bool isPlaceholderStyle(const RenderStyle&);
@@ -124,5 +124,3 @@
}
}
-
-#endif