File: featured_search_provider.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 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 (112 lines) | stat: -rw-r--r-- 4,600 bytes parent folder | download | duplicates (3)
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
// Copyright 2024 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_FEATURED_SEARCH_PROVIDER_H_
#define COMPONENTS_OMNIBOX_BROWSER_FEATURED_SEARCH_PROVIDER_H_

#include <stddef.h>

#include <string>

#include "base/memory/raw_ptr.h"
#include "components/omnibox/browser/autocomplete_match.h"
#include "components/omnibox/browser/autocomplete_provider.h"
#include "components/search_engines/template_url_service.h"

class AutocompleteInput;
class AutocompleteProviderClient;
class TemplateURLService;
class AutocompleteResult;

// This is the provider for built-in URLs, such as about:settings and
// chrome://version, as well as the built-in Starter Pack search engines.
class FeaturedSearchProvider : public AutocompleteProvider {
 public:
  explicit FeaturedSearchProvider(AutocompleteProviderClient* client);
  FeaturedSearchProvider(const FeaturedSearchProvider&) = delete;
  FeaturedSearchProvider& operator=(const FeaturedSearchProvider&) = delete;

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

  // Called by `AutocompleteController` after ranking has settled. Increments
  // IPH shown counts.
  void RegisterDisplayedMatches(const AutocompleteResult& result);

 private:
  ~FeaturedSearchProvider() override;

  // Populates `matches_` with matching starter pack keywords such as @history,
  // and @bookmarks
  void AddFeaturedKeywordMatches(const AutocompleteInput& input);

  // Constructs an AutocompleteMatch for starter pack suggestions such as
  // @bookmarks, @history, etc. and adds it to `matches_`.
  void AddStarterPackMatch(const TemplateURL& template_url,
                           const AutocompleteInput& input);

  // Constructs a NULL_RESULT_MESSAGE match that is informational only and
  // cannot be acted upon.  This match delivers an IPH message directing users
  // to the starter pack feature.
  void AddIPHMatch(IphType iph_type,
                   const std::u16string& iph_contents,
                   const std::u16string& matched_term,
                   const std::u16string& iph_link_text,
                   const GURL& iph_link_url,
                   int relevance,
                   bool deletable);

  void AddFeaturedEnterpriseSearchMatch(const TemplateURL& template_url,
                                        const AutocompleteInput& input);

  // Returns whether to show the IPH match for `iph_type`.
  bool ShouldShowIPH(IphType iph_type) const;

  // Whether to show the @gemini keyword promo row in zero-state.
  bool ShouldShowGeminiIPHMatch() const;
  void AddGeminiIPHMatch();

  // Whether to show the Enterprise Search Aggregator keyword promo row
  // in zero-state.
  bool ShouldShowEnterpriseSearchAggregatorIPHMatch() const;
  void AddEnterpriseSearchAggregatorIPHMatch();

  // Whether to show the Featured Enterprise Site Search keyword promo row in
  // zero-state.
  bool ShouldShowFeaturedEnterpriseSiteSearchIPHMatch() const;
  void AddFeaturedEnterpriseSiteSearchIPHMatch();

  // Whether to show the History Embeddings promo row in @history scope.
  bool ShouldShowHistoryEmbeddingsSettingsPromoIphMatch() const;
  void AddHistoryEmbeddingsSettingsPromoIphMatch();

  // Whether to show the History Embeddings disclaimer row in @history scope.
  bool ShouldShowHistoryEmbeddingsDisclaimerIphMatch() const;
  void AddHistoryEmbeddingsDisclaimerIphMatch();

  // Whether to show the @history keyword promo row in zero-state.
  bool ShouldShowHistoryScopePromoIphMatch() const;
  void AddHistoryScopePromoIphMatch();

  // Whether to show the @history (embeddings) keyword promo row in zero-state.
  bool ShouldShowHistoryEmbeddingsScopePromoIphMatch() const;
  void AddHistoryEmbeddingsScopePromoIphMatch();

  raw_ptr<AutocompleteProviderClient> client_;
  raw_ptr<TemplateURLService> template_url_service_;

  // The number of times the IPH row has been shown so far in this browser
  // session. Shared by all IPH types. Reset when, e.g., the user opens a new
  // browser window.
  size_t iph_shown_in_browser_session_count_{0};

  // Whether an IPH match was shown during the current omnibox session. Used to
  // avoid incrementing `iph_shown_in_browser_session_count_` more than once per
  // omnibox session. Reset when, e.g.,  the user refocuses the omnibox.
  // omnibox.
  bool iph_shown_in_omnibox_session_ = false;
};

#endif  // COMPONENTS_OMNIBOX_BROWSER_FEATURED_SEARCH_PROVIDER_H_