Make WebTaskRunner::postTask thread safe
Copying the summary from dcheng@ on the referenced bug: The current implementation looks like this: void WebTaskRunner::postTask(const WebTraceLocation& location, std::unique_ptr<CrossThreadClosure> task) { toSingleThreadTaskRunner()->PostTask(location, convertToBaseCallback(std::move(task))); } However, base::TaskRunner::PostTask() takes a const base::Closure&. When we convert the CrossThreadClosure to a base::Callback, we just extract the internal callback object. However, this callback object is never supposed to be copied, only moved. Since the base APIs haven't been updated to use base::OnceCallback, now we have two copies of the callback referencing the same base::BindState (which is holding the bound variables): one on the posting thread (call it thread 1), and one on the posted thread (call it thread 2). If the copy on thread 2 is destroyed before the copy on thread 1, base::BindState will be destroyed on thread 1. If base::BindState contained WTF::String or other thread-unsafe objects, and thread 2 copied it, this means that the thread-unsafe objects will be ref'ed and deref'ed on multiple threads, which is not good. BUG=679915, 680042 Review-Url: https://codereview.chromium.org/2626883003 Cr-Commit-Position: refs/heads/master@{#443028}
Showing
Please register or sign in to comment