ukm_data_manager.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 COMPONENTS_SEGMENTATION_PLATFORM_INTERNAL_UKM_DATA_MANAGER_H_
  5. #define COMPONENTS_SEGMENTATION_PLATFORM_INTERNAL_UKM_DATA_MANAGER_H_
  6. #include "services/metrics/public/cpp/ukm_source_id.h"
  7. #include "services/metrics/public/mojom/ukm_interface.mojom.h"
  8. #include "url/gurl.h"
  9. namespace base {
  10. class FilePath;
  11. }
  12. namespace segmentation_platform {
  13. class UkmDatabase;
  14. class UrlSignalHandler;
  15. class UkmConfig;
  16. class UkmObserver;
  17. // Manages ownership and lifetime of all UKM related classes, like database and
  18. // observer. There is only one manager per browser process. Created before
  19. // profile initialization and destroyed after all profiles are destroyed. The
  20. // database, observer and signal handler can have different lifetimes, see
  21. // comments below.
  22. class UkmDataManager {
  23. public:
  24. UkmDataManager() = default;
  25. virtual ~UkmDataManager() = default;
  26. UkmDataManager(UkmDataManager&) = delete;
  27. UkmDataManager& operator=(UkmDataManager&) = delete;
  28. // Initializes UKM database and the observer of all UKM events.
  29. virtual void Initialize(const base::FilePath& database_path,
  30. UkmObserver* ukm_observer) = 0;
  31. // Returns true when UKM engine is usable. If false, then UKM based engine is
  32. // disabled and this class is a no-op. UkmObserver, UrlSignalHandler and
  33. // UkmDatabase are not created and are unusable when this method returns
  34. // false.
  35. virtual bool IsUkmEngineEnabled() = 0;
  36. // Can be called at any time, starts observing UKM with the given config. This
  37. // must be called after the Initialize() call.
  38. virtual void StartObservingUkm(const UkmConfig& config) = 0;
  39. // Pauses or resumes observation of UKM, can be called any time, irrespective
  40. // of UKM observer's lifetime, similar to StartObservingUkm().
  41. virtual void PauseOrResumeObservation(bool pause) = 0;
  42. // Get URL signal handler. The signal handler is safe to use as long as data
  43. // manager is alive, so until after all profiles are destroyed.
  44. virtual UrlSignalHandler* GetOrCreateUrlHandler() = 0;
  45. // Get UKM database. The database is safe to use as long as data manager is
  46. // alive, so until after all profiles are destroyed.
  47. virtual UkmDatabase* GetUkmDatabase() = 0;
  48. // Called when a new UKM entry is added.
  49. virtual void OnEntryAdded(ukm::mojom::UkmEntryPtr entry) = 0;
  50. // Called when UKM source URL is updated.
  51. virtual void OnUkmSourceUpdated(ukm::SourceId source_id,
  52. const std::vector<GURL>& urls) = 0;
  53. // Keep track of all the segmentation services that hold reference to this
  54. // object.
  55. virtual void AddRef() = 0;
  56. virtual void RemoveRef() = 0;
  57. };
  58. } // namespace segmentation_platform
  59. #endif // COMPONENTS_SEGMENTATION_PLATFORM_INTERNAL_UKM_DATA_MANAGER_H_