Commit 16ebe5b1 authored by skyostil's avatar skyostil Committed by Commit bot

scheduler: Convert enums to enum classes

Convert enums to enum classes to make their purpose clearer and to make it
easier to expose them to the unit tests. Note that the task queue identifier is
maintained as a numeric enum because it serves as an index to the task queue
manager and selector. No functional changes.

Review URL: https://codereview.chromium.org/962633002

Cr-Commit-Position: refs/heads/master@{#318248}
parent 83f0b5a9
......@@ -31,9 +31,9 @@ RendererSchedulerImpl::RendererSchedulerImpl(
task_queue_manager_->TaskRunnerForQueue(COMPOSITOR_TASK_QUEUE)),
loading_task_runner_(
task_queue_manager_->TaskRunnerForQueue(LOADING_TASK_QUEUE)),
current_policy_(NORMAL_PRIORITY_POLICY),
current_policy_(Policy::NORMAL),
last_input_type_(blink::WebInputEvent::Undefined),
input_stream_state_(INPUT_INACTIVE),
input_stream_state_(InputStreamState::INACTIVE),
policy_may_need_update_(&incoming_signals_lock_),
weak_factory_(this) {
weak_renderer_scheduler_ptr_ = weak_factory_.GetWeakPtr();
......@@ -55,11 +55,11 @@ RendererSchedulerImpl::RendererSchedulerImpl(
RendererTaskQueueSelector::CONTROL_PRIORITY);
task_queue_manager_->SetPumpPolicy(
CONTROL_TASK_AFTER_WAKEUP_QUEUE,
TaskQueueManager::AUTO_PUMP_AFTER_WAKEUP_POLICY);
TaskQueueManager::PumpPolicy::AFTER_WAKEUP);
renderer_task_queue_selector_->DisableQueue(IDLE_TASK_QUEUE);
task_queue_manager_->SetPumpPolicy(IDLE_TASK_QUEUE,
TaskQueueManager::MANUAL_PUMP_POLICY);
TaskQueueManager::PumpPolicy::MANUAL);
// TODO(skyostil): Increase this to 4 (crbug.com/444764).
task_queue_manager_->SetWorkBatchSize(1);
......@@ -194,8 +194,8 @@ bool RendererSchedulerImpl::IsHighPriorityWorkAnticipated() {
MaybeUpdatePolicy();
// The touchstart and compositor policies indicate a strong likelihood of
// high-priority work in the near future.
return SchedulerPolicy() == COMPOSITOR_PRIORITY_POLICY ||
SchedulerPolicy() == TOUCHSTART_PRIORITY_POLICY;
return SchedulerPolicy() == Policy::COMPOSITOR_PRIORITY ||
SchedulerPolicy() == Policy::TOUCHSTART_PRIORITY;
}
bool RendererSchedulerImpl::ShouldYieldForHighPriorityWork() {
......@@ -210,13 +210,13 @@ bool RendererSchedulerImpl::ShouldYieldForHighPriorityWork() {
// it since these tasks are not user-provided work and they are only intended
// to run before the next task, not interrupt the tasks.
switch (SchedulerPolicy()) {
case NORMAL_PRIORITY_POLICY:
case Policy::NORMAL:
return false;
case COMPOSITOR_PRIORITY_POLICY:
case Policy::COMPOSITOR_PRIORITY:
return !task_queue_manager_->IsQueueEmpty(COMPOSITOR_TASK_QUEUE);
case TOUCHSTART_PRIORITY_POLICY:
case Policy::TOUCHSTART_PRIORITY:
return true;
default:
......@@ -258,8 +258,8 @@ void RendererSchedulerImpl::UpdatePolicy() {
base::TimeTicks now;
policy_may_need_update_.SetWhileLocked(false);
Policy new_policy = NORMAL_PRIORITY_POLICY;
if (input_stream_state_ != INPUT_INACTIVE) {
Policy new_policy = Policy::NORMAL;
if (input_stream_state_ != InputStreamState::INACTIVE) {
base::TimeDelta new_priority_duration =
base::TimeDelta::FromMilliseconds(kPriorityEscalationAfterInputMillis);
base::TimeTicks new_priority_end(last_input_time_ + new_priority_duration);
......@@ -267,14 +267,15 @@ void RendererSchedulerImpl::UpdatePolicy() {
if (time_left_in_policy > base::TimeDelta()) {
PostUpdatePolicyOnControlRunner(time_left_in_policy);
new_policy =
input_stream_state_ == INPUT_ACTIVE_AND_AWAITING_TOUCHSTART_RESPONSE
? TOUCHSTART_PRIORITY_POLICY
: COMPOSITOR_PRIORITY_POLICY;
input_stream_state_ ==
InputStreamState::ACTIVE_AND_AWAITING_TOUCHSTART_RESPONSE
? Policy::TOUCHSTART_PRIORITY
: Policy::COMPOSITOR_PRIORITY;
} else {
// Reset |input_stream_state_| to ensure
// DidReceiveInputEventOnCompositorThread will post an UpdatePolicy task
// when it's next called.
input_stream_state_ = INPUT_INACTIVE;
input_stream_state_ = InputStreamState::INACTIVE;
}
}
......@@ -282,7 +283,7 @@ void RendererSchedulerImpl::UpdatePolicy() {
return;
switch (new_policy) {
case COMPOSITOR_PRIORITY_POLICY:
case Policy::COMPOSITOR_PRIORITY:
renderer_task_queue_selector_->SetQueuePriority(
COMPOSITOR_TASK_QUEUE, RendererTaskQueueSelector::HIGH_PRIORITY);
// TODO(scheduler-dev): Add a task priority between HIGH and BEST_EFFORT
......@@ -290,12 +291,12 @@ void RendererSchedulerImpl::UpdatePolicy() {
renderer_task_queue_selector_->SetQueuePriority(
LOADING_TASK_QUEUE, RendererTaskQueueSelector::BEST_EFFORT_PRIORITY);
break;
case TOUCHSTART_PRIORITY_POLICY:
case Policy::TOUCHSTART_PRIORITY:
renderer_task_queue_selector_->SetQueuePriority(
COMPOSITOR_TASK_QUEUE, RendererTaskQueueSelector::HIGH_PRIORITY);
renderer_task_queue_selector_->DisableQueue(LOADING_TASK_QUEUE);
break;
case NORMAL_PRIORITY_POLICY:
case Policy::NORMAL:
renderer_task_queue_selector_->SetQueuePriority(
COMPOSITOR_TASK_QUEUE, RendererTaskQueueSelector::NORMAL_PRIORITY);
renderer_task_queue_selector_->SetQueuePriority(
......@@ -303,7 +304,7 @@ void RendererSchedulerImpl::UpdatePolicy() {
break;
}
DCHECK(renderer_task_queue_selector_->IsQueueEnabled(COMPOSITOR_TASK_QUEUE));
if (new_policy != TOUCHSTART_PRIORITY_POLICY)
if (new_policy != Policy::TOUCHSTART_PRIORITY)
DCHECK(renderer_task_queue_selector_->IsQueueEnabled(LOADING_TASK_QUEUE));
current_policy_ = new_policy;
......@@ -401,11 +402,11 @@ const char* RendererSchedulerImpl::TaskQueueIdToString(QueueId queue_id) {
// static
const char* RendererSchedulerImpl::PolicyToString(Policy policy) {
switch (policy) {
case NORMAL_PRIORITY_POLICY:
case Policy::NORMAL:
return "normal";
case COMPOSITOR_PRIORITY_POLICY:
case Policy::COMPOSITOR_PRIORITY:
return "compositor";
case TOUCHSTART_PRIORITY_POLICY:
case Policy::TOUCHSTART_PRIORITY:
return "touchstart";
default:
NOTREACHED();
......@@ -416,11 +417,11 @@ const char* RendererSchedulerImpl::PolicyToString(Policy policy) {
const char* RendererSchedulerImpl::InputStreamStateToString(
InputStreamState state) {
switch (state) {
case INPUT_INACTIVE:
case InputStreamState::INACTIVE:
return "inactive";
case INPUT_ACTIVE:
case InputStreamState::ACTIVE:
return "active";
case INPUT_ACTIVE_AND_AWAITING_TOUCHSTART_RESPONSE:
case InputStreamState::ACTIVE_AND_AWAITING_TOUCHSTART_RESPONSE:
return "active_and_awaiting_touchstart_response";
default:
NOTREACHED();
......@@ -458,17 +459,18 @@ RendererSchedulerImpl::ComputeNewInputStreamState(
blink::WebInputEvent::Type last_input_type) {
switch (new_input_type) {
case blink::WebInputEvent::TouchStart:
return INPUT_ACTIVE_AND_AWAITING_TOUCHSTART_RESPONSE;
return InputStreamState::ACTIVE_AND_AWAITING_TOUCHSTART_RESPONSE;
case blink::WebInputEvent::TouchMove:
// Observation of consecutive touchmoves is a strong signal that the page
// is consuming the touch sequence, in which case touchstart response
// prioritization is no longer necessary. Otherwise, the initial touchmove
// should preserve the touchstart response pending state.
if (current_state == INPUT_ACTIVE_AND_AWAITING_TOUCHSTART_RESPONSE) {
if (current_state ==
InputStreamState::ACTIVE_AND_AWAITING_TOUCHSTART_RESPONSE) {
return last_input_type == blink::WebInputEvent::TouchMove
? INPUT_ACTIVE
: INPUT_ACTIVE_AND_AWAITING_TOUCHSTART_RESPONSE;
? InputStreamState::ACTIVE
: InputStreamState::ACTIVE_AND_AWAITING_TOUCHSTART_RESPONSE;
}
break;
......@@ -483,7 +485,7 @@ RendererSchedulerImpl::ComputeNewInputStreamState(
default:
break;
}
return INPUT_ACTIVE;
return InputStreamState::ACTIVE;
}
void RendererSchedulerImpl::AddTaskObserver(
......
......@@ -66,16 +66,16 @@ class CONTENT_EXPORT RendererSchedulerImpl : public RendererScheduler {
TASK_QUEUE_COUNT,
};
enum Policy {
NORMAL_PRIORITY_POLICY,
COMPOSITOR_PRIORITY_POLICY,
TOUCHSTART_PRIORITY_POLICY,
enum class Policy {
NORMAL,
COMPOSITOR_PRIORITY,
TOUCHSTART_PRIORITY,
};
enum InputStreamState {
INPUT_INACTIVE,
INPUT_ACTIVE,
INPUT_ACTIVE_AND_AWAITING_TOUCHSTART_RESPONSE
enum class InputStreamState {
INACTIVE,
ACTIVE,
ACTIVE_AND_AWAITING_TOUCHSTART_RESPONSE
};
class PollableNeedsUpdateFlag {
......
......@@ -28,13 +28,13 @@ class TaskQueue : public base::SingleThreadTaskRunner {
bool PostDelayedTask(const tracked_objects::Location& from_here,
const base::Closure& task,
base::TimeDelta delay) override {
return PostDelayedTaskImpl(from_here, task, delay, NORMAL_TASK_TYPE);
return PostDelayedTaskImpl(from_here, task, delay, TaskType::NORMAL);
}
bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here,
const base::Closure& task,
base::TimeDelta delay) override {
return PostDelayedTaskImpl(from_here, task, delay, NON_NESTABLE_TASK_TYPE);
return PostDelayedTaskImpl(from_here, task, delay, TaskType::NON_NESTABLE);
}
bool IsQueueEmpty() const;
......@@ -55,9 +55,9 @@ class TaskQueue : public base::SingleThreadTaskRunner {
void AsValueInto(base::trace_event::TracedValue* state) const;
private:
enum TaskType {
NORMAL_TASK_TYPE,
NON_NESTABLE_TASK_TYPE,
enum class TaskType {
NORMAL,
NON_NESTABLE,
};
~TaskQueue() override;
......@@ -102,7 +102,7 @@ class TaskQueue : public base::SingleThreadTaskRunner {
TaskQueue::TaskQueue(TaskQueueManager* task_queue_manager)
: task_queue_manager_(task_queue_manager),
pump_policy_(TaskQueueManager::AUTO_PUMP_POLICY),
pump_policy_(TaskQueueManager::PumpPolicy::AUTO),
name_(nullptr) {
}
......@@ -130,7 +130,7 @@ bool TaskQueue::PostDelayedTaskImpl(const tracked_objects::Location& from_here,
return false;
base::PendingTask pending_task(from_here, task, base::TimeTicks(),
task_type != NON_NESTABLE_TASK_TYPE);
task_type != TaskType::NON_NESTABLE);
task_queue_manager_->DidQueueTask(&pending_task);
if (delay > base::TimeDelta()) {
......@@ -156,10 +156,10 @@ bool TaskQueue::IsQueueEmpty() const {
bool TaskQueue::ShouldAutoPumpQueueLocked(
TaskQueueManager::WorkQueueUpdateEventType event_type) {
lock_.AssertAcquired();
if (pump_policy_ == TaskQueueManager::MANUAL_PUMP_POLICY)
if (pump_policy_ == TaskQueueManager::PumpPolicy::MANUAL)
return false;
if (pump_policy_ == TaskQueueManager::AUTO_PUMP_AFTER_WAKEUP_POLICY &&
event_type != TaskQueueManager::AFTER_WAKEUP_EVENT_TYPE)
if (pump_policy_ == TaskQueueManager::PumpPolicy::AFTER_WAKEUP &&
event_type != TaskQueueManager::WorkQueueUpdateEventType::AFTER_WAKEUP)
return false;
if (incoming_queue_.empty())
return false;
......@@ -218,7 +218,7 @@ void TaskQueue::EnqueueTaskLocked(const base::PendingTask& pending_task) {
lock_.AssertAcquired();
if (!task_queue_manager_)
return;
if (pump_policy_ == TaskQueueManager::AUTO_PUMP_POLICY &&
if (pump_policy_ == TaskQueueManager::PumpPolicy::AUTO &&
incoming_queue_.empty())
task_queue_manager_->MaybePostDoWorkOnMainRunner();
incoming_queue_.push(pending_task);
......@@ -238,8 +238,8 @@ void TaskQueue::EnqueueTaskLocked(const base::PendingTask& pending_task) {
void TaskQueue::SetPumpPolicy(TaskQueueManager::PumpPolicy pump_policy) {
base::AutoLock lock(lock_);
if (pump_policy == TaskQueueManager::AUTO_PUMP_POLICY &&
pump_policy_ != TaskQueueManager::AUTO_PUMP_POLICY) {
if (pump_policy == TaskQueueManager::PumpPolicy::AUTO &&
pump_policy_ != TaskQueueManager::PumpPolicy::AUTO) {
PumpQueueLocked();
}
pump_policy_ = pump_policy;
......@@ -279,12 +279,12 @@ void TaskQueue::AsValueInto(base::trace_event::TracedValue* state) const {
const char* TaskQueue::PumpPolicyToString(
TaskQueueManager::PumpPolicy pump_policy) {
switch (pump_policy) {
case TaskQueueManager::AUTO_PUMP_POLICY:
return "auto_pump";
case TaskQueueManager::AUTO_PUMP_AFTER_WAKEUP_POLICY:
return "auto_pump_after_wakeup";
case TaskQueueManager::MANUAL_PUMP_POLICY:
return "manual_pump";
case TaskQueueManager::PumpPolicy::AUTO:
return "auto";
case TaskQueueManager::PumpPolicy::AFTER_WAKEUP:
return "after_wakeup";
case TaskQueueManager::PumpPolicy::MANUAL:
return "manual";
default:
NOTREACHED();
return nullptr;
......@@ -426,7 +426,8 @@ void TaskQueueManager::DoWork(bool posted_from_main_thread) {
base::TimeTicks next_pending_delayed_task(
base::TimeTicks::FromInternalValue(kMaxTimeTicks));
if (!UpdateWorkQueues(&next_pending_delayed_task, BEFORE_WAKEUP_EVENT_TYPE))
if (!UpdateWorkQueues(&next_pending_delayed_task,
WorkQueueUpdateEventType::BEFORE_WAKEUP))
return;
base::PendingTask previous_task((tracked_objects::Location()),
......@@ -445,7 +446,8 @@ void TaskQueueManager::DoWork(bool posted_from_main_thread) {
MaybePostDoWorkOnMainRunner();
ProcessTaskFromWorkQueue(queue_index, i > 0, &previous_task);
if (!UpdateWorkQueues(&next_pending_delayed_task, AFTER_WAKEUP_EVENT_TYPE))
if (!UpdateWorkQueues(&next_pending_delayed_task,
WorkQueueUpdateEventType::AFTER_WAKEUP))
return;
}
}
......
......@@ -48,20 +48,20 @@ class TaskQueueSelector;
class CONTENT_EXPORT TaskQueueManager {
public:
// Keep TaskQueue::PumpPolicyToString in sync with this enum.
enum PumpPolicy {
// Tasks posted to an incoming queue with an AUTO_PUMP_POLICY will be
enum class PumpPolicy {
// Tasks posted to an incoming queue with an AUTO pump policy will be
// automatically scheduled for execution or transferred to the work queue
// automatically.
AUTO_PUMP_POLICY,
// Tasks posted to an incoming queue with an AUTO_PUMP_AFTER_WAKEUP_POLICY
AUTO,
// Tasks posted to an incoming queue with an AFTER_WAKEUP pump policy
// will be scheduled for execution or transferred to the work queue
// automatically but only after another queue has executed a task.
AUTO_PUMP_AFTER_WAKEUP_POLICY,
// Tasks posted to an incoming queue with a MANUAL_PUMP_POLICY will not be
AFTER_WAKEUP,
// Tasks posted to an incoming queue with a MANUAL will not be
// automatically scheduled for execution or transferred to the work queue.
// Instead, the selector should call PumpQueue() when necessary to bring
// in new tasks for execution.
MANUAL_PUMP_POLICY
MANUAL
};
// Create a task queue manager with |task_queue_count| task queues.
......@@ -116,10 +116,7 @@ class CONTENT_EXPORT TaskQueueManager {
private:
friend class internal::TaskQueue;
enum WorkQueueUpdateEventType {
BEFORE_WAKEUP_EVENT_TYPE,
AFTER_WAKEUP_EVENT_TYPE
};
enum class WorkQueueUpdateEventType { BEFORE_WAKEUP, AFTER_WAKEUP };
// Called by the task queue to register a new pending task and allocate a
// sequence number for it.
......
......@@ -285,7 +285,7 @@ TEST_F(TaskQueueManagerTest, DelayedTaskDoesNotStayDelayed) {
TEST_F(TaskQueueManagerTest, ManualPumping) {
Initialize(1u);
manager_->SetPumpPolicy(0, TaskQueueManager::MANUAL_PUMP_POLICY);
manager_->SetPumpPolicy(0, TaskQueueManager::PumpPolicy::MANUAL);
std::vector<int> run_order;
scoped_refptr<base::SingleThreadTaskRunner> runner =
......@@ -309,7 +309,7 @@ TEST_F(TaskQueueManagerTest, ManualPumping) {
TEST_F(TaskQueueManagerTest, ManualPumpingToggle) {
Initialize(1u);
manager_->SetPumpPolicy(0, TaskQueueManager::MANUAL_PUMP_POLICY);
manager_->SetPumpPolicy(0, TaskQueueManager::PumpPolicy::MANUAL);
std::vector<int> run_order;
scoped_refptr<base::SingleThreadTaskRunner> runner =
......@@ -321,7 +321,7 @@ TEST_F(TaskQueueManagerTest, ManualPumpingToggle) {
EXPECT_FALSE(test_task_runner_->HasPendingTask());
// When pumping is enabled the task runs normally.
manager_->SetPumpPolicy(0, TaskQueueManager::AUTO_PUMP_POLICY);
manager_->SetPumpPolicy(0, TaskQueueManager::PumpPolicy::AUTO);
EXPECT_TRUE(test_task_runner_->HasPendingTask());
selector_->AppendQueueToService(0);
test_task_runner_->RunUntilIdle();
......@@ -350,7 +350,7 @@ TEST_F(TaskQueueManagerTest, DenyRunning) {
TEST_F(TaskQueueManagerTest, ManualPumpingWithDelayedTask) {
Initialize(1u);
manager_->SetPumpPolicy(0, TaskQueueManager::MANUAL_PUMP_POLICY);
manager_->SetPumpPolicy(0, TaskQueueManager::PumpPolicy::MANUAL);
std::vector<int> run_order;
scoped_refptr<base::SingleThreadTaskRunner> runner =
......@@ -374,7 +374,7 @@ TEST_F(TaskQueueManagerTest, ManualPumpingWithDelayedTask) {
TEST_F(TaskQueueManagerTest, ManualPumpingWithNonEmptyWorkQueue) {
Initialize(1u);
manager_->SetPumpPolicy(0, TaskQueueManager::MANUAL_PUMP_POLICY);
manager_->SetPumpPolicy(0, TaskQueueManager::PumpPolicy::MANUAL);
std::vector<int> run_order;
scoped_refptr<base::SingleThreadTaskRunner> runner =
......@@ -586,7 +586,7 @@ TEST_F(TaskQueueManagerTest, InterruptWorkBatchForDelayedTask) {
TEST_F(TaskQueueManagerTest, AutoPumpOnWakeup) {
Initialize(2u);
EXPECT_EQ(2u, selector_->work_queues().size());
manager_->SetPumpPolicy(0, TaskQueueManager::AUTO_PUMP_AFTER_WAKEUP_POLICY);
manager_->SetPumpPolicy(0, TaskQueueManager::PumpPolicy::AFTER_WAKEUP);
std::vector<int> run_order;
scoped_refptr<base::SingleThreadTaskRunner> runners[2] = {
......@@ -613,7 +613,7 @@ TEST_F(TaskQueueManagerTest, AutoPumpOnWakeup) {
TEST_F(TaskQueueManagerTest, AutoPumpOnWakeupWhenAlreadyAwake) {
Initialize(2u);
EXPECT_EQ(2u, selector_->work_queues().size());
manager_->SetPumpPolicy(0, TaskQueueManager::AUTO_PUMP_AFTER_WAKEUP_POLICY);
manager_->SetPumpPolicy(0, TaskQueueManager::PumpPolicy::AFTER_WAKEUP);
std::vector<int> run_order;
scoped_refptr<base::SingleThreadTaskRunner> runners[2] = {
......@@ -631,8 +631,8 @@ TEST_F(TaskQueueManagerTest, AutoPumpOnWakeupWhenAlreadyAwake) {
TEST_F(TaskQueueManagerTest, AutoPumpOnWakeupTriggeredByManuallyPumpedQueue) {
Initialize(2u);
EXPECT_EQ(2u, selector_->work_queues().size());
manager_->SetPumpPolicy(0, TaskQueueManager::AUTO_PUMP_AFTER_WAKEUP_POLICY);
manager_->SetPumpPolicy(1, TaskQueueManager::MANUAL_PUMP_POLICY);
manager_->SetPumpPolicy(0, TaskQueueManager::PumpPolicy::AFTER_WAKEUP);
manager_->SetPumpPolicy(1, TaskQueueManager::PumpPolicy::MANUAL);
std::vector<int> run_order;
scoped_refptr<base::SingleThreadTaskRunner> runners[2] = {
......
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