#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;
bool CompareHistoryMatch(const history::HistoryMatch& a,
const history::HistoryMatch& b) { … }
void SortAndDedupMatches(history::HistoryMatches* matches) { … }
double CalculateRelevanceUsingScoreBuckets(
const HUPScoringParams::ScoreBuckets& score_buckets,
const base::TimeDelta& time_since_last_visit,
int undecayed_relevance,
int undecayed_count) { … }
int CalculateRelevanceScoreUsingScoringParams(
const history::HistoryMatch& match,
int old_relevance,
const HUPScoringParams& scoring_params) { … }
void RecordAdditionalInfoFromUrlRow(const history::URLRow& info,
AutocompleteMatch* match) { … }
void CreateAndPromoteMatch(const history::URLRow& info,
const history::HistoryMatch& match_template,
history::HistoryMatches* matches,
bool promote) { … }
bool CanPromoteMatchForInlineAutocomplete(const history::HistoryMatch& match) { … }
GURL ConvertToHostOnly(const history::HistoryMatch& match,
const std::u16string& input) { … }
}
const int HistoryURLProvider::kScoreForBestInlineableResult = …;
const int HistoryURLProvider::kScoreForUnvisitedIntranetResult = …;
const int HistoryURLProvider::kScoreForWhatYouTypedResult = …;
const int HistoryURLProvider::kBaseScoreForNonInlineableResult = …;
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 { … }
HistoryURLProvider::~HistoryURLProvider() = default;
int HistoryURLProvider::CalculateRelevance(MatchType match_type,
int match_number) { … }
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) { … }