Roll src/third_party/WebKit 6bc4103:c61006c (svn 202175:202177)
[chromium-blink-merge.git] / ash / metrics / user_metrics_recorder.cc
blob040fc76b659475f2f68f0ce4ea4a4c650508bac0
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_LAUNCHER_BUTTON_PRESSED_WITH_MOUSE:
252 base::RecordAction(
253 base::UserMetricsAction("Launcher_ButtonPressed_Mouse"));
254 break;
255 case ash::UMA_LAUNCHER_BUTTON_PRESSED_WITH_TOUCH:
256 base::RecordAction(
257 base::UserMetricsAction("Launcher_ButtonPressed_Touch"));
258 break;
259 case ash::UMA_LAUNCHER_CLICK_ON_APP:
260 base::RecordAction(base::UserMetricsAction("Launcher_ClickOnApp"));
261 break;
262 case ash::UMA_LAUNCHER_CLICK_ON_APPLIST_BUTTON:
263 base::RecordAction(
264 base::UserMetricsAction("Launcher_ClickOnApplistButton"));
265 break;
266 case ash::UMA_LAUNCHER_LAUNCH_TASK:
267 base::RecordAction(base::UserMetricsAction("Launcher_LaunchTask"));
268 task_switch_metrics_recorder_.OnTaskSwitch(
269 TaskSwitchMetricsRecorder::SHELF);
270 break;
271 case ash::UMA_LAUNCHER_MINIMIZE_TASK:
272 base::RecordAction(base::UserMetricsAction("Launcher_MinimizeTask"));
273 break;
274 case ash::UMA_LAUNCHER_SWITCH_TASK:
275 base::RecordAction(base::UserMetricsAction("Launcher_SwitchTask"));
276 task_switch_metrics_recorder_.OnTaskSwitch(
277 TaskSwitchMetricsRecorder::SHELF);
278 break;
279 case UMA_MAXIMIZE_MODE_DISABLED:
280 base::RecordAction(base::UserMetricsAction("Touchview_Disabled"));
281 break;
282 case UMA_MAXIMIZE_MODE_ENABLED:
283 base::RecordAction(base::UserMetricsAction("Touchview_Enabled"));
284 break;
285 case UMA_MAXIMIZE_MODE_INITIALLY_DISABLED:
286 base::RecordAction(
287 base::UserMetricsAction("Touchview_Initially_Disabled"));
288 break;
289 case ash::UMA_MOUSE_DOWN:
290 base::RecordAction(base::UserMetricsAction("Mouse_Down"));
291 break;
292 case ash::UMA_PANEL_MINIMIZE_CAPTION_CLICK:
293 base::RecordAction(
294 base::UserMetricsAction("Panel_Minimize_Caption_Click"));
295 break;
296 case ash::UMA_PANEL_MINIMIZE_CAPTION_GESTURE:
297 base::RecordAction(
298 base::UserMetricsAction("Panel_Minimize_Caption_Gesture"));
299 break;
300 case ash::UMA_SHELF_ALIGNMENT_SET_BOTTOM:
301 base::RecordAction(
302 base::UserMetricsAction("Shelf_AlignmentSetBottom"));
303 break;
304 case ash::UMA_SHELF_ALIGNMENT_SET_LEFT:
305 base::RecordAction(
306 base::UserMetricsAction("Shelf_AlignmentSetLeft"));
307 break;
308 case ash::UMA_SHELF_ALIGNMENT_SET_RIGHT:
309 base::RecordAction(
310 base::UserMetricsAction("Shelf_AlignmentSetRight"));
311 break;
312 case ash::UMA_STATUS_AREA_AUDIO_CURRENT_INPUT_DEVICE:
313 base::RecordAction(
314 base::UserMetricsAction("StatusArea_Audio_CurrentInputDevice"));
315 break;
316 case ash::UMA_STATUS_AREA_AUDIO_CURRENT_OUTPUT_DEVICE:
317 base::RecordAction(
318 base::UserMetricsAction("StatusArea_Audio_CurrentOutputDevice"));
319 break;
320 case ash::UMA_STATUS_AREA_AUDIO_SWITCH_INPUT_DEVICE:
321 base::RecordAction(
322 base::UserMetricsAction("StatusArea_Audio_SwitchInputDevice"));
323 break;
324 case ash::UMA_STATUS_AREA_AUDIO_SWITCH_OUTPUT_DEVICE:
325 base::RecordAction(
326 base::UserMetricsAction("StatusArea_Audio_SwitchOutputDevice"));
327 break;
328 case ash::UMA_STATUS_AREA_BRIGHTNESS_CHANGED:
329 base::RecordAction(
330 base::UserMetricsAction("StatusArea_BrightnessChanged"));
331 break;
332 case ash::UMA_STATUS_AREA_BLUETOOTH_CONNECT_KNOWN_DEVICE:
333 base::RecordAction(
334 base::UserMetricsAction("StatusArea_Bluetooth_Connect_Known"));
335 break;
336 case ash::UMA_STATUS_AREA_BLUETOOTH_CONNECT_UNKNOWN_DEVICE:
337 base::RecordAction(
338 base::UserMetricsAction("StatusArea_Bluetooth_Connect_Unknown"));
339 break;
340 case ash::UMA_STATUS_AREA_BLUETOOTH_DISABLED:
341 base::RecordAction(
342 base::UserMetricsAction("StatusArea_Bluetooth_Disabled"));
343 break;
344 case ash::UMA_STATUS_AREA_BLUETOOTH_ENABLED:
345 base::RecordAction(
346 base::UserMetricsAction("StatusArea_Bluetooth_Enabled"));
347 break;
348 case ash::UMA_STATUS_AREA_CAPS_LOCK_DETAILED:
349 base::RecordAction(
350 base::UserMetricsAction("StatusArea_CapsLock_Detailed"));
351 break;
352 case ash::UMA_STATUS_AREA_CAPS_LOCK_DISABLED_BY_CLICK:
353 base::RecordAction(
354 base::UserMetricsAction("StatusArea_CapsLock_DisabledByClick"));
355 break;
356 case ash::UMA_STATUS_AREA_CAPS_LOCK_ENABLED_BY_CLICK:
357 base::RecordAction(
358 base::UserMetricsAction("StatusArea_CapsLock_EnabledByClick"));
359 break;
360 case ash::UMA_STATUS_AREA_CAPS_LOCK_POPUP:
361 base::RecordAction(
362 base::UserMetricsAction("StatusArea_CapsLock_Popup"));
363 break;
364 case ash::UMA_STATUS_AREA_CAST_STOP_CAST:
365 base::RecordAction(base::UserMetricsAction("StatusArea_Cast_StopCast"));
366 break;
367 case ash::UMA_STATUS_AREA_CONNECT_TO_CONFIGURED_NETWORK:
368 base::RecordAction(
369 base::UserMetricsAction("StatusArea_Network_ConnectConfigured"));
370 break;
371 case ash::UMA_STATUS_AREA_CONNECT_TO_UNCONFIGURED_NETWORK:
372 base::RecordAction(
373 base::UserMetricsAction("StatusArea_Network_ConnectUnconfigured"));
374 break;
375 case ash::UMA_STATUS_AREA_CONNECT_TO_VPN:
376 base::RecordAction(
377 base::UserMetricsAction("StatusArea_VPN_ConnectToNetwork"));
378 break;
379 case ash::UMA_STATUS_AREA_CHANGED_VOLUME_MENU:
380 base::RecordAction(
381 base::UserMetricsAction("StatusArea_Volume_ChangedMenu"));
382 break;
383 case ash::UMA_STATUS_AREA_CHANGED_VOLUME_POPUP:
384 base::RecordAction(
385 base::UserMetricsAction("StatusArea_Volume_ChangedPopup"));
386 break;
387 case ash::UMA_STATUS_AREA_DETAILED_ACCESSABILITY:
388 base::RecordAction(
389 base::UserMetricsAction("StatusArea_Accessability_DetailedView"));
390 break;
391 case ash::UMA_STATUS_AREA_DETAILED_AUDIO_VIEW:
392 base::RecordAction(
393 base::UserMetricsAction("StatusArea_Audio_Detailed"));
394 break;
395 case ash::UMA_STATUS_AREA_DETAILED_BLUETOOTH_VIEW:
396 base::RecordAction(
397 base::UserMetricsAction("StatusArea_Bluetooth_Detailed"));
398 break;
399 case ash::UMA_STATUS_AREA_DETAILED_BRIGHTNESS_VIEW:
400 base::RecordAction(
401 base::UserMetricsAction("StatusArea_Brightness_Detailed"));
402 break;
403 case ash::UMA_STATUS_AREA_DETAILED_CAST_VIEW:
404 base::RecordAction(base::UserMetricsAction("StatusArea_Cast_Detailed"));
405 break;
406 case ash::UMA_STATUS_AREA_DETAILED_CAST_VIEW_LAUNCH_CAST:
407 base::RecordAction(
408 base::UserMetricsAction("StatusArea_Cast_Detailed_Launch_Cast"));
409 break;
410 case ash::UMA_STATUS_AREA_DETAILED_DRIVE_VIEW:
411 base::RecordAction(
412 base::UserMetricsAction("StatusArea_Drive_Detailed"));
413 break;
414 case ash::UMA_STATUS_AREA_DETAILED_NETWORK_VIEW:
415 base::RecordAction(
416 base::UserMetricsAction("StatusArea_Network_Detailed"));
417 break;
418 case ash::UMA_STATUS_AREA_DETAILED_VPN_VIEW:
419 base::RecordAction(
420 base::UserMetricsAction("StatusArea_VPN_Detailed"));
421 break;
422 case ash::UMA_STATUS_AREA_DISABLE_AUTO_CLICK:
423 base::RecordAction(
424 base::UserMetricsAction("StatusArea_AutoClickDisabled"));
425 break;
426 case ash::UMA_STATUS_AREA_DISABLE_HIGH_CONTRAST:
427 base::RecordAction(
428 base::UserMetricsAction("StatusArea_HighContrastDisabled"));
429 break;
430 case ash::UMA_STATUS_AREA_DISABLE_LARGE_CURSOR:
431 base::RecordAction(
432 base::UserMetricsAction("StatusArea_LargeCursorDisabled"));
433 break;
434 case ash::UMA_STATUS_AREA_DISABLE_MAGNIFIER:
435 base::RecordAction(
436 base::UserMetricsAction("StatusArea_MagnifierDisabled"));
437 break;
438 case ash::UMA_STATUS_AREA_DISABLE_SPOKEN_FEEDBACK:
439 base::RecordAction(
440 base::UserMetricsAction("StatusArea_SpokenFeedbackDisabled"));
441 break;
442 case ash::UMA_STATUS_AREA_DISABLE_VIRTUAL_KEYBOARD:
443 base::RecordAction(
444 base::UserMetricsAction("StatusArea_VirtualKeyboardDisabled"));
445 break;
446 case ash::UMA_STATUS_AREA_DISABLE_WIFI:
447 base::RecordAction(
448 base::UserMetricsAction("StatusArea_Network_WifiDisabled"));
449 break;
450 case ash::UMA_STATUS_AREA_DRIVE_CANCEL_OPERATION:
451 base::RecordAction(
452 base::UserMetricsAction("StatusArea_Drive_CancelOperation"));
453 break;
454 case ash::UMA_STATUS_AREA_DRIVE_SETTINGS:
455 base::RecordAction(
456 base::UserMetricsAction("StatusArea_Drive_Settings"));
457 break;
458 case ash::UMA_STATUS_AREA_ENABLE_AUTO_CLICK:
459 base::RecordAction(
460 base::UserMetricsAction("StatusArea_AutoClickEnabled"));
461 break;
462 case ash::UMA_STATUS_AREA_ENABLE_HIGH_CONTRAST:
463 base::RecordAction(
464 base::UserMetricsAction("StatusArea_HighContrastEnabled"));
465 break;
466 case ash::UMA_STATUS_AREA_ENABLE_LARGE_CURSOR:
467 base::RecordAction(
468 base::UserMetricsAction("StatusArea_LargeCursorEnabled"));
469 break;
470 case ash::UMA_STATUS_AREA_ENABLE_MAGNIFIER:
471 base::RecordAction(
472 base::UserMetricsAction("StatusArea_MagnifierEnabled"));
473 break;
474 case ash::UMA_STATUS_AREA_ENABLE_SPOKEN_FEEDBACK:
475 base::RecordAction(
476 base::UserMetricsAction("StatusArea_SpokenFeedbackEnabled"));
477 break;
478 case ash::UMA_STATUS_AREA_ENABLE_VIRTUAL_KEYBOARD:
479 base::RecordAction(
480 base::UserMetricsAction("StatusArea_VirtualKeyboardEnabled"));
481 break;
482 case ash::UMA_STATUS_AREA_ENABLE_WIFI:
483 base::RecordAction(
484 base::UserMetricsAction("StatusArea_Network_WifiEnabled"));
485 break;
486 case ash::UMA_STATUS_AREA_IME_SHOW_DETAILED:
487 base::RecordAction(
488 base::UserMetricsAction("StatusArea_IME_Detailed"));
489 break;
490 case ash::UMA_STATUS_AREA_IME_SWITCH_MODE:
491 base::RecordAction(
492 base::UserMetricsAction("StatusArea_IME_SwitchMode"));
493 break;
494 case ash::UMA_STATUS_AREA_MENU_OPENED:
495 base::RecordAction(
496 base::UserMetricsAction("StatusArea_MenuOpened"));
497 break;
498 case ash::UMA_STATUS_AREA_NETWORK_JOIN_OTHER_CLICKED:
499 base::RecordAction(
500 base::UserMetricsAction("StatusArea_Network_JoinOther"));
501 break;
502 case ash::UMA_STATUS_AREA_NETWORK_SETTINGS_CLICKED:
503 base::RecordAction(
504 base::UserMetricsAction("StatusArea_Network_Settings"));
505 break;
506 case ash::UMA_STATUS_AREA_SHOW_NETWORK_CONNECTION_DETAILS:
507 base::RecordAction(
508 base::UserMetricsAction("StatusArea_Network_ConnectionDetails"));
509 break;
510 case ash::UMA_STATUS_AREA_SHOW_VPN_CONNECTION_DETAILS:
511 base::RecordAction(
512 base::UserMetricsAction("StatusArea_VPN_ConnectionDetails"));
513 break;
514 case ash::UMA_STATUS_AREA_SIGN_OUT:
515 base::RecordAction(
516 base::UserMetricsAction("StatusArea_SignOut"));
517 break;
518 case ash::UMA_STATUS_AREA_VPN_ADD_BUILT_IN_CLICKED:
519 base::RecordAction(base::UserMetricsAction("StatusArea_VPN_AddBuiltIn"));
520 break;
521 case ash::UMA_STATUS_AREA_VPN_ADD_THIRD_PARTY_CLICKED:
522 base::RecordAction(
523 base::UserMetricsAction("StatusArea_VPN_AddThirdParty"));
524 break;
525 case ash::UMA_STATUS_AREA_VPN_DISCONNECT_CLICKED:
526 base::RecordAction(base::UserMetricsAction("StatusArea_VPN_Disconnect"));
527 break;
528 case ash::UMA_STATUS_AREA_VPN_SETTINGS_CLICKED:
529 base::RecordAction(
530 base::UserMetricsAction("StatusArea_VPN_Settings"));
531 break;
532 case ash::UMA_TOGGLE_MAXIMIZE_CAPTION_CLICK:
533 base::RecordAction(
534 base::UserMetricsAction("Caption_ClickTogglesMaximize"));
535 break;
536 case ash::UMA_TOGGLE_MAXIMIZE_CAPTION_GESTURE:
537 base::RecordAction(
538 base::UserMetricsAction("Caption_GestureTogglesMaximize"));
539 break;
540 case ash::UMA_TOGGLE_SINGLE_AXIS_MAXIMIZE_BORDER_CLICK:
541 base::RecordAction(
542 base::UserMetricsAction(
543 "WindowBorder_ClickTogglesSingleAxisMaximize"));
544 break;
545 case ash::UMA_TOUCHPAD_GESTURE_OVERVIEW:
546 base::RecordAction(
547 base::UserMetricsAction("Touchpad_Gesture_Overview"));
548 break;
549 case ash::UMA_TOUCHSCREEN_TAP_DOWN:
550 base::RecordAction(base::UserMetricsAction("Touchscreen_Down"));
551 break;
552 case ash::UMA_TRAY_HELP:
553 base::RecordAction(base::UserMetricsAction("Tray_Help"));
554 break;
555 case ash::UMA_TRAY_LOCK_SCREEN:
556 base::RecordAction(base::UserMetricsAction("Tray_LockScreen"));
557 break;
558 case ash::UMA_TRAY_OVERVIEW:
559 base::RecordAction(base::UserMetricsAction("Tray_Overview"));
560 break;
561 case ash::UMA_TRAY_SHUT_DOWN:
562 base::RecordAction(base::UserMetricsAction("Tray_ShutDown"));
563 break;
564 case ash::UMA_WINDOW_APP_CLOSE_BUTTON_CLICK:
565 base::RecordAction(base::UserMetricsAction("AppCloseButton_Clk"));
566 break;
567 case ash::UMA_WINDOW_CLOSE_BUTTON_CLICK:
568 base::RecordAction(base::UserMetricsAction("CloseButton_Clk"));
569 break;
570 case ash::UMA_WINDOW_MAXIMIZE_BUTTON_CLICK_EXIT_FULLSCREEN:
571 base::RecordAction(base::UserMetricsAction("MaxButton_Clk_ExitFS"));
572 break;
573 case ash::UMA_WINDOW_MAXIMIZE_BUTTON_CLICK_RESTORE:
574 base::RecordAction(
575 base::UserMetricsAction("MaxButton_Clk_Restore"));
576 break;
577 case ash::UMA_WINDOW_MAXIMIZE_BUTTON_CLICK_MAXIMIZE:
578 base::RecordAction(
579 base::UserMetricsAction("MaxButton_Clk_Maximize"));
580 break;
581 case ash::UMA_WINDOW_MAXIMIZE_BUTTON_CLICK_MINIMIZE:
582 base::RecordAction(base::UserMetricsAction("MinButton_Clk"));
583 break;
584 case ash::UMA_WINDOW_MAXIMIZE_BUTTON_MAXIMIZE_LEFT:
585 base::RecordAction(base::UserMetricsAction("MaxButton_MaxLeft"));
586 break;
587 case ash::UMA_WINDOW_MAXIMIZE_BUTTON_MAXIMIZE_RIGHT:
588 base::RecordAction(base::UserMetricsAction("MaxButton_MaxRight"));
589 break;
590 case ash::UMA_WINDOW_OVERVIEW:
591 base::RecordAction(
592 base::UserMetricsAction("WindowSelector_Overview"));
593 break;
594 case ash::UMA_WINDOW_OVERVIEW_ACTIVE_WINDOW_CHANGED:
595 base::RecordAction(
596 base::UserMetricsAction("WindowSelector_ActiveWindowChanged"));
597 task_switch_metrics_recorder_.OnTaskSwitch(
598 TaskSwitchMetricsRecorder::OVERVIEW_MODE);
599 break;
600 case ash::UMA_WINDOW_OVERVIEW_ENTER_KEY:
601 base::RecordAction(
602 base::UserMetricsAction("WindowSelector_OverviewEnterKey"));
603 break;
604 case ash::UMA_WINDOW_CYCLE:
605 base::RecordAction(
606 base::UserMetricsAction("WindowCycleController_Cycle"));
607 break;
611 void UserMetricsRecorder::OnShellInitialized() {
612 // Lazy creation of the DesktopTaskSwitchMetricRecorder because it accesses
613 // Shell::GetInstance() which is not available when |this| is instantiated.
614 if (!desktop_task_switch_metric_recorder_) {
615 desktop_task_switch_metric_recorder_.reset(
616 new DesktopTaskSwitchMetricRecorder());
620 void UserMetricsRecorder::OnShellShuttingDown() {
621 desktop_task_switch_metric_recorder_.reset();
624 void UserMetricsRecorder::RecordPeriodicMetrics() {
625 ShelfLayoutManager* manager =
626 ShelfLayoutManager::ForShelf(Shell::GetPrimaryRootWindow());
627 // TODO(bruthig): Investigating whether the check for |manager| is necessary
628 // and add tests if it is.
629 if (manager) {
630 // TODO(bruthig): Consider tracking the time spent in each alignment.
631 UMA_HISTOGRAM_ENUMERATION("Ash.ShelfAlignmentOverTime",
632 manager->SelectValueForShelfAlignment(
633 SHELF_ALIGNMENT_UMA_ENUM_VALUE_BOTTOM,
634 SHELF_ALIGNMENT_UMA_ENUM_VALUE_LEFT,
635 SHELF_ALIGNMENT_UMA_ENUM_VALUE_RIGHT,
636 -1),
637 SHELF_ALIGNMENT_UMA_ENUM_VALUE_COUNT);
640 if (IsUserInActiveDesktopEnvironment()) {
641 RecordShelfItemCounts();
642 UMA_HISTOGRAM_COUNTS_100("Ash.NumberOfVisibleWindowsInPrimaryDisplay",
643 GetNumVisibleWindowsInPrimaryDisplay());
646 // TODO(bruthig): Find out if this should only be logged when the user is
647 // active.
648 // TODO(bruthig): Consider tracking how long a particular type of window is
649 // active at a time.
650 UMA_HISTOGRAM_ENUMERATION("Ash.ActiveWindowShowTypeOverTime",
651 GetActiveWindowState(),
652 ACTIVE_WINDOW_STATE_TYPE_COUNT);
655 bool UserMetricsRecorder::IsUserInActiveDesktopEnvironment() const {
656 return IsUserActive() && !IsKioskModeActive();
659 void UserMetricsRecorder::StartTimer() {
660 timer_.Start(FROM_HERE,
661 base::TimeDelta::FromSeconds(kAshPeriodicMetricsTimeInSeconds),
662 this, &UserMetricsRecorder::RecordPeriodicMetrics);
665 } // namespace ash