File: history_cluster_provider.h

package info (click to toggle)
chromium 139.0.7258.127-2
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 6,122,156 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (77 lines) | stat: -rw-r--r-- 3,478 bytes parent folder | download | duplicates (7)
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
// 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_HISTORY_CLUSTER_PROVIDER_H_
#define COMPONENTS_OMNIBOX_BROWSER_HISTORY_CLUSTER_PROVIDER_H_

#include "components/omnibox/browser/autocomplete_input.h"
#include "components/omnibox/browser/autocomplete_provider.h"
#include "components/omnibox/browser/autocomplete_provider_listener.h"

class AutocompleteProvider;
class AutocompleteProviderClient;

// `HistoryClusterProvider` adds suggestions to the history journey page if
// any `SearchProvider` suggestions matched a cluster keyword. Inherits
// `AutocompleteProviderListener` in order to listen to `SearchProvider`
// updates. Uses `SearchProvider` suggestions, as a proxy for what the user may
// be typing if they're typing a query. Doesn't use other search providers'
// (i.e. `VoiceSearchProvider` and `ZeroSuggestProvider`) suggestions for
// simplicity.
class HistoryClusterProvider : public AutocompleteProvider,
                               public AutocompleteProviderListener {
 public:
  HistoryClusterProvider(AutocompleteProviderClient* client,
                         AutocompleteProviderListener* listener,
                         AutocompleteProvider* search_provider,
                         AutocompleteProvider* history_url_provider,
                         AutocompleteProvider* history_quick_provider);

  // Updates `match->action` to have the `OmniboxAction`, and updates
  // `provider_suggestion_groups_map` to contain the right groups.
  // `matching_text` is necessary to pass the query down to the `OmniboxAction`
  // so it can pre-populate the query field in the Journeys searchbox.
  static void CompleteHistoryClustersMatch(
      const std::string& matching_text,
      history::ClusterKeywordData matched_keyword_data,
      AutocompleteMatch* match);

  // AutocompleteProvider:
  void Start(const AutocompleteInput& input, bool minimal_changes) override;

  // AutocompleteProviderListener:
  // `HistoryClusterProvider` listens to `SearchProvider` updates.
  void OnProviderUpdate(bool updated_matches,
                        const AutocompleteProvider* provider) override;

 private:
  ~HistoryClusterProvider() override = default;

  // Check if `search_provider_`, `history_url_provider_`, and
  // `history_quick_provider_` are all done.
  bool AllProvidersDone();

  // Iterates `search_provider_->matches()` and check if any can be used to
  // create a history cluster match. Returns whether any matches were created.
  bool CreateMatches();

  // Creates a `AutocompleteMatch`.
  AutocompleteMatch CreateMatch(
      const AutocompleteMatch& search_match,
      history::ClusterKeywordData matched_keyword_data);

  // The `AutocompleteInput` passed to `Start()`.
  AutocompleteInput input_;

  // These are never null. The providers are used to detect nav intent for which
  // no matches will be provided. Other providers can also provide search and
  // navigations suggestion, but these are the dominant sources, both in volume
  // and high scores (which is what nav intent considers).
  const raw_ptr<AutocompleteProviderClient> client_;
  const raw_ptr<AutocompleteProvider> search_provider_;
  const raw_ptr<AutocompleteProvider> history_url_provider_;
  const raw_ptr<AutocompleteProvider> history_quick_provider_;
};

#endif  // COMPONENTS_OMNIBOX_BROWSER_HISTORY_CLUSTER_PROVIDER_H_