Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(18)

Unified Diff: third_party/WebKit/Source/core/dom/ExecutionContextTask.h

Issue 1770553002: Simplify createCrossThreadTask() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@Kuroneko_EC5_CleanupCrossThreadAccess
Patch Set: Rebase Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/core/dom/CrossThreadTask.h ('k') | third_party/WebKit/Source/wtf/Functional.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/dom/ExecutionContextTask.h
diff --git a/third_party/WebKit/Source/core/dom/ExecutionContextTask.h b/third_party/WebKit/Source/core/dom/ExecutionContextTask.h
index 3567f0f37a86a73e1666018d57de0971b70f916c..4efe57675fa8104272b1a1efe92af62dce83d033 100644
--- a/third_party/WebKit/Source/core/dom/ExecutionContextTask.h
+++ b/third_party/WebKit/Source/core/dom/ExecutionContextTask.h
@@ -50,63 +50,49 @@ public:
namespace internal {
-template<typename T, WTF::FunctionThreadAffinity threadAffinity>
-class CallClosureTaskBase : public ExecutionContextTask {
-protected:
- explicit CallClosureTaskBase(std::unique_ptr<Function<T, threadAffinity>> closure)
- : m_closure(std::move(closure))
- {
- }
-
- std::unique_ptr<Function<T, threadAffinity>> m_closure;
-};
+template<WTF::FunctionThreadAffinity threadAffinity>
+void runCallClosureTask(std::unique_ptr<Function<void(), threadAffinity>> closure, ExecutionContext*)
+{
+ (*closure)();
+}
template<WTF::FunctionThreadAffinity threadAffinity>
-class CallClosureTask final : public CallClosureTaskBase<void(), threadAffinity> {
-public:
- // Do not use |create| other than in createCrossThreadTask and
- // createSameThreadTask.
- // See http://crbug.com/390851
- static std::unique_ptr<CallClosureTask<threadAffinity>> create(std::unique_ptr<Function<void(), threadAffinity>> closure)
- {
- return wrapUnique(new CallClosureTask<threadAffinity>(std::move(closure)));
- }
+void runCallClosureTask(std::unique_ptr<Function<void(ExecutionContext*), threadAffinity>> closure, ExecutionContext* executionContext)
+{
+ (*closure)(executionContext);
+}
- void performTask(ExecutionContext*) override
+template<typename T, WTF::FunctionThreadAffinity threadAffinity>
+class CallClosureTask final : public ExecutionContextTask {
+public:
+ static std::unique_ptr<CallClosureTask> create(std::unique_ptr<Function<T, threadAffinity>> closure)
{
- (*this->m_closure)();
+ return wrapUnique(new CallClosureTask(std::move(closure)));
}
private:
- explicit CallClosureTask(std::unique_ptr<Function<void(), threadAffinity>> closure)
- : CallClosureTaskBase<void(), threadAffinity>(std::move(closure))
- {
- }
-};
-
-template<WTF::FunctionThreadAffinity threadAffinity>
-class CallClosureWithExecutionContextTask final : public CallClosureTaskBase<void(ExecutionContext*), threadAffinity> {
-public:
- // Do not use |create| other than in createCrossThreadTask and
- // createSameThreadTask.
- // See http://crbug.com/390851
- static std::unique_ptr<CallClosureWithExecutionContextTask> create(std::unique_ptr<Function<void(ExecutionContext*), threadAffinity>> closure)
+ explicit CallClosureTask(std::unique_ptr<Function<T, threadAffinity>> closure)
+ : m_closure(std::move(closure))
{
- return wrapUnique(new CallClosureWithExecutionContextTask(std::move(closure)));
}
- void performTask(ExecutionContext* context) override
+ void performTask(ExecutionContext* executionContext) override
{
- (*this->m_closure)(context);
+ runCallClosureTask(std::move(m_closure), executionContext);
}
-private:
- explicit CallClosureWithExecutionContextTask(std::unique_ptr<Function<void(ExecutionContext*), threadAffinity>> closure)
- : CallClosureTaskBase<void(ExecutionContext*), threadAffinity>(std::move(closure))
- {
- }
+ std::unique_ptr<Function<T, threadAffinity>> m_closure;
};
+// Do not use |create| other than in createCrossThreadTask and
+// createSameThreadTask.
+// See http://crbug.com/390851
+template<typename T, WTF::FunctionThreadAffinity threadAffinity>
+std::unique_ptr<CallClosureTask<T, threadAffinity>> createCallClosureTask(std::unique_ptr<Function<T, threadAffinity>> closure)
+{
+ return CallClosureTask<T, threadAffinity>::create(std::move(closure));
+}
+
} // namespace internal
// Create tasks passed within a single thread.
@@ -118,7 +104,7 @@ template<typename FunctionType, typename... P>
std::unique_ptr<ExecutionContextTask> createSameThreadTask(
FunctionType function, P&&... parameters)
{
- return internal::CallClosureTask<WTF::SameThreadAffinity>::create(bind(function, std::forward<P>(parameters)...));
+ return internal::createCallClosureTask(bind(function, std::forward<P>(parameters)...));
}
} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/core/dom/CrossThreadTask.h ('k') | third_party/WebKit/Source/wtf/Functional.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698