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

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

Issue 16832003: Add UMA metrics to measure the effectiveness of views fuzzing (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comments addressed Created 7 years, 6 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 | Annotate | Revision Log
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/shell_delegate.h" 7 #include "ash/shell_delegate.h"
8 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "ui/aura/env.h" 10 #include "ui/aura/env.h"
11 #include "ui/aura/root_window.h" 11 #include "ui/aura/root_window.h"
12 #include "ui/aura/window.h" 12 #include "ui/aura/window.h"
13 #include "ui/aura/window_property.h" 13 #include "ui/aura/window_property.h"
14 #include "ui/base/events/event.h" 14 #include "ui/base/events/event.h"
15 #include "ui/base/events/event_utils.h" 15 #include "ui/base/events/event_utils.h"
16 #include "ui/gfx/point_conversions.h" 16 #include "ui/gfx/point_conversions.h"
17 17
18 #if defined(USE_XI2_MT) 18 #if defined(USE_XI2_MT)
19 #include <X11/extensions/XInput2.h> 19 #include <X11/extensions/XInput2.h>
20 #include <X11/Xlib.h> 20 #include <X11/Xlib.h>
21 #endif 21 #endif
22 22
23 namespace { 23 namespace {
24 24
25 enum GestureActionType {
26 GESTURE_UNKNOWN,
27 GESTURE_OMNIBOX_PINCH,
28 GESTURE_OMNIBOX_SCROLL,
29 GESTURE_TABSTRIP_PINCH,
30 GESTURE_TABSTRIP_SCROLL,
31 GESTURE_BEZEL_SCROLL,
32 GESTURE_DESKTOP_SCROLL,
33 GESTURE_DESKTOP_PINCH,
34 GESTURE_WEBPAGE_PINCH,
35 GESTURE_WEBPAGE_SCROLL,
36 GESTURE_WEBPAGE_TAP,
37 GESTURE_TABSTRIP_TAP,
38 GESTURE_BEZEL_DOWN,
39 // NOTE: Add new action types only immediately above this line. Also, make sure
40 // the enum list in tools/histogram/histograms.xml is updated with any change in
41 // here.
42 GESTURE_ACTION_COUNT
43 };
44
45 enum UMAEventType { 25 enum UMAEventType {
46 UMA_ET_UNKNOWN, 26 UMA_ET_UNKNOWN,
47 UMA_ET_TOUCH_RELEASED, 27 UMA_ET_TOUCH_RELEASED,
48 UMA_ET_TOUCH_PRESSED, 28 UMA_ET_TOUCH_PRESSED,
49 UMA_ET_TOUCH_MOVED, 29 UMA_ET_TOUCH_MOVED,
50 UMA_ET_TOUCH_STATIONARY, 30 UMA_ET_TOUCH_STATIONARY,
51 UMA_ET_TOUCH_CANCELLED, 31 UMA_ET_TOUCH_CANCELLED,
52 UMA_ET_GESTURE_SCROLL_BEGIN, 32 UMA_ET_GESTURE_SCROLL_BEGIN,
53 UMA_ET_GESTURE_SCROLL_END, 33 UMA_ET_GESTURE_SCROLL_END,
54 UMA_ET_GESTURE_SCROLL_UPDATE, 34 UMA_ET_GESTURE_SCROLL_UPDATE,
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 // Stores the time of the last touch released on this window (if there was a 75 // Stores the time of the last touch released on this window (if there was a
96 // multi-touch gesture on the window, then this is the release-time of the 76 // multi-touch gesture on the window, then this is the release-time of the
97 // last touch on the window). 77 // last touch on the window).
98 base::TimeDelta last_mt_time_; 78 base::TimeDelta last_mt_time_;
99 }; 79 };
100 80
101 DEFINE_OWNED_WINDOW_PROPERTY_KEY(WindowTouchDetails, 81 DEFINE_OWNED_WINDOW_PROPERTY_KEY(WindowTouchDetails,
102 kWindowTouchDetails, 82 kWindowTouchDetails,
103 NULL); 83 NULL);
104 84
105 GestureActionType FindGestureActionType(aura::Window* window,
106 const ui::GestureEvent& event) {
107 if (!window || window->GetRootWindow() == window) {
108 if (event.type() == ui::ET_GESTURE_SCROLL_BEGIN)
109 return GESTURE_BEZEL_SCROLL;
110 if (event.type() == ui::ET_GESTURE_BEGIN)
111 return GESTURE_BEZEL_DOWN;
112 return GESTURE_UNKNOWN;
113 }
114
115 std::string name = window ? window->name() : std::string();
116
117 const char kDesktopBackgroundView[] = "DesktopBackgroundView";
118 if (name == kDesktopBackgroundView) {
119 if (event.type() == ui::ET_GESTURE_SCROLL_BEGIN)
120 return GESTURE_DESKTOP_SCROLL;
121 if (event.type() == ui::ET_GESTURE_PINCH_BEGIN)
122 return GESTURE_DESKTOP_PINCH;
123 return GESTURE_UNKNOWN;
124 }
125
126 const char kWebPage[] = "RenderWidgetHostViewAura";
127 if (name == kWebPage) {
128 if (event.type() == ui::ET_GESTURE_PINCH_BEGIN)
129 return GESTURE_WEBPAGE_PINCH;
130 if (event.type() == ui::ET_GESTURE_SCROLL_BEGIN)
131 return GESTURE_WEBPAGE_SCROLL;
132 if (event.type() == ui::ET_GESTURE_TAP)
133 return GESTURE_WEBPAGE_TAP;
134 return GESTURE_UNKNOWN;
135 }
136
137 views::Widget* widget = views::Widget::GetWidgetForNativeView(window);
138 if (!widget)
139 return GESTURE_UNKNOWN;
140
141 views::View* view = widget->GetRootView()->
142 GetEventHandlerForPoint(event.location());
143 if (!view)
144 return GESTURE_UNKNOWN;
145
146 name = view->GetClassName();
147
148 const char kTabStrip[] = "TabStrip";
149 const char kTab[] = "BrowserTab";
150 if (name == kTabStrip || name == kTab) {
151 if (event.type() == ui::ET_GESTURE_SCROLL_BEGIN)
152 return GESTURE_TABSTRIP_SCROLL;
153 if (event.type() == ui::ET_GESTURE_PINCH_BEGIN)
154 return GESTURE_TABSTRIP_PINCH;
155 if (event.type() == ui::ET_GESTURE_TAP)
156 return GESTURE_TABSTRIP_TAP;
157 return GESTURE_UNKNOWN;
158 }
159
160 const char kOmnibox[] = "BrowserOmniboxViewViews";
161 if (name == kOmnibox) {
162 if (event.type() == ui::ET_GESTURE_SCROLL_BEGIN)
163 return GESTURE_OMNIBOX_SCROLL;
164 if (event.type() == ui::ET_GESTURE_PINCH_BEGIN)
165 return GESTURE_OMNIBOX_PINCH;
166 return GESTURE_UNKNOWN;
167 }
168
169 return GESTURE_UNKNOWN;
170 }
171 85
172 UMAEventType UMAEventTypeFromEvent(const ui::Event& event) { 86 UMAEventType UMAEventTypeFromEvent(const ui::Event& event) {
173 switch (event.type()) { 87 switch (event.type()) {
174 case ui::ET_TOUCH_RELEASED: 88 case ui::ET_TOUCH_RELEASED:
175 return UMA_ET_TOUCH_RELEASED; 89 return UMA_ET_TOUCH_RELEASED;
176 case ui::ET_TOUCH_PRESSED: 90 case ui::ET_TOUCH_PRESSED:
177 return UMA_ET_TOUCH_PRESSED; 91 return UMA_ET_TOUCH_PRESSED;
178 case ui::ET_TOUCH_MOVED: 92 case ui::ET_TOUCH_MOVED:
179 return UMA_ET_TOUCH_MOVED; 93 return UMA_ET_TOUCH_MOVED;
180 case ui::ET_TOUCH_STATIONARY: 94 case ui::ET_TOUCH_STATIONARY:
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 default: 166 default:
253 return UMA_ET_UNKNOWN; 167 return UMA_ET_UNKNOWN;
254 } 168 }
255 } 169 }
256 170
257 } 171 }
258 172
259 namespace ash { 173 namespace ash {
260 namespace internal { 174 namespace internal {
261 175
262 TouchUMA::TouchUMA() 176 TouchUMA::TouchUMA()
sky 2013/06/26 23:42:55 Move this to match new position in header.
tdanderson 2013/06/27 22:39:33 Done.
263 : touch_in_progress_(false), 177 : touch_in_progress_(false),
264 burst_length_(0) { 178 burst_length_(0) {
265 } 179 }
266 180
267 TouchUMA::~TouchUMA() { 181 TouchUMA::~TouchUMA() {
268 } 182 }
269 183
184 // static
185 TouchUMA* TouchUMA::GetInstance() {
186 return Singleton<TouchUMA>::get();
187 }
188
270 void TouchUMA::RecordGestureEvent(aura::Window* target, 189 void TouchUMA::RecordGestureEvent(aura::Window* target,
271 const ui::GestureEvent& event) { 190 const ui::GestureEvent& event) {
272 UMA_HISTOGRAM_ENUMERATION("Ash.GestureCreated", 191 UMA_HISTOGRAM_ENUMERATION("Ash.GestureCreated",
273 UMAEventTypeFromEvent(event), 192 UMAEventTypeFromEvent(event),
274 UMA_ET_COUNT); 193 UMA_ET_COUNT);
275 194
276 GestureActionType action = FindGestureActionType(target, event); 195 GestureActionType action = FindGestureActionType(target, event);
277 if (action != GESTURE_UNKNOWN) { 196 RecordGestureAction(action);
278 UMA_HISTOGRAM_ENUMERATION("Ash.GestureTarget",
279 action,
280 GESTURE_ACTION_COUNT);
281 }
282 197
283 if (event.type() == ui::ET_GESTURE_END && 198 if (event.type() == ui::ET_GESTURE_END &&
284 event.details().touch_points() == 2) { 199 event.details().touch_points() == 2) {
285 WindowTouchDetails* details = target->GetProperty(kWindowTouchDetails); 200 WindowTouchDetails* details = target->GetProperty(kWindowTouchDetails);
286 if (!details) { 201 if (!details) {
287 LOG(ERROR) << "Window received gesture events without receiving any touch" 202 LOG(ERROR) << "Window received gesture events without receiving any touch"
288 " events"; 203 " events";
289 return; 204 return;
290 } 205 }
291 details->last_mt_time_ = event.time_stamp(); 206 details->last_mt_time_ = event.time_stamp();
292 } 207 }
293 } 208 }
294 209
210 void TouchUMA::RecordGestureAction(GestureActionType action) {
211 if (action == GESTURE_UNKNOWN || action >= GESTURE_ACTION_COUNT)
212 return;
213 UMA_HISTOGRAM_ENUMERATION("Ash.GestureTarget", action,
214 GESTURE_ACTION_COUNT);
215 }
216
295 void TouchUMA::RecordTouchEvent(aura::Window* target, 217 void TouchUMA::RecordTouchEvent(aura::Window* target,
296 const ui::TouchEvent& event) { 218 const ui::TouchEvent& event) {
297 UMA_HISTOGRAM_CUSTOM_COUNTS("Ash.TouchRadius", 219 UMA_HISTOGRAM_CUSTOM_COUNTS("Ash.TouchRadius",
298 static_cast<int>(std::max(event.radius_x(), event.radius_y())), 220 static_cast<int>(std::max(event.radius_x(), event.radius_y())),
299 1, 500, 100); 221 1, 500, 100);
300 222
301 UpdateBurstData(event); 223 UpdateBurstData(event);
302 224
303 WindowTouchDetails* details = target->GetProperty(kWindowTouchDetails); 225 WindowTouchDetails* details = target->GetProperty(kWindowTouchDetails);
304 if (!details) { 226 if (!details) {
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 } 360 }
439 } 361 }
440 touch_in_progress_ = true; 362 touch_in_progress_ = true;
441 last_touch_down_time_ = event.time_stamp(); 363 last_touch_down_time_ = event.time_stamp();
442 } else if (event.type() == ui::ET_TOUCH_RELEASED) { 364 } else if (event.type() == ui::ET_TOUCH_RELEASED) {
443 if (!aura::Env::GetInstance()->is_touch_down()) 365 if (!aura::Env::GetInstance()->is_touch_down())
444 touch_in_progress_ = false; 366 touch_in_progress_ = false;
445 } 367 }
446 } 368 }
447 369
370 TouchUMA::GestureActionType TouchUMA::FindGestureActionType(
371 aura::Window* window,
372 const ui::GestureEvent& event) {
373 if (!window || window->GetRootWindow() == window) {
374 if (event.type() == ui::ET_GESTURE_SCROLL_BEGIN)
375 return GESTURE_BEZEL_SCROLL;
376 if (event.type() == ui::ET_GESTURE_BEGIN)
377 return GESTURE_BEZEL_DOWN;
378 return GESTURE_UNKNOWN;
379 }
380
381 std::string name = window ? window->name() : std::string();
382
383 const char kDesktopBackgroundView[] = "DesktopBackgroundView";
384 if (name == kDesktopBackgroundView) {
385 if (event.type() == ui::ET_GESTURE_SCROLL_BEGIN)
386 return GESTURE_DESKTOP_SCROLL;
387 if (event.type() == ui::ET_GESTURE_PINCH_BEGIN)
388 return GESTURE_DESKTOP_PINCH;
389 return GESTURE_UNKNOWN;
390 }
391
392 const char kWebPage[] = "RenderWidgetHostViewAura";
393 if (name == kWebPage) {
394 if (event.type() == ui::ET_GESTURE_PINCH_BEGIN)
395 return GESTURE_WEBPAGE_PINCH;
396 if (event.type() == ui::ET_GESTURE_SCROLL_BEGIN)
397 return GESTURE_WEBPAGE_SCROLL;
398 if (event.type() == ui::ET_GESTURE_TAP)
399 return GESTURE_WEBPAGE_TAP;
400 return GESTURE_UNKNOWN;
401 }
402
403 views::Widget* widget = views::Widget::GetWidgetForNativeView(window);
404 if (!widget)
405 return GESTURE_UNKNOWN;
406
407 views::View* view = widget->GetRootView()->
408 GetEventHandlerForPoint(event.location());
409 if (!view)
410 return GESTURE_UNKNOWN;
411
412 name = view->GetClassName();
413
414 const char kTabStrip[] = "TabStrip";
415 const char kTab[] = "BrowserTab";
416 if (name == kTabStrip || name == kTab) {
417 if (event.type() == ui::ET_GESTURE_SCROLL_BEGIN)
418 return GESTURE_TABSTRIP_SCROLL;
419 if (event.type() == ui::ET_GESTURE_PINCH_BEGIN)
420 return GESTURE_TABSTRIP_PINCH;
421 if (event.type() == ui::ET_GESTURE_TAP)
422 return GESTURE_TABSTRIP_TAP;
423 return GESTURE_UNKNOWN;
424 }
425
426 const char kOmnibox[] = "BrowserOmniboxViewViews";
427 if (name == kOmnibox) {
428 if (event.type() == ui::ET_GESTURE_SCROLL_BEGIN)
429 return GESTURE_OMNIBOX_SCROLL;
430 if (event.type() == ui::ET_GESTURE_PINCH_BEGIN)
431 return GESTURE_OMNIBOX_PINCH;
432 return GESTURE_UNKNOWN;
433 }
434
435 return GESTURE_UNKNOWN;
436 }
437
448 } // namespace internal 438 } // namespace internal
449 } // namespace ash 439 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698