Commit 141a4425 authored by Gabriel Charette's avatar Gabriel Charette Committed by Commit Bot

Complete TaskPriority::BACKGROUND->BEST_EFFORT mass rename

Survey base/task_scheduler for remaining unprefixed "BACKGROUND" strings
referring to task priority (i.e. not referring to
"background thread priority").

Best-effort survey of the codebase for "BACKGROUND priority" left behind
in comments.

Update docs and remove TaskPriority::BACKGROUND for good

TBR=robliao@chromium.org

Bug: 863341
Change-Id: I055ac623767c1d77895d78dbf544a2d781a6637d
Reviewed-on: https://chromium-review.googlesource.com/1153461
Commit-Queue: Gabriel Charette <gab@chromium.org>
Reviewed-by: default avatarRobert Liao <robliao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#578802}
parent 032f1acb
...@@ -77,7 +77,7 @@ BASE_EXPORT void PostTask(const Location& from_here, OnceClosure task); ...@@ -77,7 +77,7 @@ BASE_EXPORT void PostTask(const Location& from_here, OnceClosure task);
// expires. Calling this is equivalent to calling PostDelayedTaskWithTraits with // expires. Calling this is equivalent to calling PostDelayedTaskWithTraits with
// plain TaskTraits. // plain TaskTraits.
// //
// Use PostDelayedTaskWithTraits to specify a BACKGROUND priority if the task // Use PostDelayedTaskWithTraits to specify a BEST_EFFORT priority if the task
// doesn't have to run as soon as |delay| expires. // doesn't have to run as soon as |delay| expires.
BASE_EXPORT void PostDelayedTask(const Location& from_here, BASE_EXPORT void PostDelayedTask(const Location& from_here,
OnceClosure task, OnceClosure task,
...@@ -127,8 +127,8 @@ BASE_EXPORT void PostTaskWithTraits(const Location& from_here, ...@@ -127,8 +127,8 @@ BASE_EXPORT void PostTaskWithTraits(const Location& from_here,
// Posts |task| with specific |traits| to the TaskScheduler. |task| will not run // Posts |task| with specific |traits| to the TaskScheduler. |task| will not run
// before |delay| expires. // before |delay| expires.
// //
// Specify a BACKGROUND priority via |traits| if the task doesn't have to run as // Specify a BEST_EFFORT priority via |traits| if the task doesn't have to run
// soon as |delay| expires. // as soon as |delay| expires.
BASE_EXPORT void PostDelayedTaskWithTraits(const Location& from_here, BASE_EXPORT void PostDelayedTaskWithTraits(const Location& from_here,
const TaskTraits& traits, const TaskTraits& traits,
OnceClosure task, OnceClosure task,
......
...@@ -94,9 +94,9 @@ TEST(TaskSchedulerSequenceTest, PushTakeRemove) { ...@@ -94,9 +94,9 @@ TEST(TaskSchedulerSequenceTest, PushTakeRemove) {
EXPECT_TRUE(sequence->Pop()); EXPECT_TRUE(sequence->Pop());
} }
// Verifies the sort key of a sequence that contains one BACKGROUND task. // Verifies the sort key of a sequence that contains one BEST_EFFORT task.
TEST(TaskSchedulerSequenceTest, GetSortKeyBackground) { TEST(TaskSchedulerSequenceTest, GetSortKeyBackground) {
// Create a sequence with a BACKGROUND task. // Create a sequence with a BEST_EFFORT task.
Task background_task(FROM_HERE, DoNothing(), {TaskPriority::BEST_EFFORT}, Task background_task(FROM_HERE, DoNothing(), {TaskPriority::BEST_EFFORT},
TimeDelta()); TimeDelta());
scoped_refptr<Sequence> background_sequence = MakeRefCounted<Sequence>(); scoped_refptr<Sequence> background_sequence = MakeRefCounted<Sequence>();
......
...@@ -228,15 +228,14 @@ std::vector<const HistogramBase*> TaskSchedulerImpl::GetHistograms() const { ...@@ -228,15 +228,14 @@ std::vector<const HistogramBase*> TaskSchedulerImpl::GetHistograms() const {
int TaskSchedulerImpl::GetMaxConcurrentNonBlockedTasksWithTraitsDeprecated( int TaskSchedulerImpl::GetMaxConcurrentNonBlockedTasksWithTraitsDeprecated(
const TaskTraits& traits) const { const TaskTraits& traits) const {
// This method does not support getting the maximum number of BACKGROUND tasks // This method does not support getting the maximum number of BEST_EFFORT
// that can run concurrently in a pool. // tasks that can run concurrently in a pool.
DCHECK_NE(traits.priority(), TaskPriority::BEST_EFFORT); DCHECK_NE(traits.priority(), TaskPriority::BEST_EFFORT);
return GetWorkerPoolForTraits(traits) return GetWorkerPoolForTraits(traits)
->GetMaxConcurrentNonBlockedTasksDeprecated(); ->GetMaxConcurrentNonBlockedTasksDeprecated();
} }
void TaskSchedulerImpl::Shutdown() { void TaskSchedulerImpl::Shutdown() {
// TODO(fdoray): Increase the priority of BACKGROUND tasks blocking shutdown.
task_tracker_->Shutdown(); task_tracker_->Shutdown();
} }
......
...@@ -15,7 +15,7 @@ namespace base { ...@@ -15,7 +15,7 @@ namespace base {
const char* TaskPriorityToString(TaskPriority task_priority) { const char* TaskPriorityToString(TaskPriority task_priority) {
switch (task_priority) { switch (task_priority) {
case TaskPriority::BEST_EFFORT: case TaskPriority::BEST_EFFORT:
return "BACKGROUND"; return "BEST_EFFORT";
case TaskPriority::USER_VISIBLE: case TaskPriority::USER_VISIBLE:
return "USER_VISIBLE"; return "USER_VISIBLE";
case TaskPriority::USER_BLOCKING: case TaskPriority::USER_BLOCKING:
......
...@@ -23,13 +23,10 @@ namespace base { ...@@ -23,13 +23,10 @@ namespace base {
enum class TaskPriority { enum class TaskPriority {
// This will always be equal to the lowest priority available. // This will always be equal to the lowest priority available.
LOWEST = 0, LOWEST = 0,
// User won't notice if this task takes an arbitrarily long time to complete.
// TODO(gab): Eliminate BACKGROUND in favor of BEST_EFFORT.
BACKGROUND = LOWEST,
// This task will only be scheduled when machine resources are available. Once // This task will only be scheduled when machine resources are available. Once
// running, it may be descheduled if higher priority work arrives (in this // running, it may be descheduled if higher priority work arrives (in this
// process or another) and its running on a non-critical thread. // process or another) and its running on a non-critical thread.
BEST_EFFORT = BACKGROUND, BEST_EFFORT = LOWEST,
// This task affects UI or responsiveness of future user interactions. It is // This task affects UI or responsiveness of future user interactions. It is
// not an immediate response to a user interaction. // not an immediate response to a user interaction.
// Examples: // Examples:
...@@ -77,8 +74,9 @@ enum class TaskShutdownBehavior { ...@@ -77,8 +74,9 @@ enum class TaskShutdownBehavior {
// until they're executed. Generally, this should be used only to save // until they're executed. Generally, this should be used only to save
// critical user data. // critical user data.
// //
// Note: Tasks with BACKGROUND priority that block shutdown will be promoted // Note: Background threads will be promoted to normal threads at shutdown
// to USER_VISIBLE priority during shutdown. // (i.e. TaskPriority::BEST_EFFORT + TaskShutdownBehavior::BLOCK_SHUTDOWN will
// resolve without a priority inversion).
BLOCK_SHUTDOWN, BLOCK_SHUTDOWN,
}; };
......
...@@ -68,7 +68,7 @@ void IntersectCertificates( ...@@ -68,7 +68,7 @@ void IntersectCertificates(
// This is triggered by a call to the // This is triggered by a call to the
// chrome.platformKeys.selectClientCertificates extensions API. Completion // chrome.platformKeys.selectClientCertificates extensions API. Completion
// does not affect browser responsiveness, hence the BACKGROUND priority. // does not affect browser responsiveness, hence the BEST_EFFORT priority.
base::PostTaskWithTraitsAndReply( base::PostTaskWithTraitsAndReply(
FROM_HERE, FROM_HERE,
{base::TaskPriority::BEST_EFFORT, {base::TaskPriority::BEST_EFFORT,
......
...@@ -68,7 +68,7 @@ class ModuleInspector { ...@@ -68,7 +68,7 @@ class ModuleInspector {
base::queue<ModuleInfoKey> queue_; base::queue<ModuleInfoKey> queue_;
// The task runner where module inspections takes place. It originally starts // The task runner where module inspections takes place. It originally starts
// at BACKGROUND priority, but is changed to USER_VISIBLE when // at BEST_EFFORT priority, but is changed to USER_VISIBLE when
// IncreaseInspectionPriority() is called. // IncreaseInspectionPriority() is called.
scoped_refptr<base::SequencedTaskRunner> task_runner_; scoped_refptr<base::SequencedTaskRunner> task_runner_;
......
...@@ -123,7 +123,7 @@ void MaybeDeleteMediaCache(const base::FilePath& media_cache_path) { ...@@ -123,7 +123,7 @@ void MaybeDeleteMediaCache(const base::FilePath& media_cache_path) {
} }
base::PostTaskWithTraits( base::PostTaskWithTraits(
FROM_HERE, FROM_HERE,
{base::TaskPriority::BACKGROUND, base::MayBlock(), {base::TaskPriority::BEST_EFFORT, base::MayBlock(),
base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN}, base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN},
base::BindOnce(base::IgnoreResult(&base::DeleteFile), media_cache_path, base::BindOnce(base::IgnoreResult(&base::DeleteFile), media_cache_path,
true /* recursive */)); true /* recursive */));
......
...@@ -187,7 +187,7 @@ namespace internals { ...@@ -187,7 +187,7 @@ namespace internals {
// Run an IO task on a worker thread. Ownership of |shortcut_info| transfers // Run an IO task on a worker thread. Ownership of |shortcut_info| transfers
// to a closure that deletes it on the UI thread when the task is complete. // to a closure that deletes it on the UI thread when the task is complete.
// Tasks posted here run with BACKGROUND priority and block shutdown. // Tasks posted here run with BEST_EFFORT priority and block shutdown.
void PostShortcutIOTask(base::OnceCallback<void(const ShortcutInfo&)> task, void PostShortcutIOTask(base::OnceCallback<void(const ShortcutInfo&)> task,
std::unique_ptr<ShortcutInfo> shortcut_info); std::unique_ptr<ShortcutInfo> shortcut_info);
void PostShortcutIOTaskAndReply( void PostShortcutIOTaskAndReply(
......
...@@ -59,7 +59,7 @@ class OptimizationGuideService { ...@@ -59,7 +59,7 @@ class OptimizationGuideService {
void SetLatestProcessedVersionForTesting(const base::Version& version); void SetLatestProcessedVersionForTesting(const base::Version& version);
private: private:
// Always called as part of a background priority task. // Always called as part of a BEST_EFFORT priority task.
void ProcessHintsInBackground(const ComponentInfo& component_info); void ProcessHintsInBackground(const ComponentInfo& component_info);
// Adds the observer on IO thread. // Adds the observer on IO thread.
......
...@@ -380,12 +380,12 @@ of how to specify `TaskTraits`. ...@@ -380,12 +380,12 @@ of how to specify `TaskTraits`.
```cpp ```cpp
// This task has no explicit TaskTraits. It cannot block. Its priority // This task has no explicit TaskTraits. It cannot block. Its priority
// is inherited from the calling context (e.g. if it is posted from // is inherited from the calling context (e.g. if it is posted from
// a BACKGROUND task, it will have a BACKGROUND priority). It will either // a BEST_EFFORT task, it will have a BEST_EFFORT priority). It will either
// block shutdown or be skipped on shutdown. // block shutdown or be skipped on shutdown.
base::PostTask(FROM_HERE, base::BindOnce(...)); base::PostTask(FROM_HERE, base::BindOnce(...));
// This task has the highest priority. The task scheduler will try to // This task has the highest priority. The task scheduler will try to
// run it before USER_VISIBLE and BACKGROUND tasks. // run it before USER_VISIBLE and BEST_EFFORT tasks.
base::PostTaskWithTraits( base::PostTaskWithTraits(
FROM_HERE, {base::TaskPriority::USER_BLOCKING}, FROM_HERE, {base::TaskPriority::USER_BLOCKING},
base::BindOnce(...)); base::BindOnce(...));
......
...@@ -43,7 +43,7 @@ base::TaskTraits TaskQueuePriority2Traits(TaskQueue::Priority priority) { ...@@ -43,7 +43,7 @@ base::TaskTraits TaskQueuePriority2Traits(TaskQueue::Priority priority) {
#endif #endif
break; break;
case TaskQueue::Priority::LOW: case TaskQueue::Priority::LOW:
return {base::MayBlock(), base::TaskPriority::BACKGROUND}; return {base::MayBlock(), base::TaskPriority::BEST_EFFORT};
case TaskQueue::Priority::NORMAL: case TaskQueue::Priority::NORMAL:
default: default:
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
......
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