Supervised user import: Listen for profile creation/deletion
[chromium-blink-merge.git] / ash / metrics / user_metrics_recorder.cc
blobf7e1f425ccc5846ebd8ce35e30f07a8a909c1363
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ash/metrics/user_metrics_recorder.h"
7 #include "ash/session/session_state_delegate.h"
8 #include "ash/shelf/shelf_layout_manager.h"
9 #include "ash/shelf/shelf_view.h"
10 #include "ash/shelf/shelf_widget.h"
11 #include "ash/shell.h"
12 #include "ash/shell_window_ids.h"
13 #include "ash/system/tray/system_tray_delegate.h"
14 #include "ash/wm/window_state.h"
15 #include "base/metrics/histogram.h"
16 #include "base/metrics/user_metrics.h"
17 #include "ui/aura/window.h"
19 namespace ash {
21 namespace {
23 // Time in seconds between calls to "RecordPeriodicMetrics".
24 const int kAshPeriodicMetricsTimeInSeconds = 30 * 60;
26 enum ActiveWindowStateType {
27 ACTIVE_WINDOW_STATE_TYPE_NO_ACTIVE_WINDOW,
28 ACTIVE_WINDOW_STATE_TYPE_OTHER,
29 ACTIVE_WINDOW_STATE_TYPE_MAXIMIZED,
30 ACTIVE_WINDOW_STATE_TYPE_FULLSCREEN,
31 ACTIVE_WINDOW_STATE_TYPE_SNAPPED,
32 ACTIVE_WINDOW_STATE_TYPE_DOCKED,
33 ACTIVE_WINDOW_STATE_TYPE_COUNT
36 ActiveWindowStateType GetActiveWindowState() {
37 ActiveWindowStateType active_window_state_type =
38 ACTIVE_WINDOW_STATE_TYPE_NO_ACTIVE_WINDOW;
39 wm::WindowState* active_window_state = ash::wm::GetActiveWindowState();
40 if (active_window_state) {
41 switch (active_window_state->GetStateType()) {
42 case wm::WINDOW_STATE_TYPE_MAXIMIZED:
43 active_window_state_type = ACTIVE_WINDOW_STATE_TYPE_MAXIMIZED;
44 break;
45 case wm::WINDOW_STATE_TYPE_FULLSCREEN:
46 active_window_state_type = ACTIVE_WINDOW_STATE_TYPE_FULLSCREEN;
47 break;
48 case wm::WINDOW_STATE_TYPE_LEFT_SNAPPED:
49 case wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED:
50 active_window_state_type = ACTIVE_WINDOW_STATE_TYPE_SNAPPED;
51 break;
52 case wm::WINDOW_STATE_TYPE_DOCKED:
53 case wm::WINDOW_STATE_TYPE_DOCKED_MINIMIZED:
54 active_window_state_type = ACTIVE_WINDOW_STATE_TYPE_DOCKED;
55 break;
56 case wm::WINDOW_STATE_TYPE_DEFAULT:
57 case wm::WINDOW_STATE_TYPE_NORMAL:
58 case wm::WINDOW_STATE_TYPE_MINIMIZED:
59 case wm::WINDOW_STATE_TYPE_INACTIVE:
60 case wm::WINDOW_STATE_TYPE_END:
61 case wm::WINDOW_STATE_TYPE_AUTO_POSITIONED:
62 active_window_state_type = ACTIVE_WINDOW_STATE_TYPE_OTHER;
63 break;
66 return active_window_state_type;
69 // Returns true if kiosk mode is active.
70 bool IsKioskModeActive() {
71 return Shell::GetInstance()->system_tray_delegate()->GetUserLoginStatus() ==
72 user::LOGGED_IN_KIOSK_APP;
75 // Returns true if there is an active user and their session isn't currently
76 // locked.
77 bool IsUserActive() {
78 switch (Shell::GetInstance()->system_tray_delegate()->GetUserLoginStatus()) {
79 case user::LOGGED_IN_NONE:
80 case user::LOGGED_IN_LOCKED:
81 return false;
82 case user::LOGGED_IN_USER:
83 case user::LOGGED_IN_OWNER:
84 case user::LOGGED_IN_GUEST:
85 case user::LOGGED_IN_PUBLIC:
86 case user::LOGGED_IN_SUPERVISED:
87 case user::LOGGED_IN_KIOSK_APP:
88 return true;
90 NOTREACHED();
91 return false;
94 // Array of window container ids that contain visible windows to be counted for
95 // UMA statistics. Note the containers are ordered from top most visible
96 // container to the lowest to allow the |GetNumVisibleWindows| method to short
97 // circuit when processing a maximized or fullscreen window.
98 int kVisibleWindowContainerIds[] = {kShellWindowId_PanelContainer,
99 kShellWindowId_DockedContainer,
100 kShellWindowId_AlwaysOnTopContainer,
101 kShellWindowId_DefaultContainer};
103 // Returns an approximate count of how many windows are currently visible in the
104 // primary root window.
105 int GetNumVisibleWindowsInPrimaryDisplay() {
106 int visible_window_count = 0;
107 bool maximized_or_fullscreen_window_present = false;
109 for (const int& current_container_id : kVisibleWindowContainerIds) {
110 if (maximized_or_fullscreen_window_present)
111 break;
113 const aura::Window::Windows& children =
114 Shell::GetContainer(Shell::GetInstance()->GetPrimaryRootWindow(),
115 current_container_id)->children();
116 // Reverse iterate over the child windows so that they are processed in
117 // visible stacking order.
118 for (aura::Window::Windows::const_reverse_iterator it = children.rbegin(),
119 rend = children.rend();
120 it != rend; ++it) {
121 const aura::Window* child_window = *it;
122 const wm::WindowState* child_window_state =
123 wm::GetWindowState(child_window);
125 if (!child_window->IsVisible() || child_window_state->IsMinimized())
126 continue;
128 // Only count activatable windows for 2 reasons:
129 // 1. Ensures that a browser window and its transient, modal child will
130 // only count as 1 visible window.
131 // 2. Prevents counting some windows in the
132 // kShellWindowId_DockedContainer that were not opened by the user.
133 if (child_window_state->CanActivate())
134 ++visible_window_count;
136 // Stop counting windows that will be hidden by maximized or fullscreen
137 // windows. Only windows in the kShellWindowId_DefaultContainer and
138 // kShellWindowId_AlwaysOnTopContainer can be maximized or fullscreened
139 // and completely obscure windows beneath them.
140 if ((kShellWindowId_DefaultContainer == current_container_id ||
141 kShellWindowId_AlwaysOnTopContainer == current_container_id) &&
142 child_window_state->IsMaximizedOrFullscreen()) {
143 maximized_or_fullscreen_window_present = true;
144 break;
148 return visible_window_count;
151 } // namespace
153 UserMetricsRecorder::UserMetricsRecorder() {
154 StartTimer();
157 UserMetricsRecorder::UserMetricsRecorder(bool record_periodic_metrics) {
158 if (record_periodic_metrics)
159 StartTimer();
162 UserMetricsRecorder::~UserMetricsRecorder() {
163 timer_.Stop();
166 void UserMetricsRecorder::RecordUserMetricsAction(UserMetricsAction action) {
167 switch (action) {
168 case ash::UMA_ACCEL_KEYBOARD_BRIGHTNESS_DOWN_F6:
169 base::RecordAction(
170 base::UserMetricsAction("Accel_KeyboardBrightnessDown_F6"));
171 break;
172 case ash::UMA_ACCEL_KEYBOARD_BRIGHTNESS_UP_F7:
173 base::RecordAction(
174 base::UserMetricsAction("Accel_KeyboardBrightnessUp_F7"));
175 break;
176 case ash::UMA_ACCEL_LOCK_SCREEN_LOCK_BUTTON:
177 base::RecordAction(
178 base::UserMetricsAction("Accel_LockScreen_LockButton"));
179 break;
180 case ash::UMA_ACCEL_LOCK_SCREEN_POWER_BUTTON:
181 base::RecordAction(
182 base::UserMetricsAction("Accel_LockScreen_PowerButton"));
183 break;
184 case ash::UMA_ACCEL_MAXIMIZE_RESTORE_F4:
185 base::RecordAction(
186 base::UserMetricsAction("Accel_Maximize_Restore_F4"));
187 break;
188 case ash::UMA_ACCEL_PREVWINDOW_F5:
189 base::RecordAction(base::UserMetricsAction("Accel_PrevWindow_F5"));
190 break;
191 case ash::UMA_ACCEL_EXIT_FIRST_Q:
192 base::RecordAction(base::UserMetricsAction("Accel_Exit_First_Q"));
193 break;
194 case ash::UMA_ACCEL_EXIT_SECOND_Q:
195 base::RecordAction(base::UserMetricsAction("Accel_Exit_Second_Q"));
196 break;
197 case ash::UMA_ACCEL_RESTART_POWER_BUTTON:
198 base::RecordAction(
199 base::UserMetricsAction("Accel_Restart_PowerButton"));
200 break;
201 case ash::UMA_ACCEL_SHUT_DOWN_POWER_BUTTON:
202 base::RecordAction(
203 base::UserMetricsAction("Accel_ShutDown_PowerButton"));
204 break;
205 case ash::UMA_CLOSE_THROUGH_CONTEXT_MENU:
206 base::RecordAction(base::UserMetricsAction("CloseFromContextMenu"));
207 break;
208 case ash::UMA_DRAG_MAXIMIZE_LEFT:
209 base::RecordAction(base::UserMetricsAction("WindowDrag_MaximizeLeft"));
210 break;
211 case ash::UMA_DRAG_MAXIMIZE_RIGHT:
212 base::RecordAction(base::UserMetricsAction("WindowDrag_MaximizeRight"));
213 break;
214 case ash::UMA_GESTURE_OVERVIEW:
215 base::RecordAction(base::UserMetricsAction("Gesture_Overview"));
216 break;
217 case ash::UMA_LAUNCHER_BUTTON_PRESSED_WITH_MOUSE:
218 base::RecordAction(
219 base::UserMetricsAction("Launcher_ButtonPressed_Mouse"));
220 break;
221 case ash::UMA_LAUNCHER_BUTTON_PRESSED_WITH_TOUCH:
222 base::RecordAction(
223 base::UserMetricsAction("Launcher_ButtonPressed_Touch"));
224 break;
225 case ash::UMA_LAUNCHER_CLICK_ON_APP:
226 base::RecordAction(base::UserMetricsAction("Launcher_ClickOnApp"));
227 break;
228 case ash::UMA_LAUNCHER_CLICK_ON_APPLIST_BUTTON:
229 base::RecordAction(
230 base::UserMetricsAction("Launcher_ClickOnApplistButton"));
231 break;
232 case ash::UMA_LAUNCHER_LAUNCH_TASK:
233 base::RecordAction(base::UserMetricsAction("Launcher_LaunchTask"));
234 break;
235 case ash::UMA_LAUNCHER_MINIMIZE_TASK:
236 base::RecordAction(base::UserMetricsAction("Launcher_MinimizeTask"));
237 break;
238 case ash::UMA_LAUNCHER_SWITCH_TASK:
239 base::RecordAction(base::UserMetricsAction("Launcher_SwitchTask"));
240 break;
241 case UMA_MAXIMIZE_MODE_DISABLED:
242 base::RecordAction(base::UserMetricsAction("Touchview_Disabled"));
243 break;
244 case UMA_MAXIMIZE_MODE_ENABLED:
245 base::RecordAction(base::UserMetricsAction("Touchview_Enabled"));
246 break;
247 case UMA_MAXIMIZE_MODE_INITIALLY_DISABLED:
248 base::RecordAction(
249 base::UserMetricsAction("Touchview_Initially_Disabled"));
250 break;
251 case ash::UMA_MOUSE_DOWN:
252 base::RecordAction(base::UserMetricsAction("Mouse_Down"));
253 break;
254 case ash::UMA_PANEL_MINIMIZE_CAPTION_CLICK:
255 base::RecordAction(
256 base::UserMetricsAction("Panel_Minimize_Caption_Click"));
257 break;
258 case ash::UMA_PANEL_MINIMIZE_CAPTION_GESTURE:
259 base::RecordAction(
260 base::UserMetricsAction("Panel_Minimize_Caption_Gesture"));
261 break;
262 case ash::UMA_SHELF_ALIGNMENT_SET_BOTTOM:
263 base::RecordAction(
264 base::UserMetricsAction("Shelf_AlignmentSetBottom"));
265 break;
266 case ash::UMA_SHELF_ALIGNMENT_SET_LEFT:
267 base::RecordAction(
268 base::UserMetricsAction("Shelf_AlignmentSetLeft"));
269 break;
270 case ash::UMA_SHELF_ALIGNMENT_SET_RIGHT:
271 base::RecordAction(
272 base::UserMetricsAction("Shelf_AlignmentSetRight"));
273 break;
274 case ash::UMA_STATUS_AREA_AUDIO_CURRENT_INPUT_DEVICE:
275 base::RecordAction(
276 base::UserMetricsAction("StatusArea_Audio_CurrentInputDevice"));
277 break;
278 case ash::UMA_STATUS_AREA_AUDIO_CURRENT_OUTPUT_DEVICE:
279 base::RecordAction(
280 base::UserMetricsAction("StatusArea_Audio_CurrentOutputDevice"));
281 break;
282 case ash::UMA_STATUS_AREA_AUDIO_SWITCH_INPUT_DEVICE:
283 base::RecordAction(
284 base::UserMetricsAction("StatusArea_Audio_SwitchInputDevice"));
285 break;
286 case ash::UMA_STATUS_AREA_AUDIO_SWITCH_OUTPUT_DEVICE:
287 base::RecordAction(
288 base::UserMetricsAction("StatusArea_Audio_SwitchOutputDevice"));
289 break;
290 case ash::UMA_STATUS_AREA_BRIGHTNESS_CHANGED:
291 base::RecordAction(
292 base::UserMetricsAction("StatusArea_BrightnessChanged"));
293 break;
294 case ash::UMA_STATUS_AREA_BLUETOOTH_CONNECT_KNOWN_DEVICE:
295 base::RecordAction(
296 base::UserMetricsAction("StatusArea_Bluetooth_Connect_Known"));
297 break;
298 case ash::UMA_STATUS_AREA_BLUETOOTH_CONNECT_UNKNOWN_DEVICE:
299 base::RecordAction(
300 base::UserMetricsAction("StatusArea_Bluetooth_Connect_Unknown"));
301 break;
302 case ash::UMA_STATUS_AREA_BLUETOOTH_DISABLED:
303 base::RecordAction(
304 base::UserMetricsAction("StatusArea_Bluetooth_Disabled"));
305 break;
306 case ash::UMA_STATUS_AREA_BLUETOOTH_ENABLED:
307 base::RecordAction(
308 base::UserMetricsAction("StatusArea_Bluetooth_Enabled"));
309 break;
310 case ash::UMA_STATUS_AREA_CAPS_LOCK_DETAILED:
311 base::RecordAction(
312 base::UserMetricsAction("StatusArea_CapsLock_Detailed"));
313 break;
314 case ash::UMA_STATUS_AREA_CAPS_LOCK_DISABLED_BY_CLICK:
315 base::RecordAction(
316 base::UserMetricsAction("StatusArea_CapsLock_DisabledByClick"));
317 break;
318 case ash::UMA_STATUS_AREA_CAPS_LOCK_ENABLED_BY_CLICK:
319 base::RecordAction(
320 base::UserMetricsAction("StatusArea_CapsLock_EnabledByClick"));
321 break;
322 case ash::UMA_STATUS_AREA_CAPS_LOCK_POPUP:
323 base::RecordAction(
324 base::UserMetricsAction("StatusArea_CapsLock_Popup"));
325 break;
326 case ash::UMA_STATUS_AREA_CONNECT_TO_CONFIGURED_NETWORK:
327 base::RecordAction(
328 base::UserMetricsAction("StatusArea_Network_ConnectConfigured"));
329 break;
330 case ash::UMA_STATUS_AREA_CONNECT_TO_UNCONFIGURED_NETWORK:
331 base::RecordAction(
332 base::UserMetricsAction("StatusArea_Network_ConnectUnconfigured"));
333 break;
334 case ash::UMA_STATUS_AREA_CONNECT_TO_VPN:
335 base::RecordAction(
336 base::UserMetricsAction("StatusArea_VPN_ConnectToNetwork"));
337 break;
338 case ash::UMA_STATUS_AREA_CHANGED_VOLUME_MENU:
339 base::RecordAction(
340 base::UserMetricsAction("StatusArea_Volume_ChangedMenu"));
341 break;
342 case ash::UMA_STATUS_AREA_CHANGED_VOLUME_POPUP:
343 base::RecordAction(
344 base::UserMetricsAction("StatusArea_Volume_ChangedPopup"));
345 break;
346 case ash::UMA_STATUS_AREA_DETAILED_ACCESSABILITY:
347 base::RecordAction(
348 base::UserMetricsAction("StatusArea_Accessability_DetailedView"));
349 break;
350 case ash::UMA_STATUS_AREA_DETAILED_AUDIO_VIEW:
351 base::RecordAction(
352 base::UserMetricsAction("StatusArea_Audio_Detailed"));
353 break;
354 case ash::UMA_STATUS_AREA_DETAILED_BLUETOOTH_VIEW:
355 base::RecordAction(
356 base::UserMetricsAction("StatusArea_Bluetooth_Detailed"));
357 break;
358 case ash::UMA_STATUS_AREA_DETAILED_BRIGHTNESS_VIEW:
359 base::RecordAction(
360 base::UserMetricsAction("StatusArea_Brightness_Detailed"));
361 break;
362 case ash::UMA_STATUS_AREA_DETAILED_DRIVE_VIEW:
363 base::RecordAction(
364 base::UserMetricsAction("StatusArea_Drive_Detailed"));
365 break;
366 case ash::UMA_STATUS_AREA_DETAILED_NETWORK_VIEW:
367 base::RecordAction(
368 base::UserMetricsAction("StatusArea_Network_Detailed"));
369 break;
370 case ash::UMA_STATUS_AREA_DETAILED_VPN_VIEW:
371 base::RecordAction(
372 base::UserMetricsAction("StatusArea_VPN_Detailed"));
373 break;
374 case ash::UMA_STATUS_AREA_DISABLE_AUTO_CLICK:
375 base::RecordAction(
376 base::UserMetricsAction("StatusArea_AutoClickDisabled"));
377 break;
378 case ash::UMA_STATUS_AREA_DISABLE_HIGH_CONTRAST:
379 base::RecordAction(
380 base::UserMetricsAction("StatusArea_HighContrastDisabled"));
381 break;
382 case ash::UMA_STATUS_AREA_DISABLE_LARGE_CURSOR:
383 base::RecordAction(
384 base::UserMetricsAction("StatusArea_LargeCursorDisabled"));
385 break;
386 case ash::UMA_STATUS_AREA_DISABLE_MAGNIFIER:
387 base::RecordAction(
388 base::UserMetricsAction("StatusArea_MagnifierDisabled"));
389 break;
390 case ash::UMA_STATUS_AREA_DISABLE_SPOKEN_FEEDBACK:
391 base::RecordAction(
392 base::UserMetricsAction("StatusArea_SpokenFeedbackDisabled"));
393 break;
394 case ash::UMA_STATUS_AREA_DISABLE_VIRTUAL_KEYBOARD:
395 base::RecordAction(
396 base::UserMetricsAction("StatusArea_VirtualKeyboardDisabled"));
397 break;
398 case ash::UMA_STATUS_AREA_DISABLE_WIFI:
399 base::RecordAction(
400 base::UserMetricsAction("StatusArea_Network_WifiDisabled"));
401 break;
402 case ash::UMA_STATUS_AREA_DRIVE_CANCEL_OPERATION:
403 base::RecordAction(
404 base::UserMetricsAction("StatusArea_Drive_CancelOperation"));
405 break;
406 case ash::UMA_STATUS_AREA_DRIVE_SETTINGS:
407 base::RecordAction(
408 base::UserMetricsAction("StatusArea_Drive_Settings"));
409 break;
410 case ash::UMA_STATUS_AREA_ENABLE_AUTO_CLICK:
411 base::RecordAction(
412 base::UserMetricsAction("StatusArea_AutoClickEnabled"));
413 break;
414 case ash::UMA_STATUS_AREA_ENABLE_HIGH_CONTRAST:
415 base::RecordAction(
416 base::UserMetricsAction("StatusArea_HighContrastEnabled"));
417 break;
418 case ash::UMA_STATUS_AREA_ENABLE_LARGE_CURSOR:
419 base::RecordAction(
420 base::UserMetricsAction("StatusArea_LargeCursorEnabled"));
421 break;
422 case ash::UMA_STATUS_AREA_ENABLE_MAGNIFIER:
423 base::RecordAction(
424 base::UserMetricsAction("StatusArea_MagnifierEnabled"));
425 break;
426 case ash::UMA_STATUS_AREA_ENABLE_SPOKEN_FEEDBACK:
427 base::RecordAction(
428 base::UserMetricsAction("StatusArea_SpokenFeedbackEnabled"));
429 break;
430 case ash::UMA_STATUS_AREA_ENABLE_VIRTUAL_KEYBOARD:
431 base::RecordAction(
432 base::UserMetricsAction("StatusArea_VirtualKeyboardEnabled"));
433 break;
434 case ash::UMA_STATUS_AREA_ENABLE_WIFI:
435 base::RecordAction(
436 base::UserMetricsAction("StatusArea_Network_WifiEnabled"));
437 break;
438 case ash::UMA_STATUS_AREA_IME_SHOW_DETAILED:
439 base::RecordAction(
440 base::UserMetricsAction("StatusArea_IME_Detailed"));
441 break;
442 case ash::UMA_STATUS_AREA_IME_SWITCH_MODE:
443 base::RecordAction(
444 base::UserMetricsAction("StatusArea_IME_SwitchMode"));
445 break;
446 case ash::UMA_STATUS_AREA_MENU_OPENED:
447 base::RecordAction(
448 base::UserMetricsAction("StatusArea_MenuOpened"));
449 break;
450 case ash::UMA_STATUS_AREA_NETWORK_JOIN_OTHER_CLICKED:
451 base::RecordAction(
452 base::UserMetricsAction("StatusArea_Network_JoinOther"));
453 break;
454 case ash::UMA_STATUS_AREA_NETWORK_SETTINGS_CLICKED:
455 base::RecordAction(
456 base::UserMetricsAction("StatusArea_Network_Settings"));
457 break;
458 case ash::UMA_STATUS_AREA_SHOW_NETWORK_CONNECTION_DETAILS:
459 base::RecordAction(
460 base::UserMetricsAction("StatusArea_Network_ConnectionDetails"));
461 break;
462 case ash::UMA_STATUS_AREA_SHOW_VPN_CONNECTION_DETAILS:
463 base::RecordAction(
464 base::UserMetricsAction("StatusArea_VPN_ConnectionDetails"));
465 break;
466 case ash::UMA_STATUS_AREA_SIGN_OUT:
467 base::RecordAction(
468 base::UserMetricsAction("StatusArea_SignOut"));
469 break;
470 case ash::UMA_STATUS_AREA_VPN_ADD_BUILT_IN_CLICKED:
471 base::RecordAction(base::UserMetricsAction("StatusArea_VPN_AddBuiltIn"));
472 break;
473 case ash::UMA_STATUS_AREA_VPN_ADD_THIRD_PARTY_CLICKED:
474 base::RecordAction(
475 base::UserMetricsAction("StatusArea_VPN_AddThirdParty"));
476 break;
477 case ash::UMA_STATUS_AREA_VPN_DISCONNECT_CLICKED:
478 base::RecordAction(base::UserMetricsAction("StatusArea_VPN_Disconnect"));
479 break;
480 case ash::UMA_STATUS_AREA_VPN_SETTINGS_CLICKED:
481 base::RecordAction(
482 base::UserMetricsAction("StatusArea_VPN_Settings"));
483 break;
484 case ash::UMA_TOGGLE_MAXIMIZE_CAPTION_CLICK:
485 base::RecordAction(
486 base::UserMetricsAction("Caption_ClickTogglesMaximize"));
487 break;
488 case ash::UMA_TOGGLE_MAXIMIZE_CAPTION_GESTURE:
489 base::RecordAction(
490 base::UserMetricsAction("Caption_GestureTogglesMaximize"));
491 break;
492 case ash::UMA_TOGGLE_SINGLE_AXIS_MAXIMIZE_BORDER_CLICK:
493 base::RecordAction(
494 base::UserMetricsAction(
495 "WindowBorder_ClickTogglesSingleAxisMaximize"));
496 break;
497 case ash::UMA_TOUCHPAD_GESTURE_OVERVIEW:
498 base::RecordAction(
499 base::UserMetricsAction("Touchpad_Gesture_Overview"));
500 break;
501 case ash::UMA_TOUCHSCREEN_TAP_DOWN:
502 base::RecordAction(base::UserMetricsAction("Touchscreen_Down"));
503 break;
504 case ash::UMA_TRAY_HELP:
505 base::RecordAction(base::UserMetricsAction("Tray_Help"));
506 break;
507 case ash::UMA_TRAY_LOCK_SCREEN:
508 base::RecordAction(base::UserMetricsAction("Tray_LockScreen"));
509 break;
510 case ash::UMA_TRAY_SHUT_DOWN:
511 base::RecordAction(base::UserMetricsAction("Tray_ShutDown"));
512 break;
513 case ash::UMA_WINDOW_APP_CLOSE_BUTTON_CLICK:
514 base::RecordAction(base::UserMetricsAction("AppCloseButton_Clk"));
515 break;
516 case ash::UMA_WINDOW_CLOSE_BUTTON_CLICK:
517 base::RecordAction(base::UserMetricsAction("CloseButton_Clk"));
518 break;
519 case ash::UMA_WINDOW_MAXIMIZE_BUTTON_CLICK_EXIT_FULLSCREEN:
520 base::RecordAction(base::UserMetricsAction("MaxButton_Clk_ExitFS"));
521 break;
522 case ash::UMA_WINDOW_MAXIMIZE_BUTTON_CLICK_RESTORE:
523 base::RecordAction(
524 base::UserMetricsAction("MaxButton_Clk_Restore"));
525 break;
526 case ash::UMA_WINDOW_MAXIMIZE_BUTTON_CLICK_MAXIMIZE:
527 base::RecordAction(
528 base::UserMetricsAction("MaxButton_Clk_Maximize"));
529 break;
530 case ash::UMA_WINDOW_MAXIMIZE_BUTTON_CLICK_MINIMIZE:
531 base::RecordAction(base::UserMetricsAction("MinButton_Clk"));
532 break;
533 case ash::UMA_WINDOW_MAXIMIZE_BUTTON_MAXIMIZE_LEFT:
534 base::RecordAction(base::UserMetricsAction("MaxButton_MaxLeft"));
535 break;
536 case ash::UMA_WINDOW_MAXIMIZE_BUTTON_MAXIMIZE_RIGHT:
537 base::RecordAction(base::UserMetricsAction("MaxButton_MaxRight"));
538 break;
539 case ash::UMA_WINDOW_OVERVIEW:
540 base::RecordAction(
541 base::UserMetricsAction("WindowSelector_Overview"));
542 break;
543 case ash::UMA_WINDOW_OVERVIEW_ENTER_KEY:
544 base::RecordAction(
545 base::UserMetricsAction("WindowSelector_OverviewEnterKey"));
546 break;
547 case ash::UMA_WINDOW_CYCLE:
548 base::RecordAction(
549 base::UserMetricsAction("WindowCycleController_Cycle"));
550 break;
554 void UserMetricsRecorder::RecordPeriodicMetrics() {
555 ShelfLayoutManager* manager =
556 ShelfLayoutManager::ForShelf(Shell::GetPrimaryRootWindow());
557 // TODO(bruthig): Investigating whether the check for |manager| is necessary
558 // and add tests if it is.
559 if (manager) {
560 // TODO(bruthig): Consider tracking the time spent in each alignment.
561 UMA_HISTOGRAM_ENUMERATION("Ash.ShelfAlignmentOverTime",
562 manager->SelectValueForShelfAlignment(
563 SHELF_ALIGNMENT_UMA_ENUM_VALUE_BOTTOM,
564 SHELF_ALIGNMENT_UMA_ENUM_VALUE_LEFT,
565 SHELF_ALIGNMENT_UMA_ENUM_VALUE_RIGHT,
566 -1),
567 SHELF_ALIGNMENT_UMA_ENUM_VALUE_COUNT);
570 if (IsUserInActiveDesktopEnvironment()) {
571 UMA_HISTOGRAM_COUNTS_100("Ash.NumberOfVisibleWindowsInPrimaryDisplay",
572 GetNumVisibleWindowsInPrimaryDisplay());
575 // TODO(bruthig): Find out if this should only be logged when the user is
576 // active.
577 // TODO(bruthig): Consider tracking how long a particular type of window is
578 // active at a time.
579 UMA_HISTOGRAM_ENUMERATION("Ash.ActiveWindowShowTypeOverTime",
580 GetActiveWindowState(),
581 ACTIVE_WINDOW_STATE_TYPE_COUNT);
584 bool UserMetricsRecorder::IsUserInActiveDesktopEnvironment() const {
585 return IsUserActive() && !IsKioskModeActive();
588 void UserMetricsRecorder::StartTimer() {
589 timer_.Start(FROM_HERE,
590 base::TimeDelta::FromSeconds(kAshPeriodicMetricsTimeInSeconds),
591 this, &UserMetricsRecorder::RecordPeriodicMetrics);
594 } // namespace ash