OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "chrome/browser/autocomplete/autocomplete.h" | 5 #include "chrome/browser/autocomplete/autocomplete.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <set> | |
8 | 9 |
9 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
10 #include "base/command_line.h" | 11 #include "base/command_line.h" |
11 #include "base/i18n/number_formatting.h" | 12 #include "base/i18n/number_formatting.h" |
12 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
13 #include "base/string_number_conversions.h" | 14 #include "base/string_number_conversions.h" |
14 #include "base/string_util.h" | 15 #include "base/string_util.h" |
15 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
16 #include "chrome/browser/autocomplete/autocomplete_controller_delegate.h" | 17 #include "chrome/browser/autocomplete/autocomplete_controller_delegate.h" |
17 #include "chrome/browser/autocomplete/autocomplete_match.h" | 18 #include "chrome/browser/autocomplete/autocomplete_match.h" |
18 #include "chrome/browser/autocomplete/builtin_provider.h" | 19 #include "chrome/browser/autocomplete/builtin_provider.h" |
19 #include "chrome/browser/autocomplete/extension_app_provider.h" | 20 #include "chrome/browser/autocomplete/extension_app_provider.h" |
20 #include "chrome/browser/autocomplete/history_contents_provider.h" | 21 #include "chrome/browser/autocomplete/history_contents_provider.h" |
21 #include "chrome/browser/autocomplete/history_quick_provider.h" | 22 #include "chrome/browser/autocomplete/history_quick_provider.h" |
22 #include "chrome/browser/autocomplete/history_url_provider.h" | 23 #include "chrome/browser/autocomplete/history_url_provider.h" |
23 #include "chrome/browser/autocomplete/keyword_provider.h" | 24 #include "chrome/browser/autocomplete/keyword_provider.h" |
24 #include "chrome/browser/autocomplete/search_provider.h" | 25 #include "chrome/browser/autocomplete/search_provider.h" |
25 #include "chrome/browser/autocomplete/shortcuts_provider.h" | 26 #include "chrome/browser/autocomplete/shortcuts_provider.h" |
26 #include "chrome/browser/bookmarks/bookmark_model.h" | 27 #include "chrome/browser/bookmarks/bookmark_model.h" |
28 #include "chrome/browser/extensions/extension_service.h" | |
27 #include "chrome/browser/external_protocol/external_protocol_handler.h" | 29 #include "chrome/browser/external_protocol/external_protocol_handler.h" |
28 #include "chrome/browser/instant/instant_field_trial.h" | 30 #include "chrome/browser/instant/instant_field_trial.h" |
29 #include "chrome/browser/net/url_fixer_upper.h" | 31 #include "chrome/browser/net/url_fixer_upper.h" |
30 #include "chrome/browser/prefs/pref_service.h" | 32 #include "chrome/browser/prefs/pref_service.h" |
31 #include "chrome/browser/profiles/profile.h" | 33 #include "chrome/browser/profiles/profile.h" |
32 #include "chrome/browser/profiles/profile_io_data.h" | 34 #include "chrome/browser/profiles/profile_io_data.h" |
35 #include "chrome/browser/search_engines/template_url.h" | |
36 #include "chrome/browser/search_engines/template_url_service.h" | |
37 #include "chrome/browser/search_engines/template_url_service_factory.h" | |
33 #include "chrome/browser/ui/webui/history_ui.h" | 38 #include "chrome/browser/ui/webui/history_ui.h" |
34 #include "chrome/common/chrome_notification_types.h" | 39 #include "chrome/common/chrome_notification_types.h" |
35 #include "chrome/common/chrome_switches.h" | 40 #include "chrome/common/chrome_switches.h" |
36 #include "chrome/common/pref_names.h" | 41 #include "chrome/common/pref_names.h" |
37 #include "chrome/common/url_constants.h" | 42 #include "chrome/common/url_constants.h" |
38 #include "content/common/notification_service.h" | 43 #include "content/common/notification_service.h" |
39 #include "googleurl/src/gurl.h" | 44 #include "googleurl/src/gurl.h" |
40 #include "googleurl/src/url_canon_ip.h" | 45 #include "googleurl/src/url_canon_ip.h" |
41 #include "googleurl/src/url_util.h" | 46 #include "googleurl/src/url_util.h" |
42 #include "grit/generated_resources.h" | 47 #include "grit/generated_resources.h" |
(...skipping 601 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
644 std::upper_bound(begin(), end(), match, &AutocompleteMatch::MoreRelevant); | 649 std::upper_bound(begin(), end(), match, &AutocompleteMatch::MoreRelevant); |
645 ACMatches::iterator::difference_type default_offset = | 650 ACMatches::iterator::difference_type default_offset = |
646 default_match_ - begin(); | 651 default_match_ - begin(); |
647 if ((insertion_point - begin()) <= default_offset) | 652 if ((insertion_point - begin()) <= default_offset) |
648 ++default_offset; | 653 ++default_offset; |
649 matches_.insert(insertion_point, match); | 654 matches_.insert(insertion_point, match); |
650 default_match_ = begin() + default_offset; | 655 default_match_ = begin() + default_offset; |
651 } | 656 } |
652 | 657 |
653 void AutocompleteResult::SortAndCull(const AutocompleteInput& input) { | 658 void AutocompleteResult::SortAndCull(const AutocompleteInput& input) { |
659 for (ACMatches::iterator i = matches_.begin(); i != matches_.end(); ++i) | |
660 i->ComputeStrippedDestinationURL(); | |
661 | |
654 // Remove duplicates. | 662 // Remove duplicates. |
655 std::sort(matches_.begin(), matches_.end(), | 663 std::sort(matches_.begin(), matches_.end(), |
656 &AutocompleteMatch::DestinationSortFunc); | 664 &AutocompleteMatch::DestinationSortFunc); |
657 matches_.erase(std::unique(matches_.begin(), matches_.end(), | 665 matches_.erase(std::unique(matches_.begin(), matches_.end(), |
658 &AutocompleteMatch::DestinationsEqual), | 666 &AutocompleteMatch::DestinationsEqual), |
659 matches_.end()); | 667 matches_.end()); |
660 | 668 |
661 // Sort and trim to the most relevant kMaxMatches matches. | 669 // Sort and trim to the most relevant kMaxMatches matches. |
662 const size_t num_matches = std::min(kMaxMatches, matches_.size()); | 670 const size_t num_matches = std::min(kMaxMatches, matches_.size()); |
663 std::partial_sort(matches_.begin(), matches_.begin() + num_matches, | 671 std::partial_sort(matches_.begin(), matches_.begin() + num_matches, |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
946 AutocompleteResult last_result; | 954 AutocompleteResult last_result; |
947 last_result.Swap(&result_); | 955 last_result.Swap(&result_); |
948 | 956 |
949 for (ACProviders::const_iterator i(providers_.begin()); i != providers_.end(); | 957 for (ACProviders::const_iterator i(providers_.begin()); i != providers_.end(); |
950 ++i) | 958 ++i) |
951 result_.AppendMatches((*i)->matches()); | 959 result_.AppendMatches((*i)->matches()); |
952 | 960 |
953 // Sort the matches and trim to a small number of "best" matches. | 961 // Sort the matches and trim to a small number of "best" matches. |
954 result_.SortAndCull(input_); | 962 result_.SortAndCull(input_); |
955 | 963 |
964 std::set<string16> keywords; | |
sky
2011/08/01 16:02:15
What this loop is doing doesn't depend upon state
| |
965 for (ACMatches::iterator match(result_.begin()); match != result_.end(); | |
966 ++match) { | |
967 if (!match->keyword.empty()) { | |
968 keywords.insert(match->keyword); | |
969 } else { | |
970 string16 keyword = keyword_provider_->GetKeywordForText( | |
Peter Kasting
2011/07/29 21:08:44
Nit: Slightly more readable if you linebreak after
| |
971 match->fill_into_edit); | |
972 | |
973 // Only add the keyword if the match does not have a duplicate keyword | |
sky
2011/08/01 16:02:15
This comment doesn't seem to match the if (it does
aaron.randolph
2011/08/02 21:54:58
It doesn't check relevance because it expects the
| |
974 // with a more relevant match. | |
975 if (!keyword.empty() && !keywords.count(keyword)) { | |
976 match->associated_keyword.reset(new AutocompleteMatch( | |
977 keyword_provider_->CreateAutocompleteMatch(keyword, input_))); | |
978 | |
979 keywords.insert(keyword); | |
980 } | |
981 } | |
982 } | |
983 | |
956 // Need to validate before invoking CopyOldMatches as the old matches are not | 984 // Need to validate before invoking CopyOldMatches as the old matches are not |
957 // valid against the current input. | 985 // valid against the current input. |
958 #ifndef NDEBUG | 986 #ifndef NDEBUG |
959 result_.Validate(); | 987 result_.Validate(); |
960 #endif | 988 #endif |
961 | 989 |
962 if (!done_) { | 990 if (!done_) { |
963 // This conditional needs to match the conditional in Start that invokes | 991 // This conditional needs to match the conditional in Start that invokes |
964 // StartExpireTimer. | 992 // StartExpireTimer. |
965 result_.CopyOldMatches(input_, last_result); | 993 result_.CopyOldMatches(input_, last_result); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1033 } | 1061 } |
1034 } | 1062 } |
1035 done_ = true; | 1063 done_ = true; |
1036 } | 1064 } |
1037 | 1065 |
1038 void AutocompleteController::StartExpireTimer() { | 1066 void AutocompleteController::StartExpireTimer() { |
1039 if (result_.HasCopiedMatches()) | 1067 if (result_.HasCopiedMatches()) |
1040 expire_timer_.Start(base::TimeDelta::FromMilliseconds(kExpireTimeMS), | 1068 expire_timer_.Start(base::TimeDelta::FromMilliseconds(kExpireTimeMS), |
1041 this, &AutocompleteController::ExpireCopiedEntries); | 1069 this, &AutocompleteController::ExpireCopiedEntries); |
1042 } | 1070 } |
1071 | |
OLD | NEW |