#include "base/task/thread_pool/task_tracker.h"
#include <atomic>
#include <optional>
#include <string>
#include <utility>
#include "base/base_switches.h"
#include "base/command_line.h"
#include "base/compiler_specific.h"
#include "base/debug/alias.h"
#include "base/functional/callback.h"
#include "base/json/json_writer.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/metrics/histogram_macros.h"
#include "base/notreached.h"
#include "base/sequence_token.h"
#include "base/strings/string_util.h"
#include "base/synchronization/condition_variable.h"
#include "base/synchronization/waitable_event.h"
#include "base/task/scoped_set_task_priority_for_current_thread.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/single_thread_task_runner.h"
#include "base/task/thread_pool/job_task_source.h"
#include "base/task/thread_pool/task_source.h"
#include "base/threading/sequence_local_storage_map.h"
#include "base/threading/thread_restrictions.h"
#include "base/time/time.h"
#include "base/trace_event/base_tracing.h"
#include "base/values.h"
#include "build/build_config.h"
#include "third_party/abseil-cpp/absl/base/attributes.h"
namespace base {
namespace internal {
namespace {
#if BUILDFLAG(ENABLE_BASE_TRACING)
ChromeThreadPoolTask;
ChromeTrackEvent;
#endif
constexpr const char* kExecutionModeString[] = …;
static_assert …;
bool HasLogBestEffortTasksSwitch() { … }
#if BUILDFLAG(ENABLE_BASE_TRACING)
ChromeThreadPoolTask::Priority TaskPriorityToProto(TaskPriority priority) { … }
ChromeThreadPoolTask::ExecutionMode ExecutionModeToProto(
TaskSourceExecutionMode mode) { … }
ChromeThreadPoolTask::ShutdownBehavior ShutdownBehaviorToProto(
TaskShutdownBehavior shutdown_behavior) { … }
#endif
auto EmitThreadPoolTraceEventMetadata(perfetto::EventContext& ctx,
const TaskTraits& traits,
TaskSource* task_source,
const SequenceToken& token) { … }
ABSL_CONST_INIT thread_local int fizzle_block_shutdown_tasks_ref = …;
}
class TaskTracker::State { … };
TaskTracker::TaskTracker()
: … { … }
TaskTracker::~TaskTracker() = default;
void TaskTracker::StartShutdown() { … }
void TaskTracker::CompleteShutdown() { … }
void TaskTracker::FlushForTesting() { … }
void TaskTracker::FlushAsyncForTesting(OnceClosure flush_callback) { … }
void TaskTracker::SetCanRunPolicy(CanRunPolicy can_run_policy) { … }
void TaskTracker::WillEnqueueJob(JobTaskSource* task_source) { … }
bool TaskTracker::WillPostTask(Task* task,
TaskShutdownBehavior shutdown_behavior) { … }
bool TaskTracker::WillPostTaskNow(const Task& task,
TaskPriority priority) const { … }
RegisteredTaskSource TaskTracker::RegisterTaskSource(
scoped_refptr<TaskSource> task_source) { … }
bool TaskTracker::CanRunPriority(TaskPriority priority) const { … }
RegisteredTaskSource TaskTracker::RunAndPopNextTask(
RegisteredTaskSource task_source) { … }
bool TaskTracker::HasShutdownStarted() const { … }
bool TaskTracker::IsShutdownComplete() const { … }
void TaskTracker::BeginFizzlingBlockShutdownTasks() { … }
void TaskTracker::EndFizzlingBlockShutdownTasks() { … }
void TaskTracker::RunTask(Task task,
TaskSource* task_source,
const TaskTraits& traits) { … }
void TaskTracker::BeginCompleteShutdown(base::WaitableEvent& shutdown_event) { … }
bool TaskTracker::HasIncompleteTaskSourcesForTesting() const { … }
bool TaskTracker::BeforeQueueTaskSource(
TaskShutdownBehavior shutdown_behavior) { … }
bool TaskTracker::BeforeRunTask(TaskShutdownBehavior shutdown_behavior) { … }
void TaskTracker::AfterRunTask(TaskShutdownBehavior shutdown_behavior) { … }
scoped_refptr<TaskSource> TaskTracker::UnregisterTaskSource(
scoped_refptr<TaskSource> task_source) { … }
void TaskTracker::DecrementNumItemsBlockingShutdown() { … }
void TaskTracker::DecrementNumIncompleteTaskSources() { … }
void TaskTracker::InvokeFlushCallbacksForTesting() { … }
NOINLINE void TaskTracker::RunContinueOnShutdown(Task& task,
const TaskTraits& traits,
TaskSource* task_source,
const SequenceToken& token) { … }
NOINLINE void TaskTracker::RunSkipOnShutdown(Task& task,
const TaskTraits& traits,
TaskSource* task_source,
const SequenceToken& token) { … }
NOINLINE void TaskTracker::RunBlockShutdown(Task& task,
const TaskTraits& traits,
TaskSource* task_source,
const SequenceToken& token) { … }
void TaskTracker::RunTaskImpl(Task& task,
const TaskTraits& traits,
TaskSource* task_source,
const SequenceToken& token) { … }
void TaskTracker::RunTaskWithShutdownBehavior(Task& task,
const TaskTraits& traits,
TaskSource* task_source,
const SequenceToken& token) { … }
}
}