| 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 #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 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 // [0, kMaxSuggestions) indicating the relevance of the match (higher == more | 185 // [0, kMaxSuggestions) indicating the relevance of the match (higher == more |
| 186 // relevant). For other values of |match_type|, |match_number| is ignored. | 186 // relevant). For other values of |match_type|, |match_number| is ignored. |
| 187 static int CalculateRelevance(AutocompleteInput::Type input_type, | 187 static int CalculateRelevance(AutocompleteInput::Type input_type, |
| 188 MatchType match_type, | 188 MatchType match_type, |
| 189 size_t match_number); | 189 size_t match_number); |
| 190 | 190 |
| 191 // Given the user's |input| and a |match| created from it, reduce the | 191 // Given the user's |input| and a |match| created from it, reduce the |
| 192 // match's URL to just a host. If this host still matches the user input, | 192 // match's URL to just a host. If this host still matches the user input, |
| 193 // return it. Returns the empty string on failure. | 193 // return it. Returns the empty string on failure. |
| 194 static GURL ConvertToHostOnly(const history::HistoryMatch& match, | 194 static GURL ConvertToHostOnly(const history::HistoryMatch& match, |
| 195 const std::wstring& input); | 195 const string16& input); |
| 196 | 196 |
| 197 // See if a shorter version of the best match should be created, and if so | 197 // See if a shorter version of the best match should be created, and if so |
| 198 // place it at the front of |matches|. This can suggest history URLs that | 198 // place it at the front of |matches|. This can suggest history URLs that |
| 199 // are prefixes of the best match (if they've been visited enough, compared | 199 // are prefixes of the best match (if they've been visited enough, compared |
| 200 // to the best match), or create host-only suggestions even when they haven't | 200 // to the best match), or create host-only suggestions even when they haven't |
| 201 // been visited before: if the user visited http://example.com/asdf once, | 201 // been visited before: if the user visited http://example.com/asdf once, |
| 202 // we'll suggest http://example.com/ even if they've never been to it. See | 202 // we'll suggest http://example.com/ even if they've never been to it. See |
| 203 // the function body for the exact heuristics used. | 203 // the function body for the exact heuristics used. |
| 204 static void PromoteOrCreateShorterSuggestion( | 204 static void PromoteOrCreateShorterSuggestion( |
| 205 history::URLDatabase* db, | 205 history::URLDatabase* db, |
| 206 const HistoryURLProviderParams& params, | 206 const HistoryURLProviderParams& params, |
| 207 bool have_what_you_typed_match, | 207 bool have_what_you_typed_match, |
| 208 const AutocompleteMatch& what_you_typed_match, | 208 const AutocompleteMatch& what_you_typed_match, |
| 209 history::HistoryMatches* matches); | 209 history::HistoryMatches* matches); |
| 210 | 210 |
| 211 // Ensures that |matches| contains an entry for |info|, which may mean adding | 211 // Ensures that |matches| contains an entry for |info|, which may mean adding |
| 212 // a new such entry (using |input_location| and |match_in_scheme|). | 212 // a new such entry (using |input_location| and |match_in_scheme|). |
| 213 // | 213 // |
| 214 // If |promote| is true, this also ensures the entry is the first element in | 214 // If |promote| is true, this also ensures the entry is the first element in |
| 215 // |matches|, moving or adding it to the front as appropriate. When | 215 // |matches|, moving or adding it to the front as appropriate. When |
| 216 // |promote| is false, existing matches are left in place, and newly added | 216 // |promote| is false, existing matches are left in place, and newly added |
| 217 // matches are placed at the back. | 217 // matches are placed at the back. |
| 218 static void EnsureMatchPresent(const history::URLRow& info, | 218 static void EnsureMatchPresent(const history::URLRow& info, |
| 219 std::wstring::size_type input_location, | 219 string16::size_type input_location, |
| 220 bool match_in_scheme, | 220 bool match_in_scheme, |
| 221 history::HistoryMatches* matches, | 221 history::HistoryMatches* matches, |
| 222 bool promote); | 222 bool promote); |
| 223 | 223 |
| 224 // Helper function that actually launches the two autocomplete passes. | 224 // Helper function that actually launches the two autocomplete passes. |
| 225 void RunAutocompletePasses(const AutocompleteInput& input, | 225 void RunAutocompletePasses(const AutocompleteInput& input, |
| 226 bool fixup_input_and_run_pass_1); | 226 bool fixup_input_and_run_pass_1); |
| 227 | 227 |
| 228 // Returns the best prefix that begins |text|. "Best" means "greatest number | 228 // Returns the best prefix that begins |text|. "Best" means "greatest number |
| 229 // of components". This may return NULL if no prefix begins |text|. | 229 // of components". This may return NULL if no prefix begins |text|. |
| 230 // | 230 // |
| 231 // |prefix_suffix| (which may be empty) is appended to every attempted | 231 // |prefix_suffix| (which may be empty) is appended to every attempted |
| 232 // prefix. This is useful when you need to figure out the innermost match | 232 // prefix. This is useful when you need to figure out the innermost match |
| 233 // for some user input in a URL. | 233 // for some user input in a URL. |
| 234 const history::Prefix* BestPrefix(const GURL& text, | 234 const history::Prefix* BestPrefix(const GURL& text, |
| 235 const std::wstring& prefix_suffix) const; | 235 const string16& prefix_suffix) const; |
| 236 | 236 |
| 237 // Returns a match corresponding to exactly what the user has typed. | 237 // Returns a match corresponding to exactly what the user has typed. |
| 238 AutocompleteMatch SuggestExactInput(const AutocompleteInput& input, | 238 AutocompleteMatch SuggestExactInput(const AutocompleteInput& input, |
| 239 bool trim_http); | 239 bool trim_http); |
| 240 | 240 |
| 241 // Given a |match| containing the "what you typed" suggestion created by | 241 // Given a |match| containing the "what you typed" suggestion created by |
| 242 // SuggestExactInput(), looks up its info in the DB. If found, fills in the | 242 // SuggestExactInput(), looks up its info in the DB. If found, fills in the |
| 243 // title from the DB, promotes the match's priority to that of an inline | 243 // title from the DB, promotes the match's priority to that of an inline |
| 244 // autocomplete match (maybe it should be slightly better?), and places it on | 244 // autocomplete match (maybe it should be slightly better?), and places it on |
| 245 // the front of |matches| (so we pick the right matches to throw away | 245 // the front of |matches| (so we pick the right matches to throw away |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 // parameter itself is freed once it's no longer needed. The only reason we | 295 // parameter itself is freed once it's no longer needed. The only reason we |
| 296 // keep this member is so we can set the cancel bit on it. | 296 // keep this member is so we can set the cancel bit on it. |
| 297 HistoryURLProviderParams* params_; | 297 HistoryURLProviderParams* params_; |
| 298 | 298 |
| 299 // Only used by unittests; if non-empty, overrides accept-languages in the | 299 // Only used by unittests; if non-empty, overrides accept-languages in the |
| 300 // profile's pref system. | 300 // profile's pref system. |
| 301 std::string languages_; | 301 std::string languages_; |
| 302 }; | 302 }; |
| 303 | 303 |
| 304 #endif // CHROME_BROWSER_AUTOCOMPLETE_HISTORY_URL_PROVIDER_H_ | 304 #endif // CHROME_BROWSER_AUTOCOMPLETE_HISTORY_URL_PROVIDER_H_ |
| OLD | NEW |