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 #ifndef CHROME_BROWSER_AUTOCOMPLETE_HISTORY_URL_PROVIDER_H_ | 5 #ifndef CHROME_BROWSER_AUTOCOMPLETE_HISTORY_URL_PROVIDER_H_ |
6 #define CHROME_BROWSER_AUTOCOMPLETE_HISTORY_URL_PROVIDER_H_ | 6 #define CHROME_BROWSER_AUTOCOMPLETE_HISTORY_URL_PROVIDER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 static history::Prefixes GetPrefixes(); | 189 static history::Prefixes GetPrefixes(); |
190 | 190 |
191 // Determines the relevance for some input, given its type and which match it | 191 // Determines the relevance for some input, given its type and which match it |
192 // is. If |match_type| is NORMAL, |match_number| is a number | 192 // is. If |match_type| is NORMAL, |match_number| is a number |
193 // [0, kMaxSuggestions) indicating the relevance of the match (higher == more | 193 // [0, kMaxSuggestions) indicating the relevance of the match (higher == more |
194 // relevant). For other values of |match_type|, |match_number| is ignored. | 194 // relevant). For other values of |match_type|, |match_number| is ignored. |
195 static int CalculateRelevance(AutocompleteInput::Type input_type, | 195 static int CalculateRelevance(AutocompleteInput::Type input_type, |
196 MatchType match_type, | 196 MatchType match_type, |
197 size_t match_number); | 197 size_t match_number); |
198 | 198 |
| 199 // Determines the confidence for a |match| when compared to all the |
| 200 // |matches|. Returns a number in the range [0, 1]. |
| 201 static float CalculateConfidence(const history::HistoryMatch& match, |
| 202 const history::HistoryMatches& matches); |
| 203 |
199 // Given the user's |input| and a |match| created from it, reduce the | 204 // Given the user's |input| and a |match| created from it, reduce the |
200 // match's URL to just a host. If this host still matches the user input, | 205 // match's URL to just a host. If this host still matches the user input, |
201 // return it. Returns the empty string on failure. | 206 // return it. Returns the empty string on failure. |
202 static GURL ConvertToHostOnly(const history::HistoryMatch& match, | 207 static GURL ConvertToHostOnly(const history::HistoryMatch& match, |
203 const string16& input); | 208 const string16& input); |
204 | 209 |
205 // See if a shorter version of the best match should be created, and if so | 210 // See if a shorter version of the best match should be created, and if so |
206 // place it at the front of |matches|. This can suggest history URLs that | 211 // place it at the front of |matches|. This can suggest history URLs that |
207 // are prefixes of the best match (if they've been visited enough, compared | 212 // are prefixes of the best match (if they've been visited enough, compared |
208 // to the best match), or create host-only suggestions even when they haven't | 213 // to the best match), or create host-only suggestions even when they haven't |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 // autocomplete match (maybe it should be slightly better?), and places it on | 257 // autocomplete match (maybe it should be slightly better?), and places it on |
253 // the front of |matches| (so we pick the right matches to throw away | 258 // the front of |matches| (so we pick the right matches to throw away |
254 // when culling redirects to/from it). Returns whether a match was promoted. | 259 // when culling redirects to/from it). Returns whether a match was promoted. |
255 bool FixupExactSuggestion(history::URLDatabase* db, | 260 bool FixupExactSuggestion(history::URLDatabase* db, |
256 const AutocompleteInput& input, | 261 const AutocompleteInput& input, |
257 AutocompleteMatch* match, | 262 AutocompleteMatch* match, |
258 history::HistoryMatches* matches) const; | 263 history::HistoryMatches* matches) const; |
259 | 264 |
260 // Determines if |match| is suitable for inline autocomplete, and promotes it | 265 // Determines if |match| is suitable for inline autocomplete, and promotes it |
261 // if so. | 266 // if so. |
262 bool PromoteMatchForInlineAutocomplete(HistoryURLProviderParams* params, | 267 bool PromoteMatchForInlineAutocomplete( |
263 const history::HistoryMatch& match); | 268 HistoryURLProviderParams* params, |
| 269 const history::HistoryMatch& match, |
| 270 const history::HistoryMatches& history_matches); |
264 | 271 |
265 // Sorts the given list of matches. | 272 // Sorts the given list of matches. |
266 void SortMatches(history::HistoryMatches* matches) const; | 273 void SortMatches(history::HistoryMatches* matches) const; |
267 | 274 |
268 // Removes results that have been rarely typed or visited, and not any time | 275 // Removes results that have been rarely typed or visited, and not any time |
269 // recently. The exact parameters for this heuristic can be found in the | 276 // recently. The exact parameters for this heuristic can be found in the |
270 // function body. | 277 // function body. |
271 void CullPoorMatches(history::HistoryMatches* matches) const; | 278 void CullPoorMatches(history::HistoryMatches* matches) const; |
272 | 279 |
273 // Removes results that redirect to each other, leaving at most |max_results| | 280 // Removes results that redirect to each other, leaving at most |max_results| |
(...skipping 11 matching lines...) Expand all Loading... |
285 // is removed, the next item will be shifted, and this allows the caller to | 292 // is removed, the next item will be shifted, and this allows the caller to |
286 // pick up on the next one when this happens. | 293 // pick up on the next one when this happens. |
287 size_t RemoveSubsequentMatchesOf(history::HistoryMatches* matches, | 294 size_t RemoveSubsequentMatchesOf(history::HistoryMatches* matches, |
288 size_t source_index, | 295 size_t source_index, |
289 const std::vector<GURL>& remove) const; | 296 const std::vector<GURL>& remove) const; |
290 | 297 |
291 // Converts a line from the database into an autocomplete match for display. | 298 // Converts a line from the database into an autocomplete match for display. |
292 AutocompleteMatch HistoryMatchToACMatch( | 299 AutocompleteMatch HistoryMatchToACMatch( |
293 HistoryURLProviderParams* params, | 300 HistoryURLProviderParams* params, |
294 const history::HistoryMatch& history_match, | 301 const history::HistoryMatch& history_match, |
| 302 const history::HistoryMatches& history_matches, |
295 MatchType match_type, | 303 MatchType match_type, |
296 size_t match_number); | 304 size_t match_number); |
297 | 305 |
298 // Prefixes to try appending to user input when looking for a match. | 306 // Prefixes to try appending to user input when looking for a match. |
299 const history::Prefixes prefixes_; | 307 const history::Prefixes prefixes_; |
300 | 308 |
301 // Params for the current query. The provider should not free this directly; | 309 // Params for the current query. The provider should not free this directly; |
302 // instead, it is passed as a parameter through the history backend, and the | 310 // instead, it is passed as a parameter through the history backend, and the |
303 // parameter itself is freed once it's no longer needed. The only reason we | 311 // parameter itself is freed once it's no longer needed. The only reason we |
304 // keep this member is so we can set the cancel bit on it. | 312 // keep this member is so we can set the cancel bit on it. |
305 HistoryURLProviderParams* params_; | 313 HistoryURLProviderParams* params_; |
306 | 314 |
307 // Only used by unittests; if non-empty, overrides accept-languages in the | 315 // Only used by unittests; if non-empty, overrides accept-languages in the |
308 // profile's pref system. | 316 // profile's pref system. |
309 std::string languages_; | 317 std::string languages_; |
310 }; | 318 }; |
311 | 319 |
312 #endif // CHROME_BROWSER_AUTOCOMPLETE_HISTORY_URL_PROVIDER_H_ | 320 #endif // CHROME_BROWSER_AUTOCOMPLETE_HISTORY_URL_PROVIDER_H_ |
OLD | NEW |