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/shelf/shelf_layout_manager.h"
8 #include "ash/shelf/shelf_view.h"
9 #include "ash/shelf/shelf_widget.h"
10 #include "ash/shell.h"
11 #include "ash/wm/window_state.h"
12 #include "base/metrics/histogram.h"
13 #include "base/metrics/user_metrics.h"
17 // Time in seconds between calls to "RecordPeriodicMetrics".
18 const int kAshPeriodicMetricsTimeInSeconds
= 30 * 60;
20 UserMetricsRecorder::UserMetricsRecorder() {
21 timer_
.Start(FROM_HERE
,
22 base::TimeDelta::FromSeconds(kAshPeriodicMetricsTimeInSeconds
),
24 &UserMetricsRecorder::RecordPeriodicMetrics
);
27 UserMetricsRecorder::~UserMetricsRecorder() {
31 void UserMetricsRecorder::RecordUserMetricsAction(UserMetricsAction action
) {
33 case ash::UMA_ACCEL_KEYBOARD_BRIGHTNESS_DOWN_F6
:
35 base::UserMetricsAction("Accel_KeyboardBrightnessDown_F6"));
37 case ash::UMA_ACCEL_KEYBOARD_BRIGHTNESS_UP_F7
:
39 base::UserMetricsAction("Accel_KeyboardBrightnessUp_F7"));
41 case ash::UMA_ACCEL_LOCK_SCREEN_LOCK_BUTTON
:
43 base::UserMetricsAction("Accel_LockScreen_LockButton"));
45 case ash::UMA_ACCEL_LOCK_SCREEN_POWER_BUTTON
:
47 base::UserMetricsAction("Accel_LockScreen_PowerButton"));
49 case ash::UMA_ACCEL_MAXIMIZE_RESTORE_F4
:
51 base::UserMetricsAction("Accel_Maximize_Restore_F4"));
53 case ash::UMA_ACCEL_PREVWINDOW_F5
:
54 base::RecordAction(base::UserMetricsAction("Accel_PrevWindow_F5"));
56 case ash::UMA_ACCEL_EXIT_FIRST_Q
:
57 base::RecordAction(base::UserMetricsAction("Accel_Exit_First_Q"));
59 case ash::UMA_ACCEL_EXIT_SECOND_Q
:
60 base::RecordAction(base::UserMetricsAction("Accel_Exit_Second_Q"));
62 case ash::UMA_ACCEL_SHUT_DOWN_POWER_BUTTON
:
64 base::UserMetricsAction("Accel_ShutDown_PowerButton"));
66 case ash::UMA_CLOSE_THROUGH_CONTEXT_MENU
:
67 base::RecordAction(base::UserMetricsAction("CloseFromContextMenu"));
69 case ash::UMA_DRAG_MAXIMIZE_LEFT
:
70 base::RecordAction(base::UserMetricsAction("WindowDrag_MaximizeLeft"));
72 case ash::UMA_DRAG_MAXIMIZE_RIGHT
:
73 base::RecordAction(base::UserMetricsAction("WindowDrag_MaximizeRight"));
75 case ash::UMA_GESTURE_OVERVIEW
:
76 base::RecordAction(base::UserMetricsAction("Gesture_Overview"));
78 case ash::UMA_LAUNCHER_CLICK_ON_APP
:
79 base::RecordAction(base::UserMetricsAction("Launcher_ClickOnApp"));
81 case ash::UMA_LAUNCHER_CLICK_ON_APPLIST_BUTTON
:
83 base::UserMetricsAction("Launcher_ClickOnApplistButton"));
85 case ash::UMA_MOUSE_DOWN
:
86 base::RecordAction(base::UserMetricsAction("Mouse_Down"));
88 case ash::UMA_PANEL_MINIMIZE_CAPTION_CLICK
:
90 base::UserMetricsAction("Panel_Minimize_Caption_Click"));
92 case ash::UMA_PANEL_MINIMIZE_CAPTION_GESTURE
:
94 base::UserMetricsAction("Panel_Minimize_Caption_Gesture"));
96 case ash::UMA_SHELF_ALIGNMENT_SET_BOTTOM
:
98 base::UserMetricsAction("Shelf_AlignmentSetBottom"));
100 case ash::UMA_SHELF_ALIGNMENT_SET_LEFT
:
102 base::UserMetricsAction("Shelf_AlignmentSetLeft"));
104 case ash::UMA_SHELF_ALIGNMENT_SET_RIGHT
:
106 base::UserMetricsAction("Shelf_AlignmentSetRight"));
107 case ash::UMA_STATUS_AREA_AUDIO_CURRENT_INPUT_DEVICE
:
109 base::UserMetricsAction("StatusArea_Audio_CurrentInputDevice"));
111 case ash::UMA_STATUS_AREA_AUDIO_CURRENT_OUTPUT_DEVICE
:
113 base::UserMetricsAction("StatusArea_Audio_CurrentOutputDevice"));
115 case ash::UMA_STATUS_AREA_AUDIO_SWITCH_INPUT_DEVICE
:
117 base::UserMetricsAction("StatusArea_Audio_SwitchInputDevice"));
119 case ash::UMA_STATUS_AREA_AUDIO_SWITCH_OUTPUT_DEVICE
:
121 base::UserMetricsAction("StatusArea_Audio_SwitchOutputDevice"));
123 case ash::UMA_STATUS_AREA_BRIGHTNESS_CHANGED
:
125 base::UserMetricsAction("StatusArea_BrightnessChanged"));
127 case ash::UMA_STATUS_AREA_BLUETOOTH_CONNECT_KNOWN_DEVICE
:
129 base::UserMetricsAction("StatusArea_Bluetooth_Connect_Known"));
131 case ash::UMA_STATUS_AREA_BLUETOOTH_CONNECT_UNKNOWN_DEVICE
:
133 base::UserMetricsAction("StatusArea_Bluetooth_Connect_Unknown"));
135 case ash::UMA_STATUS_AREA_BLUETOOTH_DISABLED
:
137 base::UserMetricsAction("StatusArea_Bluetooth_Disabled"));
139 case ash::UMA_STATUS_AREA_BLUETOOTH_ENABLED
:
141 base::UserMetricsAction("StatusArea_Bluetooth_Enabled"));
143 case ash::UMA_STATUS_AREA_CAPS_LOCK_DETAILED
:
145 base::UserMetricsAction("StatusArea_CapsLock_Detailed"));
147 case ash::UMA_STATUS_AREA_CAPS_LOCK_DISABLED_BY_CLICK
:
149 base::UserMetricsAction("StatusArea_CapsLock_DisabledByClick"));
151 case ash::UMA_STATUS_AREA_CAPS_LOCK_ENABLED_BY_CLICK
:
153 base::UserMetricsAction("StatusArea_CapsLock_EnabledByClick"));
155 case ash::UMA_STATUS_AREA_CAPS_LOCK_POPUP
:
157 base::UserMetricsAction("StatusArea_CapsLock_Popup"));
159 case ash::UMA_STATUS_AREA_CONNECT_TO_CONFIGURED_NETWORK
:
161 base::UserMetricsAction("StatusArea_Network_ConnectConfigured"));
163 case ash::UMA_STATUS_AREA_CONNECT_TO_UNCONFIGURED_NETWORK
:
165 base::UserMetricsAction("StatusArea_Network_ConnectUnconfigured"));
167 case ash::UMA_STATUS_AREA_CONNECT_TO_VPN
:
169 base::UserMetricsAction("StatusArea_VPN_ConnectToNetwork"));
171 case ash::UMA_STATUS_AREA_CHANGED_VOLUME_MENU
:
173 base::UserMetricsAction("StatusArea_Volume_ChangedMenu"));
175 case ash::UMA_STATUS_AREA_CHANGED_VOLUME_POPUP
:
177 base::UserMetricsAction("StatusArea_Volume_ChangedPopup"));
179 case ash::UMA_STATUS_AREA_DETAILED_ACCESSABILITY
:
181 base::UserMetricsAction("StatusArea_Accessability_DetailedView"));
183 case ash::UMA_STATUS_AREA_DETAILED_AUDIO_VIEW
:
185 base::UserMetricsAction("StatusArea_Audio_Detailed"));
187 case ash::UMA_STATUS_AREA_DETAILED_BLUETOOTH_VIEW
:
189 base::UserMetricsAction("StatusArea_Bluetooth_Detailed"));
191 case ash::UMA_STATUS_AREA_DETAILED_BRIGHTNESS_VIEW
:
193 base::UserMetricsAction("StatusArea_Brightness_Detailed"));
195 case ash::UMA_STATUS_AREA_DETAILED_DRIVE_VIEW
:
197 base::UserMetricsAction("StatusArea_Drive_Detailed"));
199 case ash::UMA_STATUS_AREA_DETAILED_NETWORK_VIEW
:
201 base::UserMetricsAction("StatusArea_Network_Detailed"));
203 case ash::UMA_STATUS_AREA_DETAILED_VPN_VIEW
:
205 base::UserMetricsAction("StatusArea_VPN_Detailed"));
207 case ash::UMA_STATUS_AREA_DISABLE_AUTO_CLICK
:
209 base::UserMetricsAction("StatusArea_AutoClickDisabled"));
211 case ash::UMA_STATUS_AREA_DISABLE_HIGH_CONTRAST
:
213 base::UserMetricsAction("StatusArea_HighContrastDisabled"));
215 case ash::UMA_STATUS_AREA_DISABLE_LARGE_CURSOR
:
217 base::UserMetricsAction("StatusArea_LargeCursorDisabled"));
219 case ash::UMA_STATUS_AREA_DISABLE_MAGNIFIER
:
221 base::UserMetricsAction("StatusArea_MagnifierDisabled"));
223 case ash::UMA_STATUS_AREA_DISABLE_SPOKEN_FEEDBACK
:
225 base::UserMetricsAction("StatusArea_SpokenFeedbackDisabled"));
227 case ash::UMA_STATUS_AREA_DISABLE_VIRTUAL_KEYBOARD
:
229 base::UserMetricsAction("StatusArea_VirtualKeyboardDisabled"));
231 case ash::UMA_STATUS_AREA_DISABLE_WIFI
:
233 base::UserMetricsAction("StatusArea_Network_WifiDisabled"));
235 case ash::UMA_STATUS_AREA_DRIVE_CANCEL_OPERATION
:
237 base::UserMetricsAction("StatusArea_Drive_CancelOperation"));
239 case ash::UMA_STATUS_AREA_DRIVE_SETTINGS
:
241 base::UserMetricsAction("StatusArea_Drive_Settings"));
243 case ash::UMA_STATUS_AREA_ENABLE_AUTO_CLICK
:
245 base::UserMetricsAction("StatusArea_AutoClickEnabled"));
247 case ash::UMA_STATUS_AREA_ENABLE_HIGH_CONTRAST
:
249 base::UserMetricsAction("StatusArea_HighContrastEnabled"));
251 case ash::UMA_STATUS_AREA_ENABLE_LARGE_CURSOR
:
253 base::UserMetricsAction("StatusArea_LargeCursorEnabled"));
255 case ash::UMA_STATUS_AREA_ENABLE_MAGNIFIER
:
257 base::UserMetricsAction("StatusArea_MagnifierEnabled"));
259 case ash::UMA_STATUS_AREA_ENABLE_SPOKEN_FEEDBACK
:
261 base::UserMetricsAction("StatusArea_SpokenFeedbackEnabled"));
263 case ash::UMA_STATUS_AREA_ENABLE_VIRTUAL_KEYBOARD
:
265 base::UserMetricsAction("StatusArea_VirtualKeyboardEnabled"));
267 case ash::UMA_STATUS_AREA_ENABLE_WIFI
:
269 base::UserMetricsAction("StatusArea_Network_WifiEnabled"));
271 case ash::UMA_STATUS_AREA_IME_SHOW_DETAILED
:
273 base::UserMetricsAction("StatusArea_IME_Detailed"));
275 case ash::UMA_STATUS_AREA_IME_SWITCH_MODE
:
277 base::UserMetricsAction("StatusArea_IME_SwitchMode"));
279 case ash::UMA_STATUS_AREA_MENU_OPENED
:
281 base::UserMetricsAction("StatusArea_MenuOpened"));
283 case ash::UMA_STATUS_AREA_NETWORK_JOIN_OTHER_CLICKED
:
285 base::UserMetricsAction("StatusArea_Network_JoinOther"));
287 case ash::UMA_STATUS_AREA_NETWORK_SETTINGS_CLICKED
:
289 base::UserMetricsAction("StatusArea_Network_Settings"));
291 case ash::UMA_STATUS_AREA_SHOW_NETWORK_CONNECTION_DETAILS
:
293 base::UserMetricsAction("StatusArea_Network_ConnectionDetails"));
295 case ash::UMA_STATUS_AREA_SHOW_VPN_CONNECTION_DETAILS
:
297 base::UserMetricsAction("StatusArea_VPN_ConnectionDetails"));
299 case ash::UMA_STATUS_AREA_SIGN_OUT
:
301 base::UserMetricsAction("StatusArea_SignOut"));
303 case ash::UMA_STATUS_AREA_VPN_JOIN_OTHER_CLICKED
:
305 base::UserMetricsAction("StatusArea_VPN_JoinOther"));
307 case ash::UMA_STATUS_AREA_VPN_SETTINGS_CLICKED
:
309 base::UserMetricsAction("StatusArea_VPN_Settings"));
311 case ash::UMA_TOGGLE_MAXIMIZE_CAPTION_CLICK
:
313 base::UserMetricsAction("Caption_ClickTogglesMaximize"));
315 case ash::UMA_TOGGLE_MAXIMIZE_CAPTION_GESTURE
:
317 base::UserMetricsAction("Caption_GestureTogglesMaximize"));
319 case ash::UMA_TOGGLE_SINGLE_AXIS_MAXIMIZE_BORDER_CLICK
:
321 base::UserMetricsAction(
322 "WindowBorder_ClickTogglesSingleAxisMaximize"));
324 case ash::UMA_TOUCHPAD_GESTURE_OVERVIEW
:
326 base::UserMetricsAction("Touchpad_Gesture_Overview"));
328 case ash::UMA_TOUCHSCREEN_TAP_DOWN
:
329 base::RecordAction(base::UserMetricsAction("Touchscreen_Down"));
331 case ash::UMA_TRAY_HELP
:
332 base::RecordAction(base::UserMetricsAction("Tray_Help"));
334 case ash::UMA_TRAY_LOCK_SCREEN
:
335 base::RecordAction(base::UserMetricsAction("Tray_LockScreen"));
337 case ash::UMA_TRAY_SHUT_DOWN
:
338 base::RecordAction(base::UserMetricsAction("Tray_ShutDown"));
340 case ash::UMA_WINDOW_APP_CLOSE_BUTTON_CLICK
:
341 base::RecordAction(base::UserMetricsAction("AppCloseButton_Clk"));
343 case ash::UMA_WINDOW_CLOSE_BUTTON_CLICK
:
344 base::RecordAction(base::UserMetricsAction("CloseButton_Clk"));
346 case ash::UMA_WINDOW_MAXIMIZE_BUTTON_CLICK_EXIT_FULLSCREEN
:
347 base::RecordAction(base::UserMetricsAction("MaxButton_Clk_ExitFS"));
349 case ash::UMA_WINDOW_MAXIMIZE_BUTTON_CLICK_RESTORE
:
351 base::UserMetricsAction("MaxButton_Clk_Restore"));
353 case ash::UMA_WINDOW_MAXIMIZE_BUTTON_CLICK_MAXIMIZE
:
355 base::UserMetricsAction("MaxButton_Clk_Maximize"));
357 case ash::UMA_WINDOW_MAXIMIZE_BUTTON_CLICK_MINIMIZE
:
358 base::RecordAction(base::UserMetricsAction("MinButton_Clk"));
360 case ash::UMA_WINDOW_MAXIMIZE_BUTTON_MAXIMIZE_LEFT
:
361 base::RecordAction(base::UserMetricsAction("MaxButton_MaxLeft"));
363 case ash::UMA_WINDOW_MAXIMIZE_BUTTON_MAXIMIZE_RIGHT
:
364 base::RecordAction(base::UserMetricsAction("MaxButton_MaxRight"));
366 case ash::UMA_WINDOW_OVERVIEW
:
368 base::UserMetricsAction("WindowSelector_Overview"));
370 case ash::UMA_WINDOW_SELECTION
:
372 base::UserMetricsAction("WindowSelector_Selection"));
377 void UserMetricsRecorder::RecordPeriodicMetrics() {
378 ShelfLayoutManager
* manager
=
379 ShelfLayoutManager::ForShelf(Shell::GetPrimaryRootWindow());
381 UMA_HISTOGRAM_ENUMERATION("Ash.ShelfAlignmentOverTime",
382 manager
->SelectValueForShelfAlignment(
383 SHELF_ALIGNMENT_UMA_ENUM_VALUE_BOTTOM
,
384 SHELF_ALIGNMENT_UMA_ENUM_VALUE_LEFT
,
385 SHELF_ALIGNMENT_UMA_ENUM_VALUE_RIGHT
,
387 SHELF_ALIGNMENT_UMA_ENUM_VALUE_COUNT
);
390 enum ActiveWindowStateType
{
391 ACTIVE_WINDOW_STATE_TYPE_NO_ACTIVE_WINDOW
,
392 ACTIVE_WINDOW_STATE_TYPE_OTHER
,
393 ACTIVE_WINDOW_STATE_TYPE_MAXIMIZED
,
394 ACTIVE_WINDOW_STATE_TYPE_FULLSCREEN
,
395 ACTIVE_WINDOW_STATE_TYPE_SNAPPED
,
396 ACTIVE_WINDOW_STATE_TYPE_COUNT
399 ActiveWindowStateType active_window_state_type
=
400 ACTIVE_WINDOW_STATE_TYPE_NO_ACTIVE_WINDOW
;
401 wm::WindowState
* active_window_state
= ash::wm::GetActiveWindowState();
402 if (active_window_state
) {
403 switch(active_window_state
->GetStateType()) {
404 case wm::WINDOW_STATE_TYPE_MAXIMIZED
:
405 active_window_state_type
= ACTIVE_WINDOW_STATE_TYPE_MAXIMIZED
;
407 case wm::WINDOW_STATE_TYPE_FULLSCREEN
:
408 active_window_state_type
= ACTIVE_WINDOW_STATE_TYPE_FULLSCREEN
;
410 case wm::WINDOW_STATE_TYPE_LEFT_SNAPPED
:
411 case wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED
:
412 active_window_state_type
= ACTIVE_WINDOW_STATE_TYPE_SNAPPED
;
414 case wm::WINDOW_STATE_TYPE_DEFAULT
:
415 case wm::WINDOW_STATE_TYPE_NORMAL
:
416 case wm::WINDOW_STATE_TYPE_MINIMIZED
:
417 case wm::WINDOW_STATE_TYPE_INACTIVE
:
418 case wm::WINDOW_STATE_TYPE_DETACHED
:
419 case wm::WINDOW_STATE_TYPE_END
:
420 case wm::WINDOW_STATE_TYPE_AUTO_POSITIONED
:
421 active_window_state_type
= ACTIVE_WINDOW_STATE_TYPE_OTHER
;
425 UMA_HISTOGRAM_ENUMERATION("Ash.ActiveWindowShowTypeOverTime",
426 active_window_state_type
,
427 ACTIVE_WINDOW_STATE_TYPE_COUNT
);