diff options
author | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-12 19:19:02 +0000 |
---|---|---|
committer | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-12 19:19:02 +0000 |
commit | a28e956638c4bc0248bbd9f818349b41579fec85 (patch) | |
tree | a141d381b1a2976fb271d66164e1997c636088aa /chrome/browser/autocomplete/autocomplete.cc | |
parent | e57757c6e2a965fea7bd009dbe3f9284963e2509 (diff) | |
download | chromium_src-a28e956638c4bc0248bbd9f818349b41579fec85.zip chromium_src-a28e956638c4bc0248bbd9f818349b41579fec85.tar.gz chromium_src-a28e956638c4bc0248bbd9f818349b41579fec85.tar.bz2 |
Omnibox metrics logging patch splitout, part 2: Remove the AutocompleteMatch NULL constructor. It's too easy to forget to set various members with this.
The changes from .resize() to .erase() are necessary because the compiler doesn't know resize() won't be enlarging the vector and thus needing to access the NULL constructor. The changes to the HistoryContents shortcut code were similarly necessary to avoid a NULL construction, but in the end I think made the resulting code a bit clearer.
Review URL: http://codereview.chromium.org/10837
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@5271 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/autocomplete/autocomplete.cc')
-rw-r--r-- | chrome/browser/autocomplete/autocomplete.cc | 49 |
1 files changed, 15 insertions, 34 deletions
diff --git a/chrome/browser/autocomplete/autocomplete.cc b/chrome/browser/autocomplete/autocomplete.cc index 4a49481..5e9b083 100644 --- a/chrome/browser/autocomplete/autocomplete.cc +++ b/chrome/browser/autocomplete/autocomplete.cc @@ -235,18 +235,6 @@ void AutocompleteInput::Clear() { // AutocompleteMatch ---------------------------------------------------------- -AutocompleteMatch::AutocompleteMatch() - : provider(NULL), - relevance(0), - deletable(false), - inline_autocomplete_offset(std::wstring::npos), - transition(PageTransition::TYPED), - is_history_what_you_typed_match(false), - type(URL), - template_url(NULL), - starred(false) { -} - AutocompleteMatch::AutocompleteMatch(AutocompleteProvider* provider, int relevance, bool deletable) @@ -472,7 +460,7 @@ void AutocompleteResult::SortAndCull() { if (matches_.size() > max_matches()) { std::partial_sort(matches_.begin(), matches_.begin() + max_matches(), matches_.end(), &AutocompleteMatch::MoreRelevant); - matches_.resize(max_matches()); + matches_.erase(matches_.begin() + max_matches(), matches_.end()); } // HistoryContentsProvider use a negative relevance as a way to avoid @@ -696,11 +684,9 @@ void AutocompleteController::CommitResult() { Source<AutocompleteController>(this), NotificationService::NoDetails()); } -size_t AutocompleteController::CountMatchesNotInLatestResult( - const AutocompleteProvider* provider, - AutocompleteMatch* first_match) const { +ACMatches AutocompleteController::GetMatchesNotInLatestResult( + const AutocompleteProvider* provider) const { DCHECK(provider); - DCHECK(first_match); // Determine the set of destination URLs. std::set<std::wstring> destination_urls; @@ -708,19 +694,15 @@ size_t AutocompleteController::CountMatchesNotInLatestResult( i != latest_result_.end(); ++i) destination_urls.insert(i->destination_url); + ACMatches matches; const ACMatches& provider_matches = provider->matches(); - bool found_first_unique_match = false; - size_t showing_count = 0; for (ACMatches::const_iterator i = provider_matches.begin(); i != provider_matches.end(); ++i) { - if (destination_urls.find(i->destination_url) != destination_urls.end()) { - showing_count++; - } else if (!found_first_unique_match) { - found_first_unique_match = true; - *first_match = *i; - } + if (destination_urls.find(i->destination_url) == destination_urls.end()) + matches.push_back(*i); } - return provider_matches.size() - showing_count; + + return matches; } void AutocompleteController::AddHistoryContentsShortcut() { @@ -736,17 +718,16 @@ void AutocompleteController::AddHistoryContentsShortcut() { (latest_result_.size() + 1)) || (history_contents_provider_->db_match_count() == 1)) { // We only want to add a shortcut if we're not already showing the matches. - AutocompleteMatch first_unique_match; - size_t matches_not_shown = CountMatchesNotInLatestResult( - history_contents_provider_, &first_unique_match); - if (matches_not_shown == 0) + ACMatches matches(GetMatchesNotInLatestResult(history_contents_provider_)); + if (matches.empty()) return; - if (matches_not_shown == 1) { + if (matches.size() == 1) { // Only one match not shown, add it. The relevance may be negative, // which means we need to negate it to get the true relevance. - if (first_unique_match.relevance < 0) - first_unique_match.relevance = -first_unique_match.relevance; - latest_result_.AddMatch(first_unique_match); + AutocompleteMatch& match = matches.front(); + if (match.relevance < 0) + match.relevance = -match.relevance; + latest_result_.AddMatch(match); return; } // else, fall through and add item. } |