// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
module history_clusters.mojom;
import "mojo/public/mojom/base/time.mojom";
import "url/mojom/url.mojom";
// Available annotations for a visit.
enum Annotation {
// Indicates that the visited URL was added to the bookmarks or was already
// bookmarked.
kBookmarked,
// Indicates that the visited URL was the search results page of the default
// search provider.
kSearchResultsPage,
};
// Each MatchPosition is the [begin, end) positions of a match within a string.
// Equivalent to MatchPosition in components/query_parser/snippet.h.
struct MatchPosition {
uint32 begin;
uint32 end;
};
// Represents a search query related to a visit to the search results page.
struct SearchQuery {
// Text of the search query.
string query;
// URL of the search query page.
url.mojom.Url url;
};
/**
* The following enum must be kept in sync with their respective source in
* components/history/core/browser/history_types.h.
*/
// A cluster's visit's interaction state.
enum InteractionState {
// The default state of visits. Visible in both zero-state and searches.
kDefault = 0,
// User has marked the visit hidden. Hidden in all surfaces.
kHidden = 1,
// User has dismissed the visit with positive intent. Hidden in the
// zero-state but still searchable.
kDone = 2,
};
/**
* The following enums must be kept in sync with their respective variants in
* //tools/metrics/histograms/metadata/history/histograms.xml and
* //components/history_clusters/core/cluster_metrics_utils.h
*/
// Raw visit data needed to properly do deletion of all the duplicates.
struct RawVisitData {
url.mojom.Url url;
mojo_base.mojom.Time visit_time;
};
// Represents the most recent visit to a URL within a Cluster. Visits for which
// there are more recent visits to the same (or a qualifying near-duplicate) URL
// within the Cluster are omitted.
// However, the time of the least recent visit as well as the raw URLs of those
// duplicative visits are preserved for deletion purposes.
struct URLVisit {
// ID for this visit in the history DB.
int64 visit_id;
// Normalized URL of the visited webpage. Only Search Results Page urls will
// be normalized for now; This is because SRP visits for the same search terms
// have slightly different URLs due to various query params such as the AQS.
url.mojom.Url normalized_url;
// String version of the URL suitable for display. This has been stripped of
// extraneous details like the scheme, and has IDN hostnames pre-converted.
// The actual URL formatting is similar to the omnibox popup.
string url_for_display;
// Title of the visited webpage.
string page_title;
// The positions within the `page_title` and `url_for_display` that match the
// search terms. Used for bolding in the WebUI.
array<MatchPosition> title_match_positions;
array<MatchPosition> url_for_display_match_positions;
// Raw visit data that's not displayed by the UI, but needed to do proper
// deletion. Visits with no duplicates will have an empty `duplicates` array.
RawVisitData raw_visit_data;
array<RawVisitData> duplicates;
// Localized string of approximate `last_visit_time`, e.g., "2 days ago".
string relative_date;
// Annotations for this visit.
array<Annotation> annotations;
// Set to true for visits known to Chrome Sync, which can be:
// 1. Remote visits that have been synced to the local machine.
// 2. Local visits that have been sent to Sync.
bool is_known_to_sync;
// A key-value dictionary of additional debug info to show. This is not
// visible in production, and used for development only. Disabled by default,
// but can be enabled by the 'JourneysUserVisibleDebug' flag.
map<string, string> debug_info;
// Whether there is a URL-keyed image for this visit.
bool has_url_keyed_image;
};
// Represents a cluster of visits generated from device history by the browser
// and displayed in chrome://history/journeys. Contains cluster-level metadata
// (e.g., last_visit_time) derived from the metadata of constituent visits.
struct Cluster {
// Cluster identifier. See //components/history/core/browser/history_types.h
int64 id;
// A flat list of all the visits in the cluster. The first one is the
// "top visit" if the UI needs to specially display a "top visit".
array<URLVisit> visits;
// A label for the whole cluster.
string label;
// If the whole cluster is opened in a new tab group, this should be used as
// the tab group name.
string? tab_group_name;
// The positions within `label` that match the search terms. Used for bolding
// in the WebUI.
array<MatchPosition> label_match_positions;
// Search queries related to this cluster's visits.
array<SearchQuery> related_searches;
// The image URL associated with this cluster.
url.mojom.Url? image_url;
// Set to true if this cluster was loaded from SQL rather than dynamically
// generated.
bool from_persistence;
// Additional debug string to show. This is not visible in production, and
// used for development only. Disabled by default, but can be enabled by the
// 'JourneysUserVisibleDebug' flag.
string? debug_info;
};