#include "components/history_clusters/core/history_clusters_service.h"
#include <algorithm>
#include <memory>
#include <string>
#include <utility>
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/i18n/case_conversion.h"
#include "base/json/values_util.h"
#include "base/metrics/histogram_functions.h"
#include "base/ranges/algorithm.h"
#include "base/strings/utf_string_conversions.h"
#include "base/system/sys_info.h"
#include "base/time/time.h"
#include "base/timer/elapsed_timer.h"
#include "base/timer/timer.h"
#include "base/values.h"
#include "components/history/core/browser/history_backend.h"
#include "components/history/core/browser/history_database.h"
#include "components/history/core/browser/history_db_task.h"
#include "components/history/core/browser/history_types.h"
#include "components/history_clusters/core/config.h"
#include "components/history_clusters/core/features.h"
#include "components/history_clusters/core/file_clustering_backend.h"
#include "components/history_clusters/core/history_clusters_debug_jsons.h"
#include "components/history_clusters/core/history_clusters_prefs.h"
#include "components/history_clusters/core/history_clusters_service_task_get_most_recent_clusters.h"
#include "components/history_clusters/core/history_clusters_service_task_get_most_recent_clusters_for_ui.h"
#include "components/history_clusters/core/history_clusters_service_task_update_cluster_triggerability.h"
#include "components/history_clusters/core/history_clusters_service_task_update_clusters.h"
#include "components/history_clusters/core/history_clusters_types.h"
#include "components/history_clusters/core/history_clusters_util.h"
#include "components/history_clusters/core/on_device_clustering_backend.h"
#include "components/optimization_guide/core/optimization_guide_decider.h"
#include "components/prefs/pref_service.h"
#include "components/site_engagement/core/site_engagement_score_provider.h"
namespace history_clusters {
namespace {
void RecordUpdateClustersLatencyHistogram(const std::string& histogram_name,
base::ElapsedTimer elapsed_timer) { … }
base::Value::Dict KeywordsCacheToDict(
HistoryClustersService::KeywordMap* keyword_map) { … }
HistoryClustersService::KeywordMap DictToKeywordsCache(
const base::Value::Dict* dict) { … }
constexpr base::TimeDelta kAllKeywordsCacheRefreshAge = …;
}
HistoryClustersService::HistoryClustersService(
const std::string& application_locale,
history::HistoryService* history_service,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
site_engagement::SiteEngagementScoreProvider* engagement_score_provider,
TemplateURLService* template_url_service,
optimization_guide::OptimizationGuideDecider* optimization_guide_decider,
PrefService* prefs)
: … { … }
HistoryClustersService::~HistoryClustersService() = default;
base::WeakPtr<HistoryClustersService> HistoryClustersService::GetWeakPtr() { … }
void HistoryClustersService::Shutdown() { … }
bool HistoryClustersService::IsJourneysEnabledAndVisible() const { … }
bool HistoryClustersService::IsJourneysImagesEnabled() { … }
void HistoryClustersService::AddObserver(Observer* obs) { … }
void HistoryClustersService::RemoveObserver(Observer* obs) { … }
bool HistoryClustersService::ShouldNotifyDebugMessage() const { … }
void HistoryClustersService::NotifyDebugMessage(
const std::string& message) const { … }
IncompleteVisitContextAnnotations&
HistoryClustersService::GetIncompleteVisitContextAnnotations(int64_t nav_id) { … }
IncompleteVisitContextAnnotations&
HistoryClustersService::GetOrCreateIncompleteVisitContextAnnotations(
int64_t nav_id) { … }
bool HistoryClustersService::HasIncompleteVisitContextAnnotations(
int64_t nav_id) { … }
void HistoryClustersService::CompleteVisitContextAnnotationsIfReady(
int64_t nav_id) { … }
std::unique_ptr<HistoryClustersServiceTask>
HistoryClustersService::QueryClusters(
ClusteringRequestSource clustering_request_source,
QueryClustersFilterParams filter_params,
base::Time begin_time,
QueryClustersContinuationParams continuation_params,
bool recluster,
QueryClustersCallback callback) { … }
void HistoryClustersService::UpdateClusters() { … }
std::optional<history::ClusterKeywordData>
HistoryClustersService::DoesQueryMatchAnyCluster(const std::string& query) { … }
void HistoryClustersService::ClearKeywordCache() { … }
void HistoryClustersService::PrintKeywordBagStateToLogMessage() const { … }
void HistoryClustersService::OnURLVisited(
history::HistoryService* history_service,
const history::URLRow& url_row,
const history::VisitRow& visit_row) { … }
void HistoryClustersService::OnHistoryDeletions(
history::HistoryService* history_service,
const history::DeletionInfo& deletion_info) { … }
void HistoryClustersService::StartKeywordCacheRefresh() { … }
void HistoryClustersService::PopulateClusterKeywordCache(
base::ElapsedTimer total_latency_timer,
base::Time begin_time,
std::unique_ptr<KeywordMap> keyword_accumulator,
KeywordMap* cache,
std::vector<history::Cluster> clusters,
QueryClustersContinuationParams continuation_params) { … }
void HistoryClustersService::LoadCachesFromPrefs() { … }
void HistoryClustersService::WriteShortCacheToPrefs() { … }
void HistoryClustersService::WriteAllCacheToPrefs() { … }
}