#include "components/omnibox/browser/url_index_private_data.h"
#include <stdint.h>
#include <algorithm>
#include <limits>
#include <map>
#include <memory>
#include <numeric>
#include <set>
#include <string>
#include <utility>
#include <vector>
#include "base/containers/flat_set.h"
#include "base/containers/stack.h"
#include "base/feature_list.h"
#include "base/i18n/case_conversion.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/stl_util.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
#include "base/trace_event/memory_usage_estimator.h"
#include "components/bookmarks/browser/bookmark_model.h"
#include "components/bookmarks/browser/bookmark_utils.h"
#include "components/history/core/browser/history_database.h"
#include "components/history/core/browser/history_db_task.h"
#include "components/history/core/browser/history_service.h"
#include "components/omnibox/browser/in_memory_url_index.h"
#include "components/omnibox/browser/omnibox_field_trial.h"
#include "components/omnibox/browser/omnibox_triggered_feature_service.h"
#include "components/omnibox/browser/tailored_word_break_iterator.h"
#include "components/omnibox/common/omnibox_features.h"
#include "components/search_engines/template_url_service.h"
#include "third_party/metrics_proto/omnibox_event.pb.h"
namespace {
GURL ClearUsernameAndPassword(const GURL& url) { … }
bool LengthGreater(const std::u16string& string_a,
const std::u16string& string_b) { … }
}
class UpdateRecentVisitsFromHistoryDBTask : public history::HistoryDBTask { … };
UpdateRecentVisitsFromHistoryDBTask::UpdateRecentVisitsFromHistoryDBTask(
URLIndexPrivateData* private_data,
history::URLID url_id)
: … { … }
bool UpdateRecentVisitsFromHistoryDBTask::RunOnDBThread(
history::HistoryBackend* backend,
history::HistoryDatabase* db) { … }
void UpdateRecentVisitsFromHistoryDBTask::DoneRunOnMainThread() { … }
UpdateRecentVisitsFromHistoryDBTask::~UpdateRecentVisitsFromHistoryDBTask() =
default;
constexpr size_t URLIndexPrivateData::kMaxVisitsToStoreInCache;
URLIndexPrivateData::URLIndexPrivateData() = default;
ScoredHistoryMatches URLIndexPrivateData::HistoryItemsForTerms(
std::u16string original_search_string,
size_t cursor_position,
const std::string& host_filter,
size_t max_matches,
bookmarks::BookmarkModel* bookmark_model,
TemplateURLService* template_url_service,
OmniboxTriggeredFeatureService* triggered_feature_service) { … }
const std::vector<std::string>& URLIndexPrivateData::HighlyVisitedHosts()
const { … }
bool URLIndexPrivateData::UpdateURL(
history::HistoryService* history_service,
const history::URLRow& row,
const std::set<std::string>& scheme_allowlist,
base::CancelableTaskTracker* tracker) { … }
void URLIndexPrivateData::UpdateRecentVisits(
history::URLID url_id,
const history::VisitVector& recent_visits) { … }
void URLIndexPrivateData::ScheduleUpdateRecentVisits(
history::HistoryService* history_service,
history::URLID url_id,
base::CancelableTaskTracker* tracker) { … }
bool URLIndexPrivateData::DeleteURL(const GURL& url) { … }
scoped_refptr<URLIndexPrivateData> URLIndexPrivateData::RebuildFromHistory(
history::HistoryDatabase* history_db,
const std::set<std::string>& scheme_allowlist) { … }
scoped_refptr<URLIndexPrivateData> URLIndexPrivateData::Duplicate() const { … }
bool URLIndexPrivateData::Empty() const { … }
void URLIndexPrivateData::Clear() { … }
size_t URLIndexPrivateData::EstimateMemoryUsage() const { … }
URLIndexPrivateData::~URLIndexPrivateData() = default;
HistoryIDVector URLIndexPrivateData::HistoryIDsFromWords(
const String16Vector& unsorted_words) { … }
bool URLIndexPrivateData::TrimHistoryIdsPool(
HistoryIDVector* history_ids) const { … }
HistoryIDSet URLIndexPrivateData::HistoryIDsForTerm(
const std::u16string& term) { … }
WordIDSet URLIndexPrivateData::WordIDSetForTermChars(
const Char16Set& term_chars) { … }
void URLIndexPrivateData::HistoryIdsToScoredMatches(
HistoryIDVector history_ids,
const std::u16string& lower_raw_string,
const std::string& host_filter,
const TemplateURLService* template_url_service,
bookmarks::BookmarkModel* bookmark_model,
ScoredHistoryMatches* scored_items,
OmniboxTriggeredFeatureService* triggered_feature_service) const { … }
void URLIndexPrivateData::CalculateWordStartsOffsets(
const String16Vector& lower_terms,
WordStarts* lower_terms_to_word_starts_offsets) { … }
bool URLIndexPrivateData::IndexRow(
history::HistoryDatabase* history_db,
history::HistoryService* history_service,
const history::URLRow& row,
const std::set<std::string>& scheme_allowlist,
base::CancelableTaskTracker* tracker) { … }
void URLIndexPrivateData::AddRowWordsToIndex(const history::URLRow& row,
RowWordStarts* word_starts) { … }
void URLIndexPrivateData::AddWordToIndex(const std::u16string& term,
HistoryID history_id) { … }
WordID URLIndexPrivateData::AddNewWordToWordList(const std::u16string& term) { … }
void URLIndexPrivateData::RemoveRowFromIndex(const history::URLRow& row) { … }
void URLIndexPrivateData::RemoveRowWordsFromIndex(const history::URLRow& row) { … }
void URLIndexPrivateData::ResetSearchTermCache() { … }
bool URLIndexPrivateData::URLSchemeIsAllowlisted(
const GURL& gurl,
const std::set<std::string>& allowlist) { … }
bool URLIndexPrivateData::ShouldExclude(
const HistoryID history_id,
const std::string& host_filter,
const TemplateURLService* template_url_service) const { … }
URLIndexPrivateData::SearchTermCacheItem::SearchTermCacheItem(
const WordIDSet& word_id_set,
const HistoryIDSet& history_id_set)
: … { … }
URLIndexPrivateData::SearchTermCacheItem::SearchTermCacheItem() : … { … }
URLIndexPrivateData::SearchTermCacheItem::SearchTermCacheItem(
const SearchTermCacheItem& other) = default;
size_t URLIndexPrivateData::SearchTermCacheItem::EstimateMemoryUsage() const { … }
std::pair<String16Vector, WordStarts>
URLIndexPrivateData::GetTermsAndWordStartsOffsets(
const std::u16string& lower_raw_string) { … }
URLIndexPrivateData::SearchTermCacheItem::~SearchTermCacheItem() = default;
URLIndexPrivateData::HistoryItemFactorGreater::HistoryItemFactorGreater(
const HistoryInfoMap& history_info_map)
: … { … }
URLIndexPrivateData::HistoryItemFactorGreater::~HistoryItemFactorGreater() =
default;
bool URLIndexPrivateData::HistoryItemFactorGreater::operator()(
const HistoryID h1,
const HistoryID h2) { … }
bool URLIndexPrivateData::HostInfo::IsHighlyVisited() const { … }
void URLIndexPrivateData::HostInfo::AddUrl(const history::URLRow& row) { … }