Chromium Code Reviews| 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 #include "chrome/browser/autocomplete/autocomplete.h" | 5 #include "chrome/browser/autocomplete/autocomplete.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <iterator> | 8 #include <iterator> |
| 9 #include <set> | 9 #include <set> |
| 10 | 10 |
| (...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 712 matches_.end()); | 712 matches_.end()); |
| 713 | 713 |
| 714 // Sort and trim to the most relevant kMaxMatches matches. | 714 // Sort and trim to the most relevant kMaxMatches matches. |
| 715 const size_t num_matches = std::min(kMaxMatches, matches_.size()); | 715 const size_t num_matches = std::min(kMaxMatches, matches_.size()); |
| 716 std::partial_sort(matches_.begin(), matches_.begin() + num_matches, | 716 std::partial_sort(matches_.begin(), matches_.begin() + num_matches, |
| 717 matches_.end(), &AutocompleteMatch::MoreRelevant); | 717 matches_.end(), &AutocompleteMatch::MoreRelevant); |
| 718 matches_.resize(num_matches); | 718 matches_.resize(num_matches); |
| 719 | 719 |
| 720 default_match_ = begin(); | 720 default_match_ = begin(); |
| 721 | 721 |
| 722 // TODO(msw): Somehow need to stop inlining stale data "a[mazon]" -> "ad". | |
|
Peter Kasting
2012/05/04 00:11:33
We should never be reaching here with stale data.
msw
2012/05/04 09:43:40
It's no longer 'stale'; but see CopyOldMatches for
| |
| 723 //if (default_match() != end() && | |
| 724 // default_match()->inline_autocomplete_offset != string16::npos && | |
| 725 // !StartsWith(default_match()->contents, input.text(), false)) { | |
| 726 // matches_.begin()->inline_autocomplete_offset = string16::npos; | |
| 727 //} | |
| 728 | |
| 722 // Set the alternate nav URL. | 729 // Set the alternate nav URL. |
| 723 alternate_nav_url_ = GURL(); | 730 alternate_nav_url_ = GURL(); |
| 724 if (((input.type() == AutocompleteInput::UNKNOWN) || | 731 if (((input.type() == AutocompleteInput::UNKNOWN) || |
| 725 (input.type() == AutocompleteInput::REQUESTED_URL)) && | 732 (input.type() == AutocompleteInput::REQUESTED_URL)) && |
| 726 (default_match_ != end()) && | 733 (default_match_ != end()) && |
| 727 (default_match_->transition != content::PAGE_TRANSITION_TYPED) && | 734 (default_match_->transition != content::PAGE_TRANSITION_TYPED) && |
| 728 (default_match_->transition != content::PAGE_TRANSITION_KEYWORD) && | 735 (default_match_->transition != content::PAGE_TRANSITION_KEYWORD) && |
| 729 (input.canonicalized_url() != default_match_->destination_url)) | 736 (input.canonicalized_url() != default_match_->destination_url)) |
| 730 alternate_nav_url_ = input.canonicalized_url(); | 737 alternate_nav_url_ = input.canonicalized_url(); |
| 731 } | 738 } |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 991 | 998 |
| 992 void AutocompleteController::UpdateResult(bool is_synchronous_pass) { | 999 void AutocompleteController::UpdateResult(bool is_synchronous_pass) { |
| 993 AutocompleteResult last_result; | 1000 AutocompleteResult last_result; |
| 994 last_result.Swap(&result_); | 1001 last_result.Swap(&result_); |
| 995 | 1002 |
| 996 for (ACProviders::const_iterator i(providers_.begin()); i != providers_.end(); | 1003 for (ACProviders::const_iterator i(providers_.begin()); i != providers_.end(); |
| 997 ++i) | 1004 ++i) |
| 998 result_.AppendMatches((*i)->matches()); | 1005 result_.AppendMatches((*i)->matches()); |
| 999 | 1006 |
| 1000 // Sort the matches and trim to a small number of "best" matches. | 1007 // Sort the matches and trim to a small number of "best" matches. |
| 1008 // TODO(msw): Remove or sanitize old matches? | |
| 1009 // (type == SEARCH_SUGGEST && from_previous == true)? | |
| 1001 result_.SortAndCull(input_); | 1010 result_.SortAndCull(input_); |
| 1002 | 1011 |
| 1003 // Need to validate before invoking CopyOldMatches as the old matches are not | 1012 // Need to validate before invoking CopyOldMatches as the old matches are not |
| 1004 // valid against the current input. | 1013 // valid against the current input. |
| 1005 #ifndef NDEBUG | 1014 #ifndef NDEBUG |
| 1006 result_.Validate(); | 1015 result_.Validate(); |
| 1007 #endif | 1016 #endif |
| 1008 | 1017 |
| 1009 if (!done_) { | 1018 if (!done_) { |
| 1010 // This conditional needs to match the conditional in Start that invokes | 1019 // This conditional needs to match the conditional in Start that invokes |
| 1011 // StartExpireTimer. | 1020 // StartExpireTimer. |
| 1012 result_.CopyOldMatches(input_, last_result); | 1021 result_.CopyOldMatches(input_, last_result); |
| 1013 } | 1022 } |
| 1014 | 1023 |
| 1015 UpdateKeywordDescriptions(&result_); | 1024 UpdateKeywordDescriptions(&result_); |
| 1016 UpdateAssociatedKeywords(&result_); | 1025 UpdateAssociatedKeywords(&result_); |
| 1017 | 1026 |
| 1018 bool notify_default_match = is_synchronous_pass; | 1027 const bool last_default_was_valid = |
|
Peter Kasting
2012/05/04 00:11:33
Why wouldn't we want to always notify on the synch
msw
2012/05/04 09:43:40
Reverted.
| |
| 1019 if (!is_synchronous_pass) { | 1028 last_result.default_match() != last_result.end(); |
| 1020 const bool last_default_was_valid = | 1029 const bool default_is_valid = result_.default_match() != result_.end(); |
| 1021 last_result.default_match() != last_result.end(); | 1030 // We've gotten async results. Send notification that the default match |
| 1022 const bool default_is_valid = result_.default_match() != result_.end(); | 1031 // updated if fill_into_edit differs or associated_keyword differ. (The |
| 1023 // We've gotten async results. Send notification that the default match | 1032 // latter can change if we've just started Chrome and the keyword database |
| 1024 // updated if fill_into_edit differs or associated_keyword differ. (The | 1033 // finishes loading while processing this request.) We don't check the URL |
| 1025 // latter can change if we've just started Chrome and the keyword database | 1034 // as that may change for the default match even though the fill into edit |
| 1026 // finishes loading while processing this request.) We don't check the URL | 1035 // hasn't changed (see SearchProvider for one case of this). |
| 1027 // as that may change for the default match even though the fill into edit | 1036 bool notify_default_match = |
| 1028 // hasn't changed (see SearchProvider for one case of this). | 1037 (last_default_was_valid != default_is_valid) || |
| 1029 notify_default_match = | 1038 (default_is_valid && |
| 1030 (last_default_was_valid != default_is_valid) || | 1039 ((result_.default_match()->fill_into_edit != |
| 1031 (default_is_valid && | 1040 last_result.default_match()->fill_into_edit) || |
| 1032 ((result_.default_match()->fill_into_edit != | 1041 (result_.default_match()->associated_keyword.get() != |
| 1033 last_result.default_match()->fill_into_edit) || | 1042 last_result.default_match()->associated_keyword.get()))); |
| 1034 (result_.default_match()->associated_keyword.get() != | |
| 1035 last_result.default_match()->associated_keyword.get()))); | |
| 1036 } | |
| 1037 | 1043 |
| 1038 NotifyChanged(notify_default_match); | 1044 NotifyChanged(notify_default_match); |
| 1039 } | 1045 } |
| 1040 | 1046 |
| 1041 void AutocompleteController::UpdateAssociatedKeywords( | 1047 void AutocompleteController::UpdateAssociatedKeywords( |
| 1042 AutocompleteResult* result) { | 1048 AutocompleteResult* result) { |
| 1043 if (!keyword_provider_) | 1049 if (!keyword_provider_) |
| 1044 return; | 1050 return; |
| 1045 | 1051 |
| 1046 std::set<string16> keywords; | 1052 std::set<string16> keywords; |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1138 const AutocompleteResult& result) | 1144 const AutocompleteResult& result) |
| 1139 : text(text), | 1145 : text(text), |
| 1140 input_type(input_type), | 1146 input_type(input_type), |
| 1141 selected_index(selected_index), | 1147 selected_index(selected_index), |
| 1142 tab_id(tab_id), | 1148 tab_id(tab_id), |
| 1143 elapsed_time_since_user_first_modified_omnibox( | 1149 elapsed_time_since_user_first_modified_omnibox( |
| 1144 elapsed_time_since_user_first_modified_omnibox), | 1150 elapsed_time_since_user_first_modified_omnibox), |
| 1145 inline_autocompleted_length(inline_autocompleted_length), | 1151 inline_autocompleted_length(inline_autocompleted_length), |
| 1146 result(result) { | 1152 result(result) { |
| 1147 } | 1153 } |
| OLD | NEW |