| Index: components/scheduler/renderer/user_model.cc
|
| diff --git a/components/scheduler/renderer/user_model.cc b/components/scheduler/renderer/user_model.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..6c5ceccfc7fd493c4928fe831668c2f2b9fbd6ff
|
| --- /dev/null
|
| +++ b/components/scheduler/renderer/user_model.cc
|
| @@ -0,0 +1,96 @@
|
| +// Copyright 2015 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "components/scheduler/renderer/user_model.h"
|
| +
|
| +namespace scheduler {
|
| +
|
| +UserModel::UserModel() : pending_main_thread_input_event_count_(0) {}
|
| +UserModel::~UserModel() {}
|
| +
|
| +void UserModel::DidHandleInputEventOnCompositorThread(
|
| + blink::WebInputEvent::Type type,
|
| + RendererScheduler::InputEventState input_event_state,
|
| + const base::TimeTicks now) {
|
| + last_input_signal_time_ = now;
|
| +
|
| + if (type == blink::WebInputEvent::TouchStart)
|
| + last_touchstart_time_ = now;
|
| +
|
| + if (input_event_state ==
|
| + RendererScheduler::InputEventState::EVENT_FORWARDED_TO_MAIN_THREAD) {
|
| + pending_main_thread_input_event_count_++;
|
| + }
|
| +}
|
| +
|
| +void UserModel::DidHandleInputEventOnMainThread(const base::TimeTicks now) {
|
| + last_input_signal_time_ = now;
|
| + if (pending_main_thread_input_event_count_ > 0)
|
| + pending_main_thread_input_event_count_--;
|
| +}
|
| +
|
| +base::TimeDelta UserModel::TimeLeftInInputEscalatedPolicy(
|
| + base::TimeTicks now) const {
|
| + base::TimeDelta escalated_priority_duration =
|
| + base::TimeDelta::FromMilliseconds(kPriorityEscalationAfterInputMillis);
|
| +
|
| + // If the input event is still pending, go into input prioritized policy and
|
| + // check again later.
|
| + if (pending_main_thread_input_event_count_ > 0)
|
| + return escalated_priority_duration;
|
| + if (last_input_signal_time_.is_null() ||
|
| + last_input_signal_time_ + escalated_priority_duration < now) {
|
| + return base::TimeDelta();
|
| + }
|
| + return last_input_signal_time_ + escalated_priority_duration - now;
|
| +}
|
| +
|
| +bool UserModel::TouchStartExpectedSoon(
|
| + RendererScheduler::UseCase use_case,
|
| + const base::TimeTicks now,
|
| + base::TimeDelta* prediction_valid_duration) const {
|
| + if (use_case == RendererScheduler::UseCase::NONE) {
|
| + // If we've scrolled recently then future scrolling is likely.
|
| + base::TimeDelta expect_subsequent_input_for =
|
| + base::TimeDelta::FromMilliseconds(kExpectSubsequentInputMillis);
|
| + if (last_input_signal_time_.is_null() ||
|
| + last_input_signal_time_ + expect_subsequent_input_for <= now) {
|
| + return false;
|
| + }
|
| + *prediction_valid_duration =
|
| + last_input_signal_time_ + expect_subsequent_input_for - now;
|
| + return true;
|
| + }
|
| +
|
| + if (use_case == RendererScheduler::UseCase::COMPOSITOR_GESTURE ||
|
| + use_case == RendererScheduler::UseCase::MAIN_THREAD_GESTURE) {
|
| + // If we've only just started scrolling then, then future scrolling is
|
| + // unlikely.
|
| + base::TimeDelta minimum_typical_scroll_duration =
|
| + base::TimeDelta::FromMilliseconds(kMinimumTypicalScrollDurationMillis);
|
| + if (last_touchstart_time_.is_null() ||
|
| + last_touchstart_time_ + minimum_typical_scroll_duration <= now) {
|
| + return true;
|
| + }
|
| + *prediction_valid_duration =
|
| + last_touchstart_time_ + minimum_typical_scroll_duration - now;
|
| + return false;
|
| + }
|
| + return false;
|
| +}
|
| +
|
| +void UserModel::AsValueInto(base::trace_event::TracedValue* state) const {
|
| + state->BeginDictionary("user_model");
|
| + state->SetInteger("pending_main_thread_input_event_count",
|
| + pending_main_thread_input_event_count_);
|
| + state->SetDouble(
|
| + "last_input_signal_time",
|
| + (last_input_signal_time_ - base::TimeTicks()).InMillisecondsF());
|
| + state->SetDouble(
|
| + "last_touchstart_time",
|
| + (last_touchstart_time_ - base::TimeTicks()).InMillisecondsF());
|
| + state->EndDictionary();
|
| +}
|
| +
|
| +} // namespace scheduler
|
|
|