chrome_browser_main_extra_parts_segmentation_platform.cc 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Copyright 2021 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. #include "chrome/browser/segmentation_platform/chrome_browser_main_extra_parts_segmentation_platform.h"
  5. #include "base/feature_list.h"
  6. #include "chrome/browser/browser_process.h"
  7. #include "chrome/browser/profiles/profile_manager.h"
  8. #include "chrome/browser/segmentation_platform/segmentation_platform_service_factory.h"
  9. #include "chrome/browser/segmentation_platform/ukm_database_client.h"
  10. #include "components/segmentation_platform/public/config.h"
  11. #include "components/segmentation_platform/public/features.h"
  12. #include "components/segmentation_platform/public/local_state_helper.h"
  13. #include "components/segmentation_platform/public/segmentation_platform_service.h"
  14. void ChromeBrowserMainExtraPartsSegmentationPlatform::PreCreateThreads() {
  15. segmentation_platform::LocalStateHelper::GetInstance().Initialize(
  16. g_browser_process->local_state());
  17. }
  18. void ChromeBrowserMainExtraPartsSegmentationPlatform::PreProfileInit() {
  19. segmentation_platform::UkmDatabaseClient::GetInstance().PreProfileInit();
  20. }
  21. void ChromeBrowserMainExtraPartsSegmentationPlatform::PostProfileInit(
  22. Profile* profile,
  23. bool is_initial_profile) {
  24. if (!profile || profile->IsOffTheRecord())
  25. return;
  26. // Always create SegmentationPlatformService when a new Profile is
  27. // initialized. This will trigger model downloads and feature storage, so when
  28. // the client requests segment the platform is ready with results.
  29. auto* service =
  30. segmentation_platform::SegmentationPlatformServiceFactory::GetForProfile(
  31. profile);
  32. // If dummy feature is enabled, make sure the platform triggers all selection
  33. // code paths and computes results.
  34. if (base::FeatureList::IsEnabled(
  35. segmentation_platform::features::kSegmentationPlatformDummyFeature)) {
  36. service->GetSelectedSegment(segmentation_platform::kDummySegmentationKey,
  37. base::DoNothing());
  38. }
  39. }
  40. void ChromeBrowserMainExtraPartsSegmentationPlatform::PostMainMessageLoopRun() {
  41. segmentation_platform::UkmDatabaseClient::GetInstance().PostMessageLoopRun();
  42. }