Remove now unused BrowserThread's BlockingPool!!!
Bug: 667892 Change-Id: I98f41c80f6f7e041db2fa3713d531ce8db9932ec Reviewed-on: https://chromium-review.googlesource.com/664219 Reviewed-by: John Abd-El-Malek <jam@chromium.org> Reviewed-by: Robert Liao <robliao@chromium.org> Commit-Queue: Gabriel Charette <gab@chromium.org> Cr-Commit-Position: refs/heads/master@{#502004}
This commit is contained in:

committed by
Commit Bot

parent
7a69043896
commit
a1e0a375eb
10
PRESUBMIT.py
10
PRESUBMIT.py
@ -333,16 +333,6 @@ _BANNED_CPP_FUNCTIONS = (
|
||||
True,
|
||||
(),
|
||||
),
|
||||
(
|
||||
r'/(WebThread|BrowserThread)::GetBlockingPool',
|
||||
(
|
||||
'Use base/task_scheduler/post_task.h instead of the blocking pool. See',
|
||||
'mapping between both APIs in content/public/browser/browser_thread.h.',
|
||||
'For questions, contact base/task_scheduler/OWNERS.',
|
||||
),
|
||||
True,
|
||||
(),
|
||||
),
|
||||
(
|
||||
r'/(WebThread|BrowserThread)::(FILE|FILE_USER_BLOCKING|DB|CACHE)',
|
||||
(
|
||||
|
@ -1351,16 +1351,6 @@ void BrowserMainLoop::ShutdownThreadsAndCleanUp() {
|
||||
}
|
||||
}
|
||||
|
||||
// Close the blocking I/O pool after the other threads. Other threads such
|
||||
// as the I/O thread may need to schedule work like closing files or
|
||||
// flushing data during shutdown, so the blocking pool needs to be
|
||||
// available. There may also be slow operations pending that will blcok
|
||||
// shutdown, so closing it here (which will block until required operations
|
||||
// are complete) gives more head start for those operations to finish.
|
||||
{
|
||||
TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:ThreadPool");
|
||||
BrowserThreadImpl::ShutdownThreadPool();
|
||||
}
|
||||
{
|
||||
TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:TaskScheduler");
|
||||
base::TaskScheduler::GetInstance()->Shutdown();
|
||||
|
@ -17,7 +17,6 @@
|
||||
#include "base/run_loop.h"
|
||||
#include "base/synchronization/waitable_event.h"
|
||||
#include "base/threading/platform_thread.h"
|
||||
#include "base/threading/sequenced_worker_pool.h"
|
||||
#include "build/build_config.h"
|
||||
#include "content/public/browser/browser_thread_delegate.h"
|
||||
#include "content/public/browser/content_browser_client.h"
|
||||
@ -119,12 +118,6 @@ enum BrowserThreadState {
|
||||
using BrowserThreadDelegateAtomicPtr = base::subtle::AtomicWord;
|
||||
|
||||
struct BrowserThreadGlobals {
|
||||
BrowserThreadGlobals()
|
||||
: blocking_pool(
|
||||
new base::SequencedWorkerPool(3,
|
||||
"BrowserBlocking",
|
||||
base::TaskPriority::USER_VISIBLE)) {}
|
||||
|
||||
// This lock protects |task_runners| and |states|. Do not read or modify those
|
||||
// arrays without holding this lock. Do not block while holding this lock.
|
||||
base::Lock lock;
|
||||
@ -143,8 +136,6 @@ struct BrowserThreadGlobals {
|
||||
// by BrowserThreadGlobals, rather by whoever calls
|
||||
// BrowserThread::SetIOThreadDelegate.
|
||||
BrowserThreadDelegateAtomicPtr io_thread_delegate = 0;
|
||||
|
||||
const scoped_refptr<base::SequencedWorkerPool> blocking_pool;
|
||||
};
|
||||
|
||||
base::LazyInstance<BrowserThreadGlobals>::Leaky
|
||||
@ -175,26 +166,6 @@ BrowserThreadImpl::BrowserThreadImpl(ID identifier,
|
||||
globals.states[identifier_] = BrowserThreadState::RUNNING;
|
||||
}
|
||||
|
||||
// static
|
||||
void BrowserThreadImpl::ShutdownThreadPool() {
|
||||
// The goal is to make it impossible for chrome to 'infinite loop' during
|
||||
// shutdown, but to reasonably expect that all BLOCKING_SHUTDOWN tasks queued
|
||||
// during shutdown get run. There's nothing particularly scientific about the
|
||||
// number chosen.
|
||||
const int kMaxNewShutdownBlockingTasks = 1000;
|
||||
BrowserThreadGlobals& globals = g_globals.Get();
|
||||
globals.blocking_pool->Shutdown(kMaxNewShutdownBlockingTasks);
|
||||
}
|
||||
|
||||
// static
|
||||
void BrowserThreadImpl::FlushThreadPoolHelperForTesting() {
|
||||
// We don't want to create a pool if none exists.
|
||||
if (g_globals == nullptr)
|
||||
return;
|
||||
g_globals.Get().blocking_pool->FlushForTesting();
|
||||
disk_cache::SimpleBackendImpl::FlushWorkerPoolForTesting();
|
||||
}
|
||||
|
||||
void BrowserThreadImpl::Init() {
|
||||
BrowserThreadGlobals& globals = g_globals.Get();
|
||||
|
||||
@ -529,15 +500,6 @@ bool BrowserThreadImpl::PostTaskHelper(BrowserThread::ID identifier,
|
||||
return accepting_tasks;
|
||||
}
|
||||
|
||||
// static
|
||||
bool BrowserThread::PostBlockingPoolSequencedTask(
|
||||
const std::string& sequence_token_name,
|
||||
const base::Location& from_here,
|
||||
base::OnceClosure task) {
|
||||
return g_globals.Get().blocking_pool->PostNamedSequencedWorkerTask(
|
||||
sequence_token_name, from_here, std::move(task));
|
||||
}
|
||||
|
||||
// static
|
||||
void BrowserThread::PostAfterStartupTask(
|
||||
const base::Location& from_here,
|
||||
@ -547,11 +509,6 @@ void BrowserThread::PostAfterStartupTask(
|
||||
std::move(task));
|
||||
}
|
||||
|
||||
// static
|
||||
base::SequencedWorkerPool* BrowserThread::GetBlockingPool() {
|
||||
return g_globals.Get().blocking_pool.get();
|
||||
}
|
||||
|
||||
// static
|
||||
bool BrowserThread::IsThreadInitialized(ID identifier) {
|
||||
if (g_globals == nullptr)
|
||||
|
@ -54,8 +54,6 @@ class CONTENT_EXPORT BrowserThreadImpl : public BrowserThread,
|
||||
// Can only be called after a matching RedirectThreadIDToTaskRunner call.
|
||||
static void StopRedirectionOfThreadID(BrowserThread::ID identifier);
|
||||
|
||||
static void ShutdownThreadPool();
|
||||
|
||||
// Resets globals for |identifier|. Used in tests to clear global state that
|
||||
// would otherwise leak to the next test. Globals are not otherwise fully
|
||||
// cleaned up in ~BrowserThreadImpl() as there are subtle differences between
|
||||
@ -97,7 +95,6 @@ class CONTENT_EXPORT BrowserThreadImpl : public BrowserThread,
|
||||
// For testing.
|
||||
friend class ContentTestSuiteBaseListener;
|
||||
friend class TestBrowserThreadBundle;
|
||||
static void FlushThreadPoolHelperForTesting();
|
||||
|
||||
// The identifier of this thread. Only one thread can exist with a given
|
||||
// identifier at a given time.
|
||||
|
@ -21,7 +21,6 @@
|
||||
|
||||
namespace base {
|
||||
class MessageLoop;
|
||||
class SequencedWorkerPool;
|
||||
class Thread;
|
||||
}
|
||||
|
||||
@ -187,27 +186,6 @@ class CONTENT_EXPORT BrowserThread {
|
||||
return GetTaskRunnerForThread(identifier)->ReleaseSoon(from_here, object);
|
||||
}
|
||||
|
||||
// DEPRECATED: use base/task_scheduler/post_task.h instead.
|
||||
// * BrowserThread::PostBlockingPoolSequencedTask =>
|
||||
// Share a single SequencedTaskRunner created via
|
||||
// base::CreateSequencedTaskRunnerWithTraits() instead of sharing a
|
||||
// SequenceToken (ping base/task_scheduler/OWNERS if you find a use
|
||||
// case where that's not possible).
|
||||
//
|
||||
// Posts a task to the blocking pool. The task is guaranteed to run before
|
||||
// shutdown. Tasks posted with the same sequence token name are sequenced.
|
||||
//
|
||||
// If you need to provide different shutdown semantics (like you have
|
||||
// something slow and noncritical that doesn't need to block shutdown),
|
||||
// or you want to manually provide a sequence token (which saves a map
|
||||
// lookup and is guaranteed unique without you having to come up with a
|
||||
// unique string), you can access the sequenced worker pool directly via
|
||||
// GetBlockingPool().
|
||||
static bool PostBlockingPoolSequencedTask(
|
||||
const std::string& sequence_token_name,
|
||||
const base::Location& from_here,
|
||||
base::OnceClosure task);
|
||||
|
||||
// For use with scheduling non-critical tasks for execution after startup.
|
||||
// The order or execution of tasks posted here is unspecified even when
|
||||
// posting to a SequencedTaskRunner and tasks are not guaranteed to be run
|
||||
@ -220,18 +198,6 @@ class CONTENT_EXPORT BrowserThread {
|
||||
const scoped_refptr<base::TaskRunner>& task_runner,
|
||||
base::OnceClosure task);
|
||||
|
||||
// Returns the thread pool used for blocking file I/O. Use this object to
|
||||
// perform random blocking operations such as file writes.
|
||||
//
|
||||
// DEPRECATED: use an independent TaskRunner obtained from
|
||||
// base/task_scheduler/post_task.h instead, e.g.:
|
||||
// BrowserThread::GetBlockingPool()->GetSequencedTaskRunner(
|
||||
// base::SequencedWorkerPool::GetSequenceToken())
|
||||
// =>
|
||||
// base::CreateSequencedTaskRunnerWithTraits(
|
||||
// {base::MayBlock()}).
|
||||
static base::SequencedWorkerPool* GetBlockingPool() WARN_UNUSED_RESULT;
|
||||
|
||||
// Callable on any thread. Returns whether the given well-known thread is
|
||||
// initialized.
|
||||
static bool IsThreadInitialized(ID identifier) WARN_UNUSED_RESULT;
|
||||
|
@ -32,12 +32,6 @@ TestBrowserThreadBundle::TestBrowserThreadBundle(int options)
|
||||
TestBrowserThreadBundle::~TestBrowserThreadBundle() {
|
||||
CHECK(threads_created_);
|
||||
|
||||
// To avoid memory leaks, we must ensure that any tasks posted to the blocking
|
||||
// pool via PostTaskAndReply are able to reply back to the originating thread.
|
||||
// Thus we must flush the blocking pool while the browser threads still exist.
|
||||
base::RunLoop().RunUntilIdle();
|
||||
BrowserThreadImpl::FlushThreadPoolHelperForTesting();
|
||||
|
||||
// To ensure a clean teardown, each thread's message loop must be flushed
|
||||
// just before the thread is destroyed. But stopping a fake thread does not
|
||||
// automatically flush the message loop, so we have to do it manually.
|
||||
@ -55,11 +49,6 @@ TestBrowserThreadBundle::~TestBrowserThreadBundle() {
|
||||
base::RunLoop().RunUntilIdle();
|
||||
db_thread_->Stop();
|
||||
base::RunLoop().RunUntilIdle();
|
||||
// This is the point at which we normally shut down the thread pool. So flush
|
||||
// it again in case any shutdown tasks have been posted to the pool from the
|
||||
// threads above.
|
||||
BrowserThreadImpl::FlushThreadPoolHelperForTesting();
|
||||
base::RunLoop().RunUntilIdle();
|
||||
ui_thread_->Stop();
|
||||
base::RunLoop().RunUntilIdle();
|
||||
|
||||
|
@ -3,17 +3,17 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
// TestBrowserThreadBundle is a convenience class for creating a set of
|
||||
// TestBrowserThreads, a blocking pool, and a task scheduler in unit tests. For
|
||||
// most tests, it is sufficient to just instantiate the TestBrowserThreadBundle
|
||||
// as a member variable. It is a good idea to put the TestBrowserThreadBundle as
|
||||
// the first member variable in test classes, so it is destroyed last, and the
|
||||
// test threads always exist from the perspective of other classes.
|
||||
// TestBrowserThreads and a task scheduler in unit tests. For most tests, it is
|
||||
// sufficient to just instantiate the TestBrowserThreadBundle as a member
|
||||
// variable. It is a good idea to put the TestBrowserThreadBundle as the first
|
||||
// member variable in test classes, so it is destroyed last, and the test
|
||||
// threads always exist from the perspective of other classes.
|
||||
//
|
||||
// By default, all of the created TestBrowserThreads will be backed by a single
|
||||
// shared MessageLoop. If a test truly needs separate threads, it can do so by
|
||||
// passing the appropriate combination of option values during the
|
||||
// TestBrowserThreadBundle construction. TaskScheduler and blocking pool tasks
|
||||
// always run on dedicated threads.
|
||||
// TestBrowserThreadBundle construction. TaskScheduler tasks always run on
|
||||
// dedicated threads.
|
||||
//
|
||||
// To synchronously run tasks from the shared MessageLoop:
|
||||
//
|
||||
@ -21,8 +21,8 @@
|
||||
// base::RunLoop::RunUntilIdle();
|
||||
//
|
||||
// ... until there are no undelayed tasks in the shared MessageLoop, in
|
||||
// TaskScheduler or in the blocking pool (excluding tasks not posted from the
|
||||
// shared MessageLoop's thread, TaskScheduler or the blocking pool):
|
||||
// TaskScheduler (excluding tasks not posted from the shared MessageLoop's
|
||||
// thread or TaskScheduler):
|
||||
// content::RunAllBlockingPoolTasksUntilIdle();
|
||||
//
|
||||
// ... until a condition is met:
|
||||
@ -32,15 +32,12 @@
|
||||
// // run_loop.QuitClosure() must be kept somewhere accessible by that task).
|
||||
// run_loop.Run();
|
||||
//
|
||||
// To wait until there are no pending undelayed tasks in TaskScheduler or in the
|
||||
// blocking pool, without running tasks from the shared MessageLoop:
|
||||
// To wait until there are no pending undelayed tasks in TaskScheduler, without
|
||||
// running tasks from the shared MessageLoop:
|
||||
// base::TaskScheduler::GetInstance()->FlushForTesting();
|
||||
// // Note: content::BrowserThread::GetBlockingPool()->FlushForTesting() is
|
||||
// // equivalent but deprecated.
|
||||
//
|
||||
// The destructor of TestBrowserThreadBundle runs remaining TestBrowserThreads
|
||||
// tasks, remaining blocking pool tasks, and remaining BLOCK_SHUTDOWN task
|
||||
// scheduler tasks.
|
||||
// tasks and remaining task scheduler tasks.
|
||||
//
|
||||
// If a test needs a MessageLoopForIO on the main thread, it should use the
|
||||
// IO_MAINLOOP option. Most of the time, IO_MAINLOOP avoids needing to use a
|
||||
|
@ -156,8 +156,6 @@ void RunAllPendingInMessageLoop(BrowserThread::ID thread_id) {
|
||||
|
||||
void RunAllBlockingPoolTasksUntilIdle() {
|
||||
while (true) {
|
||||
content::BrowserThread::GetBlockingPool()->FlushForTesting();
|
||||
|
||||
// Setup a task observer to determine if MessageLoop tasks run in the
|
||||
// current loop iteration. This must be done before
|
||||
// TaskScheduler::FlushForTesting() since this may spin the MessageLoop.
|
||||
|
@ -60,8 +60,8 @@ void RunAllPendingInMessageLoop(BrowserThread::ID thread_id);
|
||||
// Runs until the blocking pool, task scheduler, and the current message loop
|
||||
// are all empty (have no more scheduled tasks) and no tasks are running.
|
||||
//
|
||||
// TODO(fdoray): Rename to RunAllTaskSchedulerTasksUntilIdle() once the blocking
|
||||
// pool is fully deprecated. https://crbug.com/667892
|
||||
// TODO(fdoray): Rename to RunAllTaskSchedulerTasksUntilIdle() now that the
|
||||
// blocking pool is fully deprecated. https://crbug.com/667892
|
||||
void RunAllBlockingPoolTasksUntilIdle();
|
||||
|
||||
// Get task to quit the given RunLoop. It allows a few generations of pending
|
||||
|
@ -591,17 +591,6 @@ content::BrowserThread::GetTaskRunnerForThread(content::BrowserThread::[IDENTIFI
|
||||
|
||||
Where `IDENTIFIER` is one of: `DB`, `FILE`, `FILE_USER_BLOCKING`, `PROCESS_LAUNCHER`, `CACHE`.
|
||||
|
||||
The Chrome browser process has a “blocking pool” API:
|
||||
|
||||
```cpp
|
||||
content::BrowserThread::PostBlockingPoolSequencedTask
|
||||
content::BrowserThread::GetBlockingPool
|
||||
```
|
||||
|
||||
All tasks posted through this API are redirected to
|
||||
[`base/task_scheduler/post_task.h`](https://cs.chromium.org/chromium/src/base/task_scheduler/post_task.h).
|
||||
Therefore, there is no reason to add calls to this API.
|
||||
|
||||
## Using TaskScheduler in a New Process
|
||||
|
||||
TaskScheduler needs to be initialized in a process before the functions in
|
||||
|
Reference in New Issue
Block a user