Commit 3111e4b1 authored by Dominic Mazzoni's avatar Dominic Mazzoni Committed by Commit Bot

Revert "[base] Remove implicit-destination PostTask"

This reverts commit 50b3e1fd.

Reason for revert: crbug.com/1090992 Compile failures:

FAILED: obj/chrome/browser/browser/recovery_component_installer.o
/b/s/w/ir/cache/goma/client/gomacc ../../third_party/llvm-build/Release+Asserts/bin/clang++ -MMD -MF...(too long)
../../chrome/browser/component_updater/recovery_component_installer.cc:419:3: error: too few arguments to function call, expected 3, have 2; did you mean 'base::ThreadPool::PostTask'?
base::PostTask(FROM_HERE, base::BindOnce(std::move(callback), result));
^~~~
base::ThreadPool::PostTask
../../base/task/thread_pool.h:95:15: note: 'base::ThreadPool::PostTask' declared here
static bool PostTask(const Location& from_here, OnceClosure task);
^

Original change's description:
> [base] Remove implicit-destination PostTask
> 
> No TaskTraits implcitly meant base::ThreadPool. The migration away
> from this paradigm is complete (task APIs v3 is bringing explicit
> API-as-destination). Remove this right away before we're ready to
> completely remove post_task.h to avoid the addition of new callers
> without an explicit destination.
> 
> Bug: 968047, 1026641
> Change-Id: I54d04872498d340cfd8ec02aa88b3e9cba1a7547
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2225541
> Commit-Queue: Gabriel Charette <gab@chromium.org>
> Reviewed-by: Sami Kyöstilä <skyostil@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#774758}

TBR=gab@chromium.org,skyostil@chromium.org

Change-Id: Ia6e764cf3293ef9ac789ce6f173951ab8e4736fe
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 968047, 1026641, 1090992
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2229410Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Commit-Queue: Dominic Mazzoni <dmazzoni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#774796}
parent e0e268ac
......@@ -62,6 +62,19 @@ TaskExecutor* GetTaskExecutorForTraits(const TaskTraits& traits) {
} // namespace
bool PostTask(const Location& from_here, OnceClosure task) {
// TODO(skyostil): Make task traits required here too.
return PostDelayedTask(from_here, {ThreadPool()}, std::move(task),
TimeDelta());
}
bool PostTaskAndReply(const Location& from_here,
OnceClosure task,
OnceClosure reply) {
return PostTaskAndReply(from_here, {ThreadPool()}, std::move(task),
std::move(reply));
}
bool PostTask(const Location& from_here,
const TaskTraits& traits,
OnceClosure task) {
......
......@@ -99,6 +99,27 @@ namespace base {
// have to worry about this. You will encounter DCHECKs or nullptr dereferences
// if this is violated. For tests, prefer base::test::TaskEnvironment.
// Equivalent to calling PostTask with default TaskTraits.
BASE_EXPORT bool PostTask(const Location& from_here, OnceClosure task);
inline bool PostTask(OnceClosure task,
const Location& from_here = Location::Current()) {
return PostTask(from_here, std::move(task));
}
// Equivalent to calling PostTaskAndReply with default TaskTraits.
BASE_EXPORT bool PostTaskAndReply(const Location& from_here,
OnceClosure task,
OnceClosure reply);
// Equivalent to calling PostTaskAndReplyWithResult with default TaskTraits.
template <typename TaskReturnType, typename ReplyArgType>
bool PostTaskAndReplyWithResult(const Location& from_here,
OnceCallback<TaskReturnType()> task,
OnceCallback<void(ReplyArgType)> reply) {
return PostTaskAndReplyWithResult(from_here, {ThreadPool()}, std::move(task),
std::move(reply));
}
// Posts |task| with specific |traits|. Returns false if the task definitely
// won't run because of current shutdown state.
BASE_EXPORT bool PostTask(const Location& from_here,
......
......@@ -99,6 +99,10 @@ class PostTaskTestWithExecutor : public ::testing::Test {
};
TEST_F(PostTaskTestWithExecutor, PostTaskToThreadPool) {
// Tasks without extension should not go to the TestTaskExecutor.
EXPECT_TRUE(PostTask(FROM_HERE, DoNothing()));
EXPECT_FALSE(executor_.runner()->HasPendingTask());
EXPECT_TRUE(PostTask(FROM_HERE, {ThreadPool(), MayBlock()}, DoNothing()));
EXPECT_FALSE(executor_.runner()->HasPendingTask());
......
......@@ -67,7 +67,7 @@ TEST_F(SequencedTaskRunnerHandleTest, FromThreadPoolSequencedTask) {
}
TEST_F(SequencedTaskRunnerHandleTest, NoHandleFromUnsequencedTask) {
base::ThreadPool::PostTask(base::BindOnce(
base::PostTask(base::BindOnce(
[]() { EXPECT_FALSE(SequencedTaskRunnerHandle::IsSet()); }));
task_environment_.RunUntilIdle();
}
......
......@@ -151,12 +151,12 @@ TEST(BrowserTaskEnvironmentTest, TraitsConstructor) {
signaled_on_real_io_thread.TimedWait(base::TimeDelta::FromSeconds(5));
EXPECT_TRUE(signaled_on_real_io_thread.IsSignaled());
// Tasks posted via ThreadPool::PostTask don't run in
// ThreadPoolExecutionMode::QUEUED until RunUntilIdle is called.
// Tasks posted via PostTask don't run in ThreadPoolExecutionMode::QUEUED
// until RunUntilIdle is called.
base::AtomicFlag task_ran;
base::ThreadPool::PostTask(
FROM_HERE, BindOnce([](base::AtomicFlag* task_ran) { task_ran->Set(); },
Unretained(&task_ran)));
PostTask(FROM_HERE,
BindOnce([](base::AtomicFlag* task_ran) { task_ran->Set(); },
Unretained(&task_ran)));
base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(100));
EXPECT_FALSE(task_ran.IsSet());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment