chromium/components/history/core/browser/history_types.h

// Copyright 2014 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_HISTORY_CORE_BROWSER_HISTORY_TYPES_H_
#define COMPONENTS_HISTORY_CORE_BROWSER_HISTORY_TYPES_H_

#include <stddef.h>
#include <stdint.h>

#include <map>
#include <optional>
#include <set>
#include <string>
#include <utility>
#include <vector>

#include "base/containers/flat_map.h"
#include "base/functional/callback_forward.h"
#include "base/time/time.h"
#include "components/favicon_base/favicon_types.h"
#include "components/history/core/browser/history_context.h"
#include "components/history/core/browser/keyword_search_term.h"
#include "components/history/core/browser/url_row.h"
#include "components/query_parser/query_parser.h"
#include "components/query_parser/snippet.h"
#include "components/sessions/core/session_id.h"
#include "components/sync_device_info/device_info.h"
#include "third_party/abseil-cpp/absl/container/inlined_vector.h"
#include "ui/base/page_transition_types.h"
#include "url/gurl.h"

namespace history {

class PageUsageData;

// Container for a list of URLs.
RedirectList;

SegmentID;  // URL segments for the most visited view.

// The enumeration of all possible sources of visits is listed below.
// The source will be propagated along with a URL or a visit item
// and eventually be stored in the history database,
// visit_source table specifically.
// Different from page transition types, they describe the origins of visits.
// (Warning): Please don't change any existing values while it is ok to add
// new values when needed.
enum VisitSource {};

// Corresponds to the "id" column of the "visits" SQL table.
VisitID;
// `kInvalidVisitID` is 0 because SQL AUTOINCREMENT's very first row has
// "id" == 1. Therefore any 0 VisitID is a sentinel null-like value.
constexpr VisitID kInvalidVisitID =;
// Corresponds to the "id" column of the "visited_links" SQL table.
VisitedLinkID;
// `kInvalidVisitedLinkID` is 0 because SQL AUTOINCREMENT's very first row has
// "id" == 1. Therefore any 0 VisitedLinkID is a sentinel null-like value.
constexpr VisitedLinkID kInvalidVisitedLinkID =;

// Structure to hold the mapping between each visit's id and its source.
VisitSourceMap;

// Constant used to represent that no app_id is used for matching.
inline constexpr std::optional<std::string> kNoAppIdFilter =;

// VisitRow -------------------------------------------------------------------

// Holds all information associated with a specific visit. A visit holds time
// and referrer information for one time a URL is visited.
class VisitRow {};

// We pass around vectors of visits a lot
VisitVector;

// The basic information associated with a visit (timestamp, type of visit),
// used by HistoryBackend::AddVisits() to create new visits for a URL.
VisitInfo;

// Specifies the possible reasons a visit (or its annotations) can get updated.
// Used by HistoryBackendNotifier::NotifyVisitUpdated() and
// HistoryBackendObserver::OnVisitUpdated().
// Only used internally and in memory (not persisted), so can be freely changed.
enum class VisitUpdateReason {};

// VisitedLinkRow --------------------------------------------------------------
// Holds all information globally associated with one visited link (one row in
// the VisitedLinkDatabase).
//
// The VisitedLinkDatabase contains the following fields:
struct VisitedLinkRow {};
VisitedLinkRows;

// QueryResults ----------------------------------------------------------------

// Encapsulates the results of a history query. It supports an ordered list of
// URLResult objects, plus an efficient way of looking up the index of each time
// a given URL appears in those results.
class QueryResults {};

// QueryOptions ----------------------------------------------------------------

struct QueryOptions {};

// QueryURLResult -------------------------------------------------------------

// QueryURLResult encapsulates the result of a call to
// `HistoryBackend::QueryURL()` or
// `HistoryBackend::GetMostRecentVisitsForGurl()`.
struct QueryURLResult {};

// VisibleVisitCountToHostResult ----------------------------------------------

// VisibleVisitCountToHostResult encapsulates the result of a call to
// HistoryBackend::GetVisibleVisitCountToHost.
struct VisibleVisitCountToHostResult {};

// MostVisitedURL --------------------------------------------------------------

// Holds the information for a Most Visited page.
struct MostVisitedURL {};

// FilteredURL -----------------------------------------------------------------

// Holds the per-URL information of the filtered url query.
struct FilteredURL {};

// GetAllAppIdsResult ----------------------------------------------------

// GetAllAppIdsResult encapsulates a list of all app IDs found in the
// database entries.
struct GetAllAppIdsResult {};

// DomainsVisitedResult --------------------------------------------------

// DomainsVisitedResult encapsulates two lists of domains visited locally
// and synced.
struct DomainsVisitedResult {};

// Opener ---------------------------------------------------------------------

// Contains the information required to determine the VisitID of an opening
// visit.
struct Opener {};

// TopSites -------------------------------------------------------------------

MostVisitedURLList;
KeywordSearchTermVisitList;
FilteredURLList;

struct MostVisitedURLWithRank {};

MostVisitedURLWithRankList;

struct TopSitesDelta {};

// Map from origins to a count of matching URLs and the last visited time to any
// URL under that origin.
OriginCountAndLastVisitMap;

// Segments -------------------------------------------------------------------

// Contains device information (i.e. OS Type, Form Factor) for all syncing
// devices (including the local device). Devices are identified by their
// Originator Cache GUID. Has the following shape:
//
// originator_cache_guid : { OsType, FormFactor }
SyncDeviceInfoMap;

// Statistics -----------------------------------------------------------------

// HistoryCountResult encapsulates the result of a call to
// HistoryBackend::GetHistoryCount or
// HistoryBackend::CountUniqueHostsVisitedLastMonth.
struct HistoryCountResult {};

// DomainDiversity  -----------------------------------------------------------
struct DomainMetricCountType {};

// DomainMetricSet represents a set of 1-day, 7-day and 28-day domain visit
// counts whose spanning periods all end at the same time.
struct DomainMetricSet {};

// DomainDiversityResults is a collection of DomainMetricSet's computed for
// a continuous range of end dates. Typically, each DomainMetricSet holds a
// metric set whose 1-day, 7-day and 28-day spanning periods all end at one
// unique midnight in that date range.
DomainDiversityResults;

// The callback to process all domain diversity metrics. The parameter is a pair
// of results, where the first member counts only local visits, and the second
// counts both local and foreign (synced) visits.
DomainDiversityCallback;

// The bitmask to specify the types of metrics to compute in
// HistoryBackend::GetDomainDiversity()
DomainMetricBitmaskType;
enum DomainMetricType : DomainMetricBitmaskType {};

// HistoryLastVisitResult encapsulates the result HistoryBackend calls to find
// the last visit to a host or URL.
struct HistoryLastVisitResult {};

// DailyVisitsResult contains the result of counting visits to a host over a
// time range.
struct DailyVisitsResult {};

struct ExpireHistoryArgs {};

// Represents the time range of a history deletion. If `IsValid()` is false,
// the time range doesn't apply to this deletion e.g. because only a list of
// urls was deleted.
class DeletionTimeRange {};

// Describes the urls that have been removed due to a history deletion.
// If `IsAllHistory()` returns true, all urls haven been deleted.
// In this case, `deleted_rows()` and `favicon_urls()` are undefined.
// Otherwise `deleted_rows()` contains the urls where all visits have been
// removed from history.
// If `expired()` returns true, this deletion is due to a regularly performed
// history expiration. Otherwise it is an explicit deletion due to a user
// action.
class DeletionInfo {};

// When a VisitedLink is deleted from the VisitedLinkDatabase, we notify the
// HistoryService with the following information. In `visited_link_row`, we are
// given a URLID. Callers should obtain the GURL associated with that URLID from
// the URLDatabase and pass it along with this payload.
struct DeletedVisitedLink {};

// When a Visit is deleted from the the VisitDatabase, we notify the
// HistoryService with the following information. `deleted_visited_link` is
// optional, as not all VisitRow deletions result in a deletion from the
// VisitedLinkDatabase.
struct DeletedVisit {};

// Represents a visit to a domain.
class DomainVisit {};

// Clusters --------------------------------------------------------------------

// Context annotations about a page visit collected during the page lifetime.
// This struct encapsulates data that's shared between UKM and the on-device
// storage for `HistoryCluster` metadata, recorded to both when the page
// lifetime ends. This is to ensure that History actually has the visit row
// already written.
struct VisitContextAnnotations {};

// A `VisitRow` along with its corresponding `URLRow`,
// `VisitContextAnnotations`, and `VisitContentAnnotations`.
struct AnnotatedVisit {};

// `ClusterVisit` tracks duplicate visits to propagate deletes. Only the
// duplicate's URL and visit time are needed to delete it, hence doesn't contain
// all the information contained in e.g. `ClusterVisit`.
struct DuplicateClusterVisit {};

// An `AnnotatedVisit` associated with some other metadata from clustering.
struct ClusterVisit {};

// Additional data for a cluster keyword.
struct ClusterKeywordData {};

// A cluster of `ClusterVisit`s with associated metadata (i.e. `keywords` and
// `should_show_on_prominent_ui_surfaces`).
struct Cluster {};

// Navigation -----------------------------------------------------------------

// Marshalling structure for AddPage.
struct HistoryAddPageArgs {};

}  // namespace history

#endif  // COMPONENTS_HISTORY_CORE_BROWSER_HISTORY_TYPES_H_