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

Unified Diff: third_party/WebKit/Source/platform/Task.h

Issue 1549143002: Add thread affinity and ASSERT() for same-thread restriction to WTF::Function (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@TRV_ThreadSafeBindByVariadicTemplate
Patch Set: Rebase. Created 4 years, 10 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
Index: third_party/WebKit/Source/platform/Task.h
diff --git a/third_party/WebKit/Source/platform/Task.h b/third_party/WebKit/Source/platform/Task.h
index 64b656c7374f14261d098c250be6bdc7c1f009db..e404408db018e93220302972fef2c06df968bac3 100644
--- a/third_party/WebKit/Source/platform/Task.h
+++ b/third_party/WebKit/Source/platform/Task.h
@@ -40,11 +40,34 @@
namespace blink {
-class Task : public WebTaskRunner::Task {
- USING_FAST_MALLOC(Task);
- WTF_MAKE_NONCOPYABLE(Task);
+// Please use WTF::SameThreadClosure or WTF::CrossThreadClosure directly,
+// instead of wrapping them by blink::SameThreadTask/CrossThreadTask here.
+
+// TODO(hiroshige): Make these classes internal to
+// Source/platform/WebTaskRunner.cpp.
+class SameThreadTask : public WebTaskRunner::Task {
+ USING_FAST_MALLOC(SameThreadTask);
+ WTF_MAKE_NONCOPYABLE(SameThreadTask);
+public:
+ explicit SameThreadTask(PassOwnPtr<SameThreadClosure> closure)
+ : m_closure(std::move(closure))
+ {
+ }
+
+ void run() override
+ {
+ (*m_closure)();
+ }
+
+private:
+ OwnPtr<SameThreadClosure> m_closure;
+};
+
+class CrossThreadTask : public WebTaskRunner::Task {
+ USING_FAST_MALLOC(CrossThreadTask);
+ WTF_MAKE_NONCOPYABLE(CrossThreadTask);
public:
- explicit Task(PassOwnPtr<Closure> closure)
+ explicit CrossThreadTask(PassOwnPtr<CrossThreadClosure> closure)
: m_closure(std::move(closure))
{
}
@@ -55,7 +78,7 @@ public:
}
private:
- OwnPtr<Closure> m_closure;
+ OwnPtr<CrossThreadClosure> m_closure;
};
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698