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(RendererScheduler::UseCase use_case, |
| 39 const base::TimeTicks now, |
| 40 base::TimeDelta* prediction_valid_duration) const; |
| 41 |
| 42 void AsValueInto(base::trace_event::TracedValue* state) const; |
| 43 |
| 44 // The time we should stay in a priority-escalated mode after an input event. |
| 45 static const int kGestureEstimationLimitMillis = 100; |
| 46 |
| 47 // TODO(alexclarke): Get a real number on actual data. |
| 48 static const int kMinimumTypicalScrollDurationMillis = 500; |
| 49 |
| 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; |
| 54 |
| 55 // Clears input signals. |
| 56 void Reset(); |
| 57 |
| 58 private: |
| 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. |
| 63 |
| 64 DISALLOW_COPY_AND_ASSIGN(UserModel); |
| 65 }; |
| 66 |
| 67 } // namespace scheduler |
| 68 |
| 69 #endif // COMPONENTS_SCHEDULER_RENDERER_USER_MODEL_H_ |
OLD | NEW |