OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 file contains the Search autocomplete provider. This provider is | 5 // This file contains the Search autocomplete provider. This provider is |
6 // responsible for all autocomplete entries that start with "Search <engine> | 6 // responsible for all autocomplete entries that start with "Search <engine> |
7 // for ...", including searching for the current input string, search | 7 // for ...", including searching for the current input string, search |
8 // history, and search suggestions. An instance of it gets created and | 8 // history, and search suggestions. An instance of it gets created and |
9 // managed by the autocomplete controller. | 9 // managed by the autocomplete controller. |
10 | 10 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 // |append_extra_query_params| should be set if |template_url| is the default | 77 // |append_extra_query_params| should be set if |template_url| is the default |
78 // search engine, so the destination URL will contain any | 78 // search engine, so the destination URL will contain any |
79 // command-line-specified query params. | 79 // command-line-specified query params. |
80 static AutocompleteMatch CreateSearchSuggestion( | 80 static AutocompleteMatch CreateSearchSuggestion( |
81 AutocompleteProvider* autocomplete_provider, | 81 AutocompleteProvider* autocomplete_provider, |
82 const AutocompleteInput& input, | 82 const AutocompleteInput& input, |
83 const string16& input_text, | 83 const string16& input_text, |
84 int relevance, | 84 int relevance, |
85 AutocompleteMatch::Type type, | 85 AutocompleteMatch::Type type, |
86 bool is_keyword, | 86 bool is_keyword, |
87 const string16& match_contents, | 87 const string16& title, |
| 88 const ACMatchClassifications& title_class, |
88 const string16& annotation, | 89 const string16& annotation, |
| 90 const ACMatchClassifications& annotation_class, |
89 const TemplateURL* template_url, | 91 const TemplateURL* template_url, |
90 const string16& query_string, | 92 const string16& query_string, |
91 const std::string& suggest_query_params, | 93 const std::string& suggest_query_params, |
92 int accepted_suggestion, | 94 int accepted_suggestion, |
93 int omnibox_start_margin, | 95 int omnibox_start_margin, |
94 bool append_extra_query_params); | 96 bool append_extra_query_params); |
95 | 97 |
96 // Returns whether the SearchProvider previously flagged |match| as a query | 98 // Returns whether the SearchProvider previously flagged |match| as a query |
97 // that should be prefetched. | 99 // that should be prefetched. |
98 static bool ShouldPrefetch(const AutocompleteMatch& match); | 100 static bool ShouldPrefetch(const AutocompleteMatch& match); |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 // based on server information, and thus is assumed to be more accurate. | 219 // based on server information, and thus is assumed to be more accurate. |
218 // This is ultimately used in | 220 // This is ultimately used in |
219 // SearchProvider::ConvertResultsToAutocompleteMatches(), see comments | 221 // SearchProvider::ConvertResultsToAutocompleteMatches(), see comments |
220 // there. | 222 // there. |
221 bool relevance_from_server_; | 223 bool relevance_from_server_; |
222 }; | 224 }; |
223 | 225 |
224 class SuggestResult : public Result { | 226 class SuggestResult : public Result { |
225 public: | 227 public: |
226 SuggestResult(const string16& suggestion, | 228 SuggestResult(const string16& suggestion, |
227 const string16& match_contents, | 229 AutocompleteMatchType::Type type, |
| 230 const string16& title, |
| 231 ACMatchClassifications title_class, |
228 const string16& annotation, | 232 const string16& annotation, |
| 233 ACMatchClassifications annotation_class, |
229 const std::string& suggest_query_params, | 234 const std::string& suggest_query_params, |
230 bool from_keyword_provider, | 235 bool from_keyword_provider, |
231 int relevance, | 236 int relevance, |
232 bool relevance_from_server, | 237 bool relevance_from_server, |
233 bool should_prefetch); | 238 bool should_prefetch); |
234 virtual ~SuggestResult(); | 239 virtual ~SuggestResult(); |
235 | 240 |
236 const string16& suggestion() const { return suggestion_; } | 241 const string16& suggestion() const { return suggestion_; } |
237 const string16& match_contents() const { return match_contents_; } | 242 AutocompleteMatchType::Type type() const { return type_; } |
| 243 const string16& title() const { return title_; } |
| 244 const ACMatchClassifications& title_class() const { return title_class_; } |
238 const string16& annotation() const { return annotation_; } | 245 const string16& annotation() const { return annotation_; } |
| 246 const ACMatchClassifications& annotation_class() const { |
| 247 return annotation_class_; |
| 248 } |
239 const std::string& suggest_query_params() const { | 249 const std::string& suggest_query_params() const { |
240 return suggest_query_params_; | 250 return suggest_query_params_; |
241 } | 251 } |
242 bool should_prefetch() const { return should_prefetch_; } | 252 bool should_prefetch() const { return should_prefetch_; } |
243 | 253 |
244 // Result: | 254 // Result: |
245 virtual bool IsInlineable(const string16& input) const OVERRIDE; | 255 virtual bool IsInlineable(const string16& input) const OVERRIDE; |
246 virtual int CalculateRelevance( | 256 virtual int CalculateRelevance( |
247 const AutocompleteInput& input, | 257 const AutocompleteInput& input, |
248 bool keyword_provider_requested) const OVERRIDE; | 258 bool keyword_provider_requested) const OVERRIDE; |
249 | 259 |
250 private: | 260 private: |
251 // The search terms to be used for this suggestion. | 261 // The search terms to be used for this suggestion. |
252 string16 suggestion_; | 262 string16 suggestion_; |
253 | 263 |
| 264 AutocompleteMatchType::Type type_; |
| 265 |
254 // The contents to be displayed in the autocomplete match. | 266 // The contents to be displayed in the autocomplete match. |
255 string16 match_contents_; | 267 string16 title_; |
| 268 ACMatchClassifications title_class_; |
256 | 269 |
257 // Optional annotation for the |match_contents_| for disambiguation. | 270 // Optional annotation for the |title_| for disambiguation. |
258 // This may be displayed in the autocomplete match contents, but is defined | 271 // This may be displayed in the autocomplete match contents, but is defined |
259 // separately to facilitate different formatting. | 272 // separately to facilitate different formatting. |
260 string16 annotation_; | 273 string16 annotation_; |
| 274 ACMatchClassifications annotation_class_; |
261 | 275 |
262 // Optional additional parameters to be added to the search URL. | 276 // Optional additional parameters to be added to the search URL. |
263 std::string suggest_query_params_; | 277 std::string suggest_query_params_; |
264 | 278 |
265 // Should this result be prefetched? | 279 // Should this result be prefetched? |
266 bool should_prefetch_; | 280 bool should_prefetch_; |
267 }; | 281 }; |
268 | 282 |
269 class NavigationResult : public Result { | 283 class NavigationResult : public Result { |
270 public: | 284 public: |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
488 // Creates an AutocompleteMatch for "Search <engine> for |query_string|" with | 502 // Creates an AutocompleteMatch for "Search <engine> for |query_string|" with |
489 // the supplied relevance. Adds this match to |map|; if such a match already | 503 // the supplied relevance. Adds this match to |map|; if such a match already |
490 // exists, whichever one has lower relevance is eliminated. | 504 // exists, whichever one has lower relevance is eliminated. |
491 void AddMatchToMap(const string16& input_text, | 505 void AddMatchToMap(const string16& input_text, |
492 int relevance, | 506 int relevance, |
493 bool relevance_from_server, | 507 bool relevance_from_server, |
494 bool should_prefetch, | 508 bool should_prefetch, |
495 const std::string& metadata, | 509 const std::string& metadata, |
496 AutocompleteMatch::Type type, | 510 AutocompleteMatch::Type type, |
497 bool is_keyword, | 511 bool is_keyword, |
498 const string16& match_contents, | 512 const string16& title, |
| 513 const ACMatchClassifications& title_class, |
499 const string16& annotation, | 514 const string16& annotation, |
| 515 const ACMatchClassifications& annotation_class, |
500 const string16& query_string, | 516 const string16& query_string, |
501 int accepted_suggestion, | 517 int accepted_suggestion, |
502 const std::string& suggest_query_params, | 518 const std::string& suggest_query_params, |
503 MatchMap* map); | 519 MatchMap* map); |
504 | 520 |
505 // Returns an AutocompleteMatch for a navigational suggestion. | 521 // Returns an AutocompleteMatch for a navigational suggestion. |
506 AutocompleteMatch NavigationToMatch(const NavigationResult& navigation); | 522 AutocompleteMatch NavigationToMatch(const NavigationResult& navigation); |
507 | 523 |
508 // Resets the scores of all |keyword_navigation_results_| matches to | 524 // Resets the scores of all |keyword_navigation_results_| matches to |
509 // be below that of the top keyword query match (the verbatim match | 525 // be below that of the top keyword query match (the verbatim match |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
584 bool field_trial_triggered_in_session_; | 600 bool field_trial_triggered_in_session_; |
585 | 601 |
586 // If true, search history query suggestions will score low enough that | 602 // If true, search history query suggestions will score low enough that |
587 // they will not be inlined. | 603 // they will not be inlined. |
588 bool prevent_search_history_inlining_; | 604 bool prevent_search_history_inlining_; |
589 | 605 |
590 DISALLOW_COPY_AND_ASSIGN(SearchProvider); | 606 DISALLOW_COPY_AND_ASSIGN(SearchProvider); |
591 }; | 607 }; |
592 | 608 |
593 #endif // CHROME_BROWSER_AUTOCOMPLETE_SEARCH_PROVIDER_H_ | 609 #endif // CHROME_BROWSER_AUTOCOMPLETE_SEARCH_PROVIDER_H_ |
OLD | NEW |