OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "components/scheduler/renderer/user_model.h" |
| 6 |
| 7 namespace scheduler { |
| 8 |
| 9 UserModel::UserModel() : pending_main_thread_input_event_count_(0) {} |
| 10 UserModel::~UserModel() {} |
| 11 |
| 12 void UserModel::DidHandleInputEventOnCompositorThread( |
| 13 blink::WebInputEvent::Type type, |
| 14 RendererScheduler::InputEventState input_event_state, |
| 15 const base::TimeTicks now) { |
| 16 last_input_signal_time_ = now; |
| 17 |
| 18 if (type == blink::WebInputEvent::TouchStart) |
| 19 last_touchstart_time_ = now; |
| 20 |
| 21 if (input_event_state == |
| 22 RendererScheduler::InputEventState::EVENT_FORWARDED_TO_MAIN_THREAD) { |
| 23 pending_main_thread_input_event_count_++; |
| 24 } |
| 25 } |
| 26 |
| 27 void UserModel::DidHandleInputEventOnMainThread(const base::TimeTicks now) { |
| 28 last_input_signal_time_ = now; |
| 29 if (pending_main_thread_input_event_count_ > 0) |
| 30 pending_main_thread_input_event_count_--; |
| 31 } |
| 32 |
| 33 base::TimeDelta UserModel::TimeLeftInInputEscalatedPolicy( |
| 34 base::TimeTicks now) const { |
| 35 base::TimeDelta escalated_priority_duration = |
| 36 base::TimeDelta::FromMilliseconds(kPriorityEscalationAfterInputMillis); |
| 37 |
| 38 // If the input event is still pending, go into input prioritized policy and |
| 39 // check again later. |
| 40 if (pending_main_thread_input_event_count_ > 0) |
| 41 return escalated_priority_duration; |
| 42 if (last_input_signal_time_.is_null() || |
| 43 last_input_signal_time_ + escalated_priority_duration < now) { |
| 44 return base::TimeDelta(); |
| 45 } |
| 46 return last_input_signal_time_ + escalated_priority_duration - now; |
| 47 } |
| 48 |
| 49 bool UserModel::TouchStartExpectedSoon( |
| 50 RendererScheduler::UseCase use_case, |
| 51 const base::TimeTicks now, |
| 52 base::TimeDelta* prediction_valid_duration) const { |
| 53 if (use_case == RendererScheduler::UseCase::NONE) { |
| 54 // If we've scrolled recently then future scrolling is likely. |
| 55 base::TimeDelta expect_subsequent_input_for = |
| 56 base::TimeDelta::FromMilliseconds(kExpectSubsequentInputMillis); |
| 57 if (last_input_signal_time_.is_null() || |
| 58 last_input_signal_time_ + expect_subsequent_input_for <= now) { |
| 59 return false; |
| 60 } |
| 61 *prediction_valid_duration = |
| 62 last_input_signal_time_ + expect_subsequent_input_for - now; |
| 63 return true; |
| 64 } |
| 65 |
| 66 if (use_case == RendererScheduler::UseCase::COMPOSITOR_GESTURE || |
| 67 use_case == RendererScheduler::UseCase::MAIN_THREAD_GESTURE) { |
| 68 // If we've only just started scrolling then, then future scrolling is |
| 69 // unlikely. |
| 70 base::TimeDelta minimum_typical_scroll_duration = |
| 71 base::TimeDelta::FromMilliseconds(kMinimumTypicalScrollDurationMillis); |
| 72 if (last_touchstart_time_.is_null() || |
| 73 last_touchstart_time_ + minimum_typical_scroll_duration <= now) { |
| 74 return true; |
| 75 } |
| 76 *prediction_valid_duration = |
| 77 last_touchstart_time_ + minimum_typical_scroll_duration - now; |
| 78 return false; |
| 79 } |
| 80 return false; |
| 81 } |
| 82 |
| 83 void UserModel::AsValueInto(base::trace_event::TracedValue* state) const { |
| 84 state->BeginDictionary("user_model"); |
| 85 state->SetInteger("pending_main_thread_input_event_count", |
| 86 pending_main_thread_input_event_count_); |
| 87 state->SetDouble( |
| 88 "last_input_signal_time", |
| 89 (last_input_signal_time_ - base::TimeTicks()).InMillisecondsF()); |
| 90 state->SetDouble( |
| 91 "last_touchstart_time", |
| 92 (last_touchstart_time_ - base::TimeTicks()).InMillisecondsF()); |
| 93 state->EndDictionary(); |
| 94 } |
| 95 |
| 96 } // namespace scheduler |
OLD | NEW |