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_result.h" | 5 #include "chrome/browser/autocomplete/autocomplete_result.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <iterator> | 8 #include <iterator> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "chrome/browser/autocomplete/autocomplete_input.h" | 11 #include "chrome/browser/autocomplete/autocomplete_input.h" |
12 #include "chrome/browser/autocomplete/autocomplete_match.h" | 12 #include "chrome/browser/autocomplete/autocomplete_match.h" |
13 #include "chrome/browser/autocomplete/autocomplete_provider.h" | 13 #include "chrome/browser/autocomplete/autocomplete_provider.h" |
14 #include "chrome/browser/omnibox/omnibox_field_trial.h" | |
14 #include "chrome/browser/search/search.h" | 15 #include "chrome/browser/search/search.h" |
15 #include "chrome/common/autocomplete_match_type.h" | 16 #include "chrome/common/autocomplete_match_type.h" |
16 | 17 |
17 // static | 18 // static |
18 const size_t AutocompleteResult::kMaxMatches = 6; | 19 const size_t AutocompleteResult::kMaxMatches = 6; |
19 const int AutocompleteResult::kLowestDefaultScore = 1200; | 20 const int AutocompleteResult::kLowestDefaultScore = 1200; |
20 | 21 |
21 void AutocompleteResult::Selection::Clear() { | 22 void AutocompleteResult::Selection::Clear() { |
22 destination_url = GURL(); | 23 destination_url = GURL(); |
23 provider_affinity = NULL; | 24 provider_affinity = NULL; |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
95 i->ComputeStrippedDestinationURL(profile); | 96 i->ComputeStrippedDestinationURL(profile); |
96 | 97 |
97 // Remove duplicates. | 98 // Remove duplicates. |
98 std::sort(matches_.begin(), matches_.end(), | 99 std::sort(matches_.begin(), matches_.end(), |
99 &AutocompleteMatch::DestinationSortFunc); | 100 &AutocompleteMatch::DestinationSortFunc); |
100 matches_.erase(std::unique(matches_.begin(), matches_.end(), | 101 matches_.erase(std::unique(matches_.begin(), matches_.end(), |
101 &AutocompleteMatch::DestinationsEqual), | 102 &AutocompleteMatch::DestinationsEqual), |
102 matches_.end()); | 103 matches_.end()); |
103 | 104 |
104 // Sort and trim to the most relevant kMaxMatches matches. | 105 // Sort and trim to the most relevant kMaxMatches matches. |
105 const size_t num_matches = std::min(kMaxMatches, matches_.size()); | 106 std::sort(matches_.begin(), matches_.end(), &AutocompleteMatch::MoreRelevant); |
106 std::partial_sort(matches_.begin(), matches_.begin() + num_matches, | 107 if (!empty() && !begin()->allowed_to_be_default_match && |
H Fung
2013/08/06 22:53:00
Nit: matches_.begin() here too?
Peter Kasting
2013/08/06 22:56:16
Nit: Fix this use of begin() too?
Mark P
2013/08/07 00:44:31
Done.
Mark P
2013/08/07 00:44:31
Done.
| |
107 matches_.end(), &AutocompleteMatch::MoreRelevant); | 108 OmniboxFieldTrial::ReorderForLegalDefaultMatch( |
108 matches_.resize(num_matches); | 109 input.current_page_classification())) { |
110 // Top match is not allowed to be the default match. Find the most | |
111 // relevance legal match and shift it to the front. | |
Peter Kasting
2013/08/06 22:56:16
Nit: relevance -> relevant
Mark P
2013/08/07 00:44:31
Done.
| |
112 for (AutocompleteResult::iterator it = matches_.begin() + 1; | |
113 it != matches_.end(); ++it) { | |
114 if (it->allowed_to_be_default_match) { | |
115 std::rotate(matches_.begin(), it, it + 1); | |
116 break; | |
117 } | |
118 } | |
119 } | |
120 matches_.resize(std::min(kMaxMatches, matches_.size())); | |
109 | 121 |
110 default_match_ = begin(); | 122 default_match_ = begin(); |
123 DCHECK((default_match_ == end()) || | |
124 default_match_->allowed_to_be_default_match); | |
111 | 125 |
112 // Set the alternate nav URL. | 126 // Set the alternate nav URL. |
113 alternate_nav_url_ = (default_match_ == end()) ? | 127 alternate_nav_url_ = (default_match_ == end()) ? |
114 GURL() : ComputeAlternateNavUrl(input, *default_match_); | 128 GURL() : ComputeAlternateNavUrl(input, *default_match_); |
115 } | 129 } |
116 | 130 |
117 bool AutocompleteResult::HasCopiedMatches() const { | 131 bool AutocompleteResult::HasCopiedMatches() const { |
118 for (ACMatches::const_iterator i(begin()); i != end(); ++i) { | 132 for (ACMatches::const_iterator i(begin()); i != end(); ++i) { |
119 if (i->from_previous) | 133 if (i->from_previous) |
120 return true; | 134 return true; |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
269 i != old_matches.rend() && delta > 0; ++i) { | 283 i != old_matches.rend() && delta > 0; ++i) { |
270 if (!HasMatchByDestination(*i, new_matches)) { | 284 if (!HasMatchByDestination(*i, new_matches)) { |
271 AutocompleteMatch match = *i; | 285 AutocompleteMatch match = *i; |
272 match.relevance = std::min(max_relevance, match.relevance); | 286 match.relevance = std::min(max_relevance, match.relevance); |
273 match.from_previous = true; | 287 match.from_previous = true; |
274 AddMatch(match); | 288 AddMatch(match); |
275 delta--; | 289 delta--; |
276 } | 290 } |
277 } | 291 } |
278 } | 292 } |
OLD | NEW |