OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/browser/renderer_host/input/render_widget_host_latency_tracker
.h" | 5 #include "content/browser/renderer_host/input/render_widget_host_latency_tracker
.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/metrics/histogram_functions.h" | 10 #include "base/metrics/histogram_functions.h" |
11 #include "base/metrics/histogram_macros.h" | 11 #include "base/metrics/histogram_macros.h" |
12 #include "build/build_config.h" | 12 #include "build/build_config.h" |
13 #include "components/rappor/public/rappor_utils.h" | 13 #include "components/rappor/public/rappor_utils.h" |
14 #include "content/browser/renderer_host/render_widget_host_delegate.h" | 14 #include "content/browser/renderer_host/render_widget_host_delegate.h" |
15 #include "content/public/browser/content_browser_client.h" | 15 #include "content/public/browser/content_browser_client.h" |
16 #include "content/public/common/content_client.h" | 16 #include "content/public/common/content_client.h" |
17 #include "ui/events/blink/web_input_event_traits.h" | 17 #include "ui/events/blink/web_input_event_traits.h" |
18 #include "ui/latency/latency_histogram_macros.h" | 18 #include "ui/latency/latency_histogram_macros.h" |
19 | 19 |
20 using blink::WebGestureEvent; | 20 using blink::WebGestureEvent; |
21 using blink::WebInputEvent; | 21 using blink::WebInputEvent; |
22 using blink::WebMouseEvent; | 22 using blink::WebMouseEvent; |
23 using blink::WebMouseWheelEvent; | 23 using blink::WebMouseWheelEvent; |
24 using blink::WebTouchEvent; | 24 using blink::WebTouchEvent; |
25 using ui::LatencyInfo; | 25 using ui::LatencyInfo; |
26 | 26 |
27 namespace content { | 27 namespace content { |
28 namespace { | 28 namespace { |
29 | 29 |
30 void UpdateLatencyCoordinatesImpl(const blink::WebTouchEvent& touch, | |
31 LatencyInfo* latency, | |
32 float device_scale_factor) { | |
33 for (uint32_t i = 0; i < touch.touches_length; ++i) { | |
34 gfx::PointF coordinate(touch.touches[i].position.x * device_scale_factor, | |
35 touch.touches[i].position.y * device_scale_factor); | |
36 if (!latency->AddInputCoordinate(coordinate)) | |
37 break; | |
38 } | |
39 } | |
40 | |
41 void UpdateLatencyCoordinatesImpl(const WebGestureEvent& gesture, | |
42 LatencyInfo* latency, | |
43 float device_scale_factor) { | |
44 latency->AddInputCoordinate(gfx::PointF(gesture.x * device_scale_factor, | |
45 gesture.y * device_scale_factor)); | |
46 } | |
47 | |
48 void UpdateLatencyCoordinatesImpl(const WebMouseEvent& mouse, | |
49 LatencyInfo* latency, | |
50 float device_scale_factor) { | |
51 latency->AddInputCoordinate( | |
52 gfx::PointF(mouse.PositionInWidget().x * device_scale_factor, | |
53 mouse.PositionInWidget().y * device_scale_factor)); | |
54 } | |
55 | |
56 void UpdateLatencyCoordinatesImpl(const WebMouseWheelEvent& wheel, | |
57 LatencyInfo* latency, | |
58 float device_scale_factor) { | |
59 latency->AddInputCoordinate( | |
60 gfx::PointF(wheel.PositionInWidget().x * device_scale_factor, | |
61 wheel.PositionInWidget().y * device_scale_factor)); | |
62 } | |
63 | |
64 void UpdateLatencyCoordinates(const WebInputEvent& event, | |
65 float device_scale_factor, | |
66 LatencyInfo* latency) { | |
67 if (WebInputEvent::IsMouseEventType(event.GetType())) { | |
68 UpdateLatencyCoordinatesImpl(static_cast<const WebMouseEvent&>(event), | |
69 latency, device_scale_factor); | |
70 } else if (WebInputEvent::IsGestureEventType(event.GetType())) { | |
71 UpdateLatencyCoordinatesImpl(static_cast<const WebGestureEvent&>(event), | |
72 latency, device_scale_factor); | |
73 } else if (WebInputEvent::IsTouchEventType(event.GetType())) { | |
74 UpdateLatencyCoordinatesImpl(static_cast<const WebTouchEvent&>(event), | |
75 latency, device_scale_factor); | |
76 } else if (event.GetType() == WebInputEvent::kMouseWheel) { | |
77 UpdateLatencyCoordinatesImpl(static_cast<const WebMouseWheelEvent&>(event), | |
78 latency, device_scale_factor); | |
79 } | |
80 } | |
81 | |
82 std::string WebInputEventTypeToInputModalityString(WebInputEvent::Type type) { | 30 std::string WebInputEventTypeToInputModalityString(WebInputEvent::Type type) { |
83 if (type == blink::WebInputEvent::kMouseWheel) { | 31 if (type == blink::WebInputEvent::kMouseWheel) { |
84 return "Wheel"; | 32 return "Wheel"; |
85 } else if (WebInputEvent::IsKeyboardEventType(type)) { | 33 } else if (WebInputEvent::IsKeyboardEventType(type)) { |
86 return "Key"; | 34 return "Key"; |
87 } else if (WebInputEvent::IsMouseEventType(type)) { | 35 } else if (WebInputEvent::IsMouseEventType(type)) { |
88 return "Mouse"; | 36 return "Mouse"; |
89 } else if (WebInputEvent::IsTouchEventType(type)) { | 37 } else if (WebInputEvent::IsTouchEventType(type)) { |
90 return "Touch"; | 38 return "Touch"; |
91 } | 39 } |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 0, | 213 0, |
266 0, | 214 0, |
267 timestamp_original, | 215 timestamp_original, |
268 1); | 216 1); |
269 } | 217 } |
270 | 218 |
271 latency->AddLatencyNumberWithTraceName( | 219 latency->AddLatencyNumberWithTraceName( |
272 ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, latency_component_id_, | 220 ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, latency_component_id_, |
273 ++last_event_id_, WebInputEvent::GetName(event.GetType())); | 221 ++last_event_id_, WebInputEvent::GetName(event.GetType())); |
274 | 222 |
275 UpdateLatencyCoordinates(event, device_scale_factor_, latency); | |
276 | |
277 if (event.GetType() == blink::WebInputEvent::kGestureScrollBegin) { | 223 if (event.GetType() == blink::WebInputEvent::kGestureScrollBegin) { |
278 has_seen_first_gesture_scroll_update_ = false; | 224 has_seen_first_gesture_scroll_update_ = false; |
279 } else if (event.GetType() == blink::WebInputEvent::kGestureScrollUpdate) { | 225 } else if (event.GetType() == blink::WebInputEvent::kGestureScrollUpdate) { |
280 // Make a copy of the INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT with a | 226 // Make a copy of the INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT with a |
281 // different name INPUT_EVENT_LATENCY_SCROLL_UPDATE_ORIGINAL_COMPONENT. | 227 // different name INPUT_EVENT_LATENCY_SCROLL_UPDATE_ORIGINAL_COMPONENT. |
282 // So we can track the latency specifically for scroll update events. | 228 // So we can track the latency specifically for scroll update events. |
283 LatencyInfo::LatencyComponent original_component; | 229 LatencyInfo::LatencyComponent original_component; |
284 if (latency->FindLatency(ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0, | 230 if (latency->FindLatency(ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0, |
285 &original_component)) { | 231 &original_component)) { |
286 latency->AddLatencyNumberWithTimestamp( | 232 latency->AddLatencyNumberWithTimestamp( |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 sample->SetUInt64Field( | 305 sample->SetUInt64Field( |
360 "Latency", | 306 "Latency", |
361 (end_component.last_event_time - start_component.first_event_time) | 307 (end_component.last_event_time - start_component.first_event_time) |
362 .InMicroseconds(), | 308 .InMicroseconds(), |
363 rappor::NO_NOISE); | 309 rappor::NO_NOISE); |
364 rappor_service->RecordSample(name, std::move(sample)); | 310 rappor_service->RecordSample(name, std::move(sample)); |
365 } | 311 } |
366 } | 312 } |
367 | 313 |
368 } // namespace content | 314 } // namespace content |
OLD | NEW |