chromium/base/task/sequence_manager/thread_controller_with_message_pump_impl.cc

// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/task/sequence_manager/thread_controller_with_message_pump_impl.h"

#include <algorithm>
#include <atomic>
#include <optional>
#include <utility>

#include "base/auto_reset.h"
#include "base/feature_list.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/memory/stack_allocated.h"
#include "base/message_loop/message_pump.h"
#include "base/metrics/histogram.h"
#include "base/metrics/histogram_macros.h"
#include "base/task/sequence_manager/tasks.h"
#include "base/task/task_features.h"
#include "base/threading/hang_watcher.h"
#include "base/time/tick_clock.h"
#include "base/time/time.h"
#include "base/trace_event/base_tracing.h"
#include "build/build_config.h"

#if BUILDFLAG(IS_IOS)
#include "base/message_loop/message_pump_apple.h"
#elif BUILDFLAG(IS_ANDROID)
#include "base/message_loop/message_pump_android.h"
#endif

namespace base {
namespace sequence_manager {
namespace internal {
namespace {

// Returns |next_run_time| capped at 1 day from |lazy_now|. This is used to
// mitigate https://crbug.com/850450 where some platforms are unhappy with
// delays > 100,000,000 seconds. In practice, a diagnosis metric showed that no
// sleep > 1 hour ever completes (always interrupted by an earlier MessageLoop
// event) and 99% of completed sleeps are the ones scheduled for <= 1 second.
// Details @ https://crrev.com/c/1142589.
TimeTicks CapAtOneDay(TimeTicks next_run_time, LazyNow* lazy_now) {}

BASE_FEATURE();

#if BUILDFLAG(IS_WIN)
// If enabled, deactivate the high resolution timer immediately in DoWork(),
// instead of waiting for next DoIdleWork.
BASE_FEATURE(kUseLessHighResTimers,
             "UseLessHighResTimers",
             base::FEATURE_ENABLED_BY_DEFAULT);
std::atomic_bool g_use_less_high_res_timers = true;
#endif

std::atomic_bool g_run_tasks_by_batches =;
std::atomic_bool g_avoid_schedule_calls_during_native_event_processing =;

base::TimeDelta GetLeewayForWakeUp(std::optional<WakeUp> wake_up) {}

}  // namespace

// static
void ThreadControllerWithMessagePumpImpl::InitializeFeatures() {}

// static
void ThreadControllerWithMessagePumpImpl::ResetFeatures() {}

ThreadControllerWithMessagePumpImpl::ThreadControllerWithMessagePumpImpl(
    const SequenceManager::Settings& settings)
    :{}

ThreadControllerWithMessagePumpImpl::ThreadControllerWithMessagePumpImpl(
    std::unique_ptr<MessagePump> message_pump,
    const SequenceManager::Settings& settings)
    :{}

ThreadControllerWithMessagePumpImpl::~ThreadControllerWithMessagePumpImpl() {}

// static
std::unique_ptr<ThreadControllerWithMessagePumpImpl>
ThreadControllerWithMessagePumpImpl::CreateUnbound(
    const SequenceManager::Settings& settings) {}

ThreadControllerWithMessagePumpImpl::MainThreadOnly::MainThreadOnly() = default;

ThreadControllerWithMessagePumpImpl::MainThreadOnly::~MainThreadOnly() =
    default;

void ThreadControllerWithMessagePumpImpl::SetSequencedTaskSource(
    SequencedTaskSource* task_source) {}

void ThreadControllerWithMessagePumpImpl::BindToCurrentThread(
    std::unique_ptr<MessagePump> message_pump) {}

void ThreadControllerWithMessagePumpImpl::SetWorkBatchSize(
    int work_batch_size) {}

void ThreadControllerWithMessagePumpImpl::WillQueueTask(
    PendingTask* pending_task) {}

void ThreadControllerWithMessagePumpImpl::ScheduleWork() {}
void ThreadControllerWithMessagePumpImpl::BeginNativeWorkBeforeDoWork() {}

void ThreadControllerWithMessagePumpImpl::SetNextDelayedDoWork(
    LazyNow* lazy_now,
    std::optional<WakeUp> wake_up) {}

bool ThreadControllerWithMessagePumpImpl::RunsTasksInCurrentSequence() {}

void ThreadControllerWithMessagePumpImpl::SetDefaultTaskRunner(
    scoped_refptr<SingleThreadTaskRunner> task_runner) {}

void ThreadControllerWithMessagePumpImpl::
    InitializeSingleThreadTaskRunnerCurrentDefaultHandle() {}

scoped_refptr<SingleThreadTaskRunner>
ThreadControllerWithMessagePumpImpl::GetDefaultTaskRunner() {}

void ThreadControllerWithMessagePumpImpl::RestoreDefaultTaskRunner() {}

void ThreadControllerWithMessagePumpImpl::AddNestingObserver(
    RunLoop::NestingObserver* observer) {}

void ThreadControllerWithMessagePumpImpl::RemoveNestingObserver(
    RunLoop::NestingObserver* observer) {}

void ThreadControllerWithMessagePumpImpl::OnBeginWorkItem() {}

void ThreadControllerWithMessagePumpImpl::OnBeginWorkItemImpl(
    LazyNow& lazy_now) {}

void ThreadControllerWithMessagePumpImpl::OnEndWorkItem(int run_level_depth) {}

void ThreadControllerWithMessagePumpImpl::OnEndWorkItemImpl(
    LazyNow& lazy_now,
    int run_level_depth) {}

void ThreadControllerWithMessagePumpImpl::BeforeWait() {}

MessagePump::Delegate::NextWorkInfo
ThreadControllerWithMessagePumpImpl::DoWork() {}

std::optional<WakeUp> ThreadControllerWithMessagePumpImpl::DoWorkImpl(
    LazyNow* continuation_lazy_now) {}

bool ThreadControllerWithMessagePumpImpl::RunsTasksByBatches() const {}

void ThreadControllerWithMessagePumpImpl::DoIdleWork() {}

int ThreadControllerWithMessagePumpImpl::RunDepth() {}

void ThreadControllerWithMessagePumpImpl::Run(bool application_tasks_allowed,
                                              TimeDelta timeout) {}

void ThreadControllerWithMessagePumpImpl::OnBeginNestedRunLoop() {}

void ThreadControllerWithMessagePumpImpl::OnExitNestedRunLoop() {}

void ThreadControllerWithMessagePumpImpl::Quit() {}

void ThreadControllerWithMessagePumpImpl::EnsureWorkScheduled() {}

void ThreadControllerWithMessagePumpImpl::
    SetTaskExecutionAllowedInNativeNestedLoop(bool allowed) {}

bool ThreadControllerWithMessagePumpImpl::IsTaskExecutionAllowed() const {}

MessagePump* ThreadControllerWithMessagePumpImpl::GetBoundMessagePump() const {}

void ThreadControllerWithMessagePumpImpl::PrioritizeYieldingToNative(
    base::TimeTicks prioritize_until) {}

#if BUILDFLAG(IS_IOS)
void ThreadControllerWithMessagePumpImpl::AttachToMessagePump() {
  static_cast<MessagePumpCFRunLoopBase*>(pump_.get())->Attach(this);
}

void ThreadControllerWithMessagePumpImpl::DetachFromMessagePump() {
  static_cast<MessagePumpCFRunLoopBase*>(pump_.get())->Detach();
}
#elif BUILDFLAG(IS_ANDROID)
void ThreadControllerWithMessagePumpImpl::AttachToMessagePump() {
  CHECK(main_thread_only().work_batch_size == 1);
  // Aborting the message pump currently relies on the batch size being 1.
  main_thread_only().can_change_batch_size = false;
  static_cast<MessagePumpForUI*>(pump_.get())->Attach(this);
}
#endif

bool ThreadControllerWithMessagePumpImpl::ShouldQuitRunLoopWhenIdle() {}

}  // namespace internal
}  // namespace sequence_manager
}  // namespace base