blob: f316c6e8937fa854a25a423d23e9941c938e0c5f [file] [log] [blame]
mattreynolds5afc01692016-08-19 22:09:561// Copyright (c) 2016 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
5#ifndef COMPONENTS_OMNIBOX_BROWSER_PHYSICAL_WEB_PROVIDER_H_
6#define COMPONENTS_OMNIBOX_BROWSER_PHYSICAL_WEB_PROVIDER_H_
7
mattreynolds1d38d1162017-01-19 02:45:248#include <vector>
9
mattreynolds2b530de2016-09-02 18:20:1610#include "base/macros.h"
mattreynoldsa04fff02017-01-06 23:46:1811#include "components/bookmarks/browser/titled_url_match.h"
mattreynolds5afc01692016-08-19 22:09:5612#include "components/omnibox/browser/autocomplete_input.h"
13#include "components/omnibox/browser/autocomplete_provider.h"
14
15class AutocompleteProviderClient;
mattreynolds2b530de2016-09-02 18:20:1616class HistoryURLProvider;
mattreynolds5afc01692016-08-19 22:09:5617
mattreynolds1d38d1162017-01-19 02:45:2418namespace physical_web {
19struct Metadata;
20using MetadataList = std::vector<Metadata>;
mattreynolds5afc01692016-08-19 22:09:5621}
22
23class PhysicalWebProvider : public AutocompleteProvider {
mattreynolds2b530de2016-09-02 18:20:1624 public:
mattreynolds08c79092016-09-14 22:00:0825 // The maximum number of match results to provide. If the number of nearby
26 // URLs exceeds this limit, an overflow item is created. Tapping the overflow
27 // item navigates to a page with the full list of nearby URLs. The overflow
28 // item is counted as a match result for the purposes of the match limit.
29 //
30 // ex: With kPhysicalWebMaxMatches == 1, there should be at most one
31 // suggestion created by this provider. If there is a single nearby URL, then
32 // the suggestion will be for that URL. If there are multiple nearby URLs, the
33 // suggestion will be the overflow item which navigates to the WebUI when
34 // tapped.
35 static const size_t kPhysicalWebMaxMatches;
36
mattreynolds2b530de2016-09-02 18:20:1637 static PhysicalWebProvider* Create(AutocompleteProviderClient* client,
38 HistoryURLProvider* history_url_provider);
mattreynolds5afc01692016-08-19 22:09:5639
40 // AutocompleteProvider:
41 void Start(const AutocompleteInput& input, bool minimal_changes) override;
42 void Stop(bool clear_cached_results, bool due_to_user_inactivity) override;
mattreynoldse2e018a42016-11-04 18:42:4543 void AddProviderInfo(ProvidersInfo* provider_info) const override;
mattreynolds5afc01692016-08-19 22:09:5644
mattreynolds2b530de2016-09-02 18:20:1645 private:
46 PhysicalWebProvider(AutocompleteProviderClient* client,
47 HistoryURLProvider* history_url_provider);
mattreynolds5afc01692016-08-19 22:09:5648 ~PhysicalWebProvider() override;
49
mattreynoldsa04fff02017-01-06 23:46:1850 // When the user has focused the omnibox but not yet entered any text (i.e.,
51 // the Zero Suggest case), calling this method adds a separate match item to
52 // |matches_| for each nearby URL in |metadata_list|, up to the maximum number
53 // of matches allowed. If the total number of nearby URLs exceeds this limit,
54 // one match is used for an overflow item.
55 void ConstructZeroSuggestMatches(
mattreynolds1d38d1162017-01-19 02:45:2456 std::unique_ptr<physical_web::MetadataList> metadata_list);
mattreynoldsa04fff02017-01-06 23:46:1857
58 // When the user has entered text into the omnibox (i.e., the Query Suggest
59 // case), calling this method adds a separate match item to |matches_| for
60 // each nearby URL in |metadata_list| that matches all of the query terms in
61 // |input|, up to the maximum number of matches allowed.
62 void ConstructQuerySuggestMatches(
mattreynolds1d38d1162017-01-19 02:45:2463 std::unique_ptr<physical_web::MetadataList> metadata_list,
mattreynoldsa04fff02017-01-06 23:46:1864 const AutocompleteInput& input);
mattreynolds5afc01692016-08-19 22:09:5665
66 // Adds an overflow match item to |matches_| with a relevance score equal to
67 // |relevance| and a label indicating there are |additional_url_count| more
mattreynolds08c79092016-09-14 22:00:0868 // nearby URLs. The page |title| of one of the additional nearby URLs will be
69 // included in the label, truncating if necessary. Selecting the overflow item
70 // navigates to the Physical Web WebUI, which displays the full list of nearby
71 // URLs.
72 void AppendOverflowItem(int additional_url_count,
73 int relevance,
74 const base::string16& title);
mattreynolds5afc01692016-08-19 22:09:5675
76 AutocompleteProviderClient* client_;
mattreynolds2b530de2016-09-02 18:20:1677
78 // Used for efficiency when creating the verbatim match. Can be null.
79 HistoryURLProvider* history_url_provider_;
80
mattreynoldse2e018a42016-11-04 18:42:4581 // The number of nearby Physical Web URLs when the provider last constructed
mattreynolds6b89f922017-02-23 20:53:2982 // matches. Initialized to string::npos.
mattreynoldse2e018a42016-11-04 18:42:4583 size_t nearby_url_count_;
84
mattreynolds6b89f922017-02-23 20:53:2985 // The number of nearby Physical Web URLs when the omnibox input was last
86 // focused. Initialized to string::npos.
87 // This value is set when the omnibox is focused and recorded when the user
88 // selects an omnibox suggestion. If the value is still string::npos when the
89 // user makes a selection, it indicates the omnibox was never focused.
90 size_t nearby_url_count_at_focus_;
91
mattreynoldsa04fff02017-01-06 23:46:1892 // If true, provide suggestions when the user has focused the omnibox but has
93 // not typed anything.
94 bool zero_suggest_enabled_;
95
96 // If true, provide suggestions when the user has entered a query into the
97 // omnibox.
98 bool after_typing_enabled_;
99
100 // The base relevance score for Physical Web URL suggestions when the user has
101 // not typed anything into the omnibox.
102 int zero_suggest_base_relevance_;
103
104 // The base relevance score for Physical Web URL suggestions after the user
105 // has typed a query into the omnibox.
106 int after_typing_base_relevance_;
107
108 // Set to true if at least one suggestion was created the last time the
109 // provider was started, even if the suggestion could not be displayed due to
110 // a field trial.
111 bool had_physical_web_suggestions_;
112
113 // Set to true if at least one suggestion was created since the last time the
114 // omnibox was focused, even if the suggestion could not be displayed due to
115 // a field trial.
116 bool had_physical_web_suggestions_at_focus_or_later_;
117
mattreynolds2b530de2016-09-02 18:20:16118 DISALLOW_COPY_AND_ASSIGN(PhysicalWebProvider);
mattreynolds5afc01692016-08-19 22:09:56119};
120
121#endif // COMPONENTS_OMNIBOX_BROWSER_PHYSICAL_WEB_PROVIDER_H_