#include "third_party/blink/renderer/platform/scheduler/main_thread/frame_scheduler_impl.h"
#include <memory>
#include "base/feature_list.h"
#include "base/memory/ptr_util.h"
#include "base/metrics/field_trial_params.h"
#include "base/metrics/histogram_functions.h"
#include "base/task/common/lazy_now.h"
#include "base/task/common/scoped_defer_task_posting.h"
#include "base/task/common/task_annotator.h"
#include "base/task/single_thread_task_runner.h"
#include "base/threading/platform_thread.h"
#include "base/time/time.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/common/scheduler/web_scheduler_tracked_feature.h"
#include "third_party/blink/public/platform/web_string.h"
#include "third_party/blink/renderer/platform/back_forward_cache_utils.h"
#include "third_party/blink/renderer/platform/runtime_enabled_features.h"
#include "third_party/blink/renderer/platform/scheduler/common/features.h"
#include "third_party/blink/renderer/platform/scheduler/common/task_priority.h"
#include "third_party/blink/renderer/platform/scheduler/common/throttling/budget_pool.h"
#include "third_party/blink/renderer/platform/scheduler/common/throttling/type.h"
#include "third_party/blink/renderer/platform/scheduler/common/tracing_helper.h"
#include "third_party/blink/renderer/platform/scheduler/main_thread/find_in_page_budget_pool_controller.h"
#include "third_party/blink/renderer/platform/scheduler/main_thread/main_thread_scheduler_impl.h"
#include "third_party/blink/renderer/platform/scheduler/main_thread/main_thread_task_queue.h"
#include "third_party/blink/renderer/platform/scheduler/main_thread/main_thread_web_scheduling_task_queue_impl.h"
#include "third_party/blink/renderer/platform/scheduler/main_thread/page_scheduler_impl.h"
#include "third_party/blink/renderer/platform/scheduler/main_thread/page_visibility_state.h"
#include "third_party/blink/renderer/platform/scheduler/main_thread/policy_updater.h"
#include "third_party/blink/renderer/platform/scheduler/main_thread/task_type_names.h"
#include "third_party/blink/renderer/platform/scheduler/public/web_scheduling_queue_type.h"
#include "third_party/blink/renderer/platform/scheduler/worker/worker_scheduler_proxy.h"
#include "third_party/perfetto/include/perfetto/tracing/traced_value.h"
namespace blink {
namespace scheduler {
TaskQueue;
QueueTraits;
RendererMainThreadTaskExecution;
namespace {
BASE_FEATURE(…);
const char* VisibilityStateToString(bool is_visible) { … }
const char* IsVisibleAreaLargeStateToString(bool is_large) { … }
const char* UserActivationStateToString(bool had_user_activation) { … }
const char* PausedStateToString(bool is_paused) { … }
const char* FrozenStateToString(bool is_frozen) { … }
void UpdatePriority(MainThreadTaskQueue* task_queue) { … }
TaskPriority GetLowPriorityAsyncScriptTaskPriority() { … }
}
FrameSchedulerImpl::PauseSubresourceLoadingHandleImpl::
PauseSubresourceLoadingHandleImpl(
base::WeakPtr<FrameSchedulerImpl> frame_scheduler)
: … { … }
FrameSchedulerImpl::PauseSubresourceLoadingHandleImpl::
~PauseSubresourceLoadingHandleImpl() { … }
FrameSchedulerImpl::FrameSchedulerImpl(PageSchedulerImpl* parent_page_scheduler,
FrameScheduler::Delegate* delegate,
bool is_in_embedded_frame_tree,
FrameScheduler::FrameType frame_type)
: … { … }
FrameSchedulerImpl::FrameSchedulerImpl(
MainThreadSchedulerImpl* main_thread_scheduler,
PageSchedulerImpl* parent_page_scheduler,
FrameScheduler::Delegate* delegate,
bool is_in_embedded_frame_tree,
FrameScheduler::FrameType frame_type)
: … { … }
FrameSchedulerImpl::FrameSchedulerImpl()
: … { … }
FrameSchedulerImpl::~FrameSchedulerImpl() { … }
AgentGroupSchedulerImpl& FrameSchedulerImpl::GetAgentGroupSchedulerImpl() { … }
void FrameSchedulerImpl::OnPageVisibilityChange(
PageVisibilityState page_visibility,
PolicyUpdater& policy_updater) { … }
void FrameSchedulerImpl::OnPageSchedulerDeletion(
PolicyUpdater& policy_updater) { … }
void FrameSchedulerImpl::OnFrameAndPageVisibleChanged(
PolicyUpdater& policy_updater) { … }
void FrameSchedulerImpl::RemoveThrottleableQueueFromBudgetPools(
MainThreadTaskQueue* task_queue) { … }
void FrameSchedulerImpl::SetFrameVisible(bool frame_visible) { … }
bool FrameSchedulerImpl::IsFrameVisible() const { … }
void FrameSchedulerImpl::SetVisibleAreaLarge(bool is_large) { … }
void FrameSchedulerImpl::SetHadUserActivation(bool had_user_activation) { … }
void FrameSchedulerImpl::SetCrossOriginToNearestMainFrame(bool cross_origin) { … }
void FrameSchedulerImpl::SetIsAdFrame(bool is_ad_frame) { … }
bool FrameSchedulerImpl::IsAdFrame() const { … }
bool FrameSchedulerImpl::IsInEmbeddedFrameTree() const { … }
bool FrameSchedulerImpl::IsCrossOriginToNearestMainFrame() const { … }
void FrameSchedulerImpl::SetAgentClusterId(
const base::UnguessableToken& agent_cluster_id) { … }
void FrameSchedulerImpl::TraceUrlChange(const String& url) { … }
void FrameSchedulerImpl::AddTaskTime(base::TimeDelta time) { … }
FrameScheduler::FrameType FrameSchedulerImpl::GetFrameType() const { … }
QueueTraits FrameSchedulerImpl::CreateQueueTraitsForTaskType(TaskType type) { … }
scoped_refptr<base::SingleThreadTaskRunner> FrameSchedulerImpl::GetTaskRunner(
TaskType type) { … }
scoped_refptr<MainThreadTaskQueue> FrameSchedulerImpl::GetTaskQueue(
TaskType type) { … }
scoped_refptr<base::SingleThreadTaskRunner>
FrameSchedulerImpl::ControlTaskRunner() { … }
AgentGroupScheduler* FrameSchedulerImpl::GetAgentGroupScheduler() { … }
blink::PageScheduler* FrameSchedulerImpl::GetPageScheduler() const { … }
void FrameSchedulerImpl::DidStartProvisionalLoad() { … }
void FrameSchedulerImpl::DidCommitProvisionalLoad(
bool is_web_history_inert_commit,
NavigationType navigation_type,
DidCommitProvisionalLoadParams params) { … }
WebScopedVirtualTimePauser FrameSchedulerImpl::CreateWebScopedVirtualTimePauser(
const WTF::String& name,
WebScopedVirtualTimePauser::VirtualTaskDuration duration) { … }
scoped_refptr<base::SingleThreadTaskRunner>
FrameSchedulerImpl::CompositorTaskRunner() { … }
void FrameSchedulerImpl::ResetForNavigation() { … }
bool FrameSchedulerImpl::IsImportant() const { … }
bool FrameSchedulerImpl::AreFrameAndPageVisible() const { … }
void FrameSchedulerImpl::OnStartedUsingNonStickyFeature(
SchedulingPolicy::Feature feature,
const SchedulingPolicy& policy,
std::unique_ptr<SourceLocation> source_location,
SchedulingAffectingFeatureHandle* handle) { … }
void FrameSchedulerImpl::OnStartedUsingStickyFeature(
SchedulingPolicy::Feature feature,
const SchedulingPolicy& policy,
std::unique_ptr<SourceLocation> source_location) { … }
void FrameSchedulerImpl::OnStoppedUsingNonStickyFeature(
SchedulingAffectingFeatureHandle* handle) { … }
base::WeakPtr<FrameScheduler> FrameSchedulerImpl::GetWeakPtr() { … }
base::WeakPtr<const FrameSchedulerImpl> FrameSchedulerImpl::GetWeakPtr() const { … }
void FrameSchedulerImpl::ReportActiveSchedulerTrackedFeatures() { … }
base::WeakPtr<FrameSchedulerImpl>
FrameSchedulerImpl::GetInvalidatingOnBFCacheRestoreWeakPtr() { … }
void FrameSchedulerImpl::OnAddedAggressiveThrottlingOptOut() { … }
void FrameSchedulerImpl::OnRemovedAggressiveThrottlingOptOut() { … }
void FrameSchedulerImpl::OnTaskCompleted(TaskQueue::TaskTiming* timing) { … }
void FrameSchedulerImpl::WriteIntoTrace(perfetto::TracedValue context) const { … }
void FrameSchedulerImpl::WriteIntoTrace(
perfetto::TracedProto<
perfetto::protos::pbzero::RendererMainThreadTaskExecution> proto)
const { … }
bool FrameSchedulerImpl::IsPageVisible() const { … }
void FrameSchedulerImpl::SetPaused(bool frame_paused) { … }
void FrameSchedulerImpl::SetShouldReportPostedTasksWhenDisabled(
bool should_report) { … }
void FrameSchedulerImpl::SetPageFrozenForTracing(bool frozen) { … }
void FrameSchedulerImpl::UpdatePolicy() { … }
void FrameSchedulerImpl::UpdateQueuePolicy(
MainThreadTaskQueue* queue,
TaskQueue::QueueEnabledVoter* voter) { … }
SchedulingLifecycleState FrameSchedulerImpl::CalculateLifecycleState(
ObserverType type) const { … }
void FrameSchedulerImpl::OnFirstContentfulPaintInMainFrame() { … }
void FrameSchedulerImpl::OnMainFrameInteractive() { … }
void FrameSchedulerImpl::OnFirstMeaningfulPaint(base::TimeTicks timestamp) { … }
void FrameSchedulerImpl::OnDispatchLoadEvent() { … }
bool FrameSchedulerImpl::IsWaitingForContentfulPaint() const { … }
bool FrameSchedulerImpl::IsWaitingForMeaningfulPaint() const { … }
bool FrameSchedulerImpl::IsLoading() const { … }
bool FrameSchedulerImpl::IsOrdinary() const { … }
ThrottlingType FrameSchedulerImpl::ComputeThrottlingType() { … }
bool FrameSchedulerImpl::IsExemptFromBudgetBasedThrottling() const { … }
TaskPriority FrameSchedulerImpl::ComputePriority(
MainThreadTaskQueue* task_queue) const { … }
std::unique_ptr<blink::mojom::blink::PauseSubresourceLoadingHandle>
FrameSchedulerImpl::GetPauseSubresourceLoadingHandle() { … }
void FrameSchedulerImpl::AddPauseSubresourceLoadingHandle() { … }
void FrameSchedulerImpl::RemovePauseSubresourceLoadingHandle() { … }
ukm::UkmRecorder* FrameSchedulerImpl::GetUkmRecorder() { … }
ukm::SourceId FrameSchedulerImpl::GetUkmSourceId() { … }
void FrameSchedulerImpl::OnTaskQueueCreated(
MainThreadTaskQueue* task_queue,
base::sequence_manager::TaskQueue::QueueEnabledVoter* voter) { … }
void FrameSchedulerImpl::SetOnIPCTaskPostedWhileInBackForwardCacheHandler() { … }
void FrameSchedulerImpl::DetachOnIPCTaskPostedWhileInBackForwardCacheHandler() { … }
void FrameSchedulerImpl::OnIPCTaskPostedWhileInBackForwardCache(
uint32_t ipc_hash,
const char* ipc_interface_name) { … }
WTF::HashSet<SchedulingPolicy::Feature>
FrameSchedulerImpl::GetActiveFeaturesTrackedForBackForwardCacheMetrics() { … }
base::WeakPtr<FrameOrWorkerScheduler>
FrameSchedulerImpl::GetFrameOrWorkerSchedulerWeakPtr() { … }
std::unique_ptr<WebSchedulingTaskQueue>
FrameSchedulerImpl::CreateWebSchedulingTaskQueue(
WebSchedulingQueueType queue_type,
WebSchedulingPriority priority) { … }
void FrameSchedulerImpl::OnWebSchedulingTaskQueuePriorityChanged(
MainThreadTaskQueue* queue) { … }
void FrameSchedulerImpl::OnWebSchedulingTaskQueueDestroyed(
MainThreadTaskQueue* queue) { … }
const base::UnguessableToken& FrameSchedulerImpl::GetAgentClusterId() const { … }
base::TimeDelta FrameSchedulerImpl::UnreportedTaskTime() const { … }
bool FrameSchedulerImpl::ComputeCanBeDeferredForRendering(
bool is_deferrable_for_touchstart,
TaskType task_type) const { … }
MainThreadTaskQueue::QueueTraits
FrameSchedulerImpl::ThrottleableTaskQueueTraits() { … }
MainThreadTaskQueue::QueueTraits
FrameSchedulerImpl::DeferrableTaskQueueTraits() { … }
MainThreadTaskQueue::QueueTraits FrameSchedulerImpl::PausableTaskQueueTraits() { … }
MainThreadTaskQueue::QueueTraits
FrameSchedulerImpl::FreezableTaskQueueTraits() { … }
MainThreadTaskQueue::QueueTraits
FrameSchedulerImpl::UnpausableTaskQueueTraits() { … }
MainThreadTaskQueue::QueueTraits
FrameSchedulerImpl::ForegroundOnlyTaskQueueTraits() { … }
MainThreadTaskQueue::QueueTraits
FrameSchedulerImpl::CanRunWhenVirtualTimePausedTaskQueueTraits() { … }
void FrameSchedulerImpl::SetPreemptedForCooperativeScheduling(
Preempted preempted) { … }
MainThreadTaskQueue::QueueTraits FrameSchedulerImpl::LoadingTaskQueueTraits() { … }
MainThreadTaskQueue::QueueTraits
FrameSchedulerImpl::UnfreezableLoadingTaskQueueTraits() { … }
MainThreadTaskQueue::QueueTraits
FrameSchedulerImpl::LoadingControlTaskQueueTraits() { … }
MainThreadTaskQueue::QueueTraits
FrameSchedulerImpl::FindInPageTaskQueueTraits() { … }
MainThreadTaskQueue::QueueTraits
FrameSchedulerImpl::InputBlockingQueueTraits() { … }
}
}