OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 // | 4 // |
5 // This class contains common functionality for search-based autocomplete | 5 // This class contains common functionality for search-based autocomplete |
6 // providers. Search provider and zero suggest provider both use it for common | 6 // providers. Search provider and zero suggest provider both use it for common |
7 // functionality. | 7 // functionality. |
8 | 8 |
9 #ifndef CHROME_BROWSER_AUTOCOMPLETE_BASE_SEARCH_PROVIDER_H_ | 9 #ifndef CHROME_BROWSER_AUTOCOMPLETE_BASE_SEARCH_PROVIDER_H_ |
10 #define CHROME_BROWSER_AUTOCOMPLETE_BASE_SEARCH_PROVIDER_H_ | 10 #define CHROME_BROWSER_AUTOCOMPLETE_BASE_SEARCH_PROVIDER_H_ |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 // Returns an AutocompleteMatch with the given |autocomplete_provider| | 107 // Returns an AutocompleteMatch with the given |autocomplete_provider| |
108 // for the search |suggestion|, which represents a search via |template_url|. | 108 // for the search |suggestion|, which represents a search via |template_url|. |
109 // If |template_url| is NULL, returns a match with an invalid destination URL. | 109 // If |template_url| is NULL, returns a match with an invalid destination URL. |
110 // | 110 // |
111 // |input| is the original user input. Text in the input is used to highlight | 111 // |input| is the original user input. Text in the input is used to highlight |
112 // portions of the match contents to distinguish locally-typed text from | 112 // portions of the match contents to distinguish locally-typed text from |
113 // suggested text. | 113 // suggested text. |
114 // | 114 // |
115 // |input| is also necessary for various other details, like whether we should | 115 // |input| is also necessary for various other details, like whether we should |
116 // allow inline autocompletion and what the transition type should be. | 116 // allow inline autocompletion and what the transition type should be. |
| 117 // |in_keyword_mode| helps guarantee a non-keyword suggestion does not |
| 118 // appear as the default match when the user is in keyword mode. |
117 // |accepted_suggestion| is used to generate Assisted Query Stats. | 119 // |accepted_suggestion| is used to generate Assisted Query Stats. |
118 // |append_extra_query_params| should be set if |template_url| is the default | 120 // |append_extra_query_params| should be set if |template_url| is the default |
119 // search engine, so the destination URL will contain any | 121 // search engine, so the destination URL will contain any |
120 // command-line-specified query params. | 122 // command-line-specified query params. |
121 static AutocompleteMatch CreateSearchSuggestion( | 123 static AutocompleteMatch CreateSearchSuggestion( |
122 AutocompleteProvider* autocomplete_provider, | 124 AutocompleteProvider* autocomplete_provider, |
123 const AutocompleteInput& input, | 125 const AutocompleteInput& input, |
| 126 const bool in_keyword_mode, |
124 const SearchSuggestionParser::SuggestResult& suggestion, | 127 const SearchSuggestionParser::SuggestResult& suggestion, |
125 const TemplateURL* template_url, | 128 const TemplateURL* template_url, |
126 const SearchTermsData& search_terms_data, | 129 const SearchTermsData& search_terms_data, |
127 int accepted_suggestion, | 130 int accepted_suggestion, |
128 bool append_extra_query_params); | 131 bool append_extra_query_params); |
129 | 132 |
130 // Returns whether the requirements for requesting zero suggest results | 133 // Returns whether the requirements for requesting zero suggest results |
131 // are met. The requirements are | 134 // are met. The requirements are |
132 // * The user is enrolled in a zero suggest experiment. | 135 // * The user is enrolled in a zero suggest experiment. |
133 // * The user is not on the NTP. | 136 // * The user is not on the NTP. |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 // the key |kDeletionUrlKey|. | 178 // the key |kDeletionUrlKey|. |
176 void SetDeletionURL(const std::string& deletion_url, | 179 void SetDeletionURL(const std::string& deletion_url, |
177 AutocompleteMatch* match); | 180 AutocompleteMatch* match); |
178 | 181 |
179 // Creates an AutocompleteMatch from |result| to search for the query in | 182 // Creates an AutocompleteMatch from |result| to search for the query in |
180 // |result|. Adds the created match to |map|; if such a match | 183 // |result|. Adds the created match to |map|; if such a match |
181 // already exists, whichever one has lower relevance is eliminated. | 184 // already exists, whichever one has lower relevance is eliminated. |
182 // |metadata| and |accepted_suggestion| are used for generating an | 185 // |metadata| and |accepted_suggestion| are used for generating an |
183 // AutocompleteMatch. | 186 // AutocompleteMatch. |
184 // |mark_as_deletable| indicates whether the match should be marked deletable. | 187 // |mark_as_deletable| indicates whether the match should be marked deletable. |
| 188 // |in_keyword_mode| helps guarantee a non-keyword suggestion does not |
| 189 // appear as the default match when the user is in keyword mode. |
185 // NOTE: Any result containing a deletion URL is always marked deletable. | 190 // NOTE: Any result containing a deletion URL is always marked deletable. |
186 void AddMatchToMap(const SearchSuggestionParser::SuggestResult& result, | 191 void AddMatchToMap(const SearchSuggestionParser::SuggestResult& result, |
187 const std::string& metadata, | 192 const std::string& metadata, |
188 int accepted_suggestion, | 193 int accepted_suggestion, |
189 bool mark_as_deletable, | 194 bool mark_as_deletable, |
| 195 bool in_keyword_mode, |
190 MatchMap* map); | 196 MatchMap* map); |
191 | 197 |
192 // Parses results from the suggest server and updates the appropriate suggest | 198 // Parses results from the suggest server and updates the appropriate suggest |
193 // and navigation result lists in |results|. |is_keyword_result| indicates | 199 // and navigation result lists in |results|. |is_keyword_result| indicates |
194 // whether the response was received from the keyword provider. | 200 // whether the response was received from the keyword provider. |
195 // Returns whether the appropriate result list members were updated. | 201 // Returns whether the appropriate result list members were updated. |
196 bool ParseSuggestResults(const base::Value& root_val, | 202 bool ParseSuggestResults(const base::Value& root_val, |
197 bool is_keyword_result, | 203 bool is_keyword_result, |
198 SearchSuggestionParser::Results* results); | 204 SearchSuggestionParser::Results* results); |
199 | 205 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 | 289 |
284 // Each deletion handler in this vector corresponds to an outstanding request | 290 // Each deletion handler in this vector corresponds to an outstanding request |
285 // that a server delete a personalized suggestion. Making this a ScopedVector | 291 // that a server delete a personalized suggestion. Making this a ScopedVector |
286 // causes us to auto-cancel all such requests on shutdown. | 292 // causes us to auto-cancel all such requests on shutdown. |
287 SuggestionDeletionHandlers deletion_handlers_; | 293 SuggestionDeletionHandlers deletion_handlers_; |
288 | 294 |
289 DISALLOW_COPY_AND_ASSIGN(BaseSearchProvider); | 295 DISALLOW_COPY_AND_ASSIGN(BaseSearchProvider); |
290 }; | 296 }; |
291 | 297 |
292 #endif // CHROME_BROWSER_AUTOCOMPLETE_BASE_SEARCH_PROVIDER_H_ | 298 #endif // CHROME_BROWSER_AUTOCOMPLETE_BASE_SEARCH_PROVIDER_H_ |
OLD | NEW |