#include "content/browser/scheduler/browser_task_executor.h"
#include <atomic>
#include "base/functional/bind.h"
#include "base/message_loop/message_pump_type.h"
#include "base/run_loop.h"
#include "base/task/deferred_sequenced_task_runner.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/single_thread_task_runner.h"
#include "base/threading/threading_features.h"
#include "base/time/time.h"
#include "base/trace_event/trace_event.h"
#include "build/build_config.h"
#include "content/browser/browser_process_io_thread.h"
#include "content/browser/browser_thread_impl.h"
#include "content/common/features.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/common/content_features.h"
#if BUILDFLAG(IS_ANDROID)
#include "base/android/task_scheduler/post_task_android.h"
#include "base/android/task_scheduler/task_runner_android.h"
#include "base/android/task_scheduler/task_traits_android.h"
#endif
QueueType;
namespace content {
namespace {
BrowserTaskExecutor* g_browser_task_executor = …;
#if BUILDFLAG(IS_ANDROID)
scoped_refptr<base::SingleThreadTaskRunner> GetTaskRunnerForAndroidMainThread(
::TaskTraits android_traits) {
BrowserTaskTraits traits;
switch (android_traits) {
case ::TaskTraits::UI_BEST_EFFORT:
traits = {base::TaskPriority::BEST_EFFORT};
break;
case ::TaskTraits::UI_USER_VISIBLE:
traits = {base::TaskPriority::USER_VISIBLE};
break;
case ::TaskTraits::UI_USER_BLOCKING:
traits = {base::TaskPriority::USER_BLOCKING};
break;
default:
NOTREACHED_IN_MIGRATION();
}
return g_browser_task_executor->GetUIThreadTaskRunner(traits);
}
#endif
}
BaseBrowserTaskExecutor::BaseBrowserTaskExecutor() = default;
BaseBrowserTaskExecutor::~BaseBrowserTaskExecutor() = default;
scoped_refptr<base::SingleThreadTaskRunner>
BaseBrowserTaskExecutor::GetTaskRunner(BrowserThread::ID identifier,
const BrowserTaskTraits& traits) const { … }
QueueType BaseBrowserTaskExecutor::GetQueueType(
const BrowserTaskTraits& traits) { … }
BrowserTaskExecutor::BrowserTaskExecutor(
std::unique_ptr<BrowserUIThreadScheduler> browser_ui_thread_scheduler,
std::unique_ptr<BrowserIOThreadDelegate> browser_io_thread_delegate)
: … { … }
BrowserTaskExecutor::~BrowserTaskExecutor() = default;
void BrowserTaskExecutor::Create() { … }
void BrowserTaskExecutor::CreateForTesting(
std::unique_ptr<BrowserUIThreadScheduler> browser_ui_thread_scheduler,
std::unique_ptr<BrowserIOThreadDelegate> browser_io_thread_delegate) { … }
void BrowserTaskExecutor::CreateInternal(
std::unique_ptr<BrowserUIThreadScheduler> browser_ui_thread_scheduler,
std::unique_ptr<BrowserIOThreadDelegate> browser_io_thread_delegate) { … }
BrowserTaskExecutor* BrowserTaskExecutor::Get() { … }
void BrowserTaskExecutor::ResetForTesting() { … }
void BrowserTaskExecutor::PostFeatureListSetup() { … }
std::optional<BrowserUIThreadScheduler::UserInputActiveHandle>
BrowserTaskExecutor::OnUserInputStart() { … }
void BrowserTaskExecutor::Shutdown() { … }
void BrowserTaskExecutor::RunAllPendingTasksOnThreadForTesting(
BrowserThread::ID identifier) { … }
void BrowserTaskExecutor::OnStartupComplete() { … }
scoped_refptr<base::SingleThreadTaskRunner>
BrowserTaskExecutor::GetUIThreadTaskRunner(const BrowserTaskTraits& traits) { … }
scoped_refptr<base::SingleThreadTaskRunner>
BrowserTaskExecutor::GetIOThreadTaskRunner(const BrowserTaskTraits& traits) { … }
void BrowserTaskExecutor::InitializeIOThread() { … }
std::unique_ptr<BrowserProcessIOThread> BrowserTaskExecutor::CreateIOThread() { … }
BrowserTaskExecutor::UIThreadExecutor::UIThreadExecutor(
std::unique_ptr<BrowserUIThreadScheduler> browser_ui_thread_scheduler)
: … { … }
BrowserTaskExecutor::UIThreadExecutor::~UIThreadExecutor() = default;
std::optional<BrowserUIThreadScheduler::UserInputActiveHandle>
BrowserTaskExecutor::UIThreadExecutor::OnUserInputStart() { … }
void BrowserTaskExecutor::UIThreadExecutor::PostFeatureListSetup() { … }
scoped_refptr<BrowserUIThreadScheduler::Handle>
BrowserTaskExecutor::UIThreadExecutor::GetUIThreadHandle() { … }
void BrowserTaskExecutor::UIThreadExecutor::SetIOThreadHandle(
scoped_refptr<BrowserUIThreadScheduler::Handle> io_thread_handle) { … }
BrowserTaskExecutor::IOThreadExecutor::IOThreadExecutor(
std::unique_ptr<BrowserIOThreadDelegate> browser_io_thread_delegate)
: … { … }
BrowserTaskExecutor::IOThreadExecutor::~IOThreadExecutor() = default;
scoped_refptr<BrowserUIThreadScheduler::Handle>
BrowserTaskExecutor::IOThreadExecutor::GetIOThreadHandle() { … }
void BrowserTaskExecutor::IOThreadExecutor::SetUIThreadHandle(
scoped_refptr<BrowserUIThreadScheduler::Handle> ui_thread_handle) { … }
}