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 #ifndef COMPONENTS_SCHEDULER_RENDERER_USER_MODEL_H_ | |
6 #define COMPONENTS_SCHEDULER_RENDERER_USER_MODEL_H_ | |
7 | |
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" | |
14 | |
15 namespace scheduler { | |
16 | |
17 class SCHEDULER_EXPORT UserModel { | |
18 public: | |
19 UserModel(); | |
20 ~UserModel(); | |
21 | |
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); | |
26 | |
27 // Tells us that the system finished processing an input event. | |
28 void DidFinishProcessingInputEvent(const base::TimeTicks now); | |
29 | |
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; | |
34 | |
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(const base::TimeTicks now, | |
39 base::TimeDelta* prediction_valid_duration); | |
40 | |
41 // Returns true if a gesture has been in progress for less than the median | |
42 // gesture duration. The prediction may change after | |
43 // |prediction_valid_duration| has elapsed. | |
44 bool IsGestureExpectedToContinue( | |
45 const base::TimeTicks now, | |
46 base::TimeDelta* prediction_valid_duration) const; | |
47 | |
48 void AsValueInto(base::trace_event::TracedValue* state) const; | |
49 | |
50 // The time we should stay in a priority-escalated mode after an input event. | |
51 static const int kGestureEstimationLimitMillis = 100; | |
52 | |
53 // This is based on two weeks of Android usage data. | |
54 static const int kMedianGestureDurationMillis = 300; | |
55 | |
56 // We consider further gesture start events to be likely if the user has | |
57 // interacted with the device in the past two seconds. | |
58 // Based on Android usage data, 2000ms between gestures is the 75th percentile | |
59 // with 700ms being the 50th. | |
60 static const int kExpectSubsequentGestureMillis = 2000; | |
61 | |
62 // Clears input signals. | |
63 void Reset(base::TimeTicks now); | |
64 | |
65 private: | |
66 bool IsGestureExpectedSoonImpl( | |
67 const base::TimeTicks now, | |
68 base::TimeDelta* prediction_valid_duration) const; | |
69 | |
70 int pending_input_event_count_; | |
71 base::TimeTicks last_input_signal_time_; | |
72 base::TimeTicks last_gesture_start_time_; | |
73 base::TimeTicks last_continuous_gesture_time_; // Doesn't include Taps. | |
74 base::TimeTicks last_gesture_expected_start_time_; | |
75 base::TimeTicks last_reset_time_; | |
76 bool is_gesture_active_; // This typically means the user's finger is down. | |
77 bool is_gesture_expected_; | |
78 | |
79 DISALLOW_COPY_AND_ASSIGN(UserModel); | |
80 }; | |
81 | |
82 } // namespace scheduler | |
83 | |
84 #endif // COMPONENTS_SCHEDULER_RENDERER_USER_MODEL_H_ | |
OLD | NEW |