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"
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
;
49 case wm::WINDOW_STATE_TYPE_FULLSCREEN
:
50 active_window_state_type
= ACTIVE_WINDOW_STATE_TYPE_FULLSCREEN
;
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
;
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
;
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
;
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
82 switch (Shell::GetInstance()->system_tray_delegate()->GetUserLoginStatus()) {
83 case user::LOGGED_IN_NONE
:
84 case user::LOGGED_IN_LOCKED
:
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
:
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
)
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();
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())
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;
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
166 if (shelf_delegate
->HasShelfIDToAppIDMapping(shelf_item
.id
) &&
167 shelf_delegate
->IsAppPinned(
168 shelf_delegate
->GetAppIDForShelfID(shelf_item
.id
))) {
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
);
185 UserMetricsRecorder::UserMetricsRecorder() {
189 UserMetricsRecorder::UserMetricsRecorder(bool record_periodic_metrics
) {
190 if (record_periodic_metrics
)
194 UserMetricsRecorder::~UserMetricsRecorder() {
198 void UserMetricsRecorder::RecordUserMetricsAction(UserMetricsAction action
) {
200 case ash::UMA_ACCEL_KEYBOARD_BRIGHTNESS_DOWN_F6
:
202 base::UserMetricsAction("Accel_KeyboardBrightnessDown_F6"));
204 case ash::UMA_ACCEL_KEYBOARD_BRIGHTNESS_UP_F7
:
206 base::UserMetricsAction("Accel_KeyboardBrightnessUp_F7"));
208 case ash::UMA_ACCEL_LOCK_SCREEN_LOCK_BUTTON
:
210 base::UserMetricsAction("Accel_LockScreen_LockButton"));
212 case ash::UMA_ACCEL_LOCK_SCREEN_POWER_BUTTON
:
214 base::UserMetricsAction("Accel_LockScreen_PowerButton"));
216 case ash::UMA_ACCEL_MAXIMIZE_RESTORE_F4
:
218 base::UserMetricsAction("Accel_Maximize_Restore_F4"));
220 case ash::UMA_ACCEL_PREVWINDOW_F5
:
221 base::RecordAction(base::UserMetricsAction("Accel_PrevWindow_F5"));
223 case ash::UMA_ACCEL_EXIT_FIRST_Q
:
224 base::RecordAction(base::UserMetricsAction("Accel_Exit_First_Q"));
226 case ash::UMA_ACCEL_EXIT_SECOND_Q
:
227 base::RecordAction(base::UserMetricsAction("Accel_Exit_Second_Q"));
229 case ash::UMA_ACCEL_RESTART_POWER_BUTTON
:
231 base::UserMetricsAction("Accel_Restart_PowerButton"));
233 case ash::UMA_ACCEL_SHUT_DOWN_POWER_BUTTON
:
235 base::UserMetricsAction("Accel_ShutDown_PowerButton"));
237 case ash::UMA_CLOSE_THROUGH_CONTEXT_MENU
:
238 base::RecordAction(base::UserMetricsAction("CloseFromContextMenu"));
240 case ash::UMA_DESKTOP_SWITCH_TASK
:
241 base::RecordAction(base::UserMetricsAction("Desktop_SwitchTask"));
242 task_switch_metrics_recorder_
.OnTaskSwitch(
243 TaskSwitchMetricsRecorder::DESKTOP
);
245 case ash::UMA_DRAG_MAXIMIZE_LEFT
:
246 base::RecordAction(base::UserMetricsAction("WindowDrag_MaximizeLeft"));
248 case ash::UMA_DRAG_MAXIMIZE_RIGHT
:
249 base::RecordAction(base::UserMetricsAction("WindowDrag_MaximizeRight"));
251 case ash::UMA_LAUNCHER_BUTTON_PRESSED_WITH_MOUSE
:
253 base::UserMetricsAction("Launcher_ButtonPressed_Mouse"));
255 case ash::UMA_LAUNCHER_BUTTON_PRESSED_WITH_TOUCH
:
257 base::UserMetricsAction("Launcher_ButtonPressed_Touch"));
259 case ash::UMA_LAUNCHER_CLICK_ON_APP
:
260 base::RecordAction(base::UserMetricsAction("Launcher_ClickOnApp"));
262 case ash::UMA_LAUNCHER_CLICK_ON_APPLIST_BUTTON
:
264 base::UserMetricsAction("Launcher_ClickOnApplistButton"));
266 case ash::UMA_LAUNCHER_LAUNCH_TASK
:
267 base::RecordAction(base::UserMetricsAction("Launcher_LaunchTask"));
268 task_switch_metrics_recorder_
.OnTaskSwitch(
269 TaskSwitchMetricsRecorder::SHELF
);
271 case ash::UMA_LAUNCHER_MINIMIZE_TASK
:
272 base::RecordAction(base::UserMetricsAction("Launcher_MinimizeTask"));
274 case ash::UMA_LAUNCHER_SWITCH_TASK
:
275 base::RecordAction(base::UserMetricsAction("Launcher_SwitchTask"));
276 task_switch_metrics_recorder_
.OnTaskSwitch(
277 TaskSwitchMetricsRecorder::SHELF
);
279 case UMA_MAXIMIZE_MODE_DISABLED
:
280 base::RecordAction(base::UserMetricsAction("Touchview_Disabled"));
282 case UMA_MAXIMIZE_MODE_ENABLED
:
283 base::RecordAction(base::UserMetricsAction("Touchview_Enabled"));
285 case UMA_MAXIMIZE_MODE_INITIALLY_DISABLED
:
287 base::UserMetricsAction("Touchview_Initially_Disabled"));
289 case ash::UMA_MOUSE_DOWN
:
290 base::RecordAction(base::UserMetricsAction("Mouse_Down"));
292 case ash::UMA_PANEL_MINIMIZE_CAPTION_CLICK
:
294 base::UserMetricsAction("Panel_Minimize_Caption_Click"));
296 case ash::UMA_PANEL_MINIMIZE_CAPTION_GESTURE
:
298 base::UserMetricsAction("Panel_Minimize_Caption_Gesture"));
300 case ash::UMA_SHELF_ALIGNMENT_SET_BOTTOM
:
302 base::UserMetricsAction("Shelf_AlignmentSetBottom"));
304 case ash::UMA_SHELF_ALIGNMENT_SET_LEFT
:
306 base::UserMetricsAction("Shelf_AlignmentSetLeft"));
308 case ash::UMA_SHELF_ALIGNMENT_SET_RIGHT
:
310 base::UserMetricsAction("Shelf_AlignmentSetRight"));
312 case ash::UMA_STATUS_AREA_AUDIO_CURRENT_INPUT_DEVICE
:
314 base::UserMetricsAction("StatusArea_Audio_CurrentInputDevice"));
316 case ash::UMA_STATUS_AREA_AUDIO_CURRENT_OUTPUT_DEVICE
:
318 base::UserMetricsAction("StatusArea_Audio_CurrentOutputDevice"));
320 case ash::UMA_STATUS_AREA_AUDIO_SWITCH_INPUT_DEVICE
:
322 base::UserMetricsAction("StatusArea_Audio_SwitchInputDevice"));
324 case ash::UMA_STATUS_AREA_AUDIO_SWITCH_OUTPUT_DEVICE
:
326 base::UserMetricsAction("StatusArea_Audio_SwitchOutputDevice"));
328 case ash::UMA_STATUS_AREA_BRIGHTNESS_CHANGED
:
330 base::UserMetricsAction("StatusArea_BrightnessChanged"));
332 case ash::UMA_STATUS_AREA_BLUETOOTH_CONNECT_KNOWN_DEVICE
:
334 base::UserMetricsAction("StatusArea_Bluetooth_Connect_Known"));
336 case ash::UMA_STATUS_AREA_BLUETOOTH_CONNECT_UNKNOWN_DEVICE
:
338 base::UserMetricsAction("StatusArea_Bluetooth_Connect_Unknown"));
340 case ash::UMA_STATUS_AREA_BLUETOOTH_DISABLED
:
342 base::UserMetricsAction("StatusArea_Bluetooth_Disabled"));
344 case ash::UMA_STATUS_AREA_BLUETOOTH_ENABLED
:
346 base::UserMetricsAction("StatusArea_Bluetooth_Enabled"));
348 case ash::UMA_STATUS_AREA_CAPS_LOCK_DETAILED
:
350 base::UserMetricsAction("StatusArea_CapsLock_Detailed"));
352 case ash::UMA_STATUS_AREA_CAPS_LOCK_DISABLED_BY_CLICK
:
354 base::UserMetricsAction("StatusArea_CapsLock_DisabledByClick"));
356 case ash::UMA_STATUS_AREA_CAPS_LOCK_ENABLED_BY_CLICK
:
358 base::UserMetricsAction("StatusArea_CapsLock_EnabledByClick"));
360 case ash::UMA_STATUS_AREA_CAPS_LOCK_POPUP
:
362 base::UserMetricsAction("StatusArea_CapsLock_Popup"));
364 case ash::UMA_STATUS_AREA_CAST_STOP_CAST
:
365 base::RecordAction(base::UserMetricsAction("StatusArea_Cast_StopCast"));
367 case ash::UMA_STATUS_AREA_CONNECT_TO_CONFIGURED_NETWORK
:
369 base::UserMetricsAction("StatusArea_Network_ConnectConfigured"));
371 case ash::UMA_STATUS_AREA_CONNECT_TO_UNCONFIGURED_NETWORK
:
373 base::UserMetricsAction("StatusArea_Network_ConnectUnconfigured"));
375 case ash::UMA_STATUS_AREA_CONNECT_TO_VPN
:
377 base::UserMetricsAction("StatusArea_VPN_ConnectToNetwork"));
379 case ash::UMA_STATUS_AREA_CHANGED_VOLUME_MENU
:
381 base::UserMetricsAction("StatusArea_Volume_ChangedMenu"));
383 case ash::UMA_STATUS_AREA_CHANGED_VOLUME_POPUP
:
385 base::UserMetricsAction("StatusArea_Volume_ChangedPopup"));
387 case ash::UMA_STATUS_AREA_DETAILED_ACCESSABILITY
:
389 base::UserMetricsAction("StatusArea_Accessability_DetailedView"));
391 case ash::UMA_STATUS_AREA_DETAILED_AUDIO_VIEW
:
393 base::UserMetricsAction("StatusArea_Audio_Detailed"));
395 case ash::UMA_STATUS_AREA_DETAILED_BLUETOOTH_VIEW
:
397 base::UserMetricsAction("StatusArea_Bluetooth_Detailed"));
399 case ash::UMA_STATUS_AREA_DETAILED_BRIGHTNESS_VIEW
:
401 base::UserMetricsAction("StatusArea_Brightness_Detailed"));
403 case ash::UMA_STATUS_AREA_DETAILED_CAST_VIEW
:
404 base::RecordAction(base::UserMetricsAction("StatusArea_Cast_Detailed"));
406 case ash::UMA_STATUS_AREA_DETAILED_CAST_VIEW_LAUNCH_CAST
:
408 base::UserMetricsAction("StatusArea_Cast_Detailed_Launch_Cast"));
410 case ash::UMA_STATUS_AREA_DETAILED_DRIVE_VIEW
:
412 base::UserMetricsAction("StatusArea_Drive_Detailed"));
414 case ash::UMA_STATUS_AREA_DETAILED_NETWORK_VIEW
:
416 base::UserMetricsAction("StatusArea_Network_Detailed"));
418 case ash::UMA_STATUS_AREA_DETAILED_VPN_VIEW
:
420 base::UserMetricsAction("StatusArea_VPN_Detailed"));
422 case ash::UMA_STATUS_AREA_DISABLE_AUTO_CLICK
:
424 base::UserMetricsAction("StatusArea_AutoClickDisabled"));
426 case ash::UMA_STATUS_AREA_DISABLE_HIGH_CONTRAST
:
428 base::UserMetricsAction("StatusArea_HighContrastDisabled"));
430 case ash::UMA_STATUS_AREA_DISABLE_LARGE_CURSOR
:
432 base::UserMetricsAction("StatusArea_LargeCursorDisabled"));
434 case ash::UMA_STATUS_AREA_DISABLE_MAGNIFIER
:
436 base::UserMetricsAction("StatusArea_MagnifierDisabled"));
438 case ash::UMA_STATUS_AREA_DISABLE_SPOKEN_FEEDBACK
:
440 base::UserMetricsAction("StatusArea_SpokenFeedbackDisabled"));
442 case ash::UMA_STATUS_AREA_DISABLE_VIRTUAL_KEYBOARD
:
444 base::UserMetricsAction("StatusArea_VirtualKeyboardDisabled"));
446 case ash::UMA_STATUS_AREA_DISABLE_WIFI
:
448 base::UserMetricsAction("StatusArea_Network_WifiDisabled"));
450 case ash::UMA_STATUS_AREA_DRIVE_CANCEL_OPERATION
:
452 base::UserMetricsAction("StatusArea_Drive_CancelOperation"));
454 case ash::UMA_STATUS_AREA_DRIVE_SETTINGS
:
456 base::UserMetricsAction("StatusArea_Drive_Settings"));
458 case ash::UMA_STATUS_AREA_ENABLE_AUTO_CLICK
:
460 base::UserMetricsAction("StatusArea_AutoClickEnabled"));
462 case ash::UMA_STATUS_AREA_ENABLE_HIGH_CONTRAST
:
464 base::UserMetricsAction("StatusArea_HighContrastEnabled"));
466 case ash::UMA_STATUS_AREA_ENABLE_LARGE_CURSOR
:
468 base::UserMetricsAction("StatusArea_LargeCursorEnabled"));
470 case ash::UMA_STATUS_AREA_ENABLE_MAGNIFIER
:
472 base::UserMetricsAction("StatusArea_MagnifierEnabled"));
474 case ash::UMA_STATUS_AREA_ENABLE_SPOKEN_FEEDBACK
:
476 base::UserMetricsAction("StatusArea_SpokenFeedbackEnabled"));
478 case ash::UMA_STATUS_AREA_ENABLE_VIRTUAL_KEYBOARD
:
480 base::UserMetricsAction("StatusArea_VirtualKeyboardEnabled"));
482 case ash::UMA_STATUS_AREA_ENABLE_WIFI
:
484 base::UserMetricsAction("StatusArea_Network_WifiEnabled"));
486 case ash::UMA_STATUS_AREA_IME_SHOW_DETAILED
:
488 base::UserMetricsAction("StatusArea_IME_Detailed"));
490 case ash::UMA_STATUS_AREA_IME_SWITCH_MODE
:
492 base::UserMetricsAction("StatusArea_IME_SwitchMode"));
494 case ash::UMA_STATUS_AREA_MENU_OPENED
:
496 base::UserMetricsAction("StatusArea_MenuOpened"));
498 case ash::UMA_STATUS_AREA_NETWORK_JOIN_OTHER_CLICKED
:
500 base::UserMetricsAction("StatusArea_Network_JoinOther"));
502 case ash::UMA_STATUS_AREA_NETWORK_SETTINGS_CLICKED
:
504 base::UserMetricsAction("StatusArea_Network_Settings"));
506 case ash::UMA_STATUS_AREA_SHOW_NETWORK_CONNECTION_DETAILS
:
508 base::UserMetricsAction("StatusArea_Network_ConnectionDetails"));
510 case ash::UMA_STATUS_AREA_SHOW_VPN_CONNECTION_DETAILS
:
512 base::UserMetricsAction("StatusArea_VPN_ConnectionDetails"));
514 case ash::UMA_STATUS_AREA_SIGN_OUT
:
516 base::UserMetricsAction("StatusArea_SignOut"));
518 case ash::UMA_STATUS_AREA_VPN_ADD_BUILT_IN_CLICKED
:
519 base::RecordAction(base::UserMetricsAction("StatusArea_VPN_AddBuiltIn"));
521 case ash::UMA_STATUS_AREA_VPN_ADD_THIRD_PARTY_CLICKED
:
523 base::UserMetricsAction("StatusArea_VPN_AddThirdParty"));
525 case ash::UMA_STATUS_AREA_VPN_DISCONNECT_CLICKED
:
526 base::RecordAction(base::UserMetricsAction("StatusArea_VPN_Disconnect"));
528 case ash::UMA_STATUS_AREA_VPN_SETTINGS_CLICKED
:
530 base::UserMetricsAction("StatusArea_VPN_Settings"));
532 case ash::UMA_TOGGLE_MAXIMIZE_CAPTION_CLICK
:
534 base::UserMetricsAction("Caption_ClickTogglesMaximize"));
536 case ash::UMA_TOGGLE_MAXIMIZE_CAPTION_GESTURE
:
538 base::UserMetricsAction("Caption_GestureTogglesMaximize"));
540 case ash::UMA_TOGGLE_SINGLE_AXIS_MAXIMIZE_BORDER_CLICK
:
542 base::UserMetricsAction(
543 "WindowBorder_ClickTogglesSingleAxisMaximize"));
545 case ash::UMA_TOUCHPAD_GESTURE_OVERVIEW
:
547 base::UserMetricsAction("Touchpad_Gesture_Overview"));
549 case ash::UMA_TOUCHSCREEN_TAP_DOWN
:
550 base::RecordAction(base::UserMetricsAction("Touchscreen_Down"));
552 case ash::UMA_TRAY_HELP
:
553 base::RecordAction(base::UserMetricsAction("Tray_Help"));
555 case ash::UMA_TRAY_LOCK_SCREEN
:
556 base::RecordAction(base::UserMetricsAction("Tray_LockScreen"));
558 case ash::UMA_TRAY_OVERVIEW
:
559 base::RecordAction(base::UserMetricsAction("Tray_Overview"));
561 case ash::UMA_TRAY_SHUT_DOWN
:
562 base::RecordAction(base::UserMetricsAction("Tray_ShutDown"));
564 case ash::UMA_WINDOW_APP_CLOSE_BUTTON_CLICK
:
565 base::RecordAction(base::UserMetricsAction("AppCloseButton_Clk"));
567 case ash::UMA_WINDOW_CLOSE_BUTTON_CLICK
:
568 base::RecordAction(base::UserMetricsAction("CloseButton_Clk"));
570 case ash::UMA_WINDOW_MAXIMIZE_BUTTON_CLICK_EXIT_FULLSCREEN
:
571 base::RecordAction(base::UserMetricsAction("MaxButton_Clk_ExitFS"));
573 case ash::UMA_WINDOW_MAXIMIZE_BUTTON_CLICK_RESTORE
:
575 base::UserMetricsAction("MaxButton_Clk_Restore"));
577 case ash::UMA_WINDOW_MAXIMIZE_BUTTON_CLICK_MAXIMIZE
:
579 base::UserMetricsAction("MaxButton_Clk_Maximize"));
581 case ash::UMA_WINDOW_MAXIMIZE_BUTTON_CLICK_MINIMIZE
:
582 base::RecordAction(base::UserMetricsAction("MinButton_Clk"));
584 case ash::UMA_WINDOW_MAXIMIZE_BUTTON_MAXIMIZE_LEFT
:
585 base::RecordAction(base::UserMetricsAction("MaxButton_MaxLeft"));
587 case ash::UMA_WINDOW_MAXIMIZE_BUTTON_MAXIMIZE_RIGHT
:
588 base::RecordAction(base::UserMetricsAction("MaxButton_MaxRight"));
590 case ash::UMA_WINDOW_OVERVIEW
:
592 base::UserMetricsAction("WindowSelector_Overview"));
594 case ash::UMA_WINDOW_OVERVIEW_ACTIVE_WINDOW_CHANGED
:
596 base::UserMetricsAction("WindowSelector_ActiveWindowChanged"));
597 task_switch_metrics_recorder_
.OnTaskSwitch(
598 TaskSwitchMetricsRecorder::OVERVIEW_MODE
);
600 case ash::UMA_WINDOW_OVERVIEW_ENTER_KEY
:
602 base::UserMetricsAction("WindowSelector_OverviewEnterKey"));
604 case ash::UMA_WINDOW_CYCLE
:
606 base::UserMetricsAction("WindowCycleController_Cycle"));
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.
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
,
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
648 // TODO(bruthig): Consider tracking how long a particular type of window is
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
);