user_metrics_recorder.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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.
  4. #ifndef ASH_METRICS_USER_METRICS_RECORDER_H_
  5. #define ASH_METRICS_USER_METRICS_RECORDER_H_
  6. #include <memory>
  7. #include "ash/ash_export.h"
  8. #include "ash/metrics/login_metrics_recorder.h"
  9. #include "ash/metrics/task_switch_metrics_recorder.h"
  10. #include "base/timer/timer.h"
  11. namespace ash {
  12. class DemoSessionMetricsRecorder;
  13. class DesktopTaskSwitchMetricRecorder;
  14. enum class DictationToggleSource;
  15. class PointerMetricsRecorder;
  16. class StylusMetricsRecorder;
  17. // User Metrics Recorder provides a repeating callback (RecordPeriodicMetrics)
  18. // on a timer to allow recording of state data over time to the UMA records.
  19. // Any additional states (in ash) that require monitoring can be added to
  20. // this class.
  21. class ASH_EXPORT UserMetricsRecorder {
  22. public:
  23. // Creates a UserMetricsRecorder that records metrics periodically. Equivalent
  24. // to calling UserMetricsRecorder(true).
  25. UserMetricsRecorder();
  26. UserMetricsRecorder(const UserMetricsRecorder&) = delete;
  27. UserMetricsRecorder& operator=(const UserMetricsRecorder&) = delete;
  28. virtual ~UserMetricsRecorder();
  29. // Record user clicks on tray on lock, login screens and in OOBE.
  30. static void RecordUserClickOnTray(
  31. LoginMetricsRecorder::TrayClickTarget target);
  32. // Record user clicks on shelf buttons on lock, login screens and in OOBE.
  33. static void RecordUserClickOnShelfButton(
  34. LoginMetricsRecorder::ShelfButtonClickTarget target);
  35. // Starts recording demo session metrics. Used in Demo Mode.
  36. void StartDemoSessionMetricsRecording();
  37. TaskSwitchMetricsRecorder& task_switch_metrics_recorder() {
  38. return task_switch_metrics_recorder_;
  39. }
  40. // Informs |this| that the Shell has been initialized.
  41. void OnShellInitialized();
  42. // Informs |this| that the Shell is going to be shut down.
  43. void OnShellShuttingDown();
  44. LoginMetricsRecorder* login_metrics_recorder() {
  45. return login_metrics_recorder_.get();
  46. }
  47. private:
  48. friend class UserMetricsRecorderTestAPI;
  49. // Creates a UserMetricsRecorder and will only record periodic metrics if
  50. // |record_periodic_metrics| is true. This is used by tests that do not want
  51. // the timer to be started.
  52. // TODO(bruthig): Add a constructor that accepts a base::RepeatingTimer so
  53. // that tests can inject a test double that can be controlled by the test. The
  54. // missing piece is a suitable base::RepeatingTimer test double.
  55. explicit UserMetricsRecorder(bool record_periodic_metrics);
  56. // Records UMA metrics. Invoked periodically by the |timer_|.
  57. void RecordPeriodicMetrics();
  58. // Returns true if the user's session is active and they are in a desktop
  59. // environment.
  60. bool IsUserInActiveDesktopEnvironment() const;
  61. // Starts the |timer_| and binds it to |RecordPeriodicMetrics|.
  62. void StartTimer();
  63. // The periodic timer that triggers metrics to be recorded.
  64. base::RepeatingTimer timer_;
  65. TaskSwitchMetricsRecorder task_switch_metrics_recorder_;
  66. // Metric recorder to track how often task windows are activated by mouse
  67. // clicks or touchscreen taps.
  68. std::unique_ptr<DesktopTaskSwitchMetricRecorder>
  69. desktop_task_switch_metric_recorder_;
  70. // Metric recorder to track pointer down events.
  71. std::unique_ptr<PointerMetricsRecorder> pointer_metrics_recorder_;
  72. // Metric recorder to track stylus events.
  73. std::unique_ptr<StylusMetricsRecorder> stylus_metrics_recorder_;
  74. // Metric recorder to track login authentication activity.
  75. std::unique_ptr<LoginMetricsRecorder> login_metrics_recorder_;
  76. // Metric recorder to track app use in demo sessions.
  77. std::unique_ptr<DemoSessionMetricsRecorder> demo_session_metrics_recorder_;
  78. };
  79. } // namespace ash
  80. #endif // ASH_METRICS_USER_METRICS_RECORDER_H_