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