Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(264)

Side by Side Diff: components/scheduler/renderer/user_model.cc

Issue 1320633002: Optimize for TouchStart responsiveness (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix unit tests and prioritize default tasks when loading tasks are priotized. Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 type == blink::WebInputEvent::GestureScrollBegin ||
17 type == blink::WebInputEvent::GesturePinchBegin) {
18 last_gesture_start_time_ = now;
19 }
20
21 pending_input_event_count_++;
22 }
23
24 void UserModel::DidFinishProcessingInputEvent(const base::TimeTicks now) {
25 last_input_signal_time_ = now;
26 if (pending_input_event_count_ > 0)
27 pending_input_event_count_--;
28 }
29
30 base::TimeDelta UserModel::TimeLeftInUserGesture(base::TimeTicks now) const {
31 base::TimeDelta escalated_priority_duration =
32 base::TimeDelta::FromMilliseconds(kGestureEstimationLimitMillis);
33
34 // If the input event is still pending, go into input prioritized policy and
35 // check again later.
36 if (pending_input_event_count_ > 0)
37 return escalated_priority_duration;
38 if (last_input_signal_time_.is_null() ||
39 last_input_signal_time_ + escalated_priority_duration < now) {
40 return base::TimeDelta();
41 }
42 return last_input_signal_time_ + escalated_priority_duration - now;
43 }
44
45 bool UserModel::IsGestureExpectedSoon(
46 RendererScheduler::UseCase use_case,
47 const base::TimeTicks now,
48 base::TimeDelta* prediction_valid_duration) const {
49 if (use_case == RendererScheduler::UseCase::NONE) {
50 // If we've scrolled recently then future scrolling is likely.
51 base::TimeDelta expect_subsequent_gesture_for =
52 base::TimeDelta::FromMilliseconds(kExpectSubsequentGestureMillis);
53 if (last_input_signal_time_.is_null() ||
54 last_input_signal_time_ + expect_subsequent_gesture_for <= now) {
55 return false;
56 }
57 *prediction_valid_duration =
58 last_input_signal_time_ + expect_subsequent_gesture_for - now;
59 return true;
60 }
61
62 if (use_case == RendererScheduler::UseCase::COMPOSITOR_GESTURE ||
63 use_case == RendererScheduler::UseCase::MAIN_THREAD_GESTURE) {
64 // If we've only just started scrolling then, then initiating a subsequent
65 // gesture is unlikely.
66 base::TimeDelta minimum_typical_scroll_duration =
67 base::TimeDelta::FromMilliseconds(kMinimumTypicalScrollDurationMillis);
68 if (last_gesture_start_time_.is_null() ||
69 last_gesture_start_time_ + minimum_typical_scroll_duration <= now) {
70 return true;
71 }
72 *prediction_valid_duration =
73 last_gesture_start_time_ + minimum_typical_scroll_duration - now;
74 return false;
75 }
76 return false;
77 }
78
79 void UserModel::AsValueInto(base::trace_event::TracedValue* state) const {
80 state->BeginDictionary("user_model");
81 state->SetInteger("pending_input_event_count", pending_input_event_count_);
82 state->SetDouble(
83 "last_input_signal_time",
84 (last_input_signal_time_ - base::TimeTicks()).InMillisecondsF());
85 state->SetDouble(
86 "last_touchstart_time",
87 (last_gesture_start_time_ - base::TimeTicks()).InMillisecondsF());
88 state->EndDictionary();
89 }
90
91 } // namespace scheduler
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698