Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 <set> | |
| 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. 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
| |
| 30 // navigations issued within a second of a user action will be attributed to a | |
| 31 // user action by default. For JS code running in a tight loop that dispatches a | |
| 32 // new navigation request every ~30ms, this can result in dozens of | |
| 33 // programatically generated navigations being considered as user | |
| 34 // initiated. UserInputTracker is used to associate at most one navigation with | |
| 35 // a given input event that was generated before the navigation event. | |
| 36 // | |
| 37 // Note that UserInputTracker does not keep track of input events processed by | |
| 38 // the browser, such as interactions with the Chrome browser UI (e.g. clicking | |
| 39 // the 'reload' button). | |
| 40 class UserInputTracker { | |
| 41 public: | |
| 42 static base::TimeTicks GetEventTime(const blink::WebInputEvent& event); | |
| 43 | |
| 44 UserInputTracker(); | |
| 45 ~UserInputTracker(); | |
| 46 | |
| 47 void OnInputEvent(const blink::WebInputEvent& event); | |
| 48 | |
| 49 // Finds the time of the most recent user input event before the given time, | |
| 50 // or a null TimeTicks if there are no user input events before the given | |
| 51 // time. | |
| 52 base::TimeTicks FindMostRecentUserInputEventBefore(base::TimeTicks time); | |
| 53 | |
| 54 // Consumes all user input events up to the specified time. | |
| 55 void ConsumeUserInputEventsUpTo(base::TimeTicks time); | |
| 56 | |
| 57 private: | |
| 58 void RemoveInputEventsUpTo(base::TimeTicks cutoff); | |
| 59 void RemoveOldInputEvents(); | |
| 60 static base::TimeTicks GetOldestAllowedEventTime(); | |
| 61 | |
| 62 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.
| |
| 63 | |
| 64 DISALLOW_COPY_AND_ASSIGN(UserInputTracker); | |
| 65 }; | |
| 66 | |
| 67 } // namespace page_load_metrics | |
| 68 | |
| 69 #endif // CHROME_BROWSER_PAGE_LOAD_METRICS_USER_INPUT_TRACKER_H_ | |
| OLD | NEW |