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

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

Issue 2573073003: Collapse the API surface on WebInputEvent via accessor functions. (Closed)
Patch Set: Fix nits Created 3 years, 11 months 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
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
(...skipping 11 matching lines...) Expand all
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 const 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:
39 case blink::WebInputEvent::KeyDown: 39 case blink::WebInputEvent::KeyDown:
40 case blink::WebInputEvent::Char: 40 case blink::WebInputEvent::Char:
41 case blink::WebInputEvent::TouchStart: 41 case blink::WebInputEvent::TouchStart:
42 case blink::WebInputEvent::TouchEnd: 42 case blink::WebInputEvent::TouchEnd:
43 return true; 43 return true;
44 default: 44 default:
45 return false; 45 return false;
(...skipping 15 matching lines...) Expand all
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 const size_t UserInputTracker::kMaxTrackedEvents = 100;
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) {
77 base::TimeDelta time_as_delta = time - base::TimeTicks(); 77 base::TimeDelta time_as_delta = time - base::TimeTicks();
78 base::TimeDelta rate_limit_remainder = 78 base::TimeDelta rate_limit_remainder =
79 time_as_delta % base::TimeDelta::FromMilliseconds(kRateLimitClampMillis); 79 time_as_delta % base::TimeDelta::FromMilliseconds(kRateLimitClampMillis);
80 return time - rate_limit_remainder; 80 return time - rate_limit_remainder;
81 } 81 }
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698