Update V8 to version 4.6.54.
[chromium-blink-merge.git] / ash / metrics / task_switch_metrics_recorder.cc
bloba6d114537379807190b90fa5879c87fbe2871cdc
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"
9 namespace ash {
11 namespace {
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::ANY:
37 return kAshTaskSwitchHistogramName;
38 case TaskSwitchMetricsRecorder::APP_LIST:
39 return kAppListHistogramName;
40 case TaskSwitchMetricsRecorder::DESKTOP:
41 return kDesktopHistogramName;
42 case TaskSwitchMetricsRecorder::OVERVIEW_MODE:
43 return kOverviewModeHistogramName;
44 case TaskSwitchMetricsRecorder::SHELF:
45 return kShelfHistogramName;
46 case TaskSwitchMetricsRecorder::TAB_STRIP:
47 return kTabStripHistogramName;
48 case TaskSwitchMetricsRecorder::WINDOW_CYCLE_CONTROLLER:
49 return kAcceleratorWindowCycleHistogramName;
51 NOTREACHED();
52 return nullptr;
55 } // namespace
57 TaskSwitchMetricsRecorder::TaskSwitchMetricsRecorder() {
60 TaskSwitchMetricsRecorder::~TaskSwitchMetricsRecorder() {
63 void TaskSwitchMetricsRecorder::OnTaskSwitch(
64 TaskSwitchSource task_switch_source) {
65 DCHECK_NE(task_switch_source, ANY);
66 if (task_switch_source != ANY) {
67 OnTaskSwitchInternal(task_switch_source);
68 OnTaskSwitchInternal(ANY);
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);
97 histogram_map_.add(
98 task_switch_source,
99 make_scoped_ptr(new TaskSwitchTimeTracker(histogram_name)));
102 } // namespace ash