OLD | NEW |
| (Empty) |
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/common/shelf/shelf_button_pressed_metric_tracker.h" | |
6 | |
7 #include "ash/common/wm_shell.h" | |
8 #include "base/metrics/histogram_macros.h" | |
9 #include "base/time/default_tick_clock.h" | |
10 #include "ui/views/controls/button/button.h" | |
11 | |
12 namespace ash { | |
13 | |
14 const char ShelfButtonPressedMetricTracker:: | |
15 kTimeBetweenWindowMinimizedAndActivatedActionsHistogramName[] = | |
16 "Ash.Shelf.TimeBetweenWindowMinimizedAndActivatedActions"; | |
17 | |
18 ShelfButtonPressedMetricTracker::ShelfButtonPressedMetricTracker() | |
19 : tick_clock_(new base::DefaultTickClock()), | |
20 time_of_last_minimize_(base::TimeTicks()), | |
21 last_minimized_source_button_(nullptr) {} | |
22 | |
23 ShelfButtonPressedMetricTracker::~ShelfButtonPressedMetricTracker() {} | |
24 | |
25 void ShelfButtonPressedMetricTracker::ButtonPressed( | |
26 const ui::Event& event, | |
27 const views::Button* sender, | |
28 ShelfAction performed_action) { | |
29 RecordButtonPressedSource(event); | |
30 RecordButtonPressedAction(performed_action); | |
31 | |
32 switch (performed_action) { | |
33 case SHELF_ACTION_WINDOW_MINIMIZED: | |
34 SetMinimizedData(sender); | |
35 break; | |
36 case SHELF_ACTION_WINDOW_ACTIVATED: | |
37 if (IsSubsequentActivationEvent(sender)) | |
38 RecordTimeBetweenMinimizedAndActivated(); | |
39 break; | |
40 default: | |
41 break; | |
42 } | |
43 | |
44 if (performed_action != SHELF_ACTION_WINDOW_MINIMIZED) | |
45 ResetMinimizedData(); | |
46 } | |
47 | |
48 void ShelfButtonPressedMetricTracker::RecordButtonPressedSource( | |
49 const ui::Event& event) { | |
50 if (event.IsMouseEvent()) { | |
51 WmShell::Get()->RecordUserMetricsAction( | |
52 UMA_LAUNCHER_BUTTON_PRESSED_WITH_MOUSE); | |
53 } else if (event.IsGestureEvent()) { | |
54 WmShell::Get()->RecordUserMetricsAction( | |
55 UMA_LAUNCHER_BUTTON_PRESSED_WITH_TOUCH); | |
56 } | |
57 } | |
58 | |
59 void ShelfButtonPressedMetricTracker::RecordButtonPressedAction( | |
60 ShelfAction performed_action) { | |
61 switch (performed_action) { | |
62 case SHELF_ACTION_NONE: | |
63 case SHELF_ACTION_APP_LIST_SHOWN: | |
64 break; | |
65 case SHELF_ACTION_NEW_WINDOW_CREATED: | |
66 WmShell::Get()->RecordUserMetricsAction(UMA_LAUNCHER_LAUNCH_TASK); | |
67 break; | |
68 case SHELF_ACTION_WINDOW_ACTIVATED: | |
69 WmShell::Get()->RecordUserMetricsAction(UMA_LAUNCHER_SWITCH_TASK); | |
70 break; | |
71 case SHELF_ACTION_WINDOW_MINIMIZED: | |
72 WmShell::Get()->RecordUserMetricsAction(UMA_LAUNCHER_MINIMIZE_TASK); | |
73 break; | |
74 } | |
75 } | |
76 | |
77 void ShelfButtonPressedMetricTracker::RecordTimeBetweenMinimizedAndActivated() { | |
78 UMA_HISTOGRAM_TIMES( | |
79 kTimeBetweenWindowMinimizedAndActivatedActionsHistogramName, | |
80 tick_clock_->NowTicks() - time_of_last_minimize_); | |
81 } | |
82 | |
83 bool ShelfButtonPressedMetricTracker::IsSubsequentActivationEvent( | |
84 const views::Button* sender) const { | |
85 return time_of_last_minimize_ != base::TimeTicks() && | |
86 last_minimized_source_button_ == sender; | |
87 } | |
88 | |
89 void ShelfButtonPressedMetricTracker::SetMinimizedData( | |
90 const views::Button* sender) { | |
91 last_minimized_source_button_ = sender; | |
92 time_of_last_minimize_ = tick_clock_->NowTicks(); | |
93 } | |
94 | |
95 void ShelfButtonPressedMetricTracker::ResetMinimizedData() { | |
96 last_minimized_source_button_ = nullptr; | |
97 time_of_last_minimize_ = base::TimeTicks(); | |
98 } | |
99 | |
100 } // namespace ash | |
OLD | NEW |