#include "components/browsing_topics/browsing_topics_calculator.h"
#include "base/containers/contains.h"
#include "base/metrics/histogram_functions.h"
#include "base/rand_util.h"
#include "base/ranges/algorithm.h"
#include "base/task/sequenced_task_runner.h"
#include "components/browsing_topics/annotator.h"
#include "components/browsing_topics/common/semantic_tree.h"
#include "components/browsing_topics/util.h"
#include "components/history/core/browser/history_service.h"
#include "components/privacy_sandbox/canonical_topic.h"
#include "components/privacy_sandbox/privacy_sandbox_settings.h"
#include "content/public/browser/browsing_topics_site_data_manager.h"
#include "services/metrics/public/cpp/ukm_builders.h"
#include "services/metrics/public/cpp/ukm_recorder.h"
#include "third_party/blink/public/common/features.h"
namespace browsing_topics {
namespace {
base::Time DeriveHistoryDataStartTime(
base::Time calculation_time,
const base::circular_deque<EpochTopics>& epochs,
base::Time data_accessible_since) { … }
base::Time DeriveApiUsageContextDataStartTime(
base::Time calculation_time,
const base::circular_deque<EpochTopics>& epochs,
base::Time data_accessible_since) { … }
void RecordCalculatorResultMetrics(
const EpochTopics& epoch_topics,
base::TimeDelta calculation_start_time_since_session_start,
int previous_timeout_count) { … }
void DeriveHostTopicsMapAndTopicHostsMap(
const std::vector<Annotation>& results,
std::map<HashedHost, std::set<Topic>>& host_topics_map,
std::map<Topic, std::set<HashedHost>>& topic_hosts_map) { … }
std::set<HashedDomain> GetTopicObservationDomains(
const Topic& topic,
const std::map<Topic, std::set<HashedHost>>& topic_hosts_map,
const std::map<HashedHost, std::vector<HashedDomain>>&
host_context_domains_map) { … }
}
BrowsingTopicsCalculator::BrowsingTopicsCalculator(
privacy_sandbox::PrivacySandboxSettings* privacy_sandbox_settings,
history::HistoryService* history_service,
content::BrowsingTopicsSiteDataManager* site_data_manager,
Annotator* annotator,
const base::circular_deque<EpochTopics>& epochs,
bool is_manually_triggered,
int previous_timeout_count,
base::Time session_start_time,
CalculateCompletedCallback callback)
: … { … }
BrowsingTopicsCalculator::~BrowsingTopicsCalculator() { … }
uint64_t BrowsingTopicsCalculator::GenerateRandUint64() { … }
void BrowsingTopicsCalculator::DeriveTopTopics(
const std::map<HashedHost, size_t>& history_hosts_count,
const std::map<HashedHost, std::set<Topic>>& host_topics_map,
std::vector<Topic>& top_topics,
size_t& padded_top_topics_start_index,
size_t& history_topics_count) { … }
void BrowsingTopicsCalculator::CheckCanCalculate() { … }
void BrowsingTopicsCalculator::OnGetRecentBrowsingTopicsApiUsagesCompleted(
browsing_topics::ApiUsageContextQueryResult result) { … }
void BrowsingTopicsCalculator::OnGetRecentlyVisitedURLsCompleted(
history::QueryResults results) { … }
void BrowsingTopicsCalculator::OnRequestModelCompleted(
std::vector<std::string> raw_hosts) { … }
void BrowsingTopicsCalculator::OnGetTopicsForHostsCompleted(
const std::vector<Annotation>& results) { … }
void BrowsingTopicsCalculator::OnCalculateCompleted(
EpochTopics epoch_topics) { … }
void BrowsingTopicsCalculator::OnCalculationHanging() { … }
}