OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_METRICS_TASK_SWITCH_METRIC_RECORDER_H_ | 5 #ifndef ASH_METRICS_TASK_SWITCH_METRIC_RECORDER_H_ |
6 #define ASH_METRICS_TASK_SWITCH_METRIC_RECORDER_H_ | 6 #define ASH_METRICS_TASK_SWITCH_METRIC_RECORDER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "ash/ash_export.h" | 10 #include "ash/ash_export.h" |
11 #include "base/containers/scoped_ptr_hash_map.h" | 11 #include "base/containers/scoped_ptr_hash_map.h" |
12 | 12 |
13 namespace ash { | 13 namespace ash { |
14 | 14 |
15 class TaskSwitchTimeTracker; | 15 class TaskSwitchTimeTracker; |
16 | 16 |
17 // The TaskSwitchMetricsRecorder class records UMA metrics related to task | 17 // The TaskSwitchMetricsRecorder class records UMA metrics related to task |
18 // switching. The main purpose of the TaskSwitchMetricsRecorder is to track time | 18 // switching. The main purpose of the TaskSwitchMetricsRecorder is to track time |
19 // deltas between task switches and record histograms of the deltas. | 19 // deltas between task switches and record histograms of the deltas. |
20 class ASH_EXPORT TaskSwitchMetricsRecorder { | 20 class ASH_EXPORT TaskSwitchMetricsRecorder { |
21 public: | 21 public: |
22 // Enumeration of the different user interfaces that could be the source of | 22 // Enumeration of the different user interfaces that could be the source of |
23 // a task switch. Note this is not necessarily comprehensive of all sources. | 23 // a task switch. Note this is not necessarily comprehensive of all sources. |
24 enum TaskSwitchSource { | 24 enum TaskSwitchSource { |
25 // Task switches between any two other sources. NOTE: This value should NOT | |
tdanderson
2015/06/02 15:56:12
nit: suggested reword: "Task switches caused by an
bruthig
2015/06/04 18:54:25
Done.
| |
26 // be used outside of this class. | |
27 kAny, | |
25 // Task switches from selecting items in the app list. | 28 // Task switches from selecting items in the app list. |
26 kAppList, | 29 kAppList, |
27 // Task switches caused by selecting a window from overview mode which is | 30 // Task switches caused by selecting a window from overview mode which is |
28 // different from the previously-active window. | 31 // different from the previously-active window. |
29 kOverviewMode, | 32 kOverviewMode, |
30 // All task switches caused by shelf buttons, not including sub-menus. | 33 // All task switches caused by shelf buttons, not including sub-menus. |
31 kShelf, | 34 kShelf, |
32 // All task switches caused by the tab strip. | 35 // All task switches caused by the tab strip. |
33 kTabStrip, | 36 kTabStrip, |
34 // Task switches caused by the WindowCycleController (ie Alt+Tab). | 37 // Task switches caused by the WindowCycleController (ie Alt+Tab). |
35 kWindowCycleController | 38 kWindowCycleController |
36 }; | 39 }; |
37 | 40 |
38 TaskSwitchMetricsRecorder(); | 41 TaskSwitchMetricsRecorder(); |
39 virtual ~TaskSwitchMetricsRecorder(); | 42 virtual ~TaskSwitchMetricsRecorder(); |
40 | 43 |
41 // Notifies |this| that a "navigate to" task switch has occurred. A | 44 // Notifies |this| that a "navigate to" task switch has occurred. A |
42 // "navigate to" operation is defined by a task switch where the specific task | 45 // "navigate to" operation is defined by a task switch where the specific task |
43 // that becomes active is user-predictable (ie Alt+Tab accelerator, launching | 46 // that becomes active is user-predictable (ie Alt+Tab accelerator, launching |
44 // a new window via the shelf, etc). Contrast to a "navigate away" operation | 47 // a new window via the shelf, etc). Contrast to a "navigate away" operation |
45 // which is defined as a user interaction that navigates away from a specified | 48 // which is defined as a user interaction that navigates away from a specified |
46 // task and the next task that becomes active is likely not user-predictable | 49 // task and the next task that becomes active is likely not user-predictable |
47 // (ie. closing or minimizing a window, closing a tab, etc). | 50 // (ie. closing or minimizing a window, closing a tab, etc). |
48 // | 51 // |
49 // Will add an entry to |histogram_map_| when called for the first time for | 52 // Will add an entry to |histogram_map_| when called for the first time for |
50 // each |task_switch_source| value. | 53 // each |task_switch_source| value. |
54 // | |
55 // NOTE: A |task_switch_source| value of TaskSwitchSource::kAny should not be | |
56 // used and behavior is undefined if it is. | |
tdanderson
2015/06/02 15:56:12
Include in the documentation of OnTaskSwitch() tha
bruthig
2015/06/04 18:54:26
Done.
| |
51 void OnTaskSwitch(TaskSwitchSource task_switch_source); | 57 void OnTaskSwitch(TaskSwitchSource task_switch_source); |
52 | 58 |
53 private: | 59 private: |
60 // Internal Implementation of OnTaskSwitch(TaskSwitchSource) that will accept | |
tdanderson
2015/06/02 15:56:11
nit: lower-case i on implementation.
bruthig
2015/06/04 18:54:26
Done.
| |
61 // the TaskSwitchSource::kAny value. | |
62 void OnTaskSwitchInternal(TaskSwitchSource task_switch_source); | |
63 | |
54 // Returns the TaskSwitchTimeTracker associated with the specified | 64 // Returns the TaskSwitchTimeTracker associated with the specified |
55 // |task_switch_source|. May return nullptr if mapping does not exist yet. | 65 // |task_switch_source|. May return nullptr if mapping does not exist yet. |
56 TaskSwitchTimeTracker* FindTaskSwitchTimeTracker( | 66 TaskSwitchTimeTracker* FindTaskSwitchTimeTracker( |
57 TaskSwitchSource task_switch_source); | 67 TaskSwitchSource task_switch_source); |
58 | 68 |
59 // Adds a TaskSwitchTimeTracker to |histogram_map_| for the specified | 69 // Adds a TaskSwitchTimeTracker to |histogram_map_| for the specified |
60 // |task_switch_source|. Behavior is undefined if a TaskSwitchTimeTracker | 70 // |task_switch_source|. Behavior is undefined if a TaskSwitchTimeTracker |
61 // |histogram_map_| already has an entry for |task_switch_source|. | 71 // |histogram_map_| already has an entry for |task_switch_source|. |
62 void AddTaskSwitchTimeTracker(TaskSwitchSource task_switch_source); | 72 void AddTaskSwitchTimeTracker(TaskSwitchSource task_switch_source); |
63 | 73 |
64 // Tracks TaskSwitchSource to TaskSwitchTimeTracker mappings. The | 74 // Tracks TaskSwitchSource to TaskSwitchTimeTracker mappings. The |
65 // |histogram_map_| is populated on demand the first time a | 75 // |histogram_map_| is populated on demand the first time a |
66 // TaskSwitchTimeTracker is needed for a given source. | 76 // TaskSwitchTimeTracker is needed for a given source. |
67 base::ScopedPtrHashMap<int, scoped_ptr<TaskSwitchTimeTracker>> histogram_map_; | 77 base::ScopedPtrHashMap<int, scoped_ptr<TaskSwitchTimeTracker>> histogram_map_; |
68 | 78 |
69 DISALLOW_COPY_AND_ASSIGN(TaskSwitchMetricsRecorder); | 79 DISALLOW_COPY_AND_ASSIGN(TaskSwitchMetricsRecorder); |
70 }; | 80 }; |
71 | 81 |
72 } // namespace ash | 82 } // namespace ash |
73 | 83 |
74 #endif // ASH_METRICS_TASK_SWITCH_METRIC_RECORDER_H_ | 84 #endif // ASH_METRICS_TASK_SWITCH_METRIC_RECORDER_H_ |
OLD | NEW |