Commit cc2090bd authored by Farah Charab's avatar Farah Charab Committed by Commit Bot

Scheduler: Minor code refactoring.

Use PageSchedulerImpl::IsBackgrounded.

Move IsLoading from main thread scheduler to page scheduler.

Change-Id: I2a7154aad19ed97ee87e44dddf655922af23fccd
Reviewed-on: https://chromium-review.googlesource.com/1111842
Commit-Queue: Farah Charab <farahcharab@chromium.org>
Reviewed-by: default avatarAlexander Timin <altimin@chromium.org>
Reviewed-by: default avatarSami Kyöstilä <skyostil@chromium.org>
Cr-Commit-Position: refs/heads/master@{#569888}
parent b8746d38
...@@ -712,9 +712,8 @@ TaskQueue::QueuePriority FrameSchedulerImpl::ComputePriority( ...@@ -712,9 +712,8 @@ TaskQueue::QueuePriority FrameSchedulerImpl::ComputePriority(
if (fixed_priority) if (fixed_priority)
return fixed_priority.value(); return fixed_priority.value();
bool background_page_with_no_audio = !IsPageVisible() && !IsAudioPlaying(); // A hidden page with no audio.
if (parent_page_scheduler_->IsBackgrounded()) {
if (background_page_with_no_audio) {
if (main_thread_scheduler_->scheduling_settings() if (main_thread_scheduler_->scheduling_settings()
.low_priority_background_page) .low_priority_background_page)
return TaskQueue::QueuePriority::kLowPriority; return TaskQueue::QueuePriority::kLowPriority;
...@@ -724,9 +723,9 @@ TaskQueue::QueuePriority FrameSchedulerImpl::ComputePriority( ...@@ -724,9 +723,9 @@ TaskQueue::QueuePriority FrameSchedulerImpl::ComputePriority(
return TaskQueue::QueuePriority::kBestEffortPriority; return TaskQueue::QueuePriority::kBestEffortPriority;
} }
// If main thread is in the loading use case or if the priority experiments // If the page is loading or if the priority experiments should take place at
// should take place at all times. // all times.
if (main_thread_scheduler_->IsLoading() || if (parent_page_scheduler_->IsLoading() ||
!main_thread_scheduler_->scheduling_settings() !main_thread_scheduler_->scheduling_settings()
.experiment_only_when_loading) { .experiment_only_when_loading) {
// Low priority feature enabled for hidden frame. // Low priority feature enabled for hidden frame.
......
...@@ -797,7 +797,7 @@ TEST_F(LowPriorityHiddenFrameDuringLoadingExperimentTest, ...@@ -797,7 +797,7 @@ TEST_F(LowPriorityHiddenFrameDuringLoadingExperimentTest,
FrameQueuesPriorities) { FrameQueuesPriorities) {
// Main thread scheduler is in the loading use case. // Main thread scheduler is in the loading use case.
scheduler_->DidStartProvisionalLoad(true); scheduler_->DidStartProvisionalLoad(true);
EXPECT_TRUE(scheduler_->IsLoading()); EXPECT_TRUE(page_scheduler_->IsLoading());
// Hidden Frame Task Queues. // Hidden Frame Task Queues.
frame_scheduler_->SetFrameVisible(false); frame_scheduler_->SetFrameVisible(false);
...@@ -816,7 +816,7 @@ TEST_F(LowPriorityHiddenFrameDuringLoadingExperimentTest, ...@@ -816,7 +816,7 @@ TEST_F(LowPriorityHiddenFrameDuringLoadingExperimentTest,
// Main thread scheduler is no longer in loading use case. // Main thread scheduler is no longer in loading use case.
scheduler_->OnFirstMeaningfulPaint(); scheduler_->OnFirstMeaningfulPaint();
EXPECT_FALSE(scheduler_->IsLoading()); EXPECT_FALSE(page_scheduler_->IsLoading());
EXPECT_EQ(LoadingTaskQueue()->GetQueuePriority(), EXPECT_EQ(LoadingTaskQueue()->GetQueuePriority(),
TaskQueue::QueuePriority::kNormalPriority); TaskQueue::QueuePriority::kNormalPriority);
...@@ -867,7 +867,7 @@ class LowPrioritySubFrameDuringLoadingExperimentTest ...@@ -867,7 +867,7 @@ class LowPrioritySubFrameDuringLoadingExperimentTest
TEST_F(LowPrioritySubFrameDuringLoadingExperimentTest, FrameQueuesPriorities) { TEST_F(LowPrioritySubFrameDuringLoadingExperimentTest, FrameQueuesPriorities) {
// Main thread scheduler is in the loading use case. // Main thread scheduler is in the loading use case.
scheduler_->DidStartProvisionalLoad(true); scheduler_->DidStartProvisionalLoad(true);
EXPECT_TRUE(scheduler_->IsLoading()); EXPECT_TRUE(page_scheduler_->IsLoading());
// Sub-Frame Task Queues. // Sub-Frame Task Queues.
EXPECT_EQ(LoadingTaskQueue()->GetQueuePriority(), EXPECT_EQ(LoadingTaskQueue()->GetQueuePriority(),
...@@ -885,7 +885,7 @@ TEST_F(LowPrioritySubFrameDuringLoadingExperimentTest, FrameQueuesPriorities) { ...@@ -885,7 +885,7 @@ TEST_F(LowPrioritySubFrameDuringLoadingExperimentTest, FrameQueuesPriorities) {
// Main thread scheduler is no longer in loading use case. // Main thread scheduler is no longer in loading use case.
scheduler_->OnFirstMeaningfulPaint(); scheduler_->OnFirstMeaningfulPaint();
EXPECT_FALSE(scheduler_->IsLoading()); EXPECT_FALSE(page_scheduler_->IsLoading());
// Sub-Frame Task Queues. // Sub-Frame Task Queues.
EXPECT_EQ(LoadingTaskQueue()->GetQueuePriority(), EXPECT_EQ(LoadingTaskQueue()->GetQueuePriority(),
...@@ -940,7 +940,7 @@ TEST_F(LowPrioritySubFrameThrottleableTaskDuringLoadingExperimentTest, ...@@ -940,7 +940,7 @@ TEST_F(LowPrioritySubFrameThrottleableTaskDuringLoadingExperimentTest,
FrameQueuesPriorities) { FrameQueuesPriorities) {
// Main thread scheduler is in the loading use case. // Main thread scheduler is in the loading use case.
scheduler_->DidStartProvisionalLoad(true); scheduler_->DidStartProvisionalLoad(true);
EXPECT_TRUE(scheduler_->IsLoading()); EXPECT_TRUE(page_scheduler_->IsLoading());
// Sub-Frame Task Queues. // Sub-Frame Task Queues.
EXPECT_EQ(LoadingTaskQueue()->GetQueuePriority(), EXPECT_EQ(LoadingTaskQueue()->GetQueuePriority(),
...@@ -958,7 +958,7 @@ TEST_F(LowPrioritySubFrameThrottleableTaskDuringLoadingExperimentTest, ...@@ -958,7 +958,7 @@ TEST_F(LowPrioritySubFrameThrottleableTaskDuringLoadingExperimentTest,
// Main thread scheduler is no longer in loading use case. // Main thread scheduler is no longer in loading use case.
scheduler_->OnFirstMeaningfulPaint(); scheduler_->OnFirstMeaningfulPaint();
EXPECT_FALSE(scheduler_->IsLoading()); EXPECT_FALSE(page_scheduler_->IsLoading());
// Sub-Frame Task Queues. // Sub-Frame Task Queues.
EXPECT_EQ(LoadingTaskQueue()->GetQueuePriority(), EXPECT_EQ(LoadingTaskQueue()->GetQueuePriority(),
...@@ -1029,7 +1029,7 @@ TEST_F(LowPriorityThrottleableTaskDuringLoadingExperimentTest, ...@@ -1029,7 +1029,7 @@ TEST_F(LowPriorityThrottleableTaskDuringLoadingExperimentTest,
SubFrameQueuesPriorities) { SubFrameQueuesPriorities) {
// Main thread is in the loading use case. // Main thread is in the loading use case.
scheduler_->DidStartProvisionalLoad(true); scheduler_->DidStartProvisionalLoad(true);
EXPECT_TRUE(scheduler_->IsLoading()); EXPECT_TRUE(page_scheduler_->IsLoading());
EXPECT_EQ(LoadingTaskQueue()->GetQueuePriority(), EXPECT_EQ(LoadingTaskQueue()->GetQueuePriority(),
TaskQueue::QueuePriority::kNormalPriority); TaskQueue::QueuePriority::kNormalPriority);
...@@ -1046,7 +1046,7 @@ TEST_F(LowPriorityThrottleableTaskDuringLoadingExperimentTest, ...@@ -1046,7 +1046,7 @@ TEST_F(LowPriorityThrottleableTaskDuringLoadingExperimentTest,
// Main thread is no longer in loading use case. // Main thread is no longer in loading use case.
scheduler_->OnFirstMeaningfulPaint(); scheduler_->OnFirstMeaningfulPaint();
EXPECT_FALSE(scheduler_->IsLoading()); EXPECT_FALSE(page_scheduler_->IsLoading());
EXPECT_EQ(LoadingTaskQueue()->GetQueuePriority(), EXPECT_EQ(LoadingTaskQueue()->GetQueuePriority(),
TaskQueue::QueuePriority::kNormalPriority); TaskQueue::QueuePriority::kNormalPriority);
...@@ -1069,7 +1069,7 @@ TEST_F(LowPriorityThrottleableTaskDuringLoadingExperimentTest, ...@@ -1069,7 +1069,7 @@ TEST_F(LowPriorityThrottleableTaskDuringLoadingExperimentTest,
// Main thread is in the loading use case. // Main thread is in the loading use case.
scheduler_->DidStartProvisionalLoad(true); scheduler_->DidStartProvisionalLoad(true);
EXPECT_TRUE(scheduler_->IsLoading()); EXPECT_TRUE(page_scheduler_->IsLoading());
// Main Frame Task Queues. // Main Frame Task Queues.
EXPECT_EQ(LoadingTaskQueue()->GetQueuePriority(), EXPECT_EQ(LoadingTaskQueue()->GetQueuePriority(),
...@@ -1087,7 +1087,7 @@ TEST_F(LowPriorityThrottleableTaskDuringLoadingExperimentTest, ...@@ -1087,7 +1087,7 @@ TEST_F(LowPriorityThrottleableTaskDuringLoadingExperimentTest,
// Main thread is no longer in loading use case. // Main thread is no longer in loading use case.
scheduler_->OnFirstMeaningfulPaint(); scheduler_->OnFirstMeaningfulPaint();
EXPECT_FALSE(scheduler_->IsLoading()); EXPECT_FALSE(page_scheduler_->IsLoading());
// Main Frame Task Queues. // Main Frame Task Queues.
EXPECT_EQ(LoadingTaskQueue()->GetQueuePriority(), EXPECT_EQ(LoadingTaskQueue()->GetQueuePriority(),
......
...@@ -2765,8 +2765,8 @@ bool MainThreadSchedulerImpl::ShouldUpdateTaskQueuePriorities( ...@@ -2765,8 +2765,8 @@ bool MainThreadSchedulerImpl::ShouldUpdateTaskQueuePriorities(
main_thread_only().current_policy.compositor_priority(); main_thread_only().current_policy.compositor_priority();
} }
bool MainThreadSchedulerImpl::IsLoading() const { UseCase MainThreadSchedulerImpl::current_use_case() const {
return main_thread_only().current_use_case == UseCase::kLoading; return main_thread_only().current_use_case;
} }
const MainThreadSchedulerImpl::SchedulingSettings& const MainThreadSchedulerImpl::SchedulingSettings&
......
...@@ -342,8 +342,7 @@ class PLATFORM_EXPORT MainThreadSchedulerImpl ...@@ -342,8 +342,7 @@ class PLATFORM_EXPORT MainThreadSchedulerImpl
void OnTraceLogEnabled() override; void OnTraceLogEnabled() override;
void OnTraceLogDisabled() override; void OnTraceLogDisabled() override;
// Returns true if main thread is in loading use case. UseCase current_use_case() const;
bool IsLoading() const;
const SchedulingSettings& scheduling_settings() const; const SchedulingSettings& scheduling_settings() const;
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "third_party/blink/renderer/platform/scheduler/main_thread/frame_scheduler_impl.h" #include "third_party/blink/renderer/platform/scheduler/main_thread/frame_scheduler_impl.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_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/page_visibility_state.h"
#include "third_party/blink/renderer/platform/scheduler/main_thread/use_case.h"
#include "third_party/blink/renderer/platform/scheduler/public/frame_scheduler.h" #include "third_party/blink/renderer/platform/scheduler/public/frame_scheduler.h"
#include "third_party/blink/renderer/platform/scheduler/public/page_lifecycle_state.h" #include "third_party/blink/renderer/platform/scheduler/public/page_lifecycle_state.h"
...@@ -257,6 +258,10 @@ bool PageSchedulerImpl::IsMainFrameLocal() const { ...@@ -257,6 +258,10 @@ bool PageSchedulerImpl::IsMainFrameLocal() const {
return is_main_frame_local_; return is_main_frame_local_;
} }
bool PageSchedulerImpl::IsLoading() const {
return main_thread_scheduler_->current_use_case() == UseCase::kLoading;
}
void PageSchedulerImpl::SetIsMainFrameLocal(bool is_local) { void PageSchedulerImpl::SetIsMainFrameLocal(bool is_local) {
is_main_frame_local_ = is_local; is_main_frame_local_ = is_local;
} }
......
...@@ -91,6 +91,8 @@ class PLATFORM_EXPORT PageSchedulerImpl : public PageScheduler { ...@@ -91,6 +91,8 @@ class PLATFORM_EXPORT PageSchedulerImpl : public PageScheduler {
bool IsThrottled() const; bool IsThrottled() const;
bool KeepActive() const; bool KeepActive() const;
bool IsLoading() const;
void RegisterFrameSchedulerImpl(FrameSchedulerImpl* frame_scheduler); void RegisterFrameSchedulerImpl(FrameSchedulerImpl* frame_scheduler);
MainThreadSchedulerImpl* GetMainThreadScheduler() const; MainThreadSchedulerImpl* GetMainThreadScheduler() const;
......
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