ukm_database_client.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 CHROME_BROWSER_SEGMENTATION_PLATFORM_UKM_DATABASE_CLIENT_H_
  5. #define CHROME_BROWSER_SEGMENTATION_PLATFORM_UKM_DATABASE_CLIENT_H_
  6. #include <memory>
  7. #include "base/files/file_path.h"
  8. #include "base/memory/raw_ptr.h"
  9. #include "base/no_destructor.h"
  10. namespace ukm {
  11. class UkmRecorderImpl;
  12. }
  13. namespace segmentation_platform {
  14. class UkmDataManager;
  15. class UkmObserver;
  16. // Provides UKM functionality to the segmentation platform service(s).
  17. class UkmDatabaseClient {
  18. public:
  19. static UkmDatabaseClient& GetInstance();
  20. UkmDatabaseClient(UkmDatabaseClient&) = delete;
  21. UkmDatabaseClient& operator=(UkmDatabaseClient&) = delete;
  22. void PreProfileInit();
  23. void PostMessageLoopRun();
  24. // UkmDataManager will be valid for the lifetime of all the profiles. It is
  25. // created before profiles are created at startup. It is safe to use this
  26. // pointer till ProfileManagerDestroying() is called.
  27. segmentation_platform::UkmDataManager* GetUkmDataManager();
  28. // UKM observer will use the test recorder to observe metrics.
  29. void set_ukm_recorder_for_testing(ukm::UkmRecorderImpl* ukm_recorder) {
  30. DCHECK(!ukm_observer_);
  31. ukm_recorder_for_testing_ = ukm_recorder;
  32. }
  33. UkmObserver* ukm_observer_for_testing() { return ukm_observer_.get(); }
  34. private:
  35. friend base::NoDestructor<UkmDatabaseClient>;
  36. UkmDatabaseClient();
  37. ~UkmDatabaseClient();
  38. raw_ptr<ukm::UkmRecorderImpl> ukm_recorder_for_testing_;
  39. std::unique_ptr<UkmObserver> ukm_observer_;
  40. std::unique_ptr<segmentation_platform::UkmDataManager> ukm_data_manager_;
  41. };
  42. } // namespace segmentation_platform
  43. #endif // CHROME_BROWSER_SEGMENTATION_PLATFORM_UKM_DATABASE_CLIENT_H_