shelf_button_pressed_metric_tracker.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. #ifndef ASH_SHELF_SHELF_BUTTON_PRESSED_METRIC_TRACKER_H_
  5. #define ASH_SHELF_SHELF_BUTTON_PRESSED_METRIC_TRACKER_H_
  6. #include "ash/ash_export.h"
  7. #include "ash/public/cpp/shelf_types.h"
  8. #include "base/time/tick_clock.h"
  9. #include "base/time/time.h"
  10. #include "ui/events/event.h"
  11. namespace views {
  12. class Button;
  13. } // namespace views
  14. namespace ash {
  15. // Tracks UMA metrics based on shelf button press actions. More specifically
  16. // data is added to the following user actions and histograms:
  17. //
  18. // User Actions:
  19. // - Launcher_ButtonPressed_Mouse
  20. // - Launcher_ButtonPressed_Touch
  21. // - Launcher_LaunchTask
  22. // - Launcher_MinimizeTask
  23. // - Launcher_SwitchTask
  24. // Histograms:
  25. // - Ash.Shelf.TimeBetweenWindowMinimizedAndActivatedActions
  26. //
  27. class ASH_EXPORT ShelfButtonPressedMetricTracker {
  28. public:
  29. static const char
  30. kTimeBetweenWindowMinimizedAndActivatedActionsHistogramName[];
  31. ShelfButtonPressedMetricTracker();
  32. ShelfButtonPressedMetricTracker(const ShelfButtonPressedMetricTracker&) =
  33. delete;
  34. ShelfButtonPressedMetricTracker& operator=(
  35. const ShelfButtonPressedMetricTracker&) = delete;
  36. ~ShelfButtonPressedMetricTracker();
  37. // Records metrics based on the |event|, |sender|, and |performed_action|.
  38. void ButtonPressed(const ui::Event& event,
  39. const views::Button* sender,
  40. ShelfAction performed_action);
  41. private:
  42. friend class ShelfButtonPressedMetricTrackerTestAPI;
  43. // Records UMA metrics for the input source when a button is pressed.
  44. void RecordButtonPressedSource(const ui::Event& event);
  45. // Records UMA metrics for the action performed when a button is pressed.
  46. void RecordButtonPressedAction(ShelfAction performed_action);
  47. // Records UMA metrics for the elapsed time since the last window minimize
  48. // action.
  49. void RecordTimeBetweenMinimizedAndActivated();
  50. // Returns true if a window activation action triggered by |sender| would
  51. // be subsequent to the last minimize window action.
  52. bool IsSubsequentActivationEvent(const views::Button* sender) const;
  53. // Caches state data for a window minimized action. The |sender| is the button
  54. // that caused the action.
  55. void SetMinimizedData(const views::Button* sender);
  56. // Resets the state data associated with the last window minimize action.
  57. void ResetMinimizedData();
  58. // Time source for performed action times.
  59. const base::TickClock* tick_clock_;
  60. // Stores the time of the last window minimize action.
  61. base::TimeTicks time_of_last_minimize_;
  62. // Stores the source button of the last window minimize action.
  63. // NOTE: This may become stale and should not be operated on. Not owned.
  64. const views::Button* last_minimized_source_button_ = nullptr;
  65. };
  66. } // namespace ash
  67. #endif // ASH_SHELF_SHELF_BUTTON_PRESSED_METRIC_TRACKER_H_