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