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

Unified 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: 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/page_load_metrics/user_input_tracker.h
diff --git a/chrome/browser/page_load_metrics/user_input_tracker.h b/chrome/browser/page_load_metrics/user_input_tracker.h
new file mode 100644
index 0000000000000000000000000000000000000000..cfb020e5778f358a6b0aff8271f1e439a636a0ca
--- /dev/null
+++ b/chrome/browser/page_load_metrics/user_input_tracker.h
@@ -0,0 +1,69 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_PAGE_LOAD_METRICS_USER_INPUT_TRACKER_H_
+#define CHROME_BROWSER_PAGE_LOAD_METRICS_USER_INPUT_TRACKER_H_
+
+#include <set>
+
+#include "base/time/time.h"
+
+namespace blink {
+class WebInputEvent;
+} // namespace blink
+
+namespace page_load_metrics {
+
+// UserInputTracker keeps track of user input events processed by web pages, and
+// allows clients to find and consume those input events. This allows us to
+// heuristically attribute user input events to navigations, in order to keep
+// track of which page loads and aborts were initiated by a user action.
+//
+// There are issues with the existing user gesture tracking in Blink and content
+// that make it unsuitable for our needs. For example, Blink considers events
+// such as navigations that occur within 1 second of a user action event to have
+// been initiated by a user action, based on the HTML spec
+// (https://html.spec.whatwg.org/multipage/interaction.html#triggered-by-user-activation).
+// This can be problematic in cases where a web page issues many navigations in
+// rapid succession, e.g. from a JavaScript tight loop, as all of the
Charlie Harrison 2016/12/02 02:58:44 "e.g. JS code that dispatches new navigation reque
Bryan McQuade 2016/12/02 20:43:01 Done
+// navigations issued within a second of a user action will be attributed to a
+// user action by default. For JS code running in a tight loop that dispatches a
+// new navigation request every ~30ms, this can result in dozens of
+// programatically generated navigations being considered as user
+// initiated. UserInputTracker is used to associate at most one navigation with
+// a given input event that was generated before the navigation event.
+//
+// Note that UserInputTracker does not keep track of input events processed by
+// the browser, such as interactions with the Chrome browser UI (e.g. clicking
+// the 'reload' button).
+class UserInputTracker {
+ public:
+ static base::TimeTicks GetEventTime(const blink::WebInputEvent& event);
+
+ UserInputTracker();
+ ~UserInputTracker();
+
+ void OnInputEvent(const blink::WebInputEvent& event);
+
+ // Finds the time of the most recent user input event before the given time,
+ // or a null TimeTicks if there are no user input events before the given
+ // time.
+ base::TimeTicks FindMostRecentUserInputEventBefore(base::TimeTicks time);
+
+ // Consumes all user input events up to the specified time.
+ void ConsumeUserInputEventsUpTo(base::TimeTicks time);
+
+ private:
+ void RemoveInputEventsUpTo(base::TimeTicks cutoff);
+ void RemoveOldInputEvents();
+ static base::TimeTicks GetOldestAllowedEventTime();
+
+ std::set<base::TimeTicks> event_times_;
Charlie Harrison 2016/12/02 02:58:44 Can this be a sorted vector instead?
Bryan McQuade 2016/12/02 20:43:01 Yeah - we discussed this & I made the switch.
+
+ DISALLOW_COPY_AND_ASSIGN(UserInputTracker);
+};
+
+} // namespace page_load_metrics
+
+#endif // CHROME_BROWSER_PAGE_LOAD_METRICS_USER_INPUT_TRACKER_H_

Powered by Google App Engine
This is Rietveld 408576698