chromium/components/visited_url_ranking/public/url_visit_util.h

// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_VISITED_URL_RANKING_PUBLIC_URL_VISIT_UTIL_H_
#define COMPONENTS_VISITED_URL_RANKING_PUBLIC_URL_VISIT_UTIL_H_

#include <array>
#include <string_view>

#include "base/containers/fixed_flat_set.h"
#include "components/segmentation_platform/public/input_context.h"
#include "components/visited_url_ranking/public/fetch_result.h"
#include "components/visited_url_ranking/public/url_visit_schema.h"
#include "url/gurl.h"

namespace url_deduplication {
class URLDeduplicationHelper;
}  // namespace url_deduplication

namespace visited_url_ranking {

// TODO(crbug.com/330580421): Remove/replace the category blocklist array
// specified in `modules_util.h` with the one below.
inline constexpr auto kBlocklistedCategories =;

// For Android, this set should be consistent with sDefaultAppBlocklist in
// TabResumptionModuleUtils.java.
inline constexpr auto kDefaultAppBlocklist =;

std::unique_ptr<url_deduplication::URLDeduplicationHelper>
CreateDefaultURLDeduplicationHelper();

// Generates an identifier for the given URL leveraged for merging and
// deduplication of similar URLs.
URLMergeKey ComputeURLMergeKey(
    const GURL& url,
    const std::u16string& title,
    url_deduplication::URLDeduplicationHelper* deduplication_helper);

// Generates an input context from a given `URLVisitAggregate` object given a
// schema definition.
scoped_refptr<segmentation_platform::InputContext> AsInputContext(
    const std::array<FieldSchema, kNumInputs>& fields_schema,
    const URLVisitAggregate& url_visit_aggregate);

// Returns tab data if it exists for a `URLVisitAggregate`.
const URLVisitAggregate::TabData* GetTabDataIfExists(
    const URLVisitAggregate& url_visit_aggregate);

// Returns a tab if it exists for a `URLVisitAggregate`.
const URLVisitAggregate::Tab* GetTabIfExists(
    const URLVisitAggregate& url_visit_aggregate);

// Returns a history entry if it exists for a `URLVisitAggregate`.
const history::AnnotatedVisit* GetHistoryEntryVisitIfExists(
    const URLVisitAggregate& url_visit_aggregate);

// Returns the highest priority decorator for a `URLVisitAggregate`.
const Decoration& GetMostRelevantDecoration(
    const URLVisitAggregate& url_visit_aggregate);

}  // namespace visited_url_ranking

#endif  // COMPONENTS_VISITED_URL_RANKING_PUBLIC_URL_VISIT_UTIL_H_