#include "components/history_clusters/core/on_device_clustering_backend.h"
#include <algorithm>
#include <iterator>
#include <set>
#include "base/containers/flat_map.h"
#include "base/i18n/case_conversion.h"
#include "base/metrics/histogram_functions.h"
#include "base/strings/string_util.h"
#include "base/task/task_traits.h"
#include "base/task/thread_pool.h"
#include "base/timer/elapsed_timer.h"
#include "components/history/core/browser/history_types.h"
#include "components/history_clusters/core/cluster_finalizer.h"
#include "components/history_clusters/core/cluster_interaction_state_processor.h"
#include "components/history_clusters/core/cluster_processor.h"
#include "components/history_clusters/core/cluster_similarity_heuristics_processor.h"
#include "components/history_clusters/core/clusterer.h"
#include "components/history_clusters/core/config.h"
#include "components/history_clusters/core/content_visibility_cluster_finalizer.h"
#include "components/history_clusters/core/features.h"
#include "components/history_clusters/core/filter_cluster_processor.h"
#include "components/history_clusters/core/history_clusters_util.h"
#include "components/history_clusters/core/keyword_cluster_finalizer.h"
#include "components/history_clusters/core/label_cluster_finalizer.h"
#include "components/history_clusters/core/noisy_cluster_finalizer.h"
#include "components/history_clusters/core/on_device_clustering_features.h"
#include "components/history_clusters/core/on_device_clustering_util.h"
#include "components/history_clusters/core/ranking_cluster_finalizer.h"
#include "components/history_clusters/core/similar_visit_deduper_cluster_finalizer.h"
#include "components/history_clusters/core/single_visit_cluster_finalizer.h"
#include "components/optimization_guide/core/optimization_guide_decider.h"
#include "components/site_engagement/core/site_engagement_score_provider.h"
#include "components/url_formatter/url_formatter.h"
namespace history_clusters {
namespace {
void RecordBatchUpdateProcessingTime(base::TimeDelta time_delta) { … }
}
OnDeviceClusteringBackend::OnDeviceClusteringBackend(
site_engagement::SiteEngagementScoreProvider* engagement_score_provider,
optimization_guide::OptimizationGuideDecider* optimization_guide_decider)
: … { … }
OnDeviceClusteringBackend::~OnDeviceClusteringBackend() { … }
void OnDeviceClusteringBackend::GetClusters(
ClusteringRequestSource clustering_request_source,
ClustersCallback callback,
std::vector<history::AnnotatedVisit> visits,
bool requires_ui_and_triggerability) { … }
void OnDeviceClusteringBackend::GetClustersForUI(
ClusteringRequestSource clustering_request_source,
QueryClustersFilterParams filter_params,
ClustersCallback callback,
std::vector<history::Cluster> clusters) { … }
void OnDeviceClusteringBackend::GetClusterTriggerability(
ClustersCallback callback,
std::vector<history::Cluster> clusters) { … }
void OnDeviceClusteringBackend::ProcessVisits(
ClusteringRequestSource clustering_request_source,
std::vector<history::AnnotatedVisit> annotated_visits,
bool requires_ui_and_triggerability,
ClustersCallback callback) { … }
void OnDeviceClusteringBackend::OnAllVisitsFinishedProcessing(
ClusteringRequestSource clustering_request_source,
std::vector<history::ClusterVisit> cluster_visits,
bool requires_ui_and_triggerability,
ClustersCallback callback) { … }
void OnDeviceClusteringBackend::DispatchGetClustersForUIToBackgroundThread(
ClusteringRequestSource clustering_request_source,
QueryClustersFilterParams filter_params,
ClustersCallback callback,
std::vector<history::Cluster> clusters) { … }
void OnDeviceClusteringBackend::
DispatchGetClusterTriggerabilityToBackgroundThread(
ClustersCallback callback,
std::vector<history::Cluster> clusters) { … }
std::vector<history::Cluster>
OnDeviceClusteringBackend::ClusterVisitsOnBackgroundThread(
ClusteringRequestSource clustering_request_source,
bool engagement_score_provider_is_valid,
std::vector<history::ClusterVisit> visits,
bool requires_ui_and_triggerability) { … }
std::vector<history::Cluster>
OnDeviceClusteringBackend::GetClustersForUIOnBackgroundThread(
ClusteringRequestSource clustering_request_source,
QueryClustersFilterParams filter_params,
bool engagement_score_provider_is_valid,
std::vector<history::Cluster> clusters,
bool calculate_triggerability) { … }
std::vector<history::Cluster>
OnDeviceClusteringBackend::GetClusterTriggerabilityOnBackgroundThread(
bool engagement_score_provider_is_valid,
std::vector<history::Cluster> clusters,
bool from_ui) { … }
}