| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/history_url_provider.h" | 5 #include "chrome/browser/autocomplete/history_url_provider.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/histogram.h" | 10 #include "base/histogram.h" |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 params->trim_http)); | 145 params->trim_http)); |
| 146 | 146 |
| 147 // Get the matching URLs from the DB | 147 // Get the matching URLs from the DB |
| 148 typedef std::vector<history::URLRow> URLRowVector; | 148 typedef std::vector<history::URLRow> URLRowVector; |
| 149 URLRowVector url_matches; | 149 URLRowVector url_matches; |
| 150 HistoryMatches history_matches; | 150 HistoryMatches history_matches; |
| 151 for (Prefixes::const_iterator i(prefixes_.begin()); i != prefixes_.end(); | 151 for (Prefixes::const_iterator i(prefixes_.begin()); i != prefixes_.end(); |
| 152 ++i) { | 152 ++i) { |
| 153 if (params->cancel) | 153 if (params->cancel) |
| 154 return; // Canceled in the middle of a query, give up. | 154 return; // Canceled in the middle of a query, give up. |
| 155 // We only need max_matches results in the end, but before we get there we | 155 // We only need kMaxMatches results in the end, but before we get there we |
| 156 // need to promote lower-quality matches that are prefixes of | 156 // need to promote lower-quality matches that are prefixes of |
| 157 // higher-quality matches, and remove lower-quality redirects. So we ask | 157 // higher-quality matches, and remove lower-quality redirects. So we ask |
| 158 // for more results than we need, of every prefix type, in hopes this will | 158 // for more results than we need, of every prefix type, in hopes this will |
| 159 // give us far more than enough to work with. CullRedirects() will then | 159 // give us far more than enough to work with. CullRedirects() will then |
| 160 // reduce the list to the best max_matches results. | 160 // reduce the list to the best kMaxMatches results. |
| 161 db->AutocompleteForPrefix(i->prefix + params->input.text(), | 161 db->AutocompleteForPrefix(i->prefix + params->input.text(), |
| 162 max_matches() * 2, &url_matches); | 162 kMaxMatches * 2, &url_matches); |
| 163 for (URLRowVector::const_iterator j(url_matches.begin()); | 163 for (URLRowVector::const_iterator j(url_matches.begin()); |
| 164 j != url_matches.end(); ++j) { | 164 j != url_matches.end(); ++j) { |
| 165 const Prefix* best_prefix = BestPrefix(j->url(), std::wstring()); | 165 const Prefix* best_prefix = BestPrefix(j->url(), std::wstring()); |
| 166 DCHECK(best_prefix != NULL); | 166 DCHECK(best_prefix != NULL); |
| 167 history_matches.push_back(HistoryMatch(*j, i->prefix.length(), | 167 history_matches.push_back(HistoryMatch(*j, i->prefix.length(), |
| 168 !i->num_components, | 168 !i->num_components, |
| 169 i->num_components >= best_prefix->num_components)); | 169 i->num_components >= best_prefix->num_components)); |
| 170 } | 170 } |
| 171 } | 171 } |
| 172 | 172 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 198 first_match = 0; | 198 first_match = 0; |
| 199 if (have_what_you_typed_match) | 199 if (have_what_you_typed_match) |
| 200 params->matches.push_back(what_you_typed_match); | 200 params->matches.push_back(what_you_typed_match); |
| 201 } | 201 } |
| 202 | 202 |
| 203 // This is the end of the synchronous pass. | 203 // This is the end of the synchronous pass. |
| 204 if (!backend) | 204 if (!backend) |
| 205 return; | 205 return; |
| 206 | 206 |
| 207 // Remove redirects and trim list to size. We want to provide up to | 207 // Remove redirects and trim list to size. We want to provide up to |
| 208 // max_matches results plus the What You Typed result, if it was added to | 208 // kMaxMatches results plus the What You Typed result, if it was added to |
| 209 // |history_matches| above. | 209 // |history_matches| above. |
| 210 CullRedirects(backend, &history_matches, max_matches() + exact_suggestion); | 210 CullRedirects(backend, &history_matches, kMaxMatches + exact_suggestion); |
| 211 | 211 |
| 212 // Convert the history matches to autocomplete matches. | 212 // Convert the history matches to autocomplete matches. |
| 213 for (size_t i = first_match; i < history_matches.size(); ++i) { | 213 for (size_t i = first_match; i < history_matches.size(); ++i) { |
| 214 const HistoryMatch& match = history_matches[i]; | 214 const HistoryMatch& match = history_matches[i]; |
| 215 DCHECK(!have_what_you_typed_match || | 215 DCHECK(!have_what_you_typed_match || |
| 216 (match.url_info.url() != | 216 (match.url_info.url() != |
| 217 GURL(params->matches.front().destination_url))); | 217 GURL(params->matches.front().destination_url))); |
| 218 params->matches.push_back(HistoryMatchToACMatch(params, match, NORMAL, | 218 params->matches.push_back(HistoryMatchToACMatch(params, match, NORMAL, |
| 219 history_matches.size() - 1 - i)); | 219 history_matches.size() - 1 - i)); |
| 220 } | 220 } |
| (...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 860 match.contents.length(), ACMatchClassification::URL, | 860 match.contents.length(), ACMatchClassification::URL, |
| 861 &match.contents_class); | 861 &match.contents_class); |
| 862 } | 862 } |
| 863 match.description = info.title(); | 863 match.description = info.title(); |
| 864 AutocompleteMatch::ClassifyMatchInString(params->input.text(), info.title(), | 864 AutocompleteMatch::ClassifyMatchInString(params->input.text(), info.title(), |
| 865 ACMatchClassification::NONE, | 865 ACMatchClassification::NONE, |
| 866 &match.description_class); | 866 &match.description_class); |
| 867 | 867 |
| 868 return match; | 868 return match; |
| 869 } | 869 } |
| OLD | NEW |