1 // Copyright 2019 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 THIRD_PARTY_BLINK_RENDERER_PLATFORM_WIDGET_INPUT_MOMENTUM_SCROLL_JANK_TRACKER_H_
6 #define THIRD_PARTY_BLINK_RENDERER_PLATFORM_WIDGET_INPUT_MOMENTUM_SCROLL_JANK_TRACKER_H_
7 
8 #include "base/time/time.h"
9 
10 namespace blink {
11 class EventWithCallback;
12 
13 // Class which is used during a scroll event to detect, accumulate, and log
14 // jank metrics for the momentum phase.
15 class MomentumScrollJankTracker {
16  public:
17   ~MomentumScrollJankTracker();
18   void OnDispatchedInputEvent(EventWithCallback* event_with_callback,
19                               const base::TimeTicks& now);
20 
21  private:
22   // The number of expected momentum events which should be coalesced in a
23   // single frame.
24   // If we update momentum event generation to happen more than once per frame,
25   // |kExpectedMomentumEventsPerFrame| should be updated or this data plumbed
26   // in from a different source.
27   static constexpr uint32_t kExpectedMomentumEventsPerFrame = 1;
28 
29   // The amount of time elapsed between coalescing an event and dispatching the
30   // event for which we consider the coalescing to be "recent" for the purposes
31   // of https://crbug.com/952930.
32   static constexpr base::TimeDelta kRecentEventCutoff =
33       base::TimeDelta::FromMilliseconds(2);
34 
35   // |jank_count_| is the number of coalesced momentum input events above
36   // kExptectedMomentumEventsPerFrame.
37   uint32_t jank_count_ = 0;
38 
39   // The number of events processed during a gesture.
40   uint32_t total_event_count_ = 0;
41 
42   // Used to avoid tracking jank in the first momentum event, as this may be
43   // unreliable.
44   bool seen_first_momentum_input_ = false;
45 };
46 
47 }  // namespace blink
48 
49 #endif  // THIRD_PARTY_BLINK_RENDERER_PLATFORM_WIDGET_INPUT_MOMENTUM_SCROLL_JANK_TRACKER_H_
50