contextual_tooltip.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. // Copyright 2020 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_CONTROLS_CONTEXTUAL_TOOLTIP_H_
  5. #define ASH_CONTROLS_CONTEXTUAL_TOOLTIP_H_
  6. #include "ash/ash_export.h"
  7. #include "base/time/clock.h"
  8. #include "components/prefs/pref_registry_simple.h"
  9. #include "components/prefs/pref_service.h"
  10. namespace ash {
  11. namespace contextual_tooltip {
  12. // Enumeration of all contextual tooltips.
  13. enum class TooltipType {
  14. kBackGesture,
  15. kHomeToOverview,
  16. kInAppToHome,
  17. kKeyboardBacklightColor,
  18. kKeyboardBacklightWallpaperColor,
  19. };
  20. // These values are persisted to logs. Entries should not be renumbered and
  21. // numeric values should never be reused. These values enumerate the reasons a
  22. // contextual nudge may be hidden.
  23. enum class DismissNudgeReason {
  24. kOther = 0,
  25. kPerformedGesture = 1,
  26. kTap = 2,
  27. kSwitchToClamshell = 3,
  28. kExitToHomeScreen = 4,
  29. kTimeout = 5,
  30. kActiveWindowChanged = 6, // dismisses back gesture nudge
  31. kNavigationEntryChanged = 7, // dismisses back gesture nudge
  32. // kBackGestureStarted = 8, deprecated
  33. kUserSessionInactive = 9, // dismisses back gesture nudge
  34. kMaxValue = kUserSessionInactive,
  35. };
  36. // Maximum number of times a user can be shown a contextual nudge if the user
  37. // hasn't performed the gesture |kSuccessLimit| times successfully.
  38. constexpr int kNotificationLimit = 3;
  39. constexpr int kSuccessLimitInAppToHome = 7;
  40. constexpr int kSuccessLimitHomeToOverview = 3;
  41. constexpr int kSuccessLimitBackGesture = 1;
  42. constexpr int kSuccessLimitKeyboardBacklightColor = 1;
  43. // Minimum time between showing contextual nudges to the user.
  44. constexpr base::TimeDelta kMinInterval = base::Days(1);
  45. // The amount of time a nudge is shown.
  46. constexpr base::TimeDelta kNudgeShowDuration = base::Seconds(5);
  47. // The minimum amount of time that has to pass since showing drag handle nudge
  48. // before showing the back gesture nudge.
  49. constexpr base::TimeDelta kMinIntervalBetweenBackAndDragHandleNudge =
  50. base::Minutes(1);
  51. // Registers profile prefs.
  52. ASH_EXPORT void RegisterProfilePrefs(PrefRegistrySimple* registry);
  53. // Returns true if the contextual tooltip of |type| should be shown for the user
  54. // with the given |prefs|.
  55. // If the nudge should not be shown at this time, the |recheck_delay| will be
  56. // set to the time delta after which the nudge might become available. If nudge
  57. // is not expected to be shown any longer, or it's not known when the nudge
  58. // might become available again (e.g. for drag handle nudge if the shelf is
  59. // hidden) |recheck_delay| will be set to zero.
  60. // |recheck_delay| might be nullptr, in which case it will be ignored.
  61. ASH_EXPORT bool ShouldShowNudge(PrefService* prefs,
  62. TooltipType type,
  63. base::TimeDelta* recheck_delay);
  64. // Checks whether the tooltip should be hidden after a timeout. Returns the
  65. // timeout if it should, returns base::TimeDelta() if not.
  66. ASH_EXPORT base::TimeDelta GetNudgeTimeout(PrefService* prefs,
  67. TooltipType type);
  68. // Returns the number of counts that |type| nudge has been shown for the user
  69. // with the given |prefs|.
  70. ASH_EXPORT int GetShownCount(PrefService* prefs, TooltipType type);
  71. // Increments the counter tracking the number of times the tooltip has been
  72. // shown. Updates the last shown time for the tooltip.
  73. ASH_EXPORT void HandleNudgeShown(PrefService* prefs, TooltipType type);
  74. // Increments the counter tracking the number of times the tooltip's
  75. // correpsonding gesture has been performed successfully.
  76. ASH_EXPORT void HandleGesturePerformed(PrefService* prefs, TooltipType type);
  77. // Sets whether drag handle nudge should be prevented from showing because the
  78. // shelf is in hidden state.
  79. ASH_EXPORT void SetDragHandleNudgeDisabledForHiddenShelf(bool nudge_disabled);
  80. // Sets whether the back gesture nudge is being shown (back gesture can be
  81. // visible before HandleNudgeShown gets called).
  82. ASH_EXPORT void SetBackGestureNudgeShowing(bool showing);
  83. // Resets all user prefs related to contextual tooltips.
  84. ASH_EXPORT void ClearPrefs();
  85. ASH_EXPORT void OverrideClockForTesting(base::Clock* test_clock);
  86. ASH_EXPORT void ClearClockOverrideForTesting();
  87. // Reset the dictionary tracking metrics for each TooltipType.
  88. ASH_EXPORT void ClearStatusTrackerTableForTesting();
  89. } // namespace contextual_tooltip
  90. } // namespace ash
  91. #endif // ASH_CONTROLS_CONTEXTUAL_TOOLTIP_H_