OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef ASH_USER_METRICS_RECORDER_H_ | 5 #ifndef ASH_USER_METRICS_RECORDER_H_ |
6 #define ASH_USER_METRICS_RECORDER_H_ | 6 #define ASH_USER_METRICS_RECORDER_H_ |
7 | 7 |
8 #include "ash/ash_export.h" | 8 #include "ash/ash_export.h" |
9 #include "base/timer/timer.h" | 9 #include "base/timer/timer.h" |
10 | 10 |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 UMA_WINDOW_CYCLE, | 120 UMA_WINDOW_CYCLE, |
121 }; | 121 }; |
122 | 122 |
123 // User Metrics Recorder provides a repeating callback (RecordPeriodicMetrics) | 123 // User Metrics Recorder provides a repeating callback (RecordPeriodicMetrics) |
124 // on a timer to allow recording of state data over time to the UMA records. | 124 // on a timer to allow recording of state data over time to the UMA records. |
125 // Any additional states (in ash) that require monitoring can be added to | 125 // Any additional states (in ash) that require monitoring can be added to |
126 // this class. As well calls to record on action metrics | 126 // this class. As well calls to record on action metrics |
127 // (RecordUserMetricsAction) are passed through the UserMetricsRecorder. | 127 // (RecordUserMetricsAction) are passed through the UserMetricsRecorder. |
128 class ASH_EXPORT UserMetricsRecorder { | 128 class ASH_EXPORT UserMetricsRecorder { |
129 public: | 129 public: |
| 130 // Creates a UserMetricsRecorder that will automatically start the repeating |
| 131 // timer. Equivalent to calling UserMetricsRecorder(true). |
130 UserMetricsRecorder(); | 132 UserMetricsRecorder(); |
131 ~UserMetricsRecorder(); | |
132 | 133 |
| 134 // Creates a UserMetricsRecorder and will only start the repeating timer if |
| 135 // |record_periodic_metrics| is true. This is useful for tests that do not |
| 136 // want the timer to be started. |
| 137 // TODO(bruthig): Add a constructor that accepts a base::RepeatingTimer so |
| 138 // that tests can inject a test double that can be controlled by the test. The |
| 139 // missing piece is a suitable base::RepeatingTimer test double. |
| 140 explicit UserMetricsRecorder(bool record_periodic_metrics); |
| 141 |
| 142 virtual ~UserMetricsRecorder(); |
| 143 |
| 144 // Records an Ash owned user action. |
133 void RecordUserMetricsAction(ash::UserMetricsAction action); | 145 void RecordUserMetricsAction(ash::UserMetricsAction action); |
134 private: | 146 |
| 147 protected: |
| 148 // Records UMA metrics. Is invoked periodically by the |timer_|. |
135 void RecordPeriodicMetrics(); | 149 void RecordPeriodicMetrics(); |
136 | 150 |
| 151 // Returns true if there is an active user and their session isn't currently |
| 152 // locked. |
| 153 bool UserIsActive(); |
| 154 |
| 155 private: |
| 156 // Starts the |timer_| and binds it to |RecordPeriodicMetrics|. |
| 157 void StartTimer(); |
| 158 |
| 159 // The periodic timer that triggers metrics to be recorded. |
137 base::RepeatingTimer<UserMetricsRecorder> timer_; | 160 base::RepeatingTimer<UserMetricsRecorder> timer_; |
| 161 |
| 162 DISALLOW_COPY_AND_ASSIGN(UserMetricsRecorder); |
138 }; | 163 }; |
139 | 164 |
140 } // namespace ash | 165 } // namespace ash |
141 | 166 |
142 #endif // ASH_USER_METRICS_RECORDER_H_ | 167 #endif // ASH_USER_METRICS_RECORDER_H_ |
OLD | NEW |