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_GESTURE_OVERVIEW
:
252 base::RecordAction(base::UserMetricsAction("Gesture_Overview"));
254 case ash::UMA_LAUNCHER_BUTTON_PRESSED_WITH_MOUSE
:
256 base::UserMetricsAction("Launcher_ButtonPressed_Mouse"));
258 case ash::UMA_LAUNCHER_BUTTON_PRESSED_WITH_TOUCH
:
260 base::UserMetricsAction("Launcher_ButtonPressed_Touch"));
262 case ash::UMA_LAUNCHER_CLICK_ON_APP
:
263 base::RecordAction(base::UserMetricsAction("Launcher_ClickOnApp"));
265 case ash::UMA_LAUNCHER_CLICK_ON_APPLIST_BUTTON
:
267 base::UserMetricsAction("Launcher_ClickOnApplistButton"));
269 case ash::UMA_LAUNCHER_LAUNCH_TASK
:
270 base::RecordAction(base::UserMetricsAction("Launcher_LaunchTask"));
271 task_switch_metrics_recorder_
.OnTaskSwitch(
272 TaskSwitchMetricsRecorder::SHELF
);
274 case ash::UMA_LAUNCHER_MINIMIZE_TASK
:
275 base::RecordAction(base::UserMetricsAction("Launcher_MinimizeTask"));
277 case ash::UMA_LAUNCHER_SWITCH_TASK
:
278 base::RecordAction(base::UserMetricsAction("Launcher_SwitchTask"));
279 task_switch_metrics_recorder_
.OnTaskSwitch(
280 TaskSwitchMetricsRecorder::SHELF
);
282 case UMA_MAXIMIZE_MODE_DISABLED
:
283 base::RecordAction(base::UserMetricsAction("Touchview_Disabled"));
285 case UMA_MAXIMIZE_MODE_ENABLED
:
286 base::RecordAction(base::UserMetricsAction("Touchview_Enabled"));
288 case UMA_MAXIMIZE_MODE_INITIALLY_DISABLED
:
290 base::UserMetricsAction("Touchview_Initially_Disabled"));
292 case ash::UMA_MOUSE_DOWN
:
293 base::RecordAction(base::UserMetricsAction("Mouse_Down"));
295 case ash::UMA_PANEL_MINIMIZE_CAPTION_CLICK
:
297 base::UserMetricsAction("Panel_Minimize_Caption_Click"));
299 case ash::UMA_PANEL_MINIMIZE_CAPTION_GESTURE
:
301 base::UserMetricsAction("Panel_Minimize_Caption_Gesture"));
303 case ash::UMA_SHELF_ALIGNMENT_SET_BOTTOM
:
305 base::UserMetricsAction("Shelf_AlignmentSetBottom"));
307 case ash::UMA_SHELF_ALIGNMENT_SET_LEFT
:
309 base::UserMetricsAction("Shelf_AlignmentSetLeft"));
311 case ash::UMA_SHELF_ALIGNMENT_SET_RIGHT
:
313 base::UserMetricsAction("Shelf_AlignmentSetRight"));
315 case ash::UMA_STATUS_AREA_AUDIO_CURRENT_INPUT_DEVICE
:
317 base::UserMetricsAction("StatusArea_Audio_CurrentInputDevice"));
319 case ash::UMA_STATUS_AREA_AUDIO_CURRENT_OUTPUT_DEVICE
:
321 base::UserMetricsAction("StatusArea_Audio_CurrentOutputDevice"));
323 case ash::UMA_STATUS_AREA_AUDIO_SWITCH_INPUT_DEVICE
:
325 base::UserMetricsAction("StatusArea_Audio_SwitchInputDevice"));
327 case ash::UMA_STATUS_AREA_AUDIO_SWITCH_OUTPUT_DEVICE
:
329 base::UserMetricsAction("StatusArea_Audio_SwitchOutputDevice"));
331 case ash::UMA_STATUS_AREA_BRIGHTNESS_CHANGED
:
333 base::UserMetricsAction("StatusArea_BrightnessChanged"));
335 case ash::UMA_STATUS_AREA_BLUETOOTH_CONNECT_KNOWN_DEVICE
:
337 base::UserMetricsAction("StatusArea_Bluetooth_Connect_Known"));
339 case ash::UMA_STATUS_AREA_BLUETOOTH_CONNECT_UNKNOWN_DEVICE
:
341 base::UserMetricsAction("StatusArea_Bluetooth_Connect_Unknown"));
343 case ash::UMA_STATUS_AREA_BLUETOOTH_DISABLED
:
345 base::UserMetricsAction("StatusArea_Bluetooth_Disabled"));
347 case ash::UMA_STATUS_AREA_BLUETOOTH_ENABLED
:
349 base::UserMetricsAction("StatusArea_Bluetooth_Enabled"));
351 case ash::UMA_STATUS_AREA_CAPS_LOCK_DETAILED
:
353 base::UserMetricsAction("StatusArea_CapsLock_Detailed"));
355 case ash::UMA_STATUS_AREA_CAPS_LOCK_DISABLED_BY_CLICK
:
357 base::UserMetricsAction("StatusArea_CapsLock_DisabledByClick"));
359 case ash::UMA_STATUS_AREA_CAPS_LOCK_ENABLED_BY_CLICK
:
361 base::UserMetricsAction("StatusArea_CapsLock_EnabledByClick"));
363 case ash::UMA_STATUS_AREA_CAPS_LOCK_POPUP
:
365 base::UserMetricsAction("StatusArea_CapsLock_Popup"));
367 case ash::UMA_STATUS_AREA_CAST_STOP_CAST
:
368 base::RecordAction(base::UserMetricsAction("StatusArea_Cast_StopCast"));
370 case ash::UMA_STATUS_AREA_CONNECT_TO_CONFIGURED_NETWORK
:
372 base::UserMetricsAction("StatusArea_Network_ConnectConfigured"));
374 case ash::UMA_STATUS_AREA_CONNECT_TO_UNCONFIGURED_NETWORK
:
376 base::UserMetricsAction("StatusArea_Network_ConnectUnconfigured"));
378 case ash::UMA_STATUS_AREA_CONNECT_TO_VPN
:
380 base::UserMetricsAction("StatusArea_VPN_ConnectToNetwork"));
382 case ash::UMA_STATUS_AREA_CHANGED_VOLUME_MENU
:
384 base::UserMetricsAction("StatusArea_Volume_ChangedMenu"));
386 case ash::UMA_STATUS_AREA_CHANGED_VOLUME_POPUP
:
388 base::UserMetricsAction("StatusArea_Volume_ChangedPopup"));
390 case ash::UMA_STATUS_AREA_DETAILED_ACCESSABILITY
:
392 base::UserMetricsAction("StatusArea_Accessability_DetailedView"));
394 case ash::UMA_STATUS_AREA_DETAILED_AUDIO_VIEW
:
396 base::UserMetricsAction("StatusArea_Audio_Detailed"));
398 case ash::UMA_STATUS_AREA_DETAILED_BLUETOOTH_VIEW
:
400 base::UserMetricsAction("StatusArea_Bluetooth_Detailed"));
402 case ash::UMA_STATUS_AREA_DETAILED_BRIGHTNESS_VIEW
:
404 base::UserMetricsAction("StatusArea_Brightness_Detailed"));
406 case ash::UMA_STATUS_AREA_DETAILED_CAST_VIEW
:
407 base::RecordAction(base::UserMetricsAction("StatusArea_Cast_Detailed"));
409 case ash::UMA_STATUS_AREA_DETAILED_CAST_VIEW_LAUNCH_CAST
:
411 base::UserMetricsAction("StatusArea_Cast_Detailed_Launch_Cast"));
413 case ash::UMA_STATUS_AREA_DETAILED_DRIVE_VIEW
:
415 base::UserMetricsAction("StatusArea_Drive_Detailed"));
417 case ash::UMA_STATUS_AREA_DETAILED_NETWORK_VIEW
:
419 base::UserMetricsAction("StatusArea_Network_Detailed"));
421 case ash::UMA_STATUS_AREA_DETAILED_VPN_VIEW
:
423 base::UserMetricsAction("StatusArea_VPN_Detailed"));
425 case ash::UMA_STATUS_AREA_DISABLE_AUTO_CLICK
:
427 base::UserMetricsAction("StatusArea_AutoClickDisabled"));
429 case ash::UMA_STATUS_AREA_DISABLE_HIGH_CONTRAST
:
431 base::UserMetricsAction("StatusArea_HighContrastDisabled"));
433 case ash::UMA_STATUS_AREA_DISABLE_LARGE_CURSOR
:
435 base::UserMetricsAction("StatusArea_LargeCursorDisabled"));
437 case ash::UMA_STATUS_AREA_DISABLE_MAGNIFIER
:
439 base::UserMetricsAction("StatusArea_MagnifierDisabled"));
441 case ash::UMA_STATUS_AREA_DISABLE_SPOKEN_FEEDBACK
:
443 base::UserMetricsAction("StatusArea_SpokenFeedbackDisabled"));
445 case ash::UMA_STATUS_AREA_DISABLE_VIRTUAL_KEYBOARD
:
447 base::UserMetricsAction("StatusArea_VirtualKeyboardDisabled"));
449 case ash::UMA_STATUS_AREA_DISABLE_WIFI
:
451 base::UserMetricsAction("StatusArea_Network_WifiDisabled"));
453 case ash::UMA_STATUS_AREA_DRIVE_CANCEL_OPERATION
:
455 base::UserMetricsAction("StatusArea_Drive_CancelOperation"));
457 case ash::UMA_STATUS_AREA_DRIVE_SETTINGS
:
459 base::UserMetricsAction("StatusArea_Drive_Settings"));
461 case ash::UMA_STATUS_AREA_ENABLE_AUTO_CLICK
:
463 base::UserMetricsAction("StatusArea_AutoClickEnabled"));
465 case ash::UMA_STATUS_AREA_ENABLE_HIGH_CONTRAST
:
467 base::UserMetricsAction("StatusArea_HighContrastEnabled"));
469 case ash::UMA_STATUS_AREA_ENABLE_LARGE_CURSOR
:
471 base::UserMetricsAction("StatusArea_LargeCursorEnabled"));
473 case ash::UMA_STATUS_AREA_ENABLE_MAGNIFIER
:
475 base::UserMetricsAction("StatusArea_MagnifierEnabled"));
477 case ash::UMA_STATUS_AREA_ENABLE_SPOKEN_FEEDBACK
:
479 base::UserMetricsAction("StatusArea_SpokenFeedbackEnabled"));
481 case ash::UMA_STATUS_AREA_ENABLE_VIRTUAL_KEYBOARD
:
483 base::UserMetricsAction("StatusArea_VirtualKeyboardEnabled"));
485 case ash::UMA_STATUS_AREA_ENABLE_WIFI
:
487 base::UserMetricsAction("StatusArea_Network_WifiEnabled"));
489 case ash::UMA_STATUS_AREA_IME_SHOW_DETAILED
:
491 base::UserMetricsAction("StatusArea_IME_Detailed"));
493 case ash::UMA_STATUS_AREA_IME_SWITCH_MODE
:
495 base::UserMetricsAction("StatusArea_IME_SwitchMode"));
497 case ash::UMA_STATUS_AREA_MENU_OPENED
:
499 base::UserMetricsAction("StatusArea_MenuOpened"));
501 case ash::UMA_STATUS_AREA_NETWORK_JOIN_OTHER_CLICKED
:
503 base::UserMetricsAction("StatusArea_Network_JoinOther"));
505 case ash::UMA_STATUS_AREA_NETWORK_SETTINGS_CLICKED
:
507 base::UserMetricsAction("StatusArea_Network_Settings"));
509 case ash::UMA_STATUS_AREA_SHOW_NETWORK_CONNECTION_DETAILS
:
511 base::UserMetricsAction("StatusArea_Network_ConnectionDetails"));
513 case ash::UMA_STATUS_AREA_SHOW_VPN_CONNECTION_DETAILS
:
515 base::UserMetricsAction("StatusArea_VPN_ConnectionDetails"));
517 case ash::UMA_STATUS_AREA_SIGN_OUT
:
519 base::UserMetricsAction("StatusArea_SignOut"));
521 case ash::UMA_STATUS_AREA_VPN_ADD_BUILT_IN_CLICKED
:
522 base::RecordAction(base::UserMetricsAction("StatusArea_VPN_AddBuiltIn"));
524 case ash::UMA_STATUS_AREA_VPN_ADD_THIRD_PARTY_CLICKED
:
526 base::UserMetricsAction("StatusArea_VPN_AddThirdParty"));
528 case ash::UMA_STATUS_AREA_VPN_DISCONNECT_CLICKED
:
529 base::RecordAction(base::UserMetricsAction("StatusArea_VPN_Disconnect"));
531 case ash::UMA_STATUS_AREA_VPN_SETTINGS_CLICKED
:
533 base::UserMetricsAction("StatusArea_VPN_Settings"));
535 case ash::UMA_TOGGLE_MAXIMIZE_CAPTION_CLICK
:
537 base::UserMetricsAction("Caption_ClickTogglesMaximize"));
539 case ash::UMA_TOGGLE_MAXIMIZE_CAPTION_GESTURE
:
541 base::UserMetricsAction("Caption_GestureTogglesMaximize"));
543 case ash::UMA_TOGGLE_SINGLE_AXIS_MAXIMIZE_BORDER_CLICK
:
545 base::UserMetricsAction(
546 "WindowBorder_ClickTogglesSingleAxisMaximize"));
548 case ash::UMA_TOUCHPAD_GESTURE_OVERVIEW
:
550 base::UserMetricsAction("Touchpad_Gesture_Overview"));
552 case ash::UMA_TOUCHSCREEN_TAP_DOWN
:
553 base::RecordAction(base::UserMetricsAction("Touchscreen_Down"));
555 case ash::UMA_TRAY_HELP
:
556 base::RecordAction(base::UserMetricsAction("Tray_Help"));
558 case ash::UMA_TRAY_LOCK_SCREEN
:
559 base::RecordAction(base::UserMetricsAction("Tray_LockScreen"));
561 case ash::UMA_TRAY_OVERVIEW
:
562 base::RecordAction(base::UserMetricsAction("Tray_Overview"));
564 case ash::UMA_TRAY_SHUT_DOWN
:
565 base::RecordAction(base::UserMetricsAction("Tray_ShutDown"));
567 case ash::UMA_WINDOW_APP_CLOSE_BUTTON_CLICK
:
568 base::RecordAction(base::UserMetricsAction("AppCloseButton_Clk"));
570 case ash::UMA_WINDOW_CLOSE_BUTTON_CLICK
:
571 base::RecordAction(base::UserMetricsAction("CloseButton_Clk"));
573 case ash::UMA_WINDOW_MAXIMIZE_BUTTON_CLICK_EXIT_FULLSCREEN
:
574 base::RecordAction(base::UserMetricsAction("MaxButton_Clk_ExitFS"));
576 case ash::UMA_WINDOW_MAXIMIZE_BUTTON_CLICK_RESTORE
:
578 base::UserMetricsAction("MaxButton_Clk_Restore"));
580 case ash::UMA_WINDOW_MAXIMIZE_BUTTON_CLICK_MAXIMIZE
:
582 base::UserMetricsAction("MaxButton_Clk_Maximize"));
584 case ash::UMA_WINDOW_MAXIMIZE_BUTTON_CLICK_MINIMIZE
:
585 base::RecordAction(base::UserMetricsAction("MinButton_Clk"));
587 case ash::UMA_WINDOW_MAXIMIZE_BUTTON_MAXIMIZE_LEFT
:
588 base::RecordAction(base::UserMetricsAction("MaxButton_MaxLeft"));
590 case ash::UMA_WINDOW_MAXIMIZE_BUTTON_MAXIMIZE_RIGHT
:
591 base::RecordAction(base::UserMetricsAction("MaxButton_MaxRight"));
593 case ash::UMA_WINDOW_OVERVIEW
:
595 base::UserMetricsAction("WindowSelector_Overview"));
597 case ash::UMA_WINDOW_OVERVIEW_ACTIVE_WINDOW_CHANGED
:
599 base::UserMetricsAction("WindowSelector_ActiveWindowChanged"));
600 task_switch_metrics_recorder_
.OnTaskSwitch(
601 TaskSwitchMetricsRecorder::OVERVIEW_MODE
);
603 case ash::UMA_WINDOW_OVERVIEW_ENTER_KEY
:
605 base::UserMetricsAction("WindowSelector_OverviewEnterKey"));
607 case ash::UMA_WINDOW_CYCLE
:
609 base::UserMetricsAction("WindowCycleController_Cycle"));
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.
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
,
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
651 // TODO(bruthig): Consider tracking how long a particular type of window is
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
);