Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / ash / shelf / shelf_button_pressed_metric_tracker.cc
blob00fab2cc57c0965dcb2519cb0e4567b8420a6403
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"
8 #include "ash/shell.h"
9 #include "base/metrics/histogram_macros.h"
10 #include "base/time/default_tick_clock.h"
11 #include "ui/views/controls/button/button.h"
13 namespace ash {
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);
38 break;
39 case ShelfItemDelegate::kExistingWindowActivated:
40 if (IsSubsequentActivationEvent(sender))
41 RecordTimeBetweenMinimizedAndActivated();
42 break;
43 default:
44 break;
47 if (performed_action != ShelfItemDelegate::kExistingWindowMinimized)
48 ResetMinimizedData();
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:
67 break;
68 case ShelfItemDelegate::kNewWindowCreated:
69 Shell::GetInstance()->metrics()->RecordUserMetricsAction(
70 UMA_LAUNCHER_LAUNCH_TASK);
71 break;
72 case ShelfItemDelegate::kExistingWindowActivated:
73 Shell::GetInstance()->metrics()->RecordUserMetricsAction(
74 UMA_LAUNCHER_SWITCH_TASK);
75 break;
76 case ShelfItemDelegate::kExistingWindowMinimized:
77 Shell::GetInstance()->metrics()->RecordUserMetricsAction(
78 UMA_LAUNCHER_MINIMIZE_TASK);
79 break;
83 void ShelfButtonPressedMetricTracker::RecordTimeBetweenMinimizedAndActivated() {
84 UMA_HISTOGRAM_TIMES(
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();
106 } // namespace ash