Skip to content

Commit

Permalink
[memories] Consolidates history_clusters mojom definitions
Browse files Browse the repository at this point in the history
With crrev.com/c/3033572 HistoryClustersService no longer uses the mojom
definitions located under //components/history_clusters/core/

This CL consolidates history_clusters mojom API and Types definitions.
Additionally it removes the `keywords` field which is not used in the UI
and renames `max_time` and `continuation_max_time` to `end_time` and
`continuation_end_time` for consistency with the HistoryClustersService.

Bug: 1173908
Change-Id: I8394f0b33be01be9df92d12ceb6fb506c9d50d3b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3035380
Reviewed-by: Alex Gough <ajgo@chromium.org>
Reviewed-by: Tommy Li <tommycli@chromium.org>
Commit-Queue: Moe Ahmadi <mahmadi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#902749}
  • Loading branch information
Moe Ahmadi authored and Chromium LUCI CQ committed Jul 17, 2021
1 parent 95848c0 commit 5c84019
Show file tree
Hide file tree
Showing 14 changed files with 124 additions and 177 deletions.
27 changes: 4 additions & 23 deletions chrome/browser/resources/memories/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ ts_library("build_ts") {
in_files = [
"app.ts",
"browser_proxy.ts",
"chrome/browser/ui/webui/history_clusters/history_clusters.mojom-webui.js",
"cluster.ts",
"components/history_clusters/core/history_clusters.mojom-webui.js",
"history_clusters.mojom-webui.js",
"history_clusters.ts",
"page_favicon.ts",
"router.ts",
Expand All @@ -30,42 +29,24 @@ ts_library("build_ts") {
"top_visit.ts",
"visit_row.ts",
]
path_mappings = [
"/chrome/browser/ui/webui/history_clusters/*|" +
rebase_path(
"$preprocess_folder/chrome/browser/ui/webui/history_clusters/*",
target_gen_dir),
"/components/history_clusters/core/*|" +
rebase_path("$preprocess_folder/components/history_clusters/core/*",
target_gen_dir),
]
deps = [
"//third_party/polymer/v3_0:library",
"//ui/webui/resources:library",
"//ui/webui/resources/mojo:library",
]
extra_deps = [
":copy_history_clusters_api_mojom",
":copy_history_clusters_definitions_mojom",
":copy_history_clusters_mojom",
":preprocess",
":preprocess_generated",
]
}

copy("copy_history_clusters_api_mojom") {
copy("copy_history_clusters_mojom") {
sources = [ "$root_gen_dir/mojom-webui/chrome/browser/ui/webui/history_clusters/history_clusters.mojom-webui.js" ]
outputs = [ "$preprocess_folder/chrome/browser/ui/webui/history_clusters/{{source_file_part}}" ]
outputs = [ "$preprocess_folder/{{source_file_part}}" ]
deps = [ "//chrome/browser/ui/webui/history_clusters:mojo_bindings_webui_js" ]
}

copy("copy_history_clusters_definitions_mojom") {
sources = [ "$root_gen_dir/mojom-webui/components/history_clusters/core/history_clusters.mojom-webui.js" ]
outputs = [
"$preprocess_folder/components/history_clusters/core/{{source_file_part}}",
]
deps = [ "//components/history_clusters/core:mojo_bindings_webui_js" ]
}

html_to_js("web_components_local") {
js_files = [
"app.ts",
Expand Down
19 changes: 9 additions & 10 deletions chrome/browser/resources/memories/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ import {IronScrollThresholdElement} from 'chrome://resources/polymer/v3_0/iron-s
import {html, PolymerElement} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';

import {BrowserProxy} from './browser_proxy.js';
import {PageCallbackRouter, PageHandlerRemote, QueryParams, QueryResult} from './chrome/browser/ui/webui/history_clusters/history_clusters.mojom-webui.js';
import {URLVisit} from './components/history_clusters/core/history_clusters.mojom-webui.js';
import {PageCallbackRouter, PageHandlerRemote, QueryParams, QueryResult, URLVisit} from './history_clusters.mojom-webui.js';

/**
* @fileoverview This file provides the root custom element for the Clusters
Expand Down Expand Up @@ -163,8 +162,8 @@ class HistoryClustersAppElement extends PolymerElement {
this.onBrowserIdle_().then(() => {
this.queryClusters_({
query: this.query_.trim(),
maxTime: undefined,
maxCount: this.result_.clusters.length,
endTime: undefined,
});
});
}
Expand Down Expand Up @@ -213,11 +212,11 @@ class HistoryClustersAppElement extends PolymerElement {
private onScrolledToBottom_() {
this.$.scrollThreshold.clearTriggers();

if (this.result_ && this.result_.continuationMaxTime) {
if (this.result_ && this.result_.continuationEndTime) {
this.queryClusters_({
query: this.result_.query,
maxTime: this.result_.continuationMaxTime,
maxCount: RESULTS_PER_PAGE,
endTime: this.result_.continuationEndTime,
});
}
}
Expand Down Expand Up @@ -252,7 +251,7 @@ class HistoryClustersAppElement extends PolymerElement {
// Do not replace the existing result. `result` contains a partial set of
// Clusters that should be appended to the existing ones.
this.push('result_.clusters', ...result.clusters);
this.result_.continuationMaxTime = result.continuationMaxTime;
this.result_.continuationEndTime = result.continuationEndTime;
} else {
this.result_ = result;
}
Expand All @@ -269,8 +268,8 @@ class HistoryClustersAppElement extends PolymerElement {
// Request up to `RESULTS_PER_PAGE` of the freshest Clusters until now.
this.queryClusters_({
query: this.query_.trim(),
maxTime: undefined,
maxCount: RESULTS_PER_PAGE,
endTime: undefined,
});
// Scroll to the top when the results change due to query change.
this.$.container.scrollTop = 0;
Expand All @@ -285,11 +284,11 @@ class HistoryClustersAppElement extends PolymerElement {
}

private queryClusters_(queryParams: QueryParams) {
// Invalidate the existing `continuationMaxTime`, if any, in order to
// Invalidate the existing `continuationEndTime`, if any, in order to
// prevent sending additional requests while a request is in-flight. A new
// `continuationMaxTime` will be supplied with the new set of results.
// `continuationEndTime` will be supplied with the new set of results.
if (this.result_) {
this.result_.continuationMaxTime = undefined;
this.result_.continuationEndTime = undefined;
}
this.pageHandler_.queryClusters(queryParams);
}
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/resources/memories/browser_proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import {PageCallbackRouter, PageHandler, PageHandlerRemote} from './chrome/browser/ui/webui/history_clusters/history_clusters.mojom-webui.js';
import {PageCallbackRouter, PageHandler, PageHandlerRemote} from './history_clusters.mojom-webui.js';

/**
* @fileoverview This file provides a singleton class that exposes the Mojo
Expand Down
3 changes: 1 addition & 2 deletions chrome/browser/resources/memories/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import {assert} from 'chrome://resources/js/assert.m.js';
import {html, PolymerElement} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';

import {BrowserProxy} from './browser_proxy.js';
import {PageCallbackRouter} from './chrome/browser/ui/webui/history_clusters/history_clusters.mojom-webui.js';
import {Cluster, URLVisit} from './components/history_clusters/core/history_clusters.mojom-webui.js';
import {Cluster, PageCallbackRouter, URLVisit} from './history_clusters.mojom-webui.js';

/**
* @fileoverview This file provides a custom element displaying a Cluster.
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/resources/memories/search_query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import './shared_style.js';

import {html, PolymerElement} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';

import {SearchQuery} from './components/history_clusters/core/history_clusters.mojom-webui.js';
import {SearchQuery} from './history_clusters.mojom-webui.js';

/**
* @fileoverview This file provides a custom element displaying a search query.
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/resources/memories/top_visit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import 'chrome://resources/polymer/v3_0/iron-collapse/iron-collapse.js';
import {loadTimeData} from 'chrome://resources/js/load_time_data.m.js';
import {html, PolymerElement} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';

import {URLVisit} from './components/history_clusters/core/history_clusters.mojom-webui.js';
import {URLVisit} from './history_clusters.mojom-webui.js';

/**
* @fileoverview This file provides a custom element displaying a top visit
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/resources/memories/visit_row.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {loadTimeData} from 'chrome://resources/js/load_time_data.m.js';
import {Url} from 'chrome://resources/mojo/url/mojom/url.mojom-webui.js';
import {html, PolymerElement} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';

import {Annotation, URLVisit} from './components/history_clusters/core/history_clusters.mojom-webui.js';
import {Annotation, URLVisit} from './history_clusters.mojom-webui.js';

/**
* @fileoverview This file provides a custom element displaying a visit to a
Expand Down
1 change: 0 additions & 1 deletion chrome/browser/ui/webui/history_clusters/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ mojom("mojo_bindings") {
sources = [ "history_clusters.mojom" ]
webui_module_path = "/chrome/browser/ui/webui/history_clusters"
public_deps = [
"//components/history_clusters/core:mojo_bindings",
"//mojo/public/mojom/base",
"//url/mojom:url_mojom_gurl",
]
Expand Down
91 changes: 87 additions & 4 deletions chrome/browser/ui/webui/history_clusters/history_clusters.mojom
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,93 @@

module history_clusters.mojom;

import "components/history_clusters/core/history_clusters.mojom";
import "mojo/public/mojom/base/time.mojom";
import "url/mojom/url.mojom";

// 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;
};

// 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 added to a tab group or was already in a
// tab group.
kTabGrouped,
// Indicates that the visited URL was the search results page of the default
// search provider.
kSearchResultsPage,
};

// 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 {
// 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;

// Title of the visited webpage.
string page_title;

// Time of the most recent visit in the Cluster to the same (or a qualifying
// near-duplicate) URL.
mojo_base.mojom.Time last_visit_time;

// Time of the least recent visit in the Cluster to the same (or a qualifying
// near-duplicate) URL. Equals `last_visit_time` if there is only one visit in
// the Cluster to the same (or a qualifying near-duplicate) URL.
mojo_base.mojom.Time first_visit_time;

// List of raw visited URLs for `normalized_url`.
array<url.mojom.Url> raw_urls;

// Localized string of approximate `last_visit_time`, e.g., "2 days ago".
string relative_date;

// Annotations for this visit.
array<Annotation> annotations;

// Search queries related to this visit or one of its related visits, if
// applicable; typically the highest scoring one.
array<SearchQuery> related_searches;

// Related visits to this visit; starting with the highest scoring one, if
// applicable. Only prominently featured visits have related visits.
array<URLVisit> related_visits;

// Whether a related visit is initially hidden. Calculated based on `score`.
bool below_the_fold;

// A calculated score (i.e., calculated based on how long the tab was in
// foreground etc).
double score;
};

// Represents a cluster of visits generated from device history by the browser
// and displayed in the chrome://memories WebUI. 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;

// Prominently featured constituent visits; typically the highest scoring
// one(s).
array<URLVisit> visits;

// Time of the most recent visit in the Cluster. Used for extracting Clusters.
mojo_base.mojom.Time last_visit_time;
};

// Parameters used to query the browser for Clusters in reverse chronological
// order.
struct QueryParams {
Expand All @@ -20,9 +103,9 @@ struct QueryParams {
uint32 max_count;

// The optional time threshold (exclusive) for how recent the Clusters can be.
// If specified, Clusters before `max_time` and if missing, Clusters until the
// If specified, Clusters before `end_time` and if missing, Clusters until the
// present time that match the other criteria are returned.
mojo_base.mojom.Time? max_time;
mojo_base.mojom.Time? end_time;
};

// Represents a set of Clusters returned by the browser in response to a request
Expand All @@ -42,7 +125,7 @@ struct QueryResult {
// The optional time threshold (exclusive) to be supplied in the follow-up UI
// request to load older Clusters. Typically set to `last_visit_time` of the
// last cluster in `clusters` if the backend supports paging.
mojo_base.mojom.Time? continuation_max_time;
mojo_base.mojom.Time? continuation_end_time;
};

// Browser-side handler for requests from WebUI page.
Expand Down
Loading

0 comments on commit 5c84019

Please sign in to comment.