config.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. // Copyright 2022 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef COMPONENTS_HISTORY_CLUSTERS_CORE_CONFIG_H_
  5. #define COMPONENTS_HISTORY_CLUSTERS_CORE_CONFIG_H_
  6. #include <string>
  7. #include "base/containers/flat_set.h"
  8. #include "base/time/time.h"
  9. class PrefService;
  10. namespace history_clusters {
  11. class HistoryClustersService;
  12. // The default configuration. Always use |GetConfig()| to get the current
  13. // configuration.
  14. //
  15. // Config has the same thread-safety as base::FeatureList. The first call to
  16. // GetConfig() (which performs initialization) must be done single threaded on
  17. // the main thread. After that, Config can be read from any thread.
  18. struct Config {
  19. // True if journeys feature is enabled as per field trial check. Does not
  20. // check for any user-specific conditions (such as locales).
  21. bool is_journeys_enabled_no_locale_check = false;
  22. // The max number of visits to use for each clustering iteration. This limits
  23. // the number of visits sent to the clustering backend per batch.
  24. int max_visits_to_cluster = 1000;
  25. // A soft cap on the number of keyword phrases to cache. 5000 should be more
  26. // than enough, as the 99.9th percentile of users has 2000. A few nuances:
  27. // - We cache both entity keywords and URLs, each limited separately.
  28. // - We have both a long and short duration cache, each limited separately.
  29. // - We complete processing each cluster even if it means slightly going over
  30. // this limit.
  31. // - 0 and -1 are not interpreted as sentinel values. We always have a limit.
  32. size_t max_keyword_phrases = 5000;
  33. // If enabled, updating clusters will persist the results to the history DB
  34. // and accessing clusters will retrieve them from the history DB. If disabled,
  35. // updating clusters is a no-op and accessing clusters will generate and
  36. // return new clusters without persisting them.
  37. bool persist_clusters_in_history_db = false;
  38. // No effect if `persist_clusters_in_history_db` is disabled. Determines how
  39. // soon to update clusters after startup in minutes. E.g., by default, will
  40. // update clusters 5 minutes after startup.
  41. int persist_clusters_in_history_db_after_startup_delay_minutes = 5;
  42. // No effect if `persist_clusters_in_history_db` is disabled. Determines how
  43. // often to update clusters in minutes. E.g., by default, will update clusters
  44. // every hour.
  45. int persist_clusters_in_history_db_period_minutes = 60;
  46. // Enables the on-device clustering backend. Enabled by default, since this is
  47. // the production mode of the whole feature. The backend is only in official
  48. // builds, so it won't work in unofficial builds.
  49. // bool use_on_device_clustering_backend;
  50. // If enabled, this is the min score that a visit needs to have to always be
  51. // shown above the fold regardless of the number of visits already shown.
  52. double min_score_to_always_show_above_the_fold = 0.5;
  53. // If enabled, this is the number of non-zero scored visits to always show
  54. // above the fold regardless of score. Note, this value includes the
  55. // "top visit". In the unlabeled "top visit" UI configuration, that means the
  56. // one "top visit" and three subordinate looking visits will be always shown.
  57. size_t num_visits_to_always_show_above_the_fold = 4;
  58. // If enabled, hidden visits are dropped entirely, instead of being gated
  59. // behind a "Show More" UI control.
  60. bool drop_hidden_visits = true;
  61. // If enabled, when there is a Journeys search query, the backend re-scores
  62. // visits within a cluster to account for whether or not that visit matches.
  63. bool rescore_visits_within_clusters_for_query = true;
  64. // If enabled, sorts clusters WITHIN a single batch from most search matches
  65. // to least search matches. The batches themselves will still be ordered
  66. // reverse chronologically, but the clusters within batches will be resorted.
  67. bool sort_clusters_within_batch_for_query = false;
  68. // Enables the Journeys Omnibox Action chip. `kJourneys` must also be enabled
  69. // for this to take effect.
  70. bool omnibox_action = false;
  71. // If enabled, allows the Omnibox Action chip to also appear on URLs. This
  72. // does nothing if `omnibox_action` is disabled. Note, that if you turn this
  73. // flag to true, you almost certainly will want to set
  74. // `omnibox_action_on_navigation_intents` to true as well, as otherwise your
  75. // desired action chips on URLs will almost certainly all be suppressed.
  76. bool omnibox_action_on_urls = false;
  77. // If enabled, allows the Omnibox Action chip to appear on URLs from noisy
  78. // visits. This does nothing if `omnibox_action_on_urls` is disabled.
  79. bool omnibox_action_on_noisy_urls = true;
  80. // If enabled, allows the Omnibox Action chip to appear when it's likely the
  81. // user is intending to perform a navigation. This does not affect which
  82. // suggestions are allowed to display the chip. Does nothing if
  83. // `omnibox_action` is disabled.
  84. bool omnibox_action_on_navigation_intents = false;
  85. // If `omnibox_action_on_navigation_intents` is false, this threshold
  86. // helps determine when the user is intending to perform a navigation.
  87. int omnibox_action_navigation_intent_score_threshold = 1300;
  88. // If enabled, allows the Omnibox Action chip to appear when the suggestions
  89. // contain pedals. Does nothing if `omnibox_action` is disabled.
  90. bool omnibox_action_with_pedals = false;
  91. // Enables `HistoryClusterProvider` to surface Journeys as a suggestion row
  92. // instead of an action chip. Enabling this won't actually disable
  93. // `omnibox_action_with_pedals`, but for user experiments, the intent is to
  94. // only have 1 enabled.
  95. bool omnibox_history_cluster_provider = false;
  96. // If enabled, adds the keywords of aliases for detected entity names to a
  97. // cluster.
  98. bool keyword_filter_on_entity_aliases = false;
  99. // If greater than 0, the max number of aliases to include in keywords. If <=
  100. // 0, all aliases will be included.
  101. size_t max_entity_aliases_in_keywords = 0;
  102. // If enabled, adds the keywords of categories for detected entities to a
  103. // cluster.
  104. bool keyword_filter_on_categories = false;
  105. // If enabled, adds the keywords of detected entities from noisy visits to a
  106. // cluster.
  107. bool keyword_filter_on_noisy_visits = false;
  108. // If enabled, adds the search terms of the visits that have them.
  109. bool keyword_filter_on_search_terms = false;
  110. // If enabled, adds the keywords of detected entities that may be for
  111. // the visit's host.
  112. bool keyword_filter_on_visit_hosts = true;
  113. // The weight for category keyword scores per cluster.
  114. float category_keyword_score_weight = 1.0;
  115. // Maximum number of keywords to keep per cluster.
  116. size_t max_num_keywords_per_cluster = 20;
  117. // Enables debug info in non-user-visible surfaces, like Chrome Inspector.
  118. // Does nothing if `kJourneys` is disabled.
  119. bool non_user_visible_debug = false;
  120. // Enables debug info in user-visible surfaces, like the actual WebUI page.
  121. // Does nothing if `kJourneys` is disabled.
  122. bool user_visible_debug = false;
  123. // Enables persisting context annotations in the History DB. They are always
  124. // calculated anyways. This just enables storing them. This is expected to be
  125. // enabled for all users shortly. This just provides a killswitch.
  126. // This flag is to enable us to turn on persisting context annotations WITHOUT
  127. // exposing the Memories UI in general. If EITHER this flag or `kJourneys` is
  128. // enabled, users will have context annotations persisted into their History
  129. // DB.
  130. bool persist_context_annotations_in_history_db = false;
  131. // Enables the history clusters internals page.
  132. bool history_clusters_internals_page = false;
  133. // Returns the maximum duration between navigations that
  134. // a visit can be considered for the same cluster.
  135. base::TimeDelta cluster_navigation_time_cutoff = base::Minutes(60);
  136. // The minimum threshold for whether an entity is considered relevant to the
  137. // visit.
  138. int entity_relevance_threshold = 60;
  139. // The minimum threshold for whether a category is considered relevant to the
  140. // visit.
  141. int category_relevance_threshold = 36; // 60 * 0.6 = 36.
  142. // Returns whether content clustering is enabled and
  143. // should be performed by the clustering backend.
  144. bool content_clustering_enabled = false;
  145. // Returns the weight that should be placed on entity similarity for
  146. // determining if two clusters are similar enough to be combined into one.
  147. float content_clustering_entity_similarity_weight = 1.0;
  148. // Returns the weight that should be placed on category similarity for
  149. // determining if two clusters are similar enough to be combined into one.
  150. float content_clustering_category_similarity_weight = 1.0;
  151. // Returns the similarity threshold, between 0 and 1, used to determine if
  152. // two clusters are similar enough to be combined into
  153. // a single cluster.
  154. float content_clustering_similarity_threshold = 0.2;
  155. // Returns the threshold for which we should mark a cluster as being able to
  156. // show on prominent UI surfaces.
  157. float content_visibility_threshold = 0.7;
  158. // Whether to hide single-visit clusters on prominent UI surfaces.
  159. bool should_hide_single_visit_clusters_on_prominent_ui_surfaces = true;
  160. // Whether to hide clusters that only contain URLs from the same domain on
  161. // prominent UI surfaces.
  162. bool should_hide_single_domain_clusters_on_prominent_ui_surfaces = false;
  163. // Whether to filter clusters that are noisy from the UI. This will
  164. // heuristically remove clusters that are unlikely to be "interesting".
  165. bool should_filter_noisy_clusters = true;
  166. // Returns the threshold used to determine if a cluster, and its visits, has
  167. // too high site engagement to be likely useful.
  168. float noisy_cluster_visits_engagement_threshold = 15.0;
  169. // Returns the number of visits considered interesting, or not noisy, required
  170. // to prevent the cluster from being filtered out (i.e., marked as not visible
  171. // on the zero state UI).
  172. size_t number_interesting_visits_filter_threshold = 1;
  173. // Returns the weight to use for the visit duration when ranking visits within
  174. // a cluster. Will always be greater than or equal to 0.
  175. float visit_duration_ranking_weight = 1.0;
  176. // Returns the weight to use for the foreground duration when ranking visits
  177. // within a cluster. Will always be greater than or equal to 0.
  178. float foreground_duration_ranking_weight = 1.5;
  179. // Returns the weight to use for bookmarked visits when ranking visits within
  180. // a cluster. Will always be greater than or equal to 0.
  181. float bookmark_ranking_weight = 1.0;
  182. // Returns the weight to use for visits that are search results pages ranking
  183. // visits within a cluster. Will always be greater than or equal to 0.
  184. float search_results_page_ranking_weight = 2.0;
  185. // Returns the weight to use for visits that have page titles ranking visits
  186. // within a cluster. Will always be greater than or equal to 0.
  187. float has_page_title_ranking_weight = 2.0;
  188. // Returns true if content clustering should use the intersection similarity
  189. // score. Note, if this is used, the threshold used for clustering by content
  190. // score should be < .5 (see ContentClusteringSimilarityThreshold above) or
  191. // the weightings between entity and category content similarity scores should
  192. // be adjusted.
  193. bool content_cluster_on_intersection_similarity = true;
  194. // Returns the threshold, in terms of the number of overlapping keywords, to
  195. // use when clustering based on intersection score.
  196. int cluster_interaction_threshold = 2;
  197. // Returns the default batch size for annotating visits when clustering.
  198. size_t clustering_tasks_batch_size = 250;
  199. // Whether to split the clusters when a search visit is encountered.
  200. bool split_clusters_at_search_visits = true;
  201. // Whether to assign labels to clusters. If the label exists, it will be shown
  202. // in the UI. If the label doesn't exist, the UI will emphasize the top visit.
  203. // Note: The default value here is meaningless, because the actual default
  204. // value is derived from the base::Feature.
  205. bool should_label_clusters = true;
  206. // Whether to assign labels to clusters from the hostnames of the cluster.
  207. // Does nothing if `should_label_clusters` is false. Note that since every
  208. // cluster has a hostname, this flag in conjunction with
  209. // `should_label_clusters` will give every cluster a label.
  210. bool labels_from_hostnames = true;
  211. // Whether to assign labels to clusters from the Entities of the cluster.
  212. // Does nothing if `should_label_clusters` is false.
  213. bool labels_from_entities = false;
  214. // Whether to check if all visits for a host should be in resulting clusters.
  215. bool should_check_hosts_to_skip_clustering_for = false;
  216. // The max number of hosts that should be stored in the engagement score
  217. // cache.
  218. int engagement_score_cache_size = 100;
  219. // The max time a host should be stored in the engagement score cache.
  220. base::TimeDelta engagement_score_cache_refresh_duration = base::Minutes(120);
  221. // True if the task runner should use trait CONTINUE_ON_SHUTDOWN.
  222. bool use_continue_on_shutdown = true;
  223. Config();
  224. Config(const Config& other);
  225. ~Config();
  226. };
  227. // Returns the set of mids that should be blocked from being used by the
  228. // clustering backend, particularly for potential keywords used for omnibox
  229. // triggering.
  230. base::flat_set<std::string> JourneysMidBlocklist();
  231. // Returns true if |application_locale| is supported by Journeys.
  232. // This is a costly check: Should be called only if
  233. // |is_journeys_enabled_no_locale_check| is true, and the result should be
  234. // cached.
  235. bool IsApplicationLocaleSupportedByJourneys(
  236. const std::string& application_locale);
  237. // Checks some prerequisites for history cluster omnibox suggestions and
  238. // actions.
  239. bool IsJourneysEnabledInOmnibox(HistoryClustersService* service,
  240. PrefService* prefs);
  241. // Gets the current configuration. OverrideWithFinch() must have been called
  242. // before GetConfig() is called.
  243. const Config& GetConfig();
  244. // Overrides the config returned by |GetConfig()|.
  245. void SetConfigForTesting(const Config& config);
  246. } // namespace history_clusters
  247. #endif // COMPONENTS_HISTORY_CLUSTERS_CORE_CONFIG_H_