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 #include "ash/metrics/task_switch_metrics_recorder.h"
7 #include "ash/metrics/task_switch_time_tracker.h"
13 const char kAshTaskSwitchHistogramName
[] = "Ash.TimeBetweenTaskSwitches";
15 const char kDesktopHistogramName
[] =
16 "Ash.Desktop.TimeBetweenNavigateToTaskSwitches";
18 const char kShelfHistogramName
[] =
19 "Ash.Shelf.TimeBetweenNavigateToTaskSwitches";
21 const char kTabStripHistogramName
[] =
22 "Ash.Tab.TimeBetweenSwitchToExistingTabUserActions";
24 const char kAcceleratorWindowCycleHistogramName
[] =
25 "Ash.WindowCycleController.TimeBetweenTaskSwitches";
27 const char kAppListHistogramName
[] = "Ash.AppList.TimeBetweenTaskSwitches";
29 const char kOverviewModeHistogramName
[] =
30 "Ash.WindowSelector.TimeBetweenActiveWindowChanges";
32 // Returns the histogram name for the given |task_switch_source|.
33 const char* GetHistogramName(
34 TaskSwitchMetricsRecorder::TaskSwitchSource task_switch_source
) {
35 switch (task_switch_source
) {
36 case TaskSwitchMetricsRecorder::kAny
:
37 return kAshTaskSwitchHistogramName
;
38 case TaskSwitchMetricsRecorder::kAppList
:
39 return kAppListHistogramName
;
40 case TaskSwitchMetricsRecorder::kDesktop
:
41 return kDesktopHistogramName
;
42 case TaskSwitchMetricsRecorder::kOverviewMode
:
43 return kOverviewModeHistogramName
;
44 case TaskSwitchMetricsRecorder::kShelf
:
45 return kShelfHistogramName
;
46 case TaskSwitchMetricsRecorder::kTabStrip
:
47 return kTabStripHistogramName
;
48 case TaskSwitchMetricsRecorder::kWindowCycleController
:
49 return kAcceleratorWindowCycleHistogramName
;
57 TaskSwitchMetricsRecorder::TaskSwitchMetricsRecorder() {
60 TaskSwitchMetricsRecorder::~TaskSwitchMetricsRecorder() {
63 void TaskSwitchMetricsRecorder::OnTaskSwitch(
64 TaskSwitchSource task_switch_source
) {
65 DCHECK_NE(task_switch_source
, kAny
);
66 if (task_switch_source
!= kAny
) {
67 OnTaskSwitchInternal(task_switch_source
);
68 OnTaskSwitchInternal(kAny
);
72 void TaskSwitchMetricsRecorder::OnTaskSwitchInternal(
73 TaskSwitchSource task_switch_source
) {
74 TaskSwitchTimeTracker
* task_switch_time_tracker
=
75 FindTaskSwitchTimeTracker(task_switch_source
);
76 if (!task_switch_time_tracker
)
77 AddTaskSwitchTimeTracker(task_switch_source
);
79 task_switch_time_tracker
= FindTaskSwitchTimeTracker(task_switch_source
);
80 CHECK(task_switch_time_tracker
);
82 task_switch_time_tracker
->OnTaskSwitch();
85 TaskSwitchTimeTracker
* TaskSwitchMetricsRecorder::FindTaskSwitchTimeTracker(
86 TaskSwitchSource task_switch_source
) {
87 return histogram_map_
.get(task_switch_source
);
90 void TaskSwitchMetricsRecorder::AddTaskSwitchTimeTracker(
91 TaskSwitchSource task_switch_source
) {
92 CHECK(histogram_map_
.find(task_switch_source
) == histogram_map_
.end());
94 const char* histogram_name
= GetHistogramName(task_switch_source
);
95 DCHECK(histogram_name
);
99 make_scoped_ptr(new TaskSwitchTimeTracker(histogram_name
)));