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

Side by Side Diff: ash/touch/touch_uma.cc

Issue 501553004: Move gesture/touch UMA logs into gesture provider (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: format Created 6 years, 3 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 | « no previous file | ui/events/BUILD.gn » ('j') | ui/events/gesture_detection/gesture_provider.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ash/touch/touch_uma.h" 5 #include "ash/touch/touch_uma.h"
6 6
7 #include "ash/metrics/user_metrics_recorder.h" 7 #include "ash/metrics/user_metrics_recorder.h"
8 #include "ash/shell.h" 8 #include "ash/shell.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
11 #include "ui/aura/env.h" 11 #include "ui/aura/env.h"
12 #include "ui/aura/window.h" 12 #include "ui/aura/window.h"
13 #include "ui/aura/window_event_dispatcher.h" 13 #include "ui/aura/window_event_dispatcher.h"
14 #include "ui/aura/window_property.h" 14 #include "ui/aura/window_property.h"
15 #include "ui/events/event.h" 15 #include "ui/events/event.h"
16 #include "ui/events/event_utils.h" 16 #include "ui/events/event_utils.h"
17 #include "ui/gfx/point_conversions.h" 17 #include "ui/gfx/point_conversions.h"
18 18
19 #if defined(USE_XI2_MT) 19 #if defined(USE_XI2_MT)
20 #include <X11/extensions/XInput2.h> 20 #include <X11/extensions/XInput2.h>
21 #include <X11/Xlib.h> 21 #include <X11/Xlib.h>
22 #endif 22 #endif
23 23
24 namespace { 24 namespace {
25 25
26 enum UMAEventType {
27 // WARNING: Do not change the numerical values of any of these types.
28 // Do not remove deprecated types - just comment them as deprecated.
29 UMA_ET_UNKNOWN = 0,
30 UMA_ET_TOUCH_RELEASED = 1,
31 UMA_ET_TOUCH_PRESSED = 2,
32 UMA_ET_TOUCH_MOVED = 3,
33 UMA_ET_TOUCH_STATIONARY = 4, // Deprecated. Do not remove.
34 UMA_ET_TOUCH_CANCELLED = 5,
35 UMA_ET_GESTURE_SCROLL_BEGIN = 6,
36 UMA_ET_GESTURE_SCROLL_END = 7,
37 UMA_ET_GESTURE_SCROLL_UPDATE = 8,
38 UMA_ET_GESTURE_TAP = 9,
39 UMA_ET_GESTURE_TAP_DOWN = 10,
40 UMA_ET_GESTURE_BEGIN = 11,
41 UMA_ET_GESTURE_END = 12,
42 UMA_ET_GESTURE_DOUBLE_TAP = 13,
43 UMA_ET_GESTURE_TRIPLE_TAP = 14,
44 UMA_ET_GESTURE_TWO_FINGER_TAP = 15,
45 UMA_ET_GESTURE_PINCH_BEGIN = 16,
46 UMA_ET_GESTURE_PINCH_END = 17,
47 UMA_ET_GESTURE_PINCH_UPDATE = 18,
48 UMA_ET_GESTURE_LONG_PRESS = 19,
49 UMA_ET_GESTURE_SWIPE_2 = 20, // Swipe with 2 fingers
50 UMA_ET_SCROLL = 21,
51 UMA_ET_SCROLL_FLING_START = 22,
52 UMA_ET_SCROLL_FLING_CANCEL = 23,
53 UMA_ET_GESTURE_SWIPE_3 = 24, // Swipe with 3 fingers
54 UMA_ET_GESTURE_SWIPE_4P = 25, // Swipe with 4+ fingers
55 UMA_ET_GESTURE_SCROLL_UPDATE_2 = 26,
56 UMA_ET_GESTURE_SCROLL_UPDATE_3 = 27,
57 UMA_ET_GESTURE_SCROLL_UPDATE_4P = 28,
58 UMA_ET_GESTURE_PINCH_UPDATE_3 = 29,
59 UMA_ET_GESTURE_PINCH_UPDATE_4P = 30,
60 UMA_ET_GESTURE_LONG_TAP = 31,
61 UMA_ET_GESTURE_SHOW_PRESS = 32,
62 UMA_ET_GESTURE_TAP_CANCEL = 33,
63 UMA_ET_GESTURE_WIN8_EDGE_SWIPE = 34,
64 UMA_ET_GESTURE_SWIPE_1 = 35, // Swipe with 1 finger
65 // NOTE: Add new event types only immediately above this line. Make sure to
66 // update the UIEventType enum in tools/metrics/histograms/histograms.xml
67 // accordingly.
68 UMA_ET_COUNT
69 };
70
71 struct WindowTouchDetails { 26 struct WindowTouchDetails {
72 WindowTouchDetails() 27 WindowTouchDetails()
73 : max_distance_from_start_squared_(0) { 28 : max_distance_from_start_squared_(0) {
tdresser 2014/08/27 12:35:38 You should be able to get rid of max_distance_from
lanwei 2014/08/27 23:31:59 Done.
74 } 29 }
75 30
76 // Move and start times of the touch points. The key is the touch-id. 31 // Move and start times of the touch points. The key is the touch-id.
77 std::map<int, base::TimeDelta> last_move_time_; 32 std::map<int, base::TimeDelta> last_move_time_;
78 std::map<int, base::TimeDelta> last_start_time_; 33 std::map<int, base::TimeDelta> last_start_time_;
79 34
80 // The first and last positions of the touch points. 35 // The first and last positions of the touch points.
81 std::map<int, gfx::Point> start_touch_position_; 36 std::map<int, gfx::Point> start_touch_position_;
82 std::map<int, gfx::Point> last_touch_position_; 37 std::map<int, gfx::Point> last_touch_position_;
83 38
84 // The maximum distance the first touch point travelled from its starting 39 // The maximum distance the first touch point travelled from its starting
85 // location in pixels. 40 // location in pixels.
86 float max_distance_from_start_squared_; 41 float max_distance_from_start_squared_;
87 42
88 // Last time-stamp of the last touch-end event. 43 // Last time-stamp of the last touch-end event.
89 base::TimeDelta last_release_time_; 44 base::TimeDelta last_release_time_;
90 45
91 // Stores the time of the last touch released on this window (if there was a 46 // Stores the time of the last touch released on this window (if there was a
92 // multi-touch gesture on the window, then this is the release-time of the 47 // multi-touch gesture on the window, then this is the release-time of the
93 // last touch on the window). 48 // last touch on the window).
94 base::TimeDelta last_mt_time_; 49 base::TimeDelta last_mt_time_;
95 }; 50 };
96 51
97 DEFINE_OWNED_WINDOW_PROPERTY_KEY(WindowTouchDetails, 52 DEFINE_OWNED_WINDOW_PROPERTY_KEY(WindowTouchDetails,
98 kWindowTouchDetails, 53 kWindowTouchDetails,
99 NULL); 54 NULL);
100
101
102 UMAEventType UMAEventTypeFromEvent(const ui::Event& event) {
103 switch (event.type()) {
104 case ui::ET_TOUCH_RELEASED:
105 return UMA_ET_TOUCH_RELEASED;
106 case ui::ET_TOUCH_PRESSED:
107 return UMA_ET_TOUCH_PRESSED;
108 case ui::ET_TOUCH_MOVED:
109 return UMA_ET_TOUCH_MOVED;
110 case ui::ET_TOUCH_CANCELLED:
111 return UMA_ET_TOUCH_CANCELLED;
112 case ui::ET_GESTURE_SCROLL_BEGIN:
113 return UMA_ET_GESTURE_SCROLL_BEGIN;
114 case ui::ET_GESTURE_SCROLL_END:
115 return UMA_ET_GESTURE_SCROLL_END;
116 case ui::ET_GESTURE_SCROLL_UPDATE: {
117 const ui::GestureEvent& gesture =
118 static_cast<const ui::GestureEvent&>(event);
119 if (gesture.details().touch_points() == 1)
120 return UMA_ET_GESTURE_SCROLL_UPDATE;
121 else if (gesture.details().touch_points() == 2)
122 return UMA_ET_GESTURE_SCROLL_UPDATE_2;
123 else if (gesture.details().touch_points() == 3)
124 return UMA_ET_GESTURE_SCROLL_UPDATE_3;
125 return UMA_ET_GESTURE_SCROLL_UPDATE_4P;
126 }
127 case ui::ET_GESTURE_TAP: {
128 const ui::GestureEvent& gesture =
129 static_cast<const ui::GestureEvent&>(event);
130 int tap_count = gesture.details().tap_count();
131 if (tap_count == 1)
132 return UMA_ET_GESTURE_TAP;
133 if (tap_count == 2)
134 return UMA_ET_GESTURE_DOUBLE_TAP;
135 if (tap_count == 3)
136 return UMA_ET_GESTURE_TRIPLE_TAP;
137 NOTREACHED() << "Received tap with tapcount " << tap_count;
138 return UMA_ET_UNKNOWN;
139 }
140 case ui::ET_GESTURE_TAP_DOWN:
141 return UMA_ET_GESTURE_TAP_DOWN;
142 case ui::ET_GESTURE_BEGIN:
143 return UMA_ET_GESTURE_BEGIN;
144 case ui::ET_GESTURE_END:
145 return UMA_ET_GESTURE_END;
146 case ui::ET_GESTURE_TWO_FINGER_TAP:
147 return UMA_ET_GESTURE_TWO_FINGER_TAP;
148 case ui::ET_GESTURE_PINCH_BEGIN:
149 return UMA_ET_GESTURE_PINCH_BEGIN;
150 case ui::ET_GESTURE_PINCH_END:
151 return UMA_ET_GESTURE_PINCH_END;
152 case ui::ET_GESTURE_PINCH_UPDATE: {
153 const ui::GestureEvent& gesture =
154 static_cast<const ui::GestureEvent&>(event);
155 if (gesture.details().touch_points() >= 4)
156 return UMA_ET_GESTURE_PINCH_UPDATE_4P;
157 else if (gesture.details().touch_points() == 3)
158 return UMA_ET_GESTURE_PINCH_UPDATE_3;
159 return UMA_ET_GESTURE_PINCH_UPDATE;
160 }
161 case ui::ET_GESTURE_LONG_PRESS:
162 return UMA_ET_GESTURE_LONG_PRESS;
163 case ui::ET_GESTURE_LONG_TAP:
164 return UMA_ET_GESTURE_LONG_TAP;
165 case ui::ET_GESTURE_SWIPE: {
166 const ui::GestureEvent& gesture =
167 static_cast<const ui::GestureEvent&>(event);
168 if (gesture.details().touch_points() == 1)
169 return UMA_ET_GESTURE_SWIPE_1;
170 else if (gesture.details().touch_points() == 2)
171 return UMA_ET_GESTURE_SWIPE_2;
172 else if (gesture.details().touch_points() == 3)
173 return UMA_ET_GESTURE_SWIPE_3;
174 return UMA_ET_GESTURE_SWIPE_4P;
175 }
176 case ui::ET_GESTURE_WIN8_EDGE_SWIPE:
177 return UMA_ET_GESTURE_WIN8_EDGE_SWIPE;
178 case ui::ET_GESTURE_TAP_CANCEL:
179 return UMA_ET_GESTURE_TAP_CANCEL;
180 case ui::ET_GESTURE_SHOW_PRESS:
181 return UMA_ET_GESTURE_SHOW_PRESS;
182 case ui::ET_SCROLL:
183 return UMA_ET_SCROLL;
184 case ui::ET_SCROLL_FLING_START:
185 return UMA_ET_SCROLL_FLING_START;
186 case ui::ET_SCROLL_FLING_CANCEL:
187 return UMA_ET_SCROLL_FLING_CANCEL;
188 default:
189 NOTREACHED();
190 return UMA_ET_UNKNOWN;
191 }
192 }
193
194 } 55 }
195 56
196 namespace ash { 57 namespace ash {
197 58
198 // static 59 // static
199 TouchUMA* TouchUMA::GetInstance() { 60 TouchUMA* TouchUMA::GetInstance() {
200 return Singleton<TouchUMA>::get(); 61 return Singleton<TouchUMA>::get();
201 } 62 }
202 63
203 void TouchUMA::RecordGestureEvent(aura::Window* target, 64 void TouchUMA::RecordGestureEvent(aura::Window* target,
204 const ui::GestureEvent& event) { 65 const ui::GestureEvent& event) {
205 UMA_HISTOGRAM_ENUMERATION("Ash.GestureCreated",
206 UMAEventTypeFromEvent(event),
207 UMA_ET_COUNT);
208
209 GestureActionType action = FindGestureActionType(target, event); 66 GestureActionType action = FindGestureActionType(target, event);
210 RecordGestureAction(action); 67 RecordGestureAction(action);
211 68
212 if (event.type() == ui::ET_GESTURE_END && 69 if (event.type() == ui::ET_GESTURE_END &&
213 event.details().touch_points() == 2) { 70 event.details().touch_points() == 2) {
214 WindowTouchDetails* details = target->GetProperty(kWindowTouchDetails); 71 WindowTouchDetails* details = target->GetProperty(kWindowTouchDetails);
215 if (!details) { 72 if (!details) {
216 LOG(ERROR) << "Window received gesture events without receiving any touch" 73 LOG(ERROR) << "Window received gesture events without receiving any touch"
217 " events"; 74 " events";
218 return; 75 return;
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 gap.InMilliseconds()); 163 gap.InMilliseconds());
307 } 164 }
308 } 165 }
309 166
310 // Record the number of touch-points currently active for the window. 167 // Record the number of touch-points currently active for the window.
311 const int kMaxTouchPoints = 10; 168 const int kMaxTouchPoints = 10;
312 UMA_HISTOGRAM_CUSTOM_COUNTS("Ash.ActiveTouchPoints", 169 UMA_HISTOGRAM_CUSTOM_COUNTS("Ash.ActiveTouchPoints",
313 details->last_start_time_.size(), 170 details->last_start_time_.size(),
314 1, kMaxTouchPoints, kMaxTouchPoints + 1); 171 1, kMaxTouchPoints, kMaxTouchPoints + 1);
315 } else if (event.type() == ui::ET_TOUCH_RELEASED) { 172 } else if (event.type() == ui::ET_TOUCH_RELEASED) {
316 if (is_single_finger_gesture_) {
317 UMA_HISTOGRAM_CUSTOM_COUNTS("Ash.TouchMaxDistance",
318 static_cast<int>(
319 sqrt(details->max_distance_from_start_squared_)), 0, 1500, 50);
320 }
321
322 if (details->last_start_time_.count(event.touch_id())) { 173 if (details->last_start_time_.count(event.touch_id())) {
323 base::TimeDelta duration = event.time_stamp() - 174 base::TimeDelta duration = event.time_stamp() -
324 details->last_start_time_[event.touch_id()]; 175 details->last_start_time_[event.touch_id()];
325 UMA_HISTOGRAM_TIMES("Ash.TouchDuration2", duration);
326
327 // Look for touches that were [almost] stationary for a long time. 176 // Look for touches that were [almost] stationary for a long time.
328 const double kLongStationaryTouchDuration = 10; 177 const double kLongStationaryTouchDuration = 10;
329 const int kLongStationaryTouchDistanceSquared = 100; 178 const int kLongStationaryTouchDistanceSquared = 100;
330 if (duration.InSecondsF() > kLongStationaryTouchDuration) { 179 if (duration.InSecondsF() > kLongStationaryTouchDuration) {
331 gfx::Vector2d distance = event.root_location() - 180 gfx::Vector2d distance = event.root_location() -
332 details->start_touch_position_[event.touch_id()]; 181 details->start_touch_position_[event.touch_id()];
333 if (distance.LengthSquared() < kLongStationaryTouchDistanceSquared) { 182 if (distance.LengthSquared() < kLongStationaryTouchDistanceSquared) {
334 UMA_HISTOGRAM_CUSTOM_COUNTS("Ash.StationaryTouchDuration", 183 UMA_HISTOGRAM_CUSTOM_COUNTS("Ash.StationaryTouchDuration",
335 duration.InSeconds(), 184 duration.InSeconds(),
336 kLongStationaryTouchDuration, 185 kLongStationaryTouchDuration,
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 return GESTURE_OMNIBOX_SCROLL; 317 return GESTURE_OMNIBOX_SCROLL;
469 if (event.type() == ui::ET_GESTURE_PINCH_BEGIN) 318 if (event.type() == ui::ET_GESTURE_PINCH_BEGIN)
470 return GESTURE_OMNIBOX_PINCH; 319 return GESTURE_OMNIBOX_PINCH;
471 return GESTURE_UNKNOWN; 320 return GESTURE_UNKNOWN;
472 } 321 }
473 322
474 return GESTURE_UNKNOWN; 323 return GESTURE_UNKNOWN;
475 } 324 }
476 325
477 } // namespace ash 326 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | ui/events/BUILD.gn » ('j') | ui/events/gesture_detection/gesture_provider.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698