James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 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. |
| 4 | |
| 5 | #include "ash/shelf/shelf_button_pressed_metric_tracker.h" |
| 6 | |
Scott Violet | 41562d1c | 2017-06-26 15:15:48 | [diff] [blame] | 7 | #include "ash/metrics/user_metrics_recorder.h" |
| 8 | #include "ash/shell.h" |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 9 | #include "base/metrics/histogram_macros.h" |
| 10 | #include "base/time/default_tick_clock.h" |
| 11 | #include "ui/views/controls/button/button.h" |
| 12 | |
| 13 | namespace ash { |
| 14 | |
| 15 | const char ShelfButtonPressedMetricTracker:: |
| 16 | kTimeBetweenWindowMinimizedAndActivatedActionsHistogramName[] = |
| 17 | "Ash.Shelf.TimeBetweenWindowMinimizedAndActivatedActions"; |
| 18 | |
| 19 | ShelfButtonPressedMetricTracker::ShelfButtonPressedMetricTracker() |
tzik | 8529bdd8 | 2018-02-28 05:47:21 | [diff] [blame] | 20 | : tick_clock_(base::DefaultTickClock::GetInstance()), |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 21 | time_of_last_minimize_(base::TimeTicks()), |
| 22 | last_minimized_source_button_(nullptr) {} |
| 23 | |
Chris Watkins | c24daf6 | 2017-11-28 03:43:09 | [diff] [blame] | 24 | ShelfButtonPressedMetricTracker::~ShelfButtonPressedMetricTracker() = default; |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 25 | |
| 26 | void ShelfButtonPressedMetricTracker::ButtonPressed( |
| 27 | const ui::Event& event, |
| 28 | const views::Button* sender, |
| 29 | ShelfAction performed_action) { |
| 30 | RecordButtonPressedSource(event); |
| 31 | RecordButtonPressedAction(performed_action); |
| 32 | |
| 33 | switch (performed_action) { |
| 34 | case SHELF_ACTION_WINDOW_MINIMIZED: |
| 35 | SetMinimizedData(sender); |
| 36 | break; |
| 37 | case SHELF_ACTION_WINDOW_ACTIVATED: |
| 38 | if (IsSubsequentActivationEvent(sender)) |
| 39 | RecordTimeBetweenMinimizedAndActivated(); |
| 40 | break; |
| 41 | default: |
| 42 | break; |
| 43 | } |
| 44 | |
| 45 | if (performed_action != SHELF_ACTION_WINDOW_MINIMIZED) |
| 46 | ResetMinimizedData(); |
| 47 | } |
| 48 | |
| 49 | void ShelfButtonPressedMetricTracker::RecordButtonPressedSource( |
| 50 | const ui::Event& event) { |
| 51 | if (event.IsMouseEvent()) { |
Scott Violet | 41562d1c | 2017-06-26 15:15:48 | [diff] [blame] | 52 | Shell::Get()->metrics()->RecordUserMetricsAction( |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 53 | UMA_LAUNCHER_BUTTON_PRESSED_WITH_MOUSE); |
| 54 | } else if (event.IsGestureEvent()) { |
Scott Violet | 41562d1c | 2017-06-26 15:15:48 | [diff] [blame] | 55 | Shell::Get()->metrics()->RecordUserMetricsAction( |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 56 | UMA_LAUNCHER_BUTTON_PRESSED_WITH_TOUCH); |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | void ShelfButtonPressedMetricTracker::RecordButtonPressedAction( |
| 61 | ShelfAction performed_action) { |
| 62 | switch (performed_action) { |
| 63 | case SHELF_ACTION_NONE: |
| 64 | case SHELF_ACTION_APP_LIST_SHOWN: |
Avery Musbach | 6277366 | 2019-01-15 00:16:56 | [diff] [blame] | 65 | case SHELF_ACTION_APP_LIST_DISMISSED: |
Matthew Mourgos | 4c287d6 | 2019-10-25 22:46:16 | [diff] [blame] | 66 | case SHELF_ACTION_APP_LIST_BACK: |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 67 | break; |
| 68 | case SHELF_ACTION_NEW_WINDOW_CREATED: |
Scott Violet | 41562d1c | 2017-06-26 15:15:48 | [diff] [blame] | 69 | Shell::Get()->metrics()->RecordUserMetricsAction( |
| 70 | UMA_LAUNCHER_LAUNCH_TASK); |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 71 | break; |
| 72 | case SHELF_ACTION_WINDOW_ACTIVATED: |
Scott Violet | 41562d1c | 2017-06-26 15:15:48 | [diff] [blame] | 73 | Shell::Get()->metrics()->RecordUserMetricsAction( |
| 74 | UMA_LAUNCHER_SWITCH_TASK); |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 75 | break; |
| 76 | case SHELF_ACTION_WINDOW_MINIMIZED: |
Scott Violet | 41562d1c | 2017-06-26 15:15:48 | [diff] [blame] | 77 | Shell::Get()->metrics()->RecordUserMetricsAction( |
| 78 | UMA_LAUNCHER_MINIMIZE_TASK); |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 79 | break; |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | void ShelfButtonPressedMetricTracker::RecordTimeBetweenMinimizedAndActivated() { |
| 84 | UMA_HISTOGRAM_TIMES( |
| 85 | kTimeBetweenWindowMinimizedAndActivatedActionsHistogramName, |
| 86 | tick_clock_->NowTicks() - time_of_last_minimize_); |
| 87 | } |
| 88 | |
| 89 | bool ShelfButtonPressedMetricTracker::IsSubsequentActivationEvent( |
| 90 | const views::Button* sender) const { |
| 91 | return time_of_last_minimize_ != base::TimeTicks() && |
| 92 | last_minimized_source_button_ == sender; |
| 93 | } |
| 94 | |
| 95 | void ShelfButtonPressedMetricTracker::SetMinimizedData( |
| 96 | const views::Button* sender) { |
| 97 | last_minimized_source_button_ = sender; |
| 98 | time_of_last_minimize_ = tick_clock_->NowTicks(); |
| 99 | } |
| 100 | |
| 101 | void ShelfButtonPressedMetricTracker::ResetMinimizedData() { |
| 102 | last_minimized_source_button_ = nullptr; |
| 103 | time_of_last_minimize_ = base::TimeTicks(); |
| 104 | } |
| 105 | |
| 106 | } // namespace ash |