Updating XTBs based on .GRDs from branch master
[chromium-blink-merge.git] / ash / metrics / task_switch_metrics_recorder.h
blob6dc718e8b49ee509e325e67462aac08922eaa73f
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
3 // found in the LICENSE file.
5 #ifndef ASH_METRICS_TASK_SWITCH_METRIC_RECORDER_H_
6 #define ASH_METRICS_TASK_SWITCH_METRIC_RECORDER_H_
8 #include <string>
10 #include "ash/ash_export.h"
11 #include "base/containers/scoped_ptr_hash_map.h"
13 namespace aura {
14 class Window;
15 } // namespace aura
17 namespace ash {
19 class TaskSwitchTimeTracker;
21 // The TaskSwitchMetricsRecorder class records UMA metrics related to task
22 // switching. The main purpose of the TaskSwitchMetricsRecorder is to track time
23 // deltas between task switches and record histograms of the deltas.
24 class ASH_EXPORT TaskSwitchMetricsRecorder {
25 public:
26 // Enumeration of the different user interfaces that could be the source of
27 // a task switch. Note this is not necessarily comprehensive of all sources.
28 enum TaskSwitchSource {
29 // Task switches caused by any two sources in this enum. NOTE: This value
30 // should NOT be used outside of this class.
31 ANY,
32 // Task switches from selecting items in the app list.
33 APP_LIST,
34 // Task switches caused by the user activating a task window by clicking or
35 // tapping on it.
36 DESKTOP,
37 // Task switches caused by selecting a window from overview mode which is
38 // different from the previously-active window.
39 OVERVIEW_MODE,
40 // All task switches caused by shelf buttons, not including sub-menus.
41 SHELF,
42 // All task switches caused by the tab strip.
43 TAB_STRIP,
44 // Task switches caused by the WindowCycleController (ie Alt+Tab).
45 WINDOW_CYCLE_CONTROLLER
48 TaskSwitchMetricsRecorder();
49 virtual ~TaskSwitchMetricsRecorder();
51 // Notifies |this| that a "navigate to" task switch has occurred from the
52 // specified |task_switch_source|. The metrics associated with
53 // TaskSwitchSource::ANY source will be updated as well.
55 // NOTE: A |task_switch_source| value of TaskSwitchSource::ANY should not be
56 // used and behavior is undefined if it is.
58 // A "navigate to" operation is defined by a task switch where the specific
59 // task that becomes active is user-predictable (e.g., Alt+Tab accelerator,
60 // launching a new window via the shelf, etc). Contrast to a "navigate away"
61 // operation which is defined as a user interaction that navigates away from a
62 // specified task and the next task that becomes active is likely not
63 // user-predictable (e.g., closing or minimizing a window, closing a tab,
64 // etc).
66 // Will add an entry to |histogram_map_| when called for the first time for
67 // each |task_switch_source| value.
68 void OnTaskSwitch(TaskSwitchSource task_switch_source);
70 private:
71 // Internal implementation of OnTaskSwitch(TaskSwitchSource) that will accept
72 // the TaskSwitchSource::ANY value.
73 void OnTaskSwitchInternal(TaskSwitchSource task_switch_source);
75 // Returns the TaskSwitchTimeTracker associated with the specified
76 // |task_switch_source|. May return nullptr if mapping does not exist yet.
77 TaskSwitchTimeTracker* FindTaskSwitchTimeTracker(
78 TaskSwitchSource task_switch_source);
80 // Adds a TaskSwitchTimeTracker to |histogram_map_| for the specified
81 // |task_switch_source|. Behavior is undefined if a TaskSwitchTimeTracker
82 // |histogram_map_| already has an entry for |task_switch_source|.
83 void AddTaskSwitchTimeTracker(TaskSwitchSource task_switch_source);
85 // Tracks TaskSwitchSource to TaskSwitchTimeTracker mappings. The
86 // |histogram_map_| is populated on demand the first time a
87 // TaskSwitchTimeTracker is needed for a given source.
88 base::ScopedPtrHashMap<int, scoped_ptr<TaskSwitchTimeTracker>> histogram_map_;
90 DISALLOW_COPY_AND_ASSIGN(TaskSwitchMetricsRecorder);
93 } // namespace ash
95 #endif // ASH_METRICS_TASK_SWITCH_METRIC_RECORDER_H_