Skip to content

Commit

Permalink
[base] Cleanup remaining mentions of post_task.h
Browse files Browse the repository at this point in the history
Bug: 1026641
Change-Id: I2bbd0822ad045651d10bd66ce81fe0fb99ff3de2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3565099
Reviewed-by: Avi Drissman <avi@chromium.org>
Reviewed-by: Rohit Rao <rohitrao@chromium.org>
Reviewed-by: Ken Rockot <rockot@google.com>
Reviewed-by: Francois Pierre Doray <fdoray@chromium.org>
Commit-Queue: Francois Pierre Doray <fdoray@chromium.org>
Owners-Override: Francois Pierre Doray <fdoray@chromium.org>
Cr-Commit-Position: refs/heads/main@{#988170}
  • Loading branch information
Gabriel Charette authored and Chromium LUCI CQ committed Apr 1, 2022
1 parent 060146c commit 9b6c040
Show file tree
Hide file tree
Showing 21 changed files with 28 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

/**
* The default {@link TaskExecutor} which maps directly to base/task/post_task.h.
* TODO(crbug.com/1026641): Clean this up now that post_task.h is deprecated.
*/
class DefaultTaskExecutor implements TaskExecutor {
private final Map<TaskTraits, TaskRunner> mTraitsToRunnerMap = new HashMap<>();
Expand Down
3 changes: 1 addition & 2 deletions base/task/post_job.cc
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,7 @@ JobHandle PostJob(const Location& from_here,
RepeatingCallback<void(JobDelegate*)> worker_task,
MaxConcurrencyCallback max_concurrency_callback) {
DCHECK(ThreadPoolInstance::Get())
<< "Ref. Prerequisite section of post_task.h.\n\n"
"Hint: if this is in a unit test, you're likely merely missing a "
<< "Hint: if this is in a unit test, you're likely merely missing a "
"base::test::TaskEnvironment member in your fixture.\n";
// ThreadPool is implicitly the destination for PostJob(). Extension traits
// cannot be used.
Expand Down
14 changes: 7 additions & 7 deletions base/task/thread_pool/thread_pool_instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ class WorkerThreadObserver;
class ThreadPoolTestHelpers;

// Interface for a thread pool and static methods to manage the instance used
// by the post_task.h API.
// by the thread_pool.h API.
//
// The thread pool doesn't create threads until Start() is called. Tasks can
// be posted at any time but will not run until after Start() is called.
//
// The instance methods of this class are thread-safe.
//
// Note: All thread pool users should go through base/task/post_task.h instead
// Note: All thread pool users should go through base/task/thread_pool.h instead
// of this interface except for the one callsite per process which manages the
// process's instance.
class BASE_EXPORT ThreadPoolInstance {
Expand Down Expand Up @@ -167,7 +167,7 @@ class BASE_EXPORT ThreadPoolInstance {
virtual void JoinForTesting() = 0;

// CreateAndStartWithDefaultParams(), Create(), and SetInstance() register a
// ThreadPoolInstance to handle tasks posted through the post_task.h API for
// ThreadPoolInstance to handle tasks posted through the thread_pool.h API for
// this process.
//
// Processes that need to initialize ThreadPoolInstance with custom params or
Expand All @@ -179,8 +179,8 @@ class BASE_EXPORT ThreadPoolInstance {
// ThreadPoolInstance is registered. The last registered ThreadPoolInstance is
// leaked on shutdown. The methods below must not be called when TaskRunners
// created by a previous ThreadPoolInstance are still alive. The methods are
// not thread-safe; proper synchronization is required to use the post_task.h
// API after registering a new ThreadPoolInstance.
// not thread-safe; proper synchronization is required to use the
// thread_pool.h API after registering a new ThreadPoolInstance.

#if !BUILDFLAG(IS_NACL)
// Creates and starts a thread pool using default params. |name| is used to
Expand All @@ -203,14 +203,14 @@ class BASE_EXPORT ThreadPoolInstance {
// (ensures isolation).
static void Create(StringPiece name);

// Registers |thread_pool| to handle tasks posted through the post_task.h
// Registers |thread_pool| to handle tasks posted through the thread_pool.h
// API for this process. For tests, prefer base::test::TaskEnvironment
// (ensures isolation).
static void Set(std::unique_ptr<ThreadPoolInstance> thread_pool);

// Retrieve the ThreadPoolInstance set via SetInstance() or Create(). This
// should be used very rarely; most users of the thread pool should use the
// post_task.h API. In particular, refrain from doing
// thread_pool.h API. In particular, refrain from doing
// if (!ThreadPoolInstance::Get()) {
// ThreadPoolInstance::Set(...);
// base::ThreadPool::PostTask(...);
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 @@ -18,7 +18,7 @@ namespace base {
class TimeDelta;

// ATTENTION: Prefer using base::test::TaskEnvironment and a task runner
// obtained from base/task/post_task.h over this class. This class isn't as
// obtained from base/task/thread_pool.h over this class. This class isn't as
// "simple" as it seems specifically because it runs tasks in a surprising order
// (delays aren't respected and nesting doesn't behave as usual). Should you
// prefer to flush all tasks regardless of delays,
Expand Down
3 changes: 2 additions & 1 deletion base/threading/post_task_and_reply_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ namespace internal {
// custom execution context.
//
// If you're looking for a concrete implementation of PostTaskAndReply, you
// probably want base::TaskRunner or base/task/post_task.h
// probably want a base::TaskRunner (typically obtained from
// base/task/thread_pool.h).
class BASE_EXPORT PostTaskAndReplyImpl {
public:
virtual ~PostTaskAndReplyImpl() = default;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include "base/memory/ref_counted.h"
#include "base/metrics/histogram_functions.h"
#include "base/path_service.h"
#include "base/task/post_task.h"
#include "base/task/task_traits.h"
#include "base/task/thread_pool.h"
#include "base/version.h"
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/downgrade/downgrade_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ void DowngradeManager::DeleteMovedUserDataSoon(
const base::FilePath& user_data_dir) {
DCHECK(!user_data_dir.empty());
// IWYU note: base/location.h and base/task/task_traits.h are guaranteed to be
// available via base/task/post_task.h.
// available via base/task/thread_pool.h.
content::BrowserThread::PostBestEffortTask(
FROM_HERE,
base::ThreadPool::CreateTaskRunner(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include "base/callback_helpers.h"
#include "base/files/file_path.h"
#include "base/metrics/histogram_functions.h"
#include "base/task/post_task.h"
#include "base/task/task_runner_util.h"
#include "base/task/thread_pool.h"
#include "base/threading/sequenced_task_runner_handle.h"
Expand Down
4 changes: 2 additions & 2 deletions content/app/content_main_runner_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1042,8 +1042,8 @@ int ContentMainRunnerImpl::RunBrowser(MainFunctionParams main_params,
mojo::core::InitFeatures();
}

// Create and start the ThreadPool early to allow upcoming code to use
// the post_task.h API.
// Create and start the ThreadPool early to allow upcoming code to use the
// thread_pool.h API.
const bool has_thread_pool =
GetContentClient()->browser()->CreateThreadPool("Browser");

Expand Down
3 changes: 1 addition & 2 deletions content/browser/renderer_host/render_widget_host_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -462,8 +462,7 @@ RenderWidgetHostImpl::RenderWidgetHostImpl(
#endif
CHECK(delegate_);
CHECK_NE(MSG_ROUTING_NONE, routing_id_);
DCHECK(base::ThreadPoolInstance::Get())
<< "Ref. Prerequisite section of post_task.h";
DCHECK(base::ThreadPoolInstance::Get());

std::pair<RoutingIDWidgetMap::iterator, bool> result =
g_routing_id_widget_map.Get().insert(std::make_pair(
Expand Down
1 change: 1 addition & 0 deletions content/browser/scheduler/browser_task_executor.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class CONTENT_EXPORT BrowserTaskExecutor : public BaseBrowserTaskExecutor {
// Creates and registers a BrowserTaskExecutor on the current thread which
// owns a BrowserUIThreadScheduler. This facilitates posting tasks to a
// BrowserThread via //base/task/post_task.h.
// TODO(crbug.com/1026641): Clean this up now that post_task.h is deprecated.
// All BrowserThread::UI task queues except best effort ones are also enabled.
// TODO(carlscab): These queues should be enabled in
// BrowserMainLoop::InitializeMainThread() but some Android tests fail if we
Expand Down
3 changes: 0 additions & 3 deletions content/public/browser/browser_task_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@ enum class BrowserTaskType {

// TaskTraits for running tasks on the browser threads.
//
// These traits enable the use of the //base/task/post_task.h APIs to post tasks
// to a BrowserThread.
//
// To post a task to the UI thread (analogous for IO thread):
// GetUIThreadTaskRunner({})->PostTask(FROM_HERE, task);
//
Expand Down
12 changes: 6 additions & 6 deletions docs/threading_and_tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ This documentation assumes familiarity with computer science
* **Thread pool**: A pool of physical threads with a shared task queue. In
Chrome, this is `base::ThreadPoolInstance`. There's exactly one instance per
Chrome process, it serves tasks posted through
[`base/task/post_task.h`](https://cs.chromium.org/chromium/src/base/task/post_task.h)
[`base/task/thread_pool.h`](https://cs.chromium.org/chromium/src/base/task/thread_pool.h)
and as such you should rarely need to use the `base::ThreadPoolInstance` API
directly (more on posting tasks later).
* **Sequence** or **Virtual thread**: A chrome-managed thread of execution.
Expand Down Expand Up @@ -702,7 +702,7 @@ Tasks](threading_and_tasks_testing.md).
To test code that uses `base::ThreadTaskRunnerHandle`,
`base::SequencedTaskRunnerHandle` or a function in
[`base/task/post_task.h`](https://cs.chromium.org/chromium/src/base/task/post_task.h),
[`base/task/thread_pool.h`](https://cs.chromium.org/chromium/src/base/task/thread_pool.h),
instantiate a
[`base::test::TaskEnvironment`](https://cs.chromium.org/chromium/src/base/test/task_environment.h)
for the scope of the test. If you need BrowserThreads, use
Expand Down Expand Up @@ -776,7 +776,7 @@ TEST(MyTest, MyTest) {
## Using ThreadPool in a New Process

ThreadPoolInstance needs to be initialized in a process before the functions in
[`base/task/post_task.h`](https://cs.chromium.org/chromium/src/base/task/post_task.h)
[`base/task/thread_pool.h`](https://cs.chromium.org/chromium/src/base/task/thread_pool.h)
can be used. Initialization of ThreadPoolInstance in the Chrome browser process
and child processes (renderer, GPU, utility) has already been taken care of. To
use ThreadPoolInstance in another process, initialize ThreadPoolInstance early
Expand All @@ -785,12 +785,12 @@ in the main function:
```cpp
// This initializes and starts ThreadPoolInstance with default params.
base::ThreadPoolInstance::CreateAndStartWithDefaultParams(“process_name”);
// The base/task/post_task.h API can now be used with base::ThreadPool trait.
// The base/task/thread_pool.h API can now be used with base::ThreadPool trait.
// Tasks will be scheduled as they are posted.

// This initializes ThreadPoolInstance.
base::ThreadPoolInstance::Create(“process_name”);
// The base/task/post_task.h API can now be used with base::ThreadPool trait. No
// The base/task/thread_pool.h API can now be used with base::ThreadPool trait. No
// threads will be created and no tasks will be scheduled until after Start() is
// called.
base::ThreadPoolInstance::Get()->Start(params);
Expand All @@ -817,7 +817,7 @@ See [this example](https://codereview.chromium.org/2885173002/) of a
refactoring where a TaskRunner was passed through a lot of components only to be
used in an eventual leaf. The leaf can and should now obtain its TaskRunner
directly from
[`base/task/post_task.h`](https://cs.chromium.org/chromium/src/base/task/post_task.h).
[`base/task/thread_pool.h`](https://cs.chromium.org/chromium/src/base/task/thread_pool.h).

As mentioned above, `base::test::TaskEnvironment` allows unit tests to
control tasks posted from underlying TaskRunners. In rare cases where a test
Expand Down
2 changes: 1 addition & 1 deletion docs/threading_and_tasks_faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ docs first.

### On which thread will a task run?

A task is posted through the `base/task/post_task.h` API with `TaskTraits`.
A task is posted through the `base/task/thread_pool.h` API with `TaskTraits`.

* If `TaskTraits` contain `BrowserThread::UI`:
* The task runs on the main thread.
Expand Down
4 changes: 2 additions & 2 deletions docs/threading_and_tasks_testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ readability term like "const", it documents that ThreadPool isn't used when it's
not but you shouldn't be afraid to lift it.

Task runners are still obtained by the product code through
[base/task/post_task.h] without necessitating a test-only task runner injection
[base/task/thread_pool.h] without necessitating a test-only task runner injection
seam :).

Typical use case:
Expand Down Expand Up @@ -461,7 +461,7 @@ individual tests provide additional traits.
[Threading and Tasks FAQ]: threading_and_tasks_faq.md
[`ValidTraits`]: https://cs.chromium.org/chromium/src/base/test/task_environment.h?type=cs&q=ValidTraits&sq=package:chromium&g=0
[task_environment.h]: https://cs.chromium.org/chromium/src/base/test/task_environment.h
[base/task/post_task.h]: https://cs.chromium.org/chromium/src/base/task/post_task.h
[base/task/thread_pool.h]: https://cs.chromium.org/chromium/src/base/task/thread_pool.h
[ViewsTestBase]: https://cs.chromium.org/chromium/src/ui/views/test/views_test_base.h
[base/traits_bag.h]: https://cs.chromium.org/chromium/src/base/traits_bag.h
[content/public/test/browser_test_utils.h]: https://cs.chromium.org/chromium/src/content/public/test/browser_test_utils.h
Expand Down
1 change: 0 additions & 1 deletion ios/chrome/browser/web/certificate_policy_app_agent.mm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#import "ios/chrome/browser/web/certificate_policy_app_agent.h"

#import "base/task/cancelable_task_tracker.h"
#import "base/task/post_task.h"
#import "ios/chrome/app/application_delegate/app_state.h"
#import "ios/chrome/browser/browser_state/chrome_browser_state.h"
#import "ios/chrome/browser/main/browser.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#import "base/bind.h"
#import "base/memory/scoped_refptr.h"
#import "base/run_loop.h"
#import "base/task/post_task.h"
#import "base/test/ios/wait_util.h"
#import "base/time/time.h"
#import "ios/chrome/app/application_delegate/app_state.h"
Expand Down
5 changes: 0 additions & 5 deletions ios/web/public/thread/web_task_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ struct NonNestable {};

// TaskTraits for running tasks on a WebThread.
//
// These traits enable the use of the //base/task/post_task.h APIs to post tasks
// to a WebThread.
//
// To post a task to the UI thread (analogous for IO thread):
// web::GetUIThreadTaskRunner({})->PostTask(FROM_HERE, task);
//
Expand All @@ -35,8 +32,6 @@ struct NonNestable {};
// in the order they were posted, regardless of the TaskRunners they were
// posted via.
//
// See //base/task/post_task.h for more detailed documentation.
//
// Posting to a WebThread must only be done after it was initialized (ref.
// WebMainLoop::CreateThreads() phase).
class WebTaskTraitsExtension {
Expand Down
1 change: 1 addition & 0 deletions ios/web/web_thread_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class WebThreadImpl : public WebThread {

// Creates and registers a TaskExecutor that facilitates posting tasks to a
// WebThread via //base/task/post_task.h.
// TODO(crbug.com/1026641): Remove this now that post_task.h is deprecated.
static void CreateTaskExecutor();

// Unregister and delete the TaskExecutor after a test.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@

#include <functional>

#include "base/no_destructor.h"
#include "base/task/post_task.h"
#include "base/bind.h"

{% for extra_traits_header in all_extra_traits_headers %}
#include "{{extra_traits_header}}"
Expand Down
1 change: 0 additions & 1 deletion third_party/blink/renderer/DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ include_rules = [
"+base/synchronization",
"+base/sys_byteorder.h",
"+base/system/sys_info.h",
"+base/task/post_task.h",
"+base/task/sequenced_task_runner.h",
"+base/task/single_thread_task_runner.h",
"+base/task/thread_pool.h",
Expand Down

0 comments on commit 9b6c040

Please sign in to comment.