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

Unified Diff: third_party/WebKit/Source/platform/WebTaskRunner.cpp

Issue 2626883003: Make WebTaskRunner::postTask thread safe (Closed)
Patch Set: dcheng review Created 3 years, 11 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/platform/WebTaskRunner.cpp
diff --git a/third_party/WebKit/Source/platform/WebTaskRunner.cpp b/third_party/WebKit/Source/platform/WebTaskRunner.cpp
index d7b0d130780aa540e5ffb9bc11ab21b645b4c390..3555a3eb8452cfbd5b251e0da7464e09d7962dfe 100644
--- a/third_party/WebKit/Source/platform/WebTaskRunner.cpp
+++ b/third_party/WebKit/Source/platform/WebTaskRunner.cpp
@@ -29,6 +29,14 @@ struct CallbackCancellationTraits<
namespace blink {
+namespace {
+
+void runCrossThreadClosure(std::unique_ptr<CrossThreadClosure> task) {
+ (*task)();
+}
+
+} // namespace
+
class TaskHandle::Runner : public WTF::ThreadSafeRefCounted<Runner> {
public:
explicit Runner(std::unique_ptr<WTF::Closure> task)
@@ -103,17 +111,21 @@ TaskHandle::TaskHandle(RefPtr<Runner> runner) : m_runner(std::move(runner)) {
DCHECK(m_runner);
}
+// Use a custom function for base::Bind instead of convertToBaseCallback to
+// avoid copying the closure later in the call chain. Copying the bound state
+// can lead to data races with ref counted objects like StringImpl. See
+// crbug.com/679915 for more details.
Wez 2017/01/11 21:21:49 Wouldn't it be better to "fix" convertToBaseCallba
void WebTaskRunner::postTask(const WebTraceLocation& location,
std::unique_ptr<CrossThreadClosure> task) {
- toSingleThreadTaskRunner()->PostTask(location,
- convertToBaseCallback(std::move(task)));
+ toSingleThreadTaskRunner()->PostTask(
+ location, base::Bind(&runCrossThreadClosure, base::Passed(&task)));
}
void WebTaskRunner::postDelayedTask(const WebTraceLocation& location,
std::unique_ptr<CrossThreadClosure> task,
long long delayMs) {
toSingleThreadTaskRunner()->PostDelayedTask(
- location, convertToBaseCallback(std::move(task)),
+ location, base::Bind(&runCrossThreadClosure, base::Passed(&task)),
base::TimeDelta::FromMilliseconds(delayMs));
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698