Chromium Code Reviews| Index: chrome/browser/autocomplete/autocomplete.cc |
| =================================================================== |
| --- chrome/browser/autocomplete/autocomplete.cc (revision 116848) |
| +++ 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" |
| @@ -684,6 +689,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); |
| @@ -989,6 +997,7 @@ |
| } |
| UpdateKeywordDescriptions(&result_); |
| + UpdateAssociatedKeywords(&result_); |
| bool notify_default_match = is_synchronous_pass; |
| if (!is_synchronous_pass) { |
| @@ -1009,6 +1018,40 @@ |
| NotifyChanged(notify_default_match); |
| } |
| +void AutocompleteController::UpdateAssociatedKeywords( |
| + AutocompleteResult* result) { |
| + if (!keyword_provider_) |
| + return; |
| + |
| + std::set<string16> keywords; |
| + string16 remaining_input; |
|
Peter Kasting
2012/01/11 03:00:16
Nit: Declare this in the most local scope
|
| + for (ACMatches::iterator match(result->begin()); match != result->end(); |
| + ++match) { |
| + if (!match->keyword.empty()) { |
| + keywords.insert(match->keyword); |
| + } else { |
| + string16 keyword = match->associated_keyword.get() ? |
| + match->associated_keyword->keyword : |
| + keyword_provider_->GetKeywordForText( |
| + KeywordProvider::SplitKeywordFromInput(match->fill_into_edit, |
| + false, &remaining_input)); |
| + |
| + // Only add the keyword if the match does not have a duplicate keyword |
| + // with a more relevant match. |
| + if (!keyword.empty() && !keywords.count(keyword)) { |
| + keywords.insert(keyword); |
| + |
| + if (!match->associated_keyword.get()) |
| + match->associated_keyword.reset(new AutocompleteMatch( |
| + keyword_provider_->CreateAutocompleteMatch(match->fill_into_edit, |
| + keyword, input_))); |
| + } else { |
| + match->associated_keyword.reset(); |
| + } |
| + } |
| + } |
| +} |
| + |
| void AutocompleteController::UpdateKeywordDescriptions( |
| AutocompleteResult* result) { |
| const TemplateURL* last_template_url = NULL; |