chromium/components/omnibox/browser/history_url_provider.cc

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

#include "components/omnibox/browser/history_url_provider.h"

#include <algorithm>
#include <memory>
#include <string>
#include <utility>

#include "base/command_line.h"
#include "base/containers/adapters.h"
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/location.h"
#include "base/memory/raw_ptr.h"
#include "base/metrics/histogram_macros.h"
#include "base/not_fatal_until.h"
#include "base/ranges/algorithm.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/single_thread_task_runner.h"
#include "base/time/time.h"
#include "base/trace_event/memory_usage_estimator.h"
#include "base/trace_event/trace_event.h"
#include "components/bookmarks/browser/bookmark_utils.h"
#include "components/history/core/browser/history_backend.h"
#include "components/history/core/browser/history_database.h"
#include "components/history/core/browser/history_service.h"
#include "components/history/core/browser/history_types.h"
#include "components/omnibox/browser/autocomplete_match.h"
#include "components/omnibox/browser/autocomplete_match_classification.h"
#include "components/omnibox/browser/autocomplete_provider.h"
#include "components/omnibox/browser/autocomplete_provider_listener.h"
#include "components/omnibox/browser/autocomplete_result.h"
#include "components/omnibox/browser/autocomplete_scoring_signals_annotator.h"
#include "components/omnibox/browser/history_provider.h"
#include "components/omnibox/browser/in_memory_url_index_types.h"
#include "components/omnibox/browser/keyword_provider.h"
#include "components/omnibox/browser/omnibox_field_trial.h"
#include "components/omnibox/browser/url_prefix.h"
#include "components/omnibox/browser/verbatim_match.h"
#include "components/prefs/pref_service.h"
#include "components/search_engines/search_terms_data.h"
#include "components/search_engines/template_url_service.h"
#include "components/url_formatter/url_fixer.h"
#include "components/url_formatter/url_formatter.h"
#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
#include "third_party/metrics_proto/omnibox_focus_type.pb.h"
#include "third_party/metrics_proto/omnibox_input_type.pb.h"
#include "third_party/metrics_proto/omnibox_scoring_signals.pb.h"
#include "ui/base/page_transition_types.h"
#include "url/gurl.h"
#include "url/third_party/mozilla/url_parse.h"
#include "url/url_util.h"

namespace {

ScoringSignals;

// Acts like the > operator for URLInfo classes.
bool CompareHistoryMatch(const history::HistoryMatch& a,
                         const history::HistoryMatch& b) {}

// Sorts and dedups the given list of matches.
void SortAndDedupMatches(history::HistoryMatches* matches) {}

// Calculates a new relevance score applying half-life time decaying to `count`
// using `time_since_last_visit` and `score_buckets`.  This function will never
// return a score higher than `undecayed_relevance`; in other words, it can only
// demote the old score.
double CalculateRelevanceUsingScoreBuckets(
    const HUPScoringParams::ScoreBuckets& score_buckets,
    const base::TimeDelta& time_since_last_visit,
    int undecayed_relevance,
    int undecayed_count) {}

// Returns a new relevance score for the given `match` based on the
// `old_relevance` score and `scoring_params`.  The new relevance score is
// guaranteed to be less than or equal to `old_relevance`.  In other words, this
// function can only demote a score, never boost it.  Returns `old_relevance` if
// experimental scoring is disabled.
int CalculateRelevanceScoreUsingScoringParams(
    const history::HistoryMatch& match,
    int old_relevance,
    const HUPScoringParams& scoring_params) {}

// Extracts typed_count, visit_count, and last_visited time from the URLRow and
// puts them in the additional info field of the `match` for display in
// about:omnibox.
void RecordAdditionalInfoFromUrlRow(const history::URLRow& info,
                                    AutocompleteMatch* match) {}

// Ensures that `matches` contains an entry for `info`, creating a new such
// entry if necessary (using `match_template` to get all the other match data).
//
// If `promote` is true, this also ensures the entry is the first element in
// `matches`, moving or adding it to the front as appropriate.  When `promote`
// is false, existing matches are left in place, and newly added matches are
// placed at the back.
void CreateAndPromoteMatch(const history::URLRow& info,
                           const history::HistoryMatch& match_template,
                           history::HistoryMatches* matches,
                           bool promote) {}

// Returns whether `match` is suitable for inline autocompletion.
bool CanPromoteMatchForInlineAutocomplete(const history::HistoryMatch& match) {}

// Given the user's `input` and a `match` created from it, reduce the match's
// URL to just a host.  If this host still matches the user input, return it.
// Returns the empty URL on failure.
GURL ConvertToHostOnly(const history::HistoryMatch& match,
                       const std::u16string& input) {}

}  // namespace

// -----------------------------------------------------------------
// HistoryURLProvider

// These ugly magic numbers will go away once we switch all scoring
// behavior (including URL-what-you-typed) to HistoryQuick provider.
const int HistoryURLProvider::kScoreForBestInlineableResult =;
const int HistoryURLProvider::kScoreForUnvisitedIntranetResult =;
const int HistoryURLProvider::kScoreForWhatYouTypedResult =;
const int HistoryURLProvider::kBaseScoreForNonInlineableResult =;

// VisitClassifier is used to classify the type of visit to a particular url.
class HistoryURLProvider::VisitClassifier {};

HistoryURLProvider::VisitClassifier::VisitClassifier(
    HistoryURLProvider* provider,
    const AutocompleteInput& input,
    history::URLDatabase* db)
    :{}

HistoryURLProviderParams::HistoryURLProviderParams(
    const AutocompleteInput& input,
    const AutocompleteInput& input_before_fixup,
    bool trim_http,
    const AutocompleteMatch& what_you_typed_match,
    const TemplateURL* default_search_provider,
    const SearchTermsData* search_terms_data,
    bool allow_deleting_browser_history,
    const TemplateURL* starter_pack_engine)
    :{}

HistoryURLProviderParams::~HistoryURLProviderParams() = default;

size_t HistoryURLProviderParams::EstimateMemoryUsage() const {}

HistoryURLProvider::HistoryURLProvider(AutocompleteProviderClient* client,
                                       AutocompleteProviderListener* listener)
    :{}

void HistoryURLProvider::Start(const AutocompleteInput& input,
                               bool minimal_changes) {}

void HistoryURLProvider::Stop(bool clear_cached_results,
                              bool due_to_user_inactivity) {}

size_t HistoryURLProvider::EstimateMemoryUsage() const {}

// Note: This object can get leaked on shutdown if there are pending
// requests on the database (which hold a reference to us). Normally, these
// messages get flushed for each thread. We do a round trip from main, to
// history, back to main while holding a reference. If the main thread
// completes before the history thread, the message to delegate back to the
// main thread will not run and the reference will leak. Therefore, don't do
// anything on destruction.
HistoryURLProvider::~HistoryURLProvider() = default;

// static
int HistoryURLProvider::CalculateRelevance(MatchType match_type,
                                           int match_number) {}

// static
ACMatchClassifications HistoryURLProvider::ClassifyDescription(
    const std::u16string& input_text,
    const std::u16string& description) {}

void HistoryURLProvider::ExecuteWithDB(HistoryURLProviderParams* params,
                                       history::HistoryBackend* backend,
                                       history::URLDatabase* db) {}

void HistoryURLProvider::DoAutocomplete(history::HistoryBackend* backend,
                                        history::URLDatabase* db,
                                        HistoryURLProviderParams* params) {}

void HistoryURLProvider::PromoteMatchesIfNecessary(
    const HistoryURLProviderParams& params) {}

void HistoryURLProvider::QueryComplete(
    HistoryURLProviderParams* params_gets_deleted) {}

bool HistoryURLProvider::FixupExactSuggestion(
    history::URLDatabase* db,
    const VisitClassifier& classifier,
    HistoryURLProviderParams* params) const {}

GURL HistoryURLProvider::AsKnownIntranetURL(
    history::URLDatabase* db,
    const AutocompleteInput& input) const {}

bool HistoryURLProvider::PromoteOrCreateShorterSuggestion(
    history::URLDatabase* db,
    HistoryURLProviderParams* params) {}

void HistoryURLProvider::CullPoorMatches(
    HistoryURLProviderParams* params) const {}

void HistoryURLProvider::CullRedirects(history::HistoryBackend* backend,
                                       history::HistoryMatches* matches,
                                       size_t max_results) const {}

size_t HistoryURLProvider::RemoveSubsequentMatchesOf(
    history::HistoryMatches* matches,
    size_t source_index,
    const std::vector<GURL>& remove) const {}

AutocompleteMatch HistoryURLProvider::HistoryMatchToACMatch(
    const HistoryURLProviderParams& params,
    size_t match_number,
    int relevance,
    bool populate_scoring_signals) {}