feature_discovery_duration_reporter.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Copyright 2022 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_PUBLIC_CPP_FEATURE_DISCOVERY_DURATION_REPORTER_H_
  5. #define ASH_PUBLIC_CPP_FEATURE_DISCOVERY_DURATION_REPORTER_H_
  6. #include "ash/public/cpp/ash_public_export.h"
  7. #include "base/observer_list_types.h"
  8. namespace ash {
  9. namespace feature_discovery {
  10. enum class TrackableFeature;
  11. }; // namespace feature_discovery
  12. // A singleton class that records feature discovery duration when the following
  13. // conditions are met:
  14. // 1. the current session state is active; and
  15. // 2. the current profile is the primary one; and
  16. // 3. the target feature's discovery duration has never been recorded for the
  17. // current user on the current device.
  18. //
  19. // Only the discovery duration under an active session is counted. Also, the
  20. // time duration when the device is suspended is not counted into the feature
  21. // discovery time. The time spent in a different account from the one where the
  22. // feature usage observation starts is excluded from the total duration. For
  23. // example, if the user:
  24. // 1. spends A time in the primary user session,
  25. // 2. switches to a secondary user session for B time,
  26. // 3. switches back to the primary user session,
  27. // 4. discovers the new feature after C time.
  28. // In this case, the feature discovery time duration should be A + C.
  29. class ASH_PUBLIC_EXPORT FeatureDiscoveryDurationReporter {
  30. public:
  31. class ReporterObserver : public base::CheckedObserver {
  32. public:
  33. // Called when the reporter is ready to use.
  34. virtual void OnReporterActivated() = 0;
  35. };
  36. FeatureDiscoveryDurationReporter();
  37. FeatureDiscoveryDurationReporter(const FeatureDiscoveryDurationReporter&) =
  38. delete;
  39. FeatureDiscoveryDurationReporter& operator=(
  40. const FeatureDiscoveryDurationReporter&) = delete;
  41. virtual ~FeatureDiscoveryDurationReporter();
  42. static FeatureDiscoveryDurationReporter* GetInstance();
  43. // Activates the observation if the restrictions, which are introduced in the
  44. // class comment, are met.
  45. virtual void MaybeActivateObservation(
  46. feature_discovery::TrackableFeature feature) = 0;
  47. // Finishes the observation on the specified feature only when the observation
  48. // on this feature is in progress.
  49. virtual void MaybeFinishObservation(
  50. feature_discovery::TrackableFeature feature) = 0;
  51. virtual void AddObserver(ReporterObserver* observer) = 0;
  52. virtual void RemoveObserver(ReporterObserver* observer) = 0;
  53. };
  54. } // namespace ash
  55. #endif // ASH_PUBLIC_CPP_FEATURE_DISCOVERY_DURATION_REPORTER_H_