| 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 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 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 Loading... |
| 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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 std::upper_bound(sorted_event_times_.begin(), sorted_event_times_.end(), | 167 std::upper_bound(sorted_event_times_.begin(), sorted_event_times_.end(), |
| 168 cutoff)); | 168 cutoff)); |
| 169 } | 169 } |
| 170 | 170 |
| 171 // static | 171 // static |
| 172 base::TimeDelta UserInputTracker::GetOldEventThreshold() { | 172 base::TimeDelta UserInputTracker::GetOldEventThreshold() { |
| 173 return base::TimeDelta::FromSeconds(kOldestAllowedEventAgeSeconds); | 173 return base::TimeDelta::FromSeconds(kOldestAllowedEventAgeSeconds); |
| 174 } | 174 } |
| 175 | 175 |
| 176 } // namespace page_load_metrics | 176 } // namespace page_load_metrics |
| OLD | NEW |