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.
5 #ifndef COMPONENTS_SCHEDULER_RENDERER_USER_MODEL_H_
6 #define COMPONENTS_SCHEDULER_RENDERER_USER_MODEL_H_
8 #include "base/macros.h"
9 #include "base/trace_event/trace_event.h"
10 #include "base/trace_event/trace_event_argument.h"
11 #include "components/scheduler/renderer/renderer_scheduler.h"
12 #include "components/scheduler/scheduler_export.h"
13 #include "third_party/WebKit/public/web/WebInputEvent.h"
17 class SCHEDULER_EXPORT UserModel
{
22 // Tells us that the system started processing an input event. Must be paired
23 // with a call to DidFinishProcessingInputEvent.
24 void DidStartProcessingInputEvent(blink::WebInputEvent::Type type
,
25 const base::TimeTicks now
);
27 // Tells us that the system finished processing an input event.
28 void DidFinishProcessingInputEvent(const base::TimeTicks now
);
30 // Returns the estimated amount of time left in the current user gesture, to a
31 // maximum of |kGestureEstimationLimitMillis|. After that time has elapased
32 // this function should be called again.
33 base::TimeDelta
TimeLeftInUserGesture(base::TimeTicks now
) const;
35 // Tries to guess if a user gesture is expected soon. Currently this is
36 // very simple, but one day I hope to do something more sophisticated here.
37 // The prediction may change after |prediction_valid_duration| has elapsed.
38 bool IsGestureExpectedSoon(RendererScheduler::UseCase use_case
,
39 const base::TimeTicks now
,
40 base::TimeDelta
* prediction_valid_duration
) const;
42 void AsValueInto(base::trace_event::TracedValue
* state
) const;
44 // The time we should stay in a priority-escalated mode after an input event.
45 static const int kGestureEstimationLimitMillis
= 100;
47 // TODO(alexclarke): Get a real number on actual data.
48 static const int kMinimumTypicalScrollDurationMillis
= 500;
50 // We consider further gesture start events to be likely if the user has
51 // interacted with the device in the past two seconds.
52 // TODO(alexclarke): Get a real number based on actual data.
53 static const int kExpectSubsequentGestureMillis
= 2000;
55 // Clears input signals.
59 int pending_input_event_count_
;
60 base::TimeTicks last_input_signal_time_
;
61 base::TimeTicks last_gesture_start_time_
;
62 base::TimeTicks last_continuous_gesture_time_
; // Doesn't include Taps.
64 DISALLOW_COPY_AND_ASSIGN(UserModel
);
67 } // namespace scheduler
69 #endif // COMPONENTS_SCHEDULER_RENDERER_USER_MODEL_H_