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

Side by Side Diff: chrome/browser/page_load_metrics/user_input_tracker.h

Issue 2540183003: Add UserInputTracker, which keeps track of recent user input events. (Closed)
Patch Set: address comments Created 4 years 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 2016 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 CHROME_BROWSER_PAGE_LOAD_METRICS_USER_INPUT_TRACKER_H_
6 #define CHROME_BROWSER_PAGE_LOAD_METRICS_USER_INPUT_TRACKER_H_
7
8 #include <vector>
9
10 #include "base/time/time.h"
11
12 namespace blink {
13 class WebInputEvent;
14 } // namespace blink
15
16 namespace page_load_metrics {
17
18 // UserInputTracker keeps track of user input events processed by web pages, and
19 // allows clients to find and consume those input events. This allows us to
20 // heuristically attribute user input events to navigations, in order to keep
21 // track of which page loads and aborts were initiated by a user action.
22 //
23 // There are issues with the existing user gesture tracking in Blink and content
24 // that make it unsuitable for our needs. For example, Blink considers events
25 // such as navigations that occur within 1 second of a user action event to have
26 // been initiated by a user action, based on the HTML spec
27 // (https://html.spec.whatwg.org/multipage/interaction.html#triggered-by-user-ac tivation).
28 // This can be problematic in cases where a web page issues many navigations in
29 // rapid succession, e.g. JS code that dispatches new navigation requests in a
30 // tight loop can result in dozens of programmatically generated navigations
31 // being user initiated.
32 //
33 // Note that UserInputTracker does not keep track of input events processed by
34 // the browser, such as interactions with the Chrome browser UI (e.g. clicking
35 // the 'reload' button).
36 class UserInputTracker {
37 public:
38 // Only public for tests.
39 static const size_t kMaxTrackedEvents;
40 static base::TimeTicks GetEventTime(const blink::WebInputEvent& event);
41
42 // Given a time, round to the nearest rate-limited offset. UserInputTracker
43 // rate limits events, such that at most one event will be recorded per every
44 // 20ms. RoundToRateLimitedOffset round a TimeTicks down to its nearest whole
45 // 20ms.
46 static base::TimeTicks RoundToRateLimitedOffset(base::TimeTicks time);
47
48 UserInputTracker();
49 ~UserInputTracker();
50
51 void OnInputEvent(const blink::WebInputEvent& event);
52
53 // Attempts to find the most recent user input event before the given time,
54 // and, if that input event exists, consumes all events up to that
55 // event. Returns whether an input event before the given time was found and
56 // consumed.
57 bool FindAndConsumeInputEventsBefore(base::TimeTicks time);
58
59 // Finds the time of the most recent user input event before the given time,
60 // or a null TimeTicks if there are no user input events before the given
61 // time. Consumers of this class should use
62 // FindAndConsumeInputEventsBefore. This method is public only for testing.
63 base::TimeTicks FindMostRecentUserInputEventBefore(base::TimeTicks time);
64
65 private:
66 void RemoveInputEventsUpToInclusive(base::TimeTicks cutoff);
67
68 // Removes input events that are too old to match recent times passed to
69 // FindAndConsumeInputEventsBefore.
70 void RemoveOldInputEvents();
71 static base::TimeTicks GetOldestAllowedEventTime(base::TimeTicks now);
72
73 std::vector<base::TimeTicks> sorted_event_times_;
74 base::TimeTicks most_recent_consumed_time_;
75
76 DISALLOW_COPY_AND_ASSIGN(UserInputTracker);
Charlie Harrison 2016/12/06 18:43:09 include base/macros.h
Bryan McQuade 2016/12/06 20:10:03 Done
77 };
78
79 } // namespace page_load_metrics
80
81 #endif // CHROME_BROWSER_PAGE_LOAD_METRICS_USER_INPUT_TRACKER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698