1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349
|
// Copyright 2022 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_OMNIBOX_BROWSER_AUTOCOMPLETE_GROUPER_SECTIONS_H_
#define COMPONENTS_OMNIBOX_BROWSER_AUTOCOMPLETE_GROUPER_SECTIONS_H_
#include <memory>
#include <vector>
#include "components/omnibox/browser/autocomplete_grouper_groups.h"
#include "components/omnibox/browser/autocomplete_match.h"
#include "components/omnibox/browser/suggestion_group_util.h"
#include "components/omnibox/common/omnibox_feature_configs.h"
class Section;
using Groups = std::vector<Group>;
using PSections = std::vector<std::unique_ptr<Section>>;
// `Section` class and subclasses used to implement the various autocomplete
// grouping algorithms.
// Section containing no `Groups` and, therefore, no matches.
class Section {
public:
explicit Section(size_t limit,
Groups groups,
omnibox::GroupConfigMap& group_configs,
omnibox::GroupConfig_SideType side_type =
omnibox::GroupConfig_SideType_DEFAULT_PRIMARY);
virtual ~Section();
// Returns `matches` ranked and culled according to `sections`. All `matches`
// should have `suggestion_group_id` set and be sorted by relevance.
static ACMatches GroupMatches(PSections sections, ACMatches& matches);
// Used to adjust this `Section`'s and its `Group`s' total limits.
virtual void InitFromMatches(ACMatches& matches) {}
protected:
// Returns the first `Group` in this `Section` `match` can be added to or
// `groups_.end()` if none can be found. Does not take the total limit into
// account.
Groups::iterator FindGroup(const AutocompleteMatch& match);
// Returns whether `match` was added to a `Group` in this `Section`. Does not
// add a match beyond the total limit.
bool Add(const AutocompleteMatch& match);
// Max number of matches this `Section` can contain across `groups_`.
size_t limit_{0};
// The number of matches this `Section` contains across `groups_`.
size_t count_{0};
// The `Group`s this `Section` contains.
Groups groups_{};
// This `Section`s map of group IDs to group information.
omnibox::GroupConfigMap group_configs_;
// This `Section`s side type.
omnibox::GroupConfig_SideType side_type_;
};
// Base section for ZPS limits and grouping. Asserts that matches are sorted by
// their `Group`s position.
class ZpsSection : public Section {
public:
ZpsSection(size_t limit,
Groups groups,
omnibox::GroupConfigMap& group_configs,
omnibox::GroupConfig_SideType side_type =
omnibox::GroupConfig_SideType_DEFAULT_PRIMARY);
// Section:
void InitFromMatches(ACMatches& matches) override;
};
// Base section for ZPS limits and grouping where local history zero-prefix
// suggestions are enabled. Sorts the matches by their `Group`s position to
// ensure zero-prefix suggestions from local history backfill remote
// personalized zero-prefix suggestions.
// TODO(crbug.com/409810808): Find a more general solution for accommodating
// local history backfill and remove this class.
class ZpsSectionWithLocalHistory : public ZpsSection {
protected:
explicit ZpsSectionWithLocalHistory(size_t limit,
Groups groups,
omnibox::GroupConfigMap& group_configs);
// Section:
void InitFromMatches(ACMatches& matches) override;
};
// A ZpsSection that automatically counts all MV Tiles as one suggestion when
// applying the total limit.
class ZpsSectionWithMVTiles : public ZpsSection {
public:
explicit ZpsSectionWithMVTiles(size_t limit,
Groups groups,
omnibox::GroupConfigMap& group_configs);
// Section:
void InitFromMatches(ACMatches& matches) override;
};
// Android prefixed section for Adaptive Suggestions grouping.
class AndroidNonZPSSection : public Section {
public:
// Construct a new instance of the grouping class used in non-zero-prefix
// context.
// When `show_only_search_suggestions` is set to `true`, URLs will not be
// offered at any position other than position 0 (the Default Match).
explicit AndroidNonZPSSection(bool show_only_search_suggestions,
omnibox::GroupConfigMap& group_configs);
// Section:
void InitFromMatches(ACMatches& matches) override;
// Specify number of matches that are at least 50% exposed while the
// software keyboard is visible.
static void set_num_visible_matches(size_t num_visible_matches) {
num_visible_matches_ = num_visible_matches;
}
private:
static size_t num_visible_matches_;
};
// Android prefix section for Hub search (ZPS).
class AndroidHubZPSSection : public Section {
public:
explicit AndroidHubZPSSection(omnibox::GroupConfigMap& group_configs);
};
// Android prefix section for Hub search (non-ZPS).
class AndroidHubNonZPSSection : public Section {
public:
explicit AndroidHubNonZPSSection(omnibox::GroupConfigMap& group_configs);
};
// Section expressing the Android ZPS limits and grouping for the NTP.
// - up to 15 + `max_related_queries` + `max_trending_queries` suggestions
// total.
// - up to 1 clipboard suggestion.
// - up to 15 MIA or personalized suggestions.
// - up to 5 trending search suggestions.
class AndroidNTPZpsSection : public ZpsSectionWithLocalHistory {
public:
AndroidNTPZpsSection(omnibox::GroupConfigMap& group_configs,
bool mia_enabled);
void InitFromMatches(ACMatches& matches) override;
};
// Section expressing the Android ZPS limits and grouping for the SRP.
// - up to 15 suggestions total.
// - up to 1 verbatim suggestion.
// - up to 1 clipboard suggestion.
// - up to 1 most visited carousel.
// - up to 15 previous search related suggestions.
// - up to 15 personalized suggestions.
class AndroidSRPZpsSection : public ZpsSection {
public:
explicit AndroidSRPZpsSection(omnibox::GroupConfigMap& group_configs);
};
// Section expressing the Android ZPS limits and grouping for the Web.
// - up to 15 suggestions total.
// - up to 1 verbatim suggestion.
// - up to 1 clipboard suggestion.
// - up to 1 most visited carousel.
// - up to 8 page related suggestions.
// - up to 15 personalized suggestions.
class AndroidWebZpsSection : public ZpsSectionWithMVTiles {
public:
explicit AndroidWebZpsSection(omnibox::GroupConfigMap& group_configs);
};
// Section expressing the Desktop ZPS limits and grouping for the NTP.
// - up to 8 suggestions total or 7 total if the ZPS IPH is enabled (the 8th
// suggestion being the IPH).
// - up to 8 MIA or personalized suggestions.
// - up to 8 trending search suggestions.
class DesktopNTPZpsSection : public ZpsSectionWithLocalHistory {
public:
DesktopNTPZpsSection(omnibox::GroupConfigMap& group_configs,
size_t limit,
bool mia_enabled);
};
// Section expressing the Desktop ZPS limits and grouping for unscoped
// extensions.
// - Up to 8 unscoped extension suggestions total.
// - Up to 4 from the first extension.
// - Up to 4 from the second extension.
class DesktopZpsUnscopedExtensionSection : public ZpsSection {
public:
explicit DesktopZpsUnscopedExtensionSection(
omnibox::GroupConfigMap& group_configs);
};
// Section expressing the Desktop ZPS limits and grouping for the IPH suggestion
// on the NTP.
// - Up to 1 IPH suggestion total
class DesktopNTPZpsIPHSection : public ZpsSection {
public:
explicit DesktopNTPZpsIPHSection(omnibox::GroupConfigMap& group_configs);
};
// Section expressing the Desktop secondary ZPS limits and grouping for the NTP.
// - up to 4 suggestions total.
// - up to 3 previous search related suggestion chips.
// - up to 4 previous search related text suggestions.
// - up to 4 trending suggestions.
class DesktopSecondaryNTPZpsSection : public ZpsSection {
public:
explicit DesktopSecondaryNTPZpsSection(
omnibox::GroupConfigMap& group_configs);
};
// Section expressing the Desktop ZPS limits and grouping for the SRP.
// - up to `max_suggestions` suggestions total.
// - up to `search_limit` previous search related suggestions.
// - up to `search_limit` personalized suggestions.
// - up to `url_limit` most visited tiles suggestions
class DesktopSRPZpsSection : public ZpsSection {
public:
explicit DesktopSRPZpsSection(omnibox::GroupConfigMap& group_configs,
size_t max_suggestions,
size_t search_limit,
size_t url_limit,
size_t contextual_action_limit);
};
// Section expressing the Desktop URL ZPS limits and grouping for the Web.
// - up to `limit` most visited tiles suggestions.
class DesktopWebURLZpsSection : public ZpsSection {
public:
explicit DesktopWebURLZpsSection(omnibox::GroupConfigMap& group_configs,
size_t limit);
};
// Section expressing the Desktop Search ZPS limits and grouping for the Web.
// - up to `limit` suggestions total.
// - up to `limit` page related or personalized search suggestions.
// - up to `contextual_action_limit` contextual search action suggestions.
// - up to `contextual_search_limit` contextual search suggestions.
class DesktopWebSearchZpsSection : public Section {
public:
explicit DesktopWebSearchZpsSection(omnibox::GroupConfigMap& group_configs,
size_t limit,
size_t contextual_action_limit,
size_t contextual_search_limit);
};
// An experimental alternative for `DesktopWebSearchZpsSection` that excludes
// all but contextual matches. It's intended as a full replacement instead
// of modifying that section, for simplicity and ease of removal after
// experimentation.
// - up to `contextual_action_limit` + `contextual_search_limit` total.
// - up to `contextual_action_limit` contextual search action suggestions.
// - up to `contextual_search_limit` contextual search suggestions.
class DesktopWebSearchZpsContextualOnlySection : public Section {
public:
explicit DesktopWebSearchZpsContextualOnlySection(
omnibox::GroupConfigMap& group_configs,
size_t contextual_action_limit,
size_t contextual_search_limit);
};
// Section expressing the Desktop ZPS limits and grouping for the Lens
// contextual searchbox.
// - up to 8 suggestions total.
// - up to 8 page related suggestions.
class DesktopLensContextualZpsSection : public ZpsSection {
public:
explicit DesktopLensContextualZpsSection(
omnibox::GroupConfigMap& group_configs);
};
// Section expressing the Desktop ZPS limits and grouping for the Lens
// multimodal searchbox.
// - up to 8 suggestions total.
// - up to 8 multimodal suggestions.
class DesktopLensMultimodalZpsSection : public ZpsSection {
public:
explicit DesktopLensMultimodalZpsSection(
omnibox::GroupConfigMap& group_configs);
};
// A ZPS section that includes only the toolbelt match.
class ToolbeltSection : public ZpsSection {
public:
explicit ToolbeltSection(omnibox::GroupConfigMap& group_configs);
};
// Section expressing the Desktop, non-ZPS limits and grouping.
// - up to 10 suggestions total.
// - up to 1 default, 10 starer packs, 10 search, 8 nav, and 1 history cluster
// suggestions.
// - Only allow more than 8 suggestions if the section does not contain navs.
// - Only allow more than 7 navs if there are no non-navs to show.
// - The history cluster suggestion should count against the search limit.
// - The default suggestion should count against either the search or nav limit.
// - Group defaults 1st, then searches and history clusters, then navs.
class DesktopNonZpsSection : public Section {
public:
explicit DesktopNonZpsSection(omnibox::GroupConfigMap& group_configs);
// Section:
void InitFromMatches(ACMatches& matches) override;
};
// Section expressing the iOS ZPS limits and grouping for the NTP.
// - up to `total_count` suggestions total.
// - up to 1 clipboard suggestion.
// - up to `psuggest_count` MIA or personalized suggestions.
// - up to `max_trending_queries` trending suggestions.
class IOSNTPZpsSection : public ZpsSectionWithLocalHistory {
public:
IOSNTPZpsSection(omnibox::GroupConfigMap& group_configs, bool mia_enabled);
void InitFromMatches(ACMatches& matches) override;
};
// Section expressing the iOS ZPS limits and grouping for the SRP.
// - up to 20 suggestions total (where all MV Tiles are counted for 1).
// - up to 1 verbatim suggestion.
// - up to 1 clipboard suggestion.
// - up to 10 most visited in a carousel.
// - up to 8 previous search related suggestions.
// - up to 20 personalized suggestions.
class IOSSRPZpsSection : public ZpsSectionWithMVTiles {
public:
explicit IOSSRPZpsSection(omnibox::GroupConfigMap& group_configs);
};
// Section expressing the iOS ZPS limits and grouping for the Web.
// - up to 20 suggestions total (but all MV Tiles are counted for 1).
// - up to 1 verbatim suggestion.
// - up to 1 clipboard suggestion.
// - up to 10 most visited in a carousel.
// - up to 8 page related suggestions.
// - up to 20 personalized suggestions.
class IOSWebZpsSection : public ZpsSectionWithMVTiles {
public:
explicit IOSWebZpsSection(omnibox::GroupConfigMap& group_configs);
};
// Section expressing the iOS ZPS limits and grouping for the Lens mutimodal
// searchbox.
// - up to 10 suggestions total.
// - up to 10 search suggestions.
class IOSLensMultimodalZpsSection : public ZpsSection {
public:
explicit IOSLensMultimodalZpsSection(omnibox::GroupConfigMap& group_configs);
};
#endif // COMPONENTS_OMNIBOX_BROWSER_AUTOCOMPLETE_GROUPER_SECTIONS_H_
|