Skip to content

Commit

Permalink
Introduce TaskRunner::RunsTasksInCurrentSequence() to replace
Browse files Browse the repository at this point in the history
TaskRunner::RunsTasksOnCurrentThread().

Make TaskRunner::RunsTasksOnCurrentThread() non-virtual and define
it in terms of TaskRunner::RunsTasksInCurrentSequence().

It's the first step to rename RunsTasksOnCurrentThread()
to RunsTasksInCurrentSequence().

BUG=665062
CQ_INCLUDE_TRYBOTS=master.tryserver.blink:linux_trusty_blink_rel

Review-Url: https://codereview.chromium.org/2823103003
Cr-Commit-Position: refs/heads/master@{#470173}
  • Loading branch information
peary2 authored and Commit bot committed May 9, 2017
1 parent 8e566f6 commit 3322df6
Show file tree
Hide file tree
Showing 77 changed files with 148 additions and 125 deletions.
4 changes: 2 additions & 2 deletions base/deferred_sequenced_task_runner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ bool DeferredSequencedTaskRunner::PostDelayedTask(
return true;
}

bool DeferredSequencedTaskRunner::RunsTasksOnCurrentThread() const {
return target_task_runner_->RunsTasksOnCurrentThread();
bool DeferredSequencedTaskRunner::RunsTasksInCurrentSequence() const {
return target_task_runner_->RunsTasksInCurrentSequence();
}

bool DeferredSequencedTaskRunner::PostNonNestableDelayedTask(
Expand Down
2 changes: 1 addition & 1 deletion base/deferred_sequenced_task_runner.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class BASE_EXPORT DeferredSequencedTaskRunner : public SequencedTaskRunner {
bool PostDelayedTask(const tracked_objects::Location& from_here,
OnceClosure task,
TimeDelta delay) override;
bool RunsTasksOnCurrentThread() const override;
bool RunsTasksInCurrentSequence() const override;

// SequencedTaskRunner implementation
bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here,
Expand Down
2 changes: 1 addition & 1 deletion base/message_loop/message_loop_task_runner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ bool MessageLoopTaskRunner::PostNonNestableDelayedTask(
false);
}

bool MessageLoopTaskRunner::RunsTasksOnCurrentThread() const {
bool MessageLoopTaskRunner::RunsTasksInCurrentSequence() const {
AutoLock lock(valid_thread_id_lock_);
return valid_thread_id_ == PlatformThread::CurrentId();
}
Expand Down
2 changes: 1 addition & 1 deletion base/message_loop/message_loop_task_runner.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class BASE_EXPORT MessageLoopTaskRunner : public SingleThreadTaskRunner {
bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here,
OnceClosure task,
base::TimeDelta delay) override;
bool RunsTasksOnCurrentThread() const override;
bool RunsTasksInCurrentSequence() const override;

private:
friend class RefCountedThreadSafe<MessageLoopTaskRunner>;
Expand Down
28 changes: 22 additions & 6 deletions base/task_runner.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,29 @@ class BASE_EXPORT TaskRunner
OnceClosure task,
base::TimeDelta delay) = 0;

// Returns true if the current thread is a thread on which a task
// may be run, and false if no task will be run on the current
// thread.
// Drepecated: favor RunsTasksInCurrentSequence().
// TODO(http://crbug.com/665062): mass redirect callers and remove this.
bool RunsTasksOnCurrentThread() const {
return RunsTasksInCurrentSequence();
}

// Returns true iff tasks posted to this TaskRunner are sequenced
// with this call.
//
// It is valid for an implementation to always return true, or in
// general to use 'true' as a default value.
virtual bool RunsTasksOnCurrentThread() const = 0;
// In particular:
// - Returns true if this is a SequencedTaskRunner to which the
// current task was posted.
// - Returns true if this is a SequencedTaskRunner bound to the
// same sequence as the SequencedTaskRunner to which the current
// task was posted.
// - Returns true if this is a SingleThreadTaskRunner bound to
// the current thread.
// TODO(http://crbug.com/665062):
// This API doesn't make sense for parallel TaskRunners.
// Introduce alternate static APIs for documentation purposes of "this runs
// in pool X", have RunsTasksInCurrentSequence() return false for parallel
// TaskRunners, and ultimately move this method down to SequencedTaskRunner.
virtual bool RunsTasksInCurrentSequence() const = 0;

// Posts |task| on the current TaskRunner. On completion, |reply|
// is posted to the thread that called PostTaskAndReply(). Both
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class SchedulerWorkerDelegate : public SchedulerWorker::Delegate {

void OnDetach() override { NOTREACHED(); }

bool RunsTasksOnCurrentThread() {
bool RunsTasksInCurrentSequence() {
// We check the thread ref instead of the sequence for the benefit of COM
// callbacks which may execute without a sequence context.
return thread_ref_checker_.IsCurrentThreadSameAsSetThread();
Expand Down Expand Up @@ -279,8 +279,8 @@ class SchedulerSingleThreadTaskRunnerManager::SchedulerSingleThreadTaskRunner
return PostDelayedTask(from_here, std::move(closure), delay);
}

bool RunsTasksOnCurrentThread() const override {
return GetDelegate()->RunsTasksOnCurrentThread();
bool RunsTasksInCurrentSequence() const override {
return GetDelegate()->RunsTasksInCurrentSequence();
}

private:
Expand Down
6 changes: 2 additions & 4 deletions base/task_scheduler/scheduler_worker_pool_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class SchedulerParallelTaskRunner : public TaskRunner {
make_scoped_refptr(new Sequence));
}

bool RunsTasksOnCurrentThread() const override {
bool RunsTasksInCurrentSequence() const override {
return tls_current_worker_pool.Get().Get() == worker_pool_;
}

Expand Down Expand Up @@ -110,9 +110,7 @@ class SchedulerSequencedTaskRunner : public SequencedTaskRunner {
return PostDelayedTask(from_here, std::move(closure), delay);
}

bool RunsTasksOnCurrentThread() const override {
// TODO(fdoray): Rename TaskRunner::RunsTaskOnCurrentThread() to something
// that reflects this behavior more accurately. crbug.com/646905
bool RunsTasksInCurrentSequence() const override {
return sequence_->token() == SequenceToken::GetForCurrentThread();
}

Expand Down
2 changes: 1 addition & 1 deletion base/test/null_task_runner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ bool NullTaskRunner::PostNonNestableDelayedTask(
return false;
}

bool NullTaskRunner::RunsTasksOnCurrentThread() const {
bool NullTaskRunner::RunsTasksInCurrentSequence() const {
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion base/test/null_task_runner.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class NullTaskRunner : public base::SingleThreadTaskRunner {
base::OnceClosure task,
base::TimeDelta delay) override;
// Always returns true to avoid triggering DCHECKs.
bool RunsTasksOnCurrentThread() const override;
bool RunsTasksInCurrentSequence() const override;

protected:
~NullTaskRunner() override;
Expand Down
12 changes: 6 additions & 6 deletions base/test/scoped_task_scheduler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class TestTaskScheduler : public TaskScheduler {
const SequenceToken& sequence_token);

// Returns true if this TaskScheduler runs its tasks on the current thread.
bool RunsTasksOnCurrentThread() const;
bool RunsTasksInCurrentSequence() const;

private:
// Returns the TaskRunner to which this TaskScheduler forwards tasks. It may
Expand Down Expand Up @@ -143,7 +143,7 @@ class TestTaskSchedulerTaskRunner : public SingleThreadTaskRunner {
bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here,
OnceClosure closure,
TimeDelta delay) override;
bool RunsTasksOnCurrentThread() const override;
bool RunsTasksInCurrentSequence() const override;

private:
~TestTaskSchedulerTaskRunner() override;
Expand Down Expand Up @@ -272,8 +272,8 @@ void TestTaskScheduler::RunTask(std::unique_ptr<internal::Task> task,
saved_task_runner_ = nullptr;
}

bool TestTaskScheduler::RunsTasksOnCurrentThread() const {
return MessageLoopTaskRunner()->RunsTasksOnCurrentThread();
bool TestTaskScheduler::RunsTasksInCurrentSequence() const {
return MessageLoopTaskRunner()->RunsTasksInCurrentSequence();
}

TestTaskSchedulerTaskRunner::TestTaskSchedulerTaskRunner(
Expand Down Expand Up @@ -308,9 +308,9 @@ bool TestTaskSchedulerTaskRunner::PostNonNestableDelayedTask(
return PostDelayedTask(from_here, std::move(closure), delay);
}

bool TestTaskSchedulerTaskRunner::RunsTasksOnCurrentThread() const {
bool TestTaskSchedulerTaskRunner::RunsTasksInCurrentSequence() const {
if (execution_mode_ == ExecutionMode::PARALLEL)
return task_scheduler_->RunsTasksOnCurrentThread();
return task_scheduler_->RunsTasksInCurrentSequence();
return sequence_token_ == SequenceToken::GetForCurrentThread();
}

Expand Down
2 changes: 1 addition & 1 deletion base/test/test_mock_time_task_runner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ TimeDelta TestMockTimeTaskRunner::NextPendingTaskDelay() const {
// TODO(gab): Combine |thread_checker_| with a SequenceToken to differentiate
// between tasks running in the scope of this TestMockTimeTaskRunner and other
// task runners sharing this thread. http://crbug.com/631186
bool TestMockTimeTaskRunner::RunsTasksOnCurrentThread() const {
bool TestMockTimeTaskRunner::RunsTasksInCurrentSequence() const {
return thread_checker_.CalledOnValidThread();
}

Expand Down
2 changes: 1 addition & 1 deletion base/test/test_mock_time_task_runner.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class TestMockTimeTaskRunner : public SingleThreadTaskRunner {
TimeDelta NextPendingTaskDelay() const;

// SingleThreadTaskRunner:
bool RunsTasksOnCurrentThread() const override;
bool RunsTasksInCurrentSequence() const override;
bool PostDelayedTask(const tracked_objects::Location& from_here,
OnceClosure task,
TimeDelta delay) override;
Expand Down
4 changes: 2 additions & 2 deletions base/test/test_simple_task_runner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ bool TestSimpleTaskRunner::PostNonNestableDelayedTask(
// TODO(gab): Use SequenceToken here to differentiate between tasks running in
// the scope of this TestSimpleTaskRunner and other task runners sharing this
// thread. http://crbug.com/631186
bool TestSimpleTaskRunner::RunsTasksOnCurrentThread() const {
bool TestSimpleTaskRunner::RunsTasksInCurrentSequence() const {
return thread_ref_ == PlatformThread::CurrentRef();
}

Expand Down Expand Up @@ -76,7 +76,7 @@ void TestSimpleTaskRunner::ClearPendingTasks() {
}

void TestSimpleTaskRunner::RunPendingTasks() {
DCHECK(RunsTasksOnCurrentThread());
DCHECK(RunsTasksInCurrentSequence());

// Swap with a local variable to avoid re-entrancy problems.
std::deque<TestPendingTask> tasks_to_run;
Expand Down
2 changes: 1 addition & 1 deletion base/test/test_simple_task_runner.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class TestSimpleTaskRunner : public SingleThreadTaskRunner {
OnceClosure task,
TimeDelta delay) override;

bool RunsTasksOnCurrentThread() const override;
bool RunsTasksInCurrentSequence() const override;

std::deque<TestPendingTask> TakePendingTasks();
size_t NumPendingTasks() const;
Expand Down
13 changes: 7 additions & 6 deletions base/threading/sequenced_worker_pool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class SequencedWorkerPoolTaskRunner : public TaskRunner {
bool PostDelayedTask(const tracked_objects::Location& from_here,
OnceClosure task,
TimeDelta delay) override;
bool RunsTasksOnCurrentThread() const override;
bool RunsTasksInCurrentSequence() const override;

private:
~SequencedWorkerPoolTaskRunner() override;
Expand Down Expand Up @@ -176,8 +176,8 @@ bool SequencedWorkerPoolTaskRunner::PostDelayedTask(
return pool_->PostDelayedWorkerTask(from_here, std::move(task), delay);
}

bool SequencedWorkerPoolTaskRunner::RunsTasksOnCurrentThread() const {
return pool_->RunsTasksOnCurrentThread();
bool SequencedWorkerPoolTaskRunner::RunsTasksInCurrentSequence() const {
return pool_->RunsTasksInCurrentSequence();
}

} // namespace
Expand All @@ -199,7 +199,8 @@ class SequencedWorkerPool::PoolSequencedTaskRunner
bool PostDelayedTask(const tracked_objects::Location& from_here,
OnceClosure task,
TimeDelta delay) override;
bool RunsTasksOnCurrentThread() const override;
bool RunsTasksInCurrentSequence() const override;


// SequencedTaskRunner implementation
bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here,
Expand Down Expand Up @@ -243,7 +244,7 @@ bool SequencedWorkerPool::PoolSequencedTaskRunner::PostDelayedTask(
}

bool SequencedWorkerPool::PoolSequencedTaskRunner::
RunsTasksOnCurrentThread() const {
RunsTasksInCurrentSequence() const {
return pool_->IsRunningSequenceOnCurrentThread(token_);
}

Expand Down Expand Up @@ -1617,7 +1618,7 @@ bool SequencedWorkerPool::PostDelayedTask(
return PostDelayedWorkerTask(from_here, std::move(task), delay);
}

bool SequencedWorkerPool::RunsTasksOnCurrentThread() const {
bool SequencedWorkerPool::RunsTasksInCurrentSequence() const {
return inner_->RunsTasksOnCurrentThread();
}

Expand Down
2 changes: 1 addition & 1 deletion base/threading/sequenced_worker_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ class BASE_EXPORT SequencedWorkerPool : public TaskRunner {
bool PostDelayedTask(const tracked_objects::Location& from_here,
OnceClosure task,
TimeDelta delay) override;
bool RunsTasksOnCurrentThread() const override;
bool RunsTasksInCurrentSequence() const override;

// Blocks until all pending tasks are complete. This should only be called in
// unit tests when you want to validate something that should have happened.
Expand Down
4 changes: 2 additions & 2 deletions base/threading/worker_pool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class WorkerPoolTaskRunner : public TaskRunner {
bool PostDelayedTask(const tracked_objects::Location& from_here,
OnceClosure task,
TimeDelta delay) override;
bool RunsTasksOnCurrentThread() const override;
bool RunsTasksInCurrentSequence() const override;

private:
~WorkerPoolTaskRunner() override;
Expand Down Expand Up @@ -78,7 +78,7 @@ bool WorkerPoolTaskRunner::PostDelayedTask(
return PostDelayedTaskAssertZeroDelay(from_here, std::move(task), delay);
}

bool WorkerPoolTaskRunner::RunsTasksOnCurrentThread() const {
bool WorkerPoolTaskRunner::RunsTasksInCurrentSequence() const {
return WorkerPool::RunsTasksOnCurrentThread();
}

Expand Down
4 changes: 2 additions & 2 deletions base/trace_event/memory_dump_manager_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ class TestSequencedTaskRunner : public SequencedTaskRunner {
return false;
}

bool RunsTasksOnCurrentThread() const override {
return worker_pool_.pool()->RunsTasksOnCurrentThread();
bool RunsTasksInCurrentSequence() const override {
return worker_pool_.pool()->RunsTasksInCurrentSequence();
}

private:
Expand Down
2 changes: 1 addition & 1 deletion cc/test/ordered_simple_task_runner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ bool OrderedSimpleTaskRunner::PostNonNestableDelayedTask(
return true;
}

bool OrderedSimpleTaskRunner::RunsTasksOnCurrentThread() const {
bool OrderedSimpleTaskRunner::RunsTasksInCurrentSequence() const {
DCHECK(thread_checker_.CalledOnValidThread());
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion cc/test/ordered_simple_task_runner.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class OrderedSimpleTaskRunner : public base::SingleThreadTaskRunner {
base::OnceClosure task,
base::TimeDelta delay) override;

bool RunsTasksOnCurrentThread() const override;
bool RunsTasksInCurrentSequence() const override;

static base::TimeTicks AbsoluteMaxNow();

Expand Down
2 changes: 1 addition & 1 deletion cc/tiles/image_controller_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class WorkerTaskRunner : public base::SequencedTaskRunner {
return true;
}

bool RunsTasksOnCurrentThread() const override { return false; }
bool RunsTasksInCurrentSequence() const override { return false; }

protected:
~WorkerTaskRunner() override {
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/after_startup_task_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,8 @@ bool AfterStartupTaskUtils::Runner::PostDelayedTask(
return true;
}

bool AfterStartupTaskUtils::Runner::RunsTasksOnCurrentThread() const {
return destination_runner_->RunsTasksOnCurrentThread();
bool AfterStartupTaskUtils::Runner::RunsTasksInCurrentSequence() const {
return destination_runner_->RunsTasksInCurrentSequence();
}

void AfterStartupTaskUtils::StartMonitoringStartup() {
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/after_startup_task_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class AfterStartupTaskUtils {
bool PostDelayedTask(const tracked_objects::Location& from_here,
base::OnceClosure task,
base::TimeDelta delay) override;
bool RunsTasksOnCurrentThread() const override;
bool RunsTasksInCurrentSequence() const override;

private:
~Runner() override;
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/after_startup_task_utils_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ class WrappedTaskRunner : public base::TaskRunner {
base::TimeDelta()); // Squash all delays so our tests complete asap.
}

bool RunsTasksOnCurrentThread() const override {
return real_task_runner_->RunsTasksOnCurrentThread();
bool RunsTasksInCurrentSequence() const override {
return real_task_runner_->RunsTasksInCurrentSequence();
}

base::TaskRunner* real_runner() const { return real_task_runner_.get(); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class FakeTaskRunner : public base::TaskRunner {
std::move(task).Run();
return true;
}
bool RunsTasksOnCurrentThread() const override { return true; }
bool RunsTasksInCurrentSequence() const override { return true; }

DISALLOW_COPY_AND_ASSIGN(FakeTaskRunner);
};
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/chromeos/login/users/mock_user_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class FakeTaskRunner : public base::TaskRunner {
std::move(task).Run();
return true;
}
bool RunsTasksOnCurrentThread() const override { return true; }
bool RunsTasksInCurrentSequence() const override { return true; }

protected:
~FakeTaskRunner() override {}
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/memory/tab_manager_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class TaskRunnerProxy : public base::TaskRunner {
TaskRunnerProxy(MockTaskRunner* mock,
base::SimpleTestTickClock* clock)
: mock_(mock), clock_(clock) {}
bool RunsTasksOnCurrentThread() const override { return true; }
bool RunsTasksInCurrentSequence() const override { return true; }
bool PostDelayedTask(const tracked_objects::Location& location,
base::OnceClosure closure,
base::TimeDelta delta) override {
Expand Down
2 changes: 1 addition & 1 deletion chromecast/base/system_time_change_notifier_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class SequencedTaskRunnerNoDelay : public base::SequencedTaskRunner {
return true;
}

bool RunsTasksOnCurrentThread() const override { return true; }
bool RunsTasksInCurrentSequence() const override { return true; }

private:
~SequencedTaskRunnerNoDelay() override {}
Expand Down
Loading

0 comments on commit 3322df6

Please sign in to comment.