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

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

Issue 2662803002: Chromium doesn't compile with -Wglobal-constructors (Closed)
Patch Set: Created 3 years, 10 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
« no previous file with comments | « chrome/browser/page_load_metrics/user_input_tracker.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
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
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
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
« no previous file with comments | « chrome/browser/page_load_metrics/user_input_tracker.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698