noisy_cluster_finalizer.cc 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637
  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 "components/history_clusters/core/noisy_cluster_finalizer.h"
  5. #include "components/history_clusters/core/cluster_metrics_utils.h"
  6. #include "components/history_clusters/core/config.h"
  7. #include "components/history_clusters/core/on_device_clustering_features.h"
  8. #include "components/history_clusters/core/on_device_clustering_util.h"
  9. namespace history_clusters {
  10. NoisyClusterFinalizer::NoisyClusterFinalizer() = default;
  11. NoisyClusterFinalizer::~NoisyClusterFinalizer() = default;
  12. void NoisyClusterFinalizer::FinalizeCluster(history::Cluster& cluster) {
  13. size_t interesting_visit_cnt = 0;
  14. ScopedFilterClusterMetricsRecorder metrics_recorder("NoisyCluster");
  15. for (const auto& visit : cluster.visits) {
  16. if (!IsNoisyVisit(visit)) {
  17. // Use the canonical visit's noisiness for all its duplicates too.
  18. interesting_visit_cnt += 1 + visit.duplicate_visits.size();
  19. }
  20. if (interesting_visit_cnt >=
  21. GetConfig().number_interesting_visits_filter_threshold) {
  22. return;
  23. }
  24. }
  25. // If we check all the visits in the cluster and all have high engagement
  26. // scores, then its probably not interesting so we can hide it.
  27. cluster.should_show_on_prominent_ui_surfaces = false;
  28. metrics_recorder.set_was_filtered(true);
  29. }
  30. } // namespace history_clusters