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_input_event_count_(0) {} |
| 10 UserModel::~UserModel() {} |
| 11 |
| 12 void UserModel::DidStartProcessingInputEvent(blink::WebInputEvent::Type type, |
| 13 const base::TimeTicks now) { |
| 14 last_input_signal_time_ = now; |
| 15 if (type == blink::WebInputEvent::TouchStart) |
| 16 last_touchstart_time_ = now; |
| 17 |
| 18 pending_input_event_count_++; |
| 19 } |
| 20 |
| 21 void UserModel::DidFinishProcessingInputEvent(const base::TimeTicks now) { |
| 22 last_input_signal_time_ = now; |
| 23 if (pending_input_event_count_ > 0) |
| 24 pending_input_event_count_--; |
| 25 } |
| 26 |
| 27 base::TimeDelta UserModel::TimeLeftInInputEscalatedPolicy( |
| 28 base::TimeTicks now) const { |
| 29 base::TimeDelta escalated_priority_duration = |
| 30 base::TimeDelta::FromMilliseconds(kPriorityEscalationAfterInputMillis); |
| 31 |
| 32 // If the input event is still pending, go into input prioritized policy and |
| 33 // check again later. |
| 34 if (pending_input_event_count_ > 0) |
| 35 return escalated_priority_duration; |
| 36 if (last_input_signal_time_.is_null() || |
| 37 last_input_signal_time_ + escalated_priority_duration < now) { |
| 38 return base::TimeDelta(); |
| 39 } |
| 40 return last_input_signal_time_ + escalated_priority_duration - now; |
| 41 } |
| 42 |
| 43 bool UserModel::IsTouchStartExpectedSoon( |
| 44 RendererScheduler::UseCase use_case, |
| 45 const base::TimeTicks now, |
| 46 base::TimeDelta* prediction_valid_duration) const { |
| 47 if (use_case == RendererScheduler::UseCase::NONE) { |
| 48 // If we've scrolled recently then future scrolling is likely. |
| 49 base::TimeDelta expect_subsequent_input_for = |
| 50 base::TimeDelta::FromMilliseconds(kExpectSubsequentInputMillis); |
| 51 if (last_input_signal_time_.is_null() || |
| 52 last_input_signal_time_ + expect_subsequent_input_for <= now) { |
| 53 return false; |
| 54 } |
| 55 *prediction_valid_duration = |
| 56 last_input_signal_time_ + expect_subsequent_input_for - now; |
| 57 return true; |
| 58 } |
| 59 |
| 60 if (use_case == RendererScheduler::UseCase::COMPOSITOR_GESTURE || |
| 61 use_case == RendererScheduler::UseCase::MAIN_THREAD_GESTURE) { |
| 62 // If we've only just started scrolling then, then future scrolling is |
| 63 // unlikely. |
| 64 base::TimeDelta minimum_typical_scroll_duration = |
| 65 base::TimeDelta::FromMilliseconds(kMinimumTypicalScrollDurationMillis); |
| 66 if (last_touchstart_time_.is_null() || |
| 67 last_touchstart_time_ + minimum_typical_scroll_duration <= now) { |
| 68 return true; |
| 69 } |
| 70 *prediction_valid_duration = |
| 71 last_touchstart_time_ + minimum_typical_scroll_duration - now; |
| 72 return false; |
| 73 } |
| 74 return false; |
| 75 } |
| 76 |
| 77 void UserModel::AsValueInto(base::trace_event::TracedValue* state) const { |
| 78 state->BeginDictionary("user_model"); |
| 79 state->SetInteger("pending_input_event_count", pending_input_event_count_); |
| 80 state->SetDouble( |
| 81 "last_input_signal_time", |
| 82 (last_input_signal_time_ - base::TimeTicks()).InMillisecondsF()); |
| 83 state->SetDouble( |
| 84 "last_touchstart_time", |
| 85 (last_touchstart_time_ - base::TimeTicks()).InMillisecondsF()); |
| 86 state->EndDictionary(); |
| 87 } |
| 88 |
| 89 } // namespace scheduler |
OLD | NEW |