#include "components/visited_url_ranking/internal/visited_url_ranking_service_impl.h"
#include <array>
#include <cmath>
#include <map>
#include <memory>
#include <queue>
#include <string>
#include <utility>
#include <variant>
#include <vector>
#include "base/barrier_callback.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/location.h"
#include "base/logging.h"
#include "base/memory/scoped_refptr.h"
#include "base/metrics/field_trial_params.h"
#include "base/metrics/histogram_functions.h"
#include "base/rand_util.h"
#include "base/strings/stringprintf.h"
#include "base/task/sequenced_task_runner.h"
#include "base/time/time.h"
#include "components/history/core/browser/history_service.h"
#include "components/segmentation_platform/public/features.h"
#include "components/segmentation_platform/public/input_context.h"
#include "components/segmentation_platform/public/prediction_options.h"
#include "components/segmentation_platform/public/proto/model_metadata.pb.h"
#include "components/segmentation_platform/public/result.h"
#include "components/segmentation_platform/public/segmentation_platform_service.h"
#include "components/segmentation_platform/public/types/processed_value.h"
#include "components/strings/grit/components_strings.h"
#include "components/sync_sessions/session_sync_service.h"
#include "components/url_deduplication/url_deduplication_helper.h"
#include "components/visited_url_ranking/internal/history_url_visit_data_fetcher.h"
#include "components/visited_url_ranking/internal/session_url_visit_data_fetcher.h"
#include "components/visited_url_ranking/public/decoration.h"
#include "components/visited_url_ranking/public/features.h"
#include "components/visited_url_ranking/public/fetch_options.h"
#include "components/visited_url_ranking/public/fetch_result.h"
#include "components/visited_url_ranking/public/fetcher_config.h"
#include "components/visited_url_ranking/public/url_visit.h"
#include "components/visited_url_ranking/public/url_visit_aggregates_transformer.h"
#include "components/visited_url_ranking/public/url_visit_schema.h"
#include "components/visited_url_ranking/public/url_visit_util.h"
#include "components/visited_url_ranking/public/visited_url_ranking_service.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/l10n/time_format.h"
AnnotatedNumericResult;
InputContext;
PredictionOptions;
PredictionStatus;
ProcessedValue;
URLVisit;
namespace visited_url_ranking {
namespace {
constexpr int kSeenRecordsSamplingRate = …;
const char* EventNameForAction(ScoredURLUserAction action) { … }
const char* URLVisitAggregatesTransformTypeName(
URLVisitAggregatesTransformType type) { … }
const char* URLVisitAggregatesFetcherName(Fetcher fetcher) { … }
std::vector<URLVisitAggregate> ComputeURLVisitAggregates(
std::vector<std::pair<Fetcher, FetchResult>> fetcher_results) { … }
void SortScoredAggregatesAndCallback(
std::vector<URLVisitAggregate> scored_visits,
VisitedURLRankingService::RankURLVisitAggregatesCallback callback) { … }
std::u16string FormatRelativeTime(const base::Time& time) { … }
std::u16string GetStringForDecoration(DecorationType type,
bool visited_recently = false) { … }
void AddMostRecentDecoration(URLVisitAggregate& url_visit_aggregate,
URLVisitAggregate* curr_most_recent_aggregate,
bool last_visit) { … }
void AddFrequentlyVisitedDecoration(URLVisitAggregate& url_visit_aggregate) { … }
void AddFrequentlyVisitedAtTimeDecoration(
URLVisitAggregate& url_visit_aggregate) { … }
void AddVisitedXAgoDecoration(URLVisitAggregate& url_visit_aggregate) { … }
}
VisitedURLRankingServiceImpl::VisitedURLRankingServiceImpl(
segmentation_platform::SegmentationPlatformService*
segmentation_platform_service,
std::map<Fetcher, std::unique_ptr<URLVisitDataFetcher>> data_fetchers,
std::map<URLVisitAggregatesTransformType,
std::unique_ptr<URLVisitAggregatesTransformer>> transformers,
std::unique_ptr<url_deduplication::URLDeduplicationHelper>
deduplication_helper)
: … { … }
VisitedURLRankingServiceImpl::~VisitedURLRankingServiceImpl() = default;
void VisitedURLRankingServiceImpl::FetchURLVisitAggregates(
const FetchOptions& options,
GetURLVisitAggregatesCallback callback) { … }
void VisitedURLRankingServiceImpl::RankURLVisitAggregates(
const Config& config,
std::vector<URLVisitAggregate> visit_aggregates,
RankURLVisitAggregatesCallback callback) { … }
void VisitedURLRankingServiceImpl::DecorateURLVisitAggregates(
const Config& config,
std::vector<URLVisitAggregate> visit_aggregates,
DecorateURLVisitAggregatesCallback callback) { … }
void VisitedURLRankingServiceImpl::RecordAction(
ScoredURLUserAction action,
const std::string& visit_id,
segmentation_platform::TrainingRequestId visit_request_id) { … }
void VisitedURLRankingServiceImpl::TriggerTrainingData(
ScoredURLUserAction action,
const std::string& visit_id,
segmentation_platform::TrainingRequestId visit_request_id) { … }
void VisitedURLRankingServiceImpl::MergeVisitsAndCallback(
GetURLVisitAggregatesCallback callback,
const FetchOptions& options,
const std::vector<URLVisitAggregatesTransformType>& ordered_transforms,
std::vector<std::pair<Fetcher, FetchResult>> fetcher_results) { … }
void VisitedURLRankingServiceImpl::TransformVisitsAndCallback(
GetURLVisitAggregatesCallback callback,
const FetchOptions& options,
std::queue<URLVisitAggregatesTransformType> transform_type_queue,
URLVisitAggregatesTransformType transform_type,
size_t previous_aggregates_count,
base::Time start_time,
URLVisitAggregatesTransformer::Status status,
std::vector<URLVisitAggregate> aggregates) { … }
void VisitedURLRankingServiceImpl::GetNextResult(
const std::string& segmentation_key,
std::deque<URLVisitAggregate> visit_aggregates,
std::vector<URLVisitAggregate> scored_visits,
RankURLVisitAggregatesCallback callback) { … }
void VisitedURLRankingServiceImpl::OnGetResult(
const std::string& segmentation_key,
std::deque<URLVisitAggregate> visit_aggregates,
std::vector<URLVisitAggregate> scored_visits,
RankURLVisitAggregatesCallback callback,
const AnnotatedNumericResult& result) { … }
}