Blink roll 174125:174137
[chromium-blink-merge.git] / ash / metrics / user_metrics_recorder.cc
bloba44cc788504cfea753c5127e212370c7635a2a63
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"
15 namespace ash {
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),
23 this,
24 &UserMetricsRecorder::RecordPeriodicMetrics);
27 UserMetricsRecorder::~UserMetricsRecorder() {
28 timer_.Stop();
31 void UserMetricsRecorder::RecordUserMetricsAction(UserMetricsAction action) {
32 switch (action) {
33 case ash::UMA_ACCEL_KEYBOARD_BRIGHTNESS_DOWN_F6:
34 base::RecordAction(
35 base::UserMetricsAction("Accel_KeyboardBrightnessDown_F6"));
36 break;
37 case ash::UMA_ACCEL_KEYBOARD_BRIGHTNESS_UP_F7:
38 base::RecordAction(
39 base::UserMetricsAction("Accel_KeyboardBrightnessUp_F7"));
40 break;
41 case ash::UMA_ACCEL_LOCK_SCREEN_LOCK_BUTTON:
42 base::RecordAction(
43 base::UserMetricsAction("Accel_LockScreen_LockButton"));
44 break;
45 case ash::UMA_ACCEL_LOCK_SCREEN_POWER_BUTTON:
46 base::RecordAction(
47 base::UserMetricsAction("Accel_LockScreen_PowerButton"));
48 break;
49 case ash::UMA_ACCEL_MAXIMIZE_RESTORE_F4:
50 base::RecordAction(
51 base::UserMetricsAction("Accel_Maximize_Restore_F4"));
52 break;
53 case ash::UMA_ACCEL_PREVWINDOW_F5:
54 base::RecordAction(base::UserMetricsAction("Accel_PrevWindow_F5"));
55 break;
56 case ash::UMA_ACCEL_EXIT_FIRST_Q:
57 base::RecordAction(base::UserMetricsAction("Accel_Exit_First_Q"));
58 break;
59 case ash::UMA_ACCEL_EXIT_SECOND_Q:
60 base::RecordAction(base::UserMetricsAction("Accel_Exit_Second_Q"));
61 break;
62 case ash::UMA_ACCEL_SHUT_DOWN_POWER_BUTTON:
63 base::RecordAction(
64 base::UserMetricsAction("Accel_ShutDown_PowerButton"));
65 break;
66 case ash::UMA_CLOSE_THROUGH_CONTEXT_MENU:
67 base::RecordAction(base::UserMetricsAction("CloseFromContextMenu"));
68 break;
69 case ash::UMA_DRAG_MAXIMIZE_LEFT:
70 base::RecordAction(base::UserMetricsAction("WindowDrag_MaximizeLeft"));
71 break;
72 case ash::UMA_DRAG_MAXIMIZE_RIGHT:
73 base::RecordAction(base::UserMetricsAction("WindowDrag_MaximizeRight"));
74 break;
75 case ash::UMA_GESTURE_OVERVIEW:
76 base::RecordAction(base::UserMetricsAction("Gesture_Overview"));
77 break;
78 case ash::UMA_LAUNCHER_CLICK_ON_APP:
79 base::RecordAction(base::UserMetricsAction("Launcher_ClickOnApp"));
80 break;
81 case ash::UMA_LAUNCHER_CLICK_ON_APPLIST_BUTTON:
82 base::RecordAction(
83 base::UserMetricsAction("Launcher_ClickOnApplistButton"));
84 break;
85 case ash::UMA_MOUSE_DOWN:
86 base::RecordAction(base::UserMetricsAction("Mouse_Down"));
87 break;
88 case ash::UMA_PANEL_MINIMIZE_CAPTION_CLICK:
89 base::RecordAction(
90 base::UserMetricsAction("Panel_Minimize_Caption_Click"));
91 break;
92 case ash::UMA_PANEL_MINIMIZE_CAPTION_GESTURE:
93 base::RecordAction(
94 base::UserMetricsAction("Panel_Minimize_Caption_Gesture"));
95 break;
96 case ash::UMA_SHELF_ALIGNMENT_SET_BOTTOM:
97 base::RecordAction(
98 base::UserMetricsAction("Shelf_AlignmentSetBottom"));
99 break;
100 case ash::UMA_SHELF_ALIGNMENT_SET_LEFT:
101 base::RecordAction(
102 base::UserMetricsAction("Shelf_AlignmentSetLeft"));
103 break;
104 case ash::UMA_SHELF_ALIGNMENT_SET_RIGHT:
105 base::RecordAction(
106 base::UserMetricsAction("Shelf_AlignmentSetRight"));
107 case ash::UMA_STATUS_AREA_AUDIO_CURRENT_INPUT_DEVICE:
108 base::RecordAction(
109 base::UserMetricsAction("StatusArea_Audio_CurrentInputDevice"));
110 break;
111 case ash::UMA_STATUS_AREA_AUDIO_CURRENT_OUTPUT_DEVICE:
112 base::RecordAction(
113 base::UserMetricsAction("StatusArea_Audio_CurrentOutputDevice"));
114 break;
115 case ash::UMA_STATUS_AREA_AUDIO_SWITCH_INPUT_DEVICE:
116 base::RecordAction(
117 base::UserMetricsAction("StatusArea_Audio_SwitchInputDevice"));
118 break;
119 case ash::UMA_STATUS_AREA_AUDIO_SWITCH_OUTPUT_DEVICE:
120 base::RecordAction(
121 base::UserMetricsAction("StatusArea_Audio_SwitchOutputDevice"));
122 break;
123 case ash::UMA_STATUS_AREA_BRIGHTNESS_CHANGED:
124 base::RecordAction(
125 base::UserMetricsAction("StatusArea_BrightnessChanged"));
126 break;
127 case ash::UMA_STATUS_AREA_BLUETOOTH_CONNECT_KNOWN_DEVICE:
128 base::RecordAction(
129 base::UserMetricsAction("StatusArea_Bluetooth_Connect_Known"));
130 break;
131 case ash::UMA_STATUS_AREA_BLUETOOTH_CONNECT_UNKNOWN_DEVICE:
132 base::RecordAction(
133 base::UserMetricsAction("StatusArea_Bluetooth_Connect_Unknown"));
134 break;
135 case ash::UMA_STATUS_AREA_BLUETOOTH_DISABLED:
136 base::RecordAction(
137 base::UserMetricsAction("StatusArea_Bluetooth_Disabled"));
138 break;
139 case ash::UMA_STATUS_AREA_BLUETOOTH_ENABLED:
140 base::RecordAction(
141 base::UserMetricsAction("StatusArea_Bluetooth_Enabled"));
142 break;
143 case ash::UMA_STATUS_AREA_CAPS_LOCK_DETAILED:
144 base::RecordAction(
145 base::UserMetricsAction("StatusArea_CapsLock_Detailed"));
146 break;
147 case ash::UMA_STATUS_AREA_CAPS_LOCK_DISABLED_BY_CLICK:
148 base::RecordAction(
149 base::UserMetricsAction("StatusArea_CapsLock_DisabledByClick"));
150 break;
151 case ash::UMA_STATUS_AREA_CAPS_LOCK_ENABLED_BY_CLICK:
152 base::RecordAction(
153 base::UserMetricsAction("StatusArea_CapsLock_EnabledByClick"));
154 break;
155 case ash::UMA_STATUS_AREA_CAPS_LOCK_POPUP:
156 base::RecordAction(
157 base::UserMetricsAction("StatusArea_CapsLock_Popup"));
158 break;
159 case ash::UMA_STATUS_AREA_CONNECT_TO_CONFIGURED_NETWORK:
160 base::RecordAction(
161 base::UserMetricsAction("StatusArea_Network_ConnectConfigured"));
162 break;
163 case ash::UMA_STATUS_AREA_CONNECT_TO_UNCONFIGURED_NETWORK:
164 base::RecordAction(
165 base::UserMetricsAction("StatusArea_Network_ConnectUnconfigured"));
166 break;
167 case ash::UMA_STATUS_AREA_CONNECT_TO_VPN:
168 base::RecordAction(
169 base::UserMetricsAction("StatusArea_VPN_ConnectToNetwork"));
170 break;
171 case ash::UMA_STATUS_AREA_CHANGED_VOLUME_MENU:
172 base::RecordAction(
173 base::UserMetricsAction("StatusArea_Volume_ChangedMenu"));
174 break;
175 case ash::UMA_STATUS_AREA_CHANGED_VOLUME_POPUP:
176 base::RecordAction(
177 base::UserMetricsAction("StatusArea_Volume_ChangedPopup"));
178 break;
179 case ash::UMA_STATUS_AREA_DETAILED_ACCESSABILITY:
180 base::RecordAction(
181 base::UserMetricsAction("StatusArea_Accessability_DetailedView"));
182 break;
183 case ash::UMA_STATUS_AREA_DETAILED_AUDIO_VIEW:
184 base::RecordAction(
185 base::UserMetricsAction("StatusArea_Audio_Detailed"));
186 break;
187 case ash::UMA_STATUS_AREA_DETAILED_BLUETOOTH_VIEW:
188 base::RecordAction(
189 base::UserMetricsAction("StatusArea_Bluetooth_Detailed"));
190 break;
191 case ash::UMA_STATUS_AREA_DETAILED_BRIGHTNESS_VIEW:
192 base::RecordAction(
193 base::UserMetricsAction("StatusArea_Brightness_Detailed"));
194 break;
195 case ash::UMA_STATUS_AREA_DETAILED_DRIVE_VIEW:
196 base::RecordAction(
197 base::UserMetricsAction("StatusArea_Drive_Detailed"));
198 break;
199 case ash::UMA_STATUS_AREA_DETAILED_NETWORK_VIEW:
200 base::RecordAction(
201 base::UserMetricsAction("StatusArea_Network_Detailed"));
202 break;
203 case ash::UMA_STATUS_AREA_DETAILED_VPN_VIEW:
204 base::RecordAction(
205 base::UserMetricsAction("StatusArea_VPN_Detailed"));
206 break;
207 case ash::UMA_STATUS_AREA_DISABLE_AUTO_CLICK:
208 base::RecordAction(
209 base::UserMetricsAction("StatusArea_AutoClickDisabled"));
210 break;
211 case ash::UMA_STATUS_AREA_DISABLE_HIGH_CONTRAST:
212 base::RecordAction(
213 base::UserMetricsAction("StatusArea_HighContrastDisabled"));
214 break;
215 case ash::UMA_STATUS_AREA_DISABLE_LARGE_CURSOR:
216 base::RecordAction(
217 base::UserMetricsAction("StatusArea_LargeCursorDisabled"));
218 break;
219 case ash::UMA_STATUS_AREA_DISABLE_MAGNIFIER:
220 base::RecordAction(
221 base::UserMetricsAction("StatusArea_MagnifierDisabled"));
222 break;
223 case ash::UMA_STATUS_AREA_DISABLE_SPOKEN_FEEDBACK:
224 base::RecordAction(
225 base::UserMetricsAction("StatusArea_SpokenFeedbackDisabled"));
226 break;
227 case ash::UMA_STATUS_AREA_DISABLE_VIRTUAL_KEYBOARD:
228 base::RecordAction(
229 base::UserMetricsAction("StatusArea_VirtualKeyboardDisabled"));
230 break;
231 case ash::UMA_STATUS_AREA_DISABLE_WIFI:
232 base::RecordAction(
233 base::UserMetricsAction("StatusArea_Network_WifiDisabled"));
234 break;
235 case ash::UMA_STATUS_AREA_DRIVE_CANCEL_OPERATION:
236 base::RecordAction(
237 base::UserMetricsAction("StatusArea_Drive_CancelOperation"));
238 break;
239 case ash::UMA_STATUS_AREA_DRIVE_SETTINGS:
240 base::RecordAction(
241 base::UserMetricsAction("StatusArea_Drive_Settings"));
242 break;
243 case ash::UMA_STATUS_AREA_ENABLE_AUTO_CLICK:
244 base::RecordAction(
245 base::UserMetricsAction("StatusArea_AutoClickEnabled"));
246 break;
247 case ash::UMA_STATUS_AREA_ENABLE_HIGH_CONTRAST:
248 base::RecordAction(
249 base::UserMetricsAction("StatusArea_HighContrastEnabled"));
250 break;
251 case ash::UMA_STATUS_AREA_ENABLE_LARGE_CURSOR:
252 base::RecordAction(
253 base::UserMetricsAction("StatusArea_LargeCursorEnabled"));
254 break;
255 case ash::UMA_STATUS_AREA_ENABLE_MAGNIFIER:
256 base::RecordAction(
257 base::UserMetricsAction("StatusArea_MagnifierEnabled"));
258 break;
259 case ash::UMA_STATUS_AREA_ENABLE_SPOKEN_FEEDBACK:
260 base::RecordAction(
261 base::UserMetricsAction("StatusArea_SpokenFeedbackEnabled"));
262 break;
263 case ash::UMA_STATUS_AREA_ENABLE_VIRTUAL_KEYBOARD:
264 base::RecordAction(
265 base::UserMetricsAction("StatusArea_VirtualKeyboardEnabled"));
266 break;
267 case ash::UMA_STATUS_AREA_ENABLE_WIFI:
268 base::RecordAction(
269 base::UserMetricsAction("StatusArea_Network_WifiEnabled"));
270 break;
271 case ash::UMA_STATUS_AREA_IME_SHOW_DETAILED:
272 base::RecordAction(
273 base::UserMetricsAction("StatusArea_IME_Detailed"));
274 break;
275 case ash::UMA_STATUS_AREA_IME_SWITCH_MODE:
276 base::RecordAction(
277 base::UserMetricsAction("StatusArea_IME_SwitchMode"));
278 break;
279 case ash::UMA_STATUS_AREA_MENU_OPENED:
280 base::RecordAction(
281 base::UserMetricsAction("StatusArea_MenuOpened"));
282 break;
283 case ash::UMA_STATUS_AREA_NETWORK_JOIN_OTHER_CLICKED:
284 base::RecordAction(
285 base::UserMetricsAction("StatusArea_Network_JoinOther"));
286 break;
287 case ash::UMA_STATUS_AREA_NETWORK_SETTINGS_CLICKED:
288 base::RecordAction(
289 base::UserMetricsAction("StatusArea_Network_Settings"));
290 break;
291 case ash::UMA_STATUS_AREA_SHOW_NETWORK_CONNECTION_DETAILS:
292 base::RecordAction(
293 base::UserMetricsAction("StatusArea_Network_ConnectionDetails"));
294 break;
295 case ash::UMA_STATUS_AREA_SHOW_VPN_CONNECTION_DETAILS:
296 base::RecordAction(
297 base::UserMetricsAction("StatusArea_VPN_ConnectionDetails"));
298 break;
299 case ash::UMA_STATUS_AREA_SIGN_OUT:
300 base::RecordAction(
301 base::UserMetricsAction("StatusArea_SignOut"));
302 break;
303 case ash::UMA_STATUS_AREA_VPN_JOIN_OTHER_CLICKED:
304 base::RecordAction(
305 base::UserMetricsAction("StatusArea_VPN_JoinOther"));
306 break;
307 case ash::UMA_STATUS_AREA_VPN_SETTINGS_CLICKED:
308 base::RecordAction(
309 base::UserMetricsAction("StatusArea_VPN_Settings"));
310 break;
311 case ash::UMA_TOGGLE_MAXIMIZE_CAPTION_CLICK:
312 base::RecordAction(
313 base::UserMetricsAction("Caption_ClickTogglesMaximize"));
314 break;
315 case ash::UMA_TOGGLE_MAXIMIZE_CAPTION_GESTURE:
316 base::RecordAction(
317 base::UserMetricsAction("Caption_GestureTogglesMaximize"));
318 break;
319 case ash::UMA_TOGGLE_SINGLE_AXIS_MAXIMIZE_BORDER_CLICK:
320 base::RecordAction(
321 base::UserMetricsAction(
322 "WindowBorder_ClickTogglesSingleAxisMaximize"));
323 break;
324 case ash::UMA_TOUCHPAD_GESTURE_OVERVIEW:
325 base::RecordAction(
326 base::UserMetricsAction("Touchpad_Gesture_Overview"));
327 break;
328 case ash::UMA_TOUCHSCREEN_TAP_DOWN:
329 base::RecordAction(base::UserMetricsAction("Touchscreen_Down"));
330 break;
331 case ash::UMA_TRAY_HELP:
332 base::RecordAction(base::UserMetricsAction("Tray_Help"));
333 break;
334 case ash::UMA_TRAY_LOCK_SCREEN:
335 base::RecordAction(base::UserMetricsAction("Tray_LockScreen"));
336 break;
337 case ash::UMA_TRAY_SHUT_DOWN:
338 base::RecordAction(base::UserMetricsAction("Tray_ShutDown"));
339 break;
340 case ash::UMA_WINDOW_APP_CLOSE_BUTTON_CLICK:
341 base::RecordAction(base::UserMetricsAction("AppCloseButton_Clk"));
342 break;
343 case ash::UMA_WINDOW_CLOSE_BUTTON_CLICK:
344 base::RecordAction(base::UserMetricsAction("CloseButton_Clk"));
345 break;
346 case ash::UMA_WINDOW_MAXIMIZE_BUTTON_CLICK_EXIT_FULLSCREEN:
347 base::RecordAction(base::UserMetricsAction("MaxButton_Clk_ExitFS"));
348 break;
349 case ash::UMA_WINDOW_MAXIMIZE_BUTTON_CLICK_RESTORE:
350 base::RecordAction(
351 base::UserMetricsAction("MaxButton_Clk_Restore"));
352 break;
353 case ash::UMA_WINDOW_MAXIMIZE_BUTTON_CLICK_MAXIMIZE:
354 base::RecordAction(
355 base::UserMetricsAction("MaxButton_Clk_Maximize"));
356 break;
357 case ash::UMA_WINDOW_MAXIMIZE_BUTTON_CLICK_MINIMIZE:
358 base::RecordAction(base::UserMetricsAction("MinButton_Clk"));
359 break;
360 case ash::UMA_WINDOW_MAXIMIZE_BUTTON_MAXIMIZE_LEFT:
361 base::RecordAction(base::UserMetricsAction("MaxButton_MaxLeft"));
362 break;
363 case ash::UMA_WINDOW_MAXIMIZE_BUTTON_MAXIMIZE_RIGHT:
364 base::RecordAction(base::UserMetricsAction("MaxButton_MaxRight"));
365 break;
366 case ash::UMA_WINDOW_OVERVIEW:
367 base::RecordAction(
368 base::UserMetricsAction("WindowSelector_Overview"));
369 break;
370 case ash::UMA_WINDOW_SELECTION:
371 base::RecordAction(
372 base::UserMetricsAction("WindowSelector_Selection"));
373 break;
377 void UserMetricsRecorder::RecordPeriodicMetrics() {
378 ShelfLayoutManager* manager =
379 ShelfLayoutManager::ForShelf(Shell::GetPrimaryRootWindow());
380 if (manager) {
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,
386 -1),
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;
406 break;
407 case wm::WINDOW_STATE_TYPE_FULLSCREEN:
408 active_window_state_type = ACTIVE_WINDOW_STATE_TYPE_FULLSCREEN;
409 break;
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;
413 break;
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;
422 break;
425 UMA_HISTOGRAM_ENUMERATION("Ash.ActiveWindowShowTypeOverTime",
426 active_window_state_type,
427 ACTIVE_WINDOW_STATE_TYPE_COUNT);
430 } // namespace ash