Chromium Code Reviews| Index: chrome/browser/autocomplete/autocomplete.cc |
| =================================================================== |
| --- chrome/browser/autocomplete/autocomplete.cc (revision 95169) |
| +++ chrome/browser/autocomplete/autocomplete.cc (working copy) |
| @@ -5,6 +5,7 @@ |
| #include "chrome/browser/autocomplete/autocomplete.h" |
| #include <algorithm> |
| +#include <set> |
| #include "base/basictypes.h" |
| #include "base/command_line.h" |
| @@ -24,12 +25,16 @@ |
| #include "chrome/browser/autocomplete/search_provider.h" |
| #include "chrome/browser/autocomplete/shortcuts_provider.h" |
| #include "chrome/browser/bookmarks/bookmark_model.h" |
| +#include "chrome/browser/extensions/extension_service.h" |
| #include "chrome/browser/external_protocol/external_protocol_handler.h" |
| #include "chrome/browser/instant/instant_field_trial.h" |
| #include "chrome/browser/net/url_fixer_upper.h" |
| #include "chrome/browser/prefs/pref_service.h" |
| #include "chrome/browser/profiles/profile.h" |
| #include "chrome/browser/profiles/profile_io_data.h" |
| +#include "chrome/browser/search_engines/template_url.h" |
| +#include "chrome/browser/search_engines/template_url_service.h" |
| +#include "chrome/browser/search_engines/template_url_service_factory.h" |
| #include "chrome/browser/ui/webui/history_ui.h" |
| #include "chrome/common/chrome_notification_types.h" |
| #include "chrome/common/chrome_switches.h" |
| @@ -651,6 +656,9 @@ |
| } |
| void AutocompleteResult::SortAndCull(const AutocompleteInput& input) { |
| + for (ACMatches::iterator i = matches_.begin(); i != matches_.end(); ++i) |
| + i->ComputeStrippedDestinationURL(); |
| + |
| // Remove duplicates. |
| std::sort(matches_.begin(), matches_.end(), |
| &AutocompleteMatch::DestinationSortFunc); |
| @@ -953,6 +961,8 @@ |
| // Sort the matches and trim to a small number of "best" matches. |
| result_.SortAndCull(input_); |
| + PopulateMatchKeywordHints(); |
| + |
| // Need to validate before invoking CopyOldMatches as the old matches are not |
| // valid against the current input. |
| #ifndef NDEBUG |
| @@ -986,6 +996,28 @@ |
| NotifyChanged(notify_default_match); |
| } |
| +void AutocompleteController::PopulateMatchKeywordHints() { |
| + std::set<string16> keywords; |
| + for (ACMatches::iterator match(result_.begin()); match != result_.end(); |
| + ++match) { |
| + if (!match->keyword.empty()) { |
| + keywords.insert(match->keyword); |
| + } else if (keyword_provider_) { |
| + string16 keyword = |
| + keyword_provider_->GetKeywordForText(match->fill_into_edit); |
| + |
| + // Only add the keyword if the match does not have a duplicate keyword |
| + // with a more relevant match. |
| + if (!keyword.empty() && !keywords.count(keyword)) { |
| + match->associated_keyword.reset(new AutocompleteMatch( |
| + keyword_provider_->CreateAutocompleteMatch(keyword, input_))); |
|
sky
2011/08/09 00:32:51
Because we might copy old results do we always nee
aaron.randolph
2011/08/16 17:52:43
I don't think they are necessary as this function
sky
2011/08/17 17:02:19
How come you don't invoke this (PopuplateMatchKeyw
aaron.randolph
2011/08/17 18:02:46
Honestly, because I forgot that besides setting as
|
| + |
| + keywords.insert(keyword); |
| + } |
| + } |
| + } |
| +} |
| + |
| void AutocompleteController::UpdateKeywordDescriptions( |
| AutocompleteResult* result) { |
| const TemplateURL* last_template_url = NULL; |
| @@ -1040,3 +1072,4 @@ |
| expire_timer_.Start(base::TimeDelta::FromMilliseconds(kExpireTimeMS), |
| this, &AutocompleteController::ExpireCopiedEntries); |
| } |
| + |