feature_promo_registry.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 COMPONENTS_USER_EDUCATION_COMMON_FEATURE_PROMO_REGISTRY_H_
  5. #define COMPONENTS_USER_EDUCATION_COMMON_FEATURE_PROMO_REGISTRY_H_
  6. #include <map>
  7. #include "components/user_education/common/feature_promo_specification.h"
  8. namespace base {
  9. struct Feature;
  10. }
  11. namespace user_education {
  12. // Stores parameters for in-product help promos. For each registered
  13. // IPH, has the bubble parameters and a method for getting an anchor
  14. // view for a given BrowserView. Promos should be registered here when
  15. // feasible.
  16. class FeaturePromoRegistry {
  17. public:
  18. FeaturePromoRegistry();
  19. ~FeaturePromoRegistry();
  20. // Determines whether or not a particular feature is registered.
  21. bool IsFeatureRegistered(const base::Feature& iph_feature) const;
  22. // Returns the FeaturePromoSpecification to start an IPH for
  23. // the given feature. |iph_feature| is the feature to show for.
  24. // |browser_view| is the window it should show in.
  25. //
  26. // The params must be used immediately since it contains a View
  27. // pointer that may become stale. This may return nothing in which
  28. // case the promo shouldn't show.
  29. const FeaturePromoSpecification* GetParamsForFeature(
  30. const base::Feature& iph_feature) const;
  31. // Registers a feature promo.
  32. //
  33. // Prefer putting these calls in the body of RegisterKnownFeatures()
  34. // when possible.
  35. void RegisterFeature(FeaturePromoSpecification spec);
  36. const std::map<const base::Feature*, FeaturePromoSpecification>&
  37. GetRegisteredFeaturePromoSpecifications() {
  38. return feature_promo_data_;
  39. }
  40. void ClearFeaturesForTesting();
  41. private:
  42. std::map<const base::Feature*, FeaturePromoSpecification> feature_promo_data_;
  43. };
  44. } // namespace user_education
  45. #endif // COMPONENTS_USER_EDUCATION_COMMON_FEATURE_PROMO_REGISTRY_H_