forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimple_task_executor.cc
62 lines (52 loc) · 1.96 KB
/
simple_task_executor.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/task/simple_task_executor.h"
namespace base {
SimpleTaskExecutor::SimpleTaskExecutor(
scoped_refptr<SingleThreadTaskRunner> task_queue)
: task_queue_(std::move(task_queue)),
previous_task_executor_(GetTaskExecutorForCurrentThread()) {
DCHECK(task_queue_);
// The TaskExecutor API does not expect nesting, but this can happen in tests
// so we have to work around it here.
if (previous_task_executor_)
SetTaskExecutorForCurrentThread(nullptr);
SetTaskExecutorForCurrentThread(this);
}
SimpleTaskExecutor::~SimpleTaskExecutor() {
if (previous_task_executor_)
SetTaskExecutorForCurrentThread(nullptr);
SetTaskExecutorForCurrentThread(previous_task_executor_);
}
bool SimpleTaskExecutor::PostDelayedTask(const Location& from_here,
const TaskTraits& traits,
OnceClosure task,
TimeDelta delay) {
return task_queue_->PostDelayedTask(from_here, std::move(task), delay);
}
scoped_refptr<TaskRunner> SimpleTaskExecutor::CreateTaskRunner(
const TaskTraits& traits) {
return task_queue_;
}
scoped_refptr<SequencedTaskRunner>
SimpleTaskExecutor::CreateSequencedTaskRunner(const TaskTraits& traits) {
return task_queue_;
}
scoped_refptr<SingleThreadTaskRunner>
SimpleTaskExecutor::CreateSingleThreadTaskRunner(
const TaskTraits& traits,
SingleThreadTaskRunnerThreadMode thread_mode) {
return task_queue_;
}
#if defined(OS_WIN)
scoped_refptr<SingleThreadTaskRunner>
SimpleTaskExecutor::CreateCOMSTATaskRunner(
const TaskTraits& traits,
SingleThreadTaskRunnerThreadMode thread_mode) {
// It seems pretty unlikely this will be used on a comsta task thread.
NOTREACHED();
return task_queue_;
}
#endif // defined(OS_WIN)
} // namespace base