OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/page_load_metrics/user_input_tracker.h" | 5 #include "chrome/browser/page_load_metrics/user_input_tracker.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "third_party/WebKit/public/platform/WebInputEvent.h" | 9 #include "third_party/WebKit/public/platform/WebInputEvent.h" |
10 | 10 |
11 namespace page_load_metrics { | 11 namespace page_load_metrics { |
12 | 12 |
13 namespace { | 13 namespace { |
14 | 14 |
15 // Blink's UserGestureIndicator allows events to be associated with gestures | 15 // Blink's UserGestureIndicator allows events to be associated with gestures |
16 // that are up to 1 second old, based on guidance in the HTML spec: | 16 // that are up to 1 second old, based on guidance in the HTML spec: |
17 // https://html.spec.whatwg.org/multipage/interaction.html#triggered-by-user-act ivation. | 17 // https://html.spec.whatwg.org/multipage/interaction.html#triggered-by-user-act ivation. |
18 const int kMaxEventAgeSeconds = 1; | 18 const int kMaxEventAgeSeconds = 1; |
19 | 19 |
20 // Allow for up to 2x the oldest time. This allows consumers to continue to | 20 // Allow for up to 2x the oldest time. This allows consumers to continue to |
21 // find events for timestamps up to 1 second in the past. | 21 // find events for timestamps up to 1 second in the past. |
22 const int kOldestAllowedEventAgeSeconds = kMaxEventAgeSeconds * 2; | 22 const int kOldestAllowedEventAgeSeconds = kMaxEventAgeSeconds * 2; |
23 | 23 |
24 // In order to limit to at most kMaxTrackedEvents, we rate limit the recorded | 24 // In order to limit to at most kMaxTrackedEvents, we rate limit the recorded |
25 // events, | 25 // events, |
26 // allowing one per rate limit period. | 26 // allowing one per rate limit period. |
27 const int kRateLimitClampMillis = (kOldestAllowedEventAgeSeconds * 1000) / | 27 constexpr int kRateLimitClampMillis = (kOldestAllowedEventAgeSeconds * 1000) / |
28 UserInputTracker::kMaxTrackedEvents; | 28 UserInputTracker::kMaxTrackedEvents; |
29 | 29 |
30 bool IsInterestingInputEvent(const blink::WebInputEvent& event) { | 30 bool IsInterestingInputEvent(const blink::WebInputEvent& event) { |
31 // Ignore synthesized auto repeat events. | 31 // Ignore synthesized auto repeat events. |
32 if (event.modifiers() & blink::WebInputEvent::IsAutoRepeat) | 32 if (event.modifiers() & blink::WebInputEvent::IsAutoRepeat) |
33 return false; | 33 return false; |
34 | 34 |
35 switch (event.type()) { | 35 switch (event.type()) { |
36 case blink::WebInputEvent::MouseDown: | 36 case blink::WebInputEvent::MouseDown: |
37 case blink::WebInputEvent::MouseUp: | 37 case blink::WebInputEvent::MouseUp: |
38 case blink::WebInputEvent::RawKeyDown: | 38 case blink::WebInputEvent::RawKeyDown: |
(...skipping 17 matching lines...) Expand all Loading... | |
56 } | 56 } |
57 | 57 |
58 } // namespace | 58 } // namespace |
59 | 59 |
60 UserInputTracker::UserInputTracker() { | 60 UserInputTracker::UserInputTracker() { |
61 sorted_event_times_.reserve(kMaxTrackedEvents); | 61 sorted_event_times_.reserve(kMaxTrackedEvents); |
62 } | 62 } |
63 | 63 |
64 UserInputTracker::~UserInputTracker() {} | 64 UserInputTracker::~UserInputTracker() {} |
65 | 65 |
66 const size_t UserInputTracker::kMaxTrackedEvents = 100; | 66 constexpr size_t UserInputTracker::kMaxTrackedEvents; |
Charlie Harrison
2017/01/30 14:17:51
Can you move this bit of code nearer to the kRateL
ckulakowski
2017/01/30 15:46:56
Done.
| |
67 | 67 |
68 // static | 68 // static |
69 base::TimeTicks UserInputTracker::GetEventTime( | 69 base::TimeTicks UserInputTracker::GetEventTime( |
70 const blink::WebInputEvent& event) { | 70 const blink::WebInputEvent& event) { |
71 return GetTimeTicksFromSeconds(event.timeStampSeconds()); | 71 return GetTimeTicksFromSeconds(event.timeStampSeconds()); |
72 } | 72 } |
73 | 73 |
74 // static | 74 // static |
75 base::TimeTicks UserInputTracker::RoundToRateLimitedOffset( | 75 base::TimeTicks UserInputTracker::RoundToRateLimitedOffset( |
76 base::TimeTicks time) { | 76 base::TimeTicks time) { |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
172 std::upper_bound(sorted_event_times_.begin(), sorted_event_times_.end(), | 172 std::upper_bound(sorted_event_times_.begin(), sorted_event_times_.end(), |
173 cutoff)); | 173 cutoff)); |
174 } | 174 } |
175 | 175 |
176 // static | 176 // static |
177 base::TimeDelta UserInputTracker::GetOldEventThreshold() { | 177 base::TimeDelta UserInputTracker::GetOldEventThreshold() { |
178 return base::TimeDelta::FromSeconds(kOldestAllowedEventAgeSeconds); | 178 return base::TimeDelta::FromSeconds(kOldestAllowedEventAgeSeconds); |
179 } | 179 } |
180 | 180 |
181 } // namespace page_load_metrics | 181 } // namespace page_load_metrics |
OLD | NEW |