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/shelf/shelf_button_pressed_metric_tracker.h"
7 #include "ash/metrics/user_metrics_recorder.h"
9 #include "base/metrics/histogram_macros.h"
10 #include "base/time/default_tick_clock.h"
11 #include "ui/views/controls/button/button.h"
15 const char ShelfButtonPressedMetricTracker::
16 kTimeBetweenWindowMinimizedAndActivatedActionsHistogramName
[] =
17 "Ash.Shelf.TimeBetweenWindowMinimizedAndActivatedActions";
19 ShelfButtonPressedMetricTracker::ShelfButtonPressedMetricTracker()
20 : tick_clock_(new base::DefaultTickClock()),
21 time_of_last_minimize_(base::TimeTicks()),
22 last_minimized_source_button_(nullptr) {
25 ShelfButtonPressedMetricTracker::~ShelfButtonPressedMetricTracker() {
28 void ShelfButtonPressedMetricTracker::ButtonPressed(
29 const ui::Event
& event
,
30 const views::Button
* sender
,
31 ShelfItemDelegate::PerformedAction performed_action
) {
32 RecordButtonPressedSource(event
);
33 RecordButtonPressedAction(performed_action
);
35 switch (performed_action
) {
36 case ShelfItemDelegate::kExistingWindowMinimized
:
37 SetMinimizedData(sender
);
39 case ShelfItemDelegate::kExistingWindowActivated
:
40 if (IsSubsequentActivationEvent(sender
))
41 RecordTimeBetweenMinimizedAndActivated();
47 if (performed_action
!= ShelfItemDelegate::kExistingWindowMinimized
)
51 void ShelfButtonPressedMetricTracker::RecordButtonPressedSource(
52 const ui::Event
& event
) {
53 if (event
.IsMouseEvent()) {
54 Shell::GetInstance()->metrics()->RecordUserMetricsAction(
55 UMA_LAUNCHER_BUTTON_PRESSED_WITH_MOUSE
);
56 } else if (event
.IsGestureEvent()) {
57 Shell::GetInstance()->metrics()->RecordUserMetricsAction(
58 UMA_LAUNCHER_BUTTON_PRESSED_WITH_TOUCH
);
62 void ShelfButtonPressedMetricTracker::RecordButtonPressedAction(
63 ShelfItemDelegate::PerformedAction performed_action
) {
64 switch (performed_action
) {
65 case ShelfItemDelegate::kNoAction
:
66 case ShelfItemDelegate::kAppListMenuShown
:
68 case ShelfItemDelegate::kNewWindowCreated
:
69 Shell::GetInstance()->metrics()->RecordUserMetricsAction(
70 UMA_LAUNCHER_LAUNCH_TASK
);
72 case ShelfItemDelegate::kExistingWindowActivated
:
73 Shell::GetInstance()->metrics()->RecordUserMetricsAction(
74 UMA_LAUNCHER_SWITCH_TASK
);
76 case ShelfItemDelegate::kExistingWindowMinimized
:
77 Shell::GetInstance()->metrics()->RecordUserMetricsAction(
78 UMA_LAUNCHER_MINIMIZE_TASK
);
83 void ShelfButtonPressedMetricTracker::RecordTimeBetweenMinimizedAndActivated() {
85 kTimeBetweenWindowMinimizedAndActivatedActionsHistogramName
,
86 tick_clock_
->NowTicks() - time_of_last_minimize_
);
89 bool ShelfButtonPressedMetricTracker::IsSubsequentActivationEvent(
90 const views::Button
* sender
) const {
91 return time_of_last_minimize_
!= base::TimeTicks() &&
92 last_minimized_source_button_
== sender
;
95 void ShelfButtonPressedMetricTracker::SetMinimizedData(
96 const views::Button
* sender
) {
97 last_minimized_source_button_
= sender
;
98 time_of_last_minimize_
= tick_clock_
->NowTicks();
101 void ShelfButtonPressedMetricTracker::ResetMinimizedData() {
102 last_minimized_source_button_
= nullptr;
103 time_of_last_minimize_
= base::TimeTicks();