chromium/components/omnibox/browser/search_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/search_provider.h"

#include <stddef.h>

#include <algorithm>
#include <cmath>
#include <optional>
#include <utility>

#include "base/base64.h"
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/i18n/break_iterator.h"
#include "base/i18n/case_conversion.h"
#include "base/json/json_string_value_serializer.h"
#include "base/metrics/field_trial_params.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/user_metrics.h"
#include "base/rand_util.h"
#include "base/strings/escape.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/timer/elapsed_timer.h"
#include "base/trace_event/trace_event.h"
#include "components/history/core/browser/in_memory_database.h"
#include "components/history/core/browser/keyword_search_term.h"
#include "components/history/core/browser/keyword_search_term_util.h"
#include "components/omnibox/browser/autocomplete_provider_client.h"
#include "components/omnibox/browser/autocomplete_provider_listener.h"
#include "components/omnibox/browser/autocomplete_result.h"
#include "components/omnibox/browser/keyword_provider.h"
#include "components/omnibox/browser/omnibox_feature_configs.h"
#include "components/omnibox/browser/omnibox_field_trial.h"
#include "components/omnibox/browser/omnibox_triggered_feature_service.h"
#include "components/omnibox/browser/page_classification_functions.h"
#include "components/omnibox/browser/remote_suggestions_service.h"
#include "components/omnibox/browser/search_scoring_signals_annotator.h"
#include "components/omnibox/browser/suggestion_answer.h"
#include "components/omnibox/browser/url_prefix.h"
#include "components/omnibox/common/omnibox_features.h"
#include "components/search/search.h"
#include "components/search_engines/template_url_service.h"
#include "components/search_engines/template_url_starter_pack_data.h"
#include "components/strings/grit/components_strings.h"
#include "components/url_formatter/url_formatter.h"
#include "components/variations/net/variations_http_headers.h"
#include "net/base/load_flags.h"
#include "net/http/http_request_headers.h"
#include "net/traffic_annotation/network_traffic_annotation.h"
#include "services/network/public/cpp/resource_request.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "services/network/public/cpp/simple_url_loader.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
#include "third_party/metrics_proto/omnibox_event.pb.h"
#include "third_party/metrics_proto/omnibox_focus_type.pb.h"
#include "third_party/metrics_proto/omnibox_input_type.pb.h"
#include "third_party/omnibox_proto/navigational_intent.pb.h"
#include "ui/base/l10n/l10n_util.h"
#include "url/url_constants.h"
#include "url/url_util.h"

OmniboxEventProto;

// Helpers --------------------------------------------------------------------

namespace {

// Increments the appropriate event in the histogram by one.
void LogOmniboxSuggestRequest(RemoteRequestEvent request_event) {}

bool HasMultipleWords(const std::u16string& text) {}

}  // namespace

// SearchProvider::Providers --------------------------------------------------

SearchProvider::Providers::Providers(TemplateURLService* template_url_service)
    :{}

const TemplateURL* SearchProvider::Providers::GetDefaultProviderURL() const {}

const TemplateURL* SearchProvider::Providers::GetKeywordProviderURL() const {}

// SearchProvider::CompareScoredResults ---------------------------------------

class SearchProvider::CompareScoredResults {};

// SearchProvider -------------------------------------------------------------

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

void SearchProvider::RegisterDisplayedAnswers(
    const AutocompleteResult& result) {}

// static
int SearchProvider::CalculateRelevanceForKeywordVerbatim(
    metrics::OmniboxInputType type,
    bool allow_exact_keyword_match,
    bool prefer_keyword) {}

bool SearchProvider::CanSendCurrentPageURLInRequest(
    const GURL& current_page_url,
    metrics::OmniboxEventProto::PageClassification page_classification,
    const TemplateURL* template_url,
    const SearchTermsData& search_terms_data,
    const AutocompleteProviderClient* client) {}

SearchProvider::~SearchProvider() = default;

// static
void SearchProvider::UpdateOldResults(
    bool minimal_changes,
    SearchSuggestionParser::Results* results) {}

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

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

bool SearchProvider::ShouldAppendExtraParams(
    const SearchSuggestionParser::SuggestResult& result) const {}

void SearchProvider::RecordDeletionResult(bool success) {}

void SearchProvider::OnTemplateURLServiceChanged() {}

const TemplateURL* SearchProvider::GetTemplateURL(bool is_keyword) const {}

const AutocompleteInput SearchProvider::GetInput(bool is_keyword) const {}

void SearchProvider::OnURLLoadComplete(
    const network::SimpleURLLoader* source,
    const int response_code,
    std::unique_ptr<std::string> response_body) {}

void SearchProvider::StopSuggest() {}

void SearchProvider::ClearAllResults() {}

void SearchProvider::UpdateMatchContentsClass(
    const std::u16string& input_text,
    SearchSuggestionParser::Results* results) {}

void SearchProvider::SortResults(bool is_keyword,
                                 SearchSuggestionParser::Results* results) {}

void SearchProvider::LogLoadComplete(bool success, bool is_keyword) {}

void SearchProvider::UpdateMatches() {}

void SearchProvider::EnforceConstraints() {}

void SearchProvider::RecordTopSuggestion() {}

void SearchProvider::Run(bool query_is_private) {}

void SearchProvider::DoHistoryQuery(bool minimal_changes) {}

base::TimeDelta SearchProvider::GetSuggestQueryDelay() const {}

void SearchProvider::StartOrStopSuggestQuery(bool minimal_changes) {}

void SearchProvider::CancelLoader(
    std::unique_ptr<network::SimpleURLLoader>* loader) {}

bool SearchProvider::IsQuerySuitableForSuggest(bool* query_is_private) const {}

bool SearchProvider::IsQueryPotentiallyPrivate() const {}

void SearchProvider::UpdateAllOldResults(bool minimal_changes) {}

void SearchProvider::PersistTopSuggestions(
    SearchSuggestionParser::Results* results) {}

void SearchProvider::ApplyCalculatedSuggestRelevance(
    SearchSuggestionParser::SuggestResults* list) {}

void SearchProvider::ApplyCalculatedNavigationRelevance(
    SearchSuggestionParser::NavigationResults* list) {}

std::unique_ptr<network::SimpleURLLoader> SearchProvider::CreateSuggestLoader(
    const TemplateURL* template_url,
    const AutocompleteInput& input) {}

void SearchProvider::ConvertResultsToAutocompleteMatches() {}

void SearchProvider::RemoveExtraAnswers(ACMatches* matches) {}

void SearchProvider::DuplicateCardAnswer(ACMatches* matches) {}

bool SearchProvider::IsTopMatchSearchWithURLInput() const {}

void SearchProvider::AddNavigationResultsToMatches(
    const SearchSuggestionParser::NavigationResults& navigation_results,
    ACMatches* matches) {}

void SearchProvider::AddRawHistoryResultsToMap(bool is_keyword,
                                               int did_not_accept_suggestion,
                                               MatchMap* map) {}

void SearchProvider::AddTransformedHistoryResultsToMap(
    const SearchSuggestionParser::SuggestResults& transformed_results,
    int did_not_accept_suggestion,
    MatchMap* map) {}

SearchSuggestionParser::SuggestResults
SearchProvider::ScoreHistoryResultsHelper(const HistoryResults& results,
                                          bool base_prevent_inline_autocomplete,
                                          bool input_multiple_words,
                                          const std::u16string& input_text,
                                          bool is_keyword) {}

void SearchProvider::ScoreHistoryResults(
    const HistoryResults& results,
    bool is_keyword,
    SearchSuggestionParser::SuggestResults* scored_results) {}

void SearchProvider::AddSuggestResultsToMap(
    const SearchSuggestionParser::SuggestResults& results,
    MatchMap* map) {}

int SearchProvider::GetVerbatimRelevance(bool* relevance_from_server) const {}

bool SearchProvider::ShouldCurbDefaultSuggestions() const {}

int SearchProvider::CalculateRelevanceForVerbatim() const {}

int SearchProvider::CalculateRelevanceForVerbatimIgnoringKeywordModeState()
    const {}

int SearchProvider::GetKeywordVerbatimRelevance(
    bool* relevance_from_server) const {}

int SearchProvider::CalculateRelevanceForHistory(
    const base::Time& time,
    bool is_keyword,
    bool use_aggressive_method) const {}

AutocompleteMatch SearchProvider::NavigationToMatch(
    const SearchSuggestionParser::NavigationResult& navigation) {}

void SearchProvider::UpdateDone() {}

AnswersQueryData SearchProvider::FindAnswersPrefetchData() {}

void SearchProvider::PrefetchImages(SearchSuggestionParser::Results* results) {}