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 #ifndef ASH_METRICS_USER_METRICS_RECORDER_H_
6 #define ASH_METRICS_USER_METRICS_RECORDER_H_
8 #include "ash/ash_export.h"
9 #include "ash/metrics/task_switch_metrics_recorder.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/timer/timer.h"
15 class DesktopTaskSwitchMetricRecorder
;
18 class UserMetricsRecorderTestAPI
;
21 enum UserMetricsAction
{
22 UMA_ACCEL_EXIT_FIRST_Q
,
23 UMA_ACCEL_EXIT_SECOND_Q
,
24 UMA_ACCEL_KEYBOARD_BRIGHTNESS_DOWN_F6
,
25 UMA_ACCEL_KEYBOARD_BRIGHTNESS_UP_F7
,
26 UMA_ACCEL_LOCK_SCREEN_LOCK_BUTTON
,
27 UMA_ACCEL_LOCK_SCREEN_POWER_BUTTON
,
28 UMA_ACCEL_MAXIMIZE_RESTORE_F4
,
29 UMA_ACCEL_PREVWINDOW_F5
,
30 UMA_ACCEL_RESTART_POWER_BUTTON
,
31 UMA_ACCEL_SHUT_DOWN_POWER_BUTTON
,
32 UMA_CLOSE_THROUGH_CONTEXT_MENU
,
33 UMA_DESKTOP_SWITCH_TASK
,
34 UMA_DRAG_MAXIMIZE_LEFT
,
35 UMA_DRAG_MAXIMIZE_RIGHT
,
36 UMA_LAUNCHER_BUTTON_PRESSED_WITH_MOUSE
,
37 UMA_LAUNCHER_BUTTON_PRESSED_WITH_TOUCH
,
38 UMA_LAUNCHER_CLICK_ON_APP
,
39 UMA_LAUNCHER_CLICK_ON_APPLIST_BUTTON
,
40 UMA_LAUNCHER_LAUNCH_TASK
,
41 UMA_LAUNCHER_MINIMIZE_TASK
,
42 UMA_LAUNCHER_SWITCH_TASK
,
43 UMA_MAXIMIZE_MODE_DISABLED
,
44 UMA_MAXIMIZE_MODE_ENABLED
,
45 UMA_MAXIMIZE_MODE_INITIALLY_DISABLED
,
47 UMA_PANEL_MINIMIZE_CAPTION_CLICK
,
48 UMA_PANEL_MINIMIZE_CAPTION_GESTURE
,
49 UMA_SHELF_ALIGNMENT_SET_BOTTOM
,
50 UMA_SHELF_ALIGNMENT_SET_LEFT
,
51 UMA_SHELF_ALIGNMENT_SET_RIGHT
,
52 UMA_STATUS_AREA_AUDIO_CURRENT_INPUT_DEVICE
,
53 UMA_STATUS_AREA_AUDIO_CURRENT_OUTPUT_DEVICE
,
54 UMA_STATUS_AREA_AUDIO_SWITCH_INPUT_DEVICE
,
55 UMA_STATUS_AREA_AUDIO_SWITCH_OUTPUT_DEVICE
,
56 UMA_STATUS_AREA_BRIGHTNESS_CHANGED
,
57 UMA_STATUS_AREA_BLUETOOTH_CONNECT_KNOWN_DEVICE
,
58 UMA_STATUS_AREA_BLUETOOTH_CONNECT_UNKNOWN_DEVICE
,
59 UMA_STATUS_AREA_BLUETOOTH_DISABLED
,
60 UMA_STATUS_AREA_BLUETOOTH_ENABLED
,
61 UMA_STATUS_AREA_CAPS_LOCK_DETAILED
,
62 UMA_STATUS_AREA_CAPS_LOCK_DISABLED_BY_CLICK
,
63 UMA_STATUS_AREA_CAPS_LOCK_ENABLED_BY_CLICK
,
64 UMA_STATUS_AREA_CAPS_LOCK_POPUP
,
65 UMA_STATUS_AREA_CAST_STOP_CAST
,
66 UMA_STATUS_AREA_CONNECT_TO_CONFIGURED_NETWORK
,
67 UMA_STATUS_AREA_CONNECT_TO_UNCONFIGURED_NETWORK
,
68 UMA_STATUS_AREA_CONNECT_TO_VPN
,
69 UMA_STATUS_AREA_CHANGED_VOLUME_MENU
,
70 UMA_STATUS_AREA_CHANGED_VOLUME_POPUP
,
71 UMA_STATUS_AREA_DETAILED_ACCESSABILITY
,
72 UMA_STATUS_AREA_DETAILED_AUDIO_VIEW
,
73 UMA_STATUS_AREA_DETAILED_BLUETOOTH_VIEW
,
74 UMA_STATUS_AREA_DETAILED_BRIGHTNESS_VIEW
,
75 UMA_STATUS_AREA_DETAILED_CAST_VIEW
,
76 UMA_STATUS_AREA_DETAILED_CAST_VIEW_LAUNCH_CAST
,
77 UMA_STATUS_AREA_DETAILED_DRIVE_VIEW
,
78 UMA_STATUS_AREA_DETAILED_NETWORK_VIEW
,
79 UMA_STATUS_AREA_DETAILED_VPN_VIEW
,
80 UMA_STATUS_AREA_DISABLE_AUTO_CLICK
,
81 UMA_STATUS_AREA_DISABLE_HIGH_CONTRAST
,
82 UMA_STATUS_AREA_DISABLE_LARGE_CURSOR
,
83 UMA_STATUS_AREA_DISABLE_MAGNIFIER
,
84 UMA_STATUS_AREA_DISABLE_SPOKEN_FEEDBACK
,
85 UMA_STATUS_AREA_DISABLE_WIFI
,
86 UMA_STATUS_AREA_DISABLE_VIRTUAL_KEYBOARD
,
87 UMA_STATUS_AREA_DRIVE_CANCEL_OPERATION
,
88 UMA_STATUS_AREA_DRIVE_SETTINGS
,
89 UMA_STATUS_AREA_ENABLE_AUTO_CLICK
,
90 UMA_STATUS_AREA_ENABLE_HIGH_CONTRAST
,
91 UMA_STATUS_AREA_ENABLE_LARGE_CURSOR
,
92 UMA_STATUS_AREA_ENABLE_MAGNIFIER
,
93 UMA_STATUS_AREA_ENABLE_SPOKEN_FEEDBACK
,
94 UMA_STATUS_AREA_ENABLE_WIFI
,
95 UMA_STATUS_AREA_ENABLE_VIRTUAL_KEYBOARD
,
96 UMA_STATUS_AREA_IME_SHOW_DETAILED
,
97 UMA_STATUS_AREA_IME_SWITCH_MODE
,
98 UMA_STATUS_AREA_MENU_OPENED
,
99 UMA_STATUS_AREA_NETWORK_JOIN_OTHER_CLICKED
,
100 UMA_STATUS_AREA_NETWORK_SETTINGS_CLICKED
,
101 UMA_STATUS_AREA_SHOW_NETWORK_CONNECTION_DETAILS
,
102 UMA_STATUS_AREA_SHOW_VPN_CONNECTION_DETAILS
,
103 UMA_STATUS_AREA_SIGN_OUT
,
104 UMA_STATUS_AREA_VPN_ADD_BUILT_IN_CLICKED
,
105 UMA_STATUS_AREA_VPN_ADD_THIRD_PARTY_CLICKED
,
106 UMA_STATUS_AREA_VPN_DISCONNECT_CLICKED
,
107 UMA_STATUS_AREA_VPN_SETTINGS_CLICKED
,
108 UMA_TOGGLE_MAXIMIZE_CAPTION_CLICK
,
109 UMA_TOGGLE_MAXIMIZE_CAPTION_GESTURE
,
110 UMA_TOGGLE_SINGLE_AXIS_MAXIMIZE_BORDER_CLICK
,
111 UMA_TOUCHPAD_GESTURE_OVERVIEW
,
112 UMA_TOUCHSCREEN_TAP_DOWN
,
114 UMA_TRAY_LOCK_SCREEN
,
117 UMA_WINDOW_APP_CLOSE_BUTTON_CLICK
,
118 UMA_WINDOW_CLOSE_BUTTON_CLICK
,
119 UMA_WINDOW_MAXIMIZE_BUTTON_CLICK_EXIT_FULLSCREEN
,
120 UMA_WINDOW_MAXIMIZE_BUTTON_CLICK_MAXIMIZE
,
121 UMA_WINDOW_MAXIMIZE_BUTTON_CLICK_MINIMIZE
,
122 UMA_WINDOW_MAXIMIZE_BUTTON_CLICK_RESTORE
,
123 UMA_WINDOW_MAXIMIZE_BUTTON_MAXIMIZE_LEFT
,
124 UMA_WINDOW_MAXIMIZE_BUTTON_MAXIMIZE_RIGHT
,
126 // Thumbnail sized overview of windows triggered by pressing the overview key.
129 // User selected a window in overview mode different from the
130 // previously-active window.
131 UMA_WINDOW_OVERVIEW_ACTIVE_WINDOW_CHANGED
,
133 // Selecting a window in overview mode by pressing the enter key.
134 UMA_WINDOW_OVERVIEW_ENTER_KEY
,
136 // Window selection started by beginning an alt+tab cycle. This does not count
137 // each step through an alt+tab cycle.
141 // User Metrics Recorder provides a repeating callback (RecordPeriodicMetrics)
142 // on a timer to allow recording of state data over time to the UMA records.
143 // Any additional states (in ash) that require monitoring can be added to
144 // this class. As well calls to record on action metrics
145 // (RecordUserMetricsAction) are passed through the UserMetricsRecorder.
146 class ASH_EXPORT UserMetricsRecorder
{
148 // Creates a UserMetricsRecorder that records metrics periodically. Equivalent
149 // to calling UserMetricsRecorder(true).
150 UserMetricsRecorder();
152 virtual ~UserMetricsRecorder();
154 // Records an Ash owned user action.
155 void RecordUserMetricsAction(ash::UserMetricsAction action
);
157 TaskSwitchMetricsRecorder
& task_switch_metrics_recorder() {
158 return task_switch_metrics_recorder_
;
161 // Informs |this| that the Shell has been initialized.
162 void OnShellInitialized();
164 // Informs |this| that the Shell is going to be shut down.
165 void OnShellShuttingDown();
168 friend class test::UserMetricsRecorderTestAPI
;
170 // Creates a UserMetricsRecorder and will only record periodic metrics if
171 // |record_periodic_metrics| is true. This is used by tests that do not want
172 // the timer to be started.
173 // TODO(bruthig): Add a constructor that accepts a base::RepeatingTimer so
174 // that tests can inject a test double that can be controlled by the test. The
175 // missing piece is a suitable base::RepeatingTimer test double.
176 explicit UserMetricsRecorder(bool record_periodic_metrics
);
178 // Records UMA metrics. Invoked periodically by the |timer_|.
179 void RecordPeriodicMetrics();
181 // Returns true if the user's session is active and they are in a desktop
183 bool IsUserInActiveDesktopEnvironment() const;
185 // Starts the |timer_| and binds it to |RecordPeriodicMetrics|.
188 // The periodic timer that triggers metrics to be recorded.
189 base::RepeatingTimer
<UserMetricsRecorder
> timer_
;
191 TaskSwitchMetricsRecorder task_switch_metrics_recorder_
;
193 // Metric recorder to track how often task windows are activated by mouse
194 // clicks or touchscreen taps.
195 scoped_ptr
<DesktopTaskSwitchMetricRecorder
>
196 desktop_task_switch_metric_recorder_
;
198 DISALLOW_COPY_AND_ASSIGN(UserMetricsRecorder
);
203 #endif // ASH_METRICS_USER_METRICS_RECORDER_H_