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