forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask_switch_metrics_recorder.cc
95 lines (72 loc) · 2.93 KB
/
task_switch_metrics_recorder.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/metrics/task_switch_metrics_recorder.h"
#include "ash/metrics/task_switch_time_tracker.h"
#include "base/memory/ptr_util.h"
namespace ash {
namespace {
const char kAshTaskSwitchHistogramName[] = "Ash.TimeBetweenTaskSwitches";
const char kDesktopHistogramName[] =
"Ash.Desktop.TimeBetweenNavigateToTaskSwitches";
const char kShelfHistogramName[] =
"Ash.Shelf.TimeBetweenNavigateToTaskSwitches";
const char kAcceleratorWindowCycleHistogramName[] =
"Ash.WindowCycleController.TimeBetweenTaskSwitches";
const char kOverviewModeHistogramName[] =
"Ash.WindowSelector.TimeBetweenActiveWindowChanges";
// Returns the histogram name for the given |task_switch_source|.
const char* GetHistogramName(TaskSwitchSource task_switch_source) {
switch (task_switch_source) {
case TaskSwitchSource::ANY:
return kAshTaskSwitchHistogramName;
case TaskSwitchSource::DESKTOP:
return kDesktopHistogramName;
case TaskSwitchSource::OVERVIEW_MODE:
return kOverviewModeHistogramName;
case TaskSwitchSource::SHELF:
return kShelfHistogramName;
case TaskSwitchSource::WINDOW_CYCLE_CONTROLLER:
return kAcceleratorWindowCycleHistogramName;
}
NOTREACHED();
return nullptr;
}
} // namespace
TaskSwitchMetricsRecorder::TaskSwitchMetricsRecorder() {}
TaskSwitchMetricsRecorder::~TaskSwitchMetricsRecorder() {}
void TaskSwitchMetricsRecorder::OnTaskSwitch(
TaskSwitchSource task_switch_source) {
DCHECK_NE(task_switch_source, TaskSwitchSource::ANY);
if (task_switch_source != TaskSwitchSource::ANY) {
OnTaskSwitchInternal(task_switch_source);
OnTaskSwitchInternal(TaskSwitchSource::ANY);
}
}
void TaskSwitchMetricsRecorder::OnTaskSwitchInternal(
TaskSwitchSource task_switch_source) {
TaskSwitchTimeTracker* task_switch_time_tracker =
FindTaskSwitchTimeTracker(task_switch_source);
if (!task_switch_time_tracker)
AddTaskSwitchTimeTracker(task_switch_source);
task_switch_time_tracker = FindTaskSwitchTimeTracker(task_switch_source);
CHECK(task_switch_time_tracker);
task_switch_time_tracker->OnTaskSwitch();
}
TaskSwitchTimeTracker* TaskSwitchMetricsRecorder::FindTaskSwitchTimeTracker(
TaskSwitchSource task_switch_source) {
auto it = histogram_map_.find(static_cast<int>(task_switch_source));
if (it == histogram_map_.end())
return nullptr;
return it->second.get();
}
void TaskSwitchMetricsRecorder::AddTaskSwitchTimeTracker(
TaskSwitchSource task_switch_source) {
CHECK(histogram_map_.find(static_cast<int>(task_switch_source)) ==
histogram_map_.end());
const char* histogram_name = GetHistogramName(task_switch_source);
DCHECK(histogram_name);
histogram_map_[static_cast<int>(task_switch_source)] =
base::MakeUnique<TaskSwitchTimeTracker>(histogram_name);
}
} // namespace ash