| 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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 | 128 |
| 129 // When true, we should avoid calling SuggestExactInput(). | 129 // When true, we should avoid calling SuggestExactInput(). |
| 130 bool dont_suggest_exact_input; | 130 bool dont_suggest_exact_input; |
| 131 | 131 |
| 132 private: | 132 private: |
| 133 DISALLOW_COPY_AND_ASSIGN(HistoryURLProviderParams); | 133 DISALLOW_COPY_AND_ASSIGN(HistoryURLProviderParams); |
| 134 }; | 134 }; |
| 135 | 135 |
| 136 // This class is an autocomplete provider and is also a pseudo-internal | 136 // This class is an autocomplete provider and is also a pseudo-internal |
| 137 // component of the history system. See comments above. | 137 // component of the history system. See comments above. |
| 138 // | |
| 139 // Note: This object can get leaked on shutdown if there are pending | |
| 140 // requests on the database (which hold a reference to us). Normally, these | |
| 141 // messages get flushed for each thread. We do a round trip from main, to | |
| 142 // history, back to main while holding a reference. If the main thread | |
| 143 // completes before the history thread, the message to delegate back to the | |
| 144 // main thread will not run and the reference will leak. Therefore, don't do | |
| 145 // anything on destruction. | |
| 146 class HistoryURLProvider : public HistoryProvider { | 138 class HistoryURLProvider : public HistoryProvider { |
| 147 public: | 139 public: |
| 148 HistoryURLProvider(ACProviderListener* listener, Profile* profile); | 140 HistoryURLProvider(ACProviderListener* listener, Profile* profile); |
| 149 | 141 |
| 150 #ifdef UNIT_TEST | 142 #ifdef UNIT_TEST |
| 151 HistoryURLProvider(ACProviderListener* listener, | 143 HistoryURLProvider(ACProviderListener* listener, |
| 152 Profile* profile, | 144 Profile* profile, |
| 153 const std::string& languages) | 145 const std::string& languages) |
| 154 : HistoryProvider(listener, profile, "History"), | 146 : HistoryProvider(listener, profile, "History"), |
| 155 prefixes_(GetPrefixes()), | 147 prefixes_(GetPrefixes()), |
| 156 params_(NULL), | 148 params_(NULL), |
| 157 languages_(languages) {} | 149 languages_(languages) {} |
| 158 #endif | 150 #endif |
| 159 // no destructor (see note above) | |
| 160 | 151 |
| 161 // AutocompleteProvider | 152 // AutocompleteProvider |
| 162 virtual void Start(const AutocompleteInput& input, | 153 virtual void Start(const AutocompleteInput& input, |
| 163 bool minimal_changes) OVERRIDE; | 154 bool minimal_changes) OVERRIDE; |
| 164 virtual void Stop() OVERRIDE; | 155 virtual void Stop() OVERRIDE; |
| 165 | 156 |
| 166 // Runs the history query on the history thread, called by the history | 157 // Runs the history query on the history thread, called by the history |
| 167 // system. The history database MAY BE NULL in which case it is not | 158 // system. The history database MAY BE NULL in which case it is not |
| 168 // available and we should return no data. Also schedules returning the | 159 // available and we should return no data. Also schedules returning the |
| 169 // results to the main thread | 160 // results to the main thread |
| (...skipping 19 matching lines...) Expand all Loading... |
| 189 static history::Prefixes GetPrefixes(); | 180 static history::Prefixes GetPrefixes(); |
| 190 | 181 |
| 191 // Determines the relevance for some input, given its type and which match it | 182 // 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 | 183 // is. If |match_type| is NORMAL, |match_number| is a number |
| 193 // [0, kMaxSuggestions) indicating the relevance of the match (higher == more | 184 // [0, kMaxSuggestions) indicating the relevance of the match (higher == more |
| 194 // relevant). For other values of |match_type|, |match_number| is ignored. | 185 // relevant). For other values of |match_type|, |match_number| is ignored. |
| 195 static int CalculateRelevance(AutocompleteInput::Type input_type, | 186 static int CalculateRelevance(AutocompleteInput::Type input_type, |
| 196 MatchType match_type, | 187 MatchType match_type, |
| 197 size_t match_number); | 188 size_t match_number); |
| 198 | 189 |
| 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 | |
| 204 // Given the user's |input| and a |match| created from it, reduce the | |
| 205 // match's URL to just a host. If this host still matches the user input, | |
| 206 // return it. Returns the empty string on failure. | |
| 207 static GURL ConvertToHostOnly(const history::HistoryMatch& match, | |
| 208 const string16& input); | |
| 209 | |
| 210 // See if a shorter version of the best match should be created, and if so | |
| 211 // place it at the front of |matches|. This can suggest history URLs that | |
| 212 // are prefixes of the best match (if they've been visited enough, compared | |
| 213 // to the best match), or create host-only suggestions even when they haven't | |
| 214 // been visited before: if the user visited http://example.com/asdf once, | |
| 215 // we'll suggest http://example.com/ even if they've never been to it. See | |
| 216 // the function body for the exact heuristics used. | |
| 217 static void PromoteOrCreateShorterSuggestion( | |
| 218 history::URLDatabase* db, | |
| 219 const HistoryURLProviderParams& params, | |
| 220 bool have_what_you_typed_match, | |
| 221 const AutocompleteMatch& what_you_typed_match, | |
| 222 history::HistoryMatches* matches); | |
| 223 | |
| 224 // Ensures that |matches| contains an entry for |info|, which may mean adding | |
| 225 // a new such entry (using |input_location| and |match_in_scheme|). | |
| 226 // | |
| 227 // If |promote| is true, this also ensures the entry is the first element in | |
| 228 // |matches|, moving or adding it to the front as appropriate. When | |
| 229 // |promote| is false, existing matches are left in place, and newly added | |
| 230 // matches are placed at the back. | |
| 231 static void EnsureMatchPresent(const history::URLRow& info, | |
| 232 size_t input_location, | |
| 233 bool match_in_scheme, | |
| 234 history::HistoryMatches* matches, | |
| 235 bool promote); | |
| 236 | |
| 237 // Helper function that actually launches the two autocomplete passes. | 190 // Helper function that actually launches the two autocomplete passes. |
| 238 void RunAutocompletePasses(const AutocompleteInput& input, | 191 void RunAutocompletePasses(const AutocompleteInput& input, |
| 239 bool fixup_input_and_run_pass_1); | 192 bool fixup_input_and_run_pass_1); |
| 240 | 193 |
| 241 // Returns the best prefix that begins |text|. "Best" means "greatest number | 194 // Returns the best prefix that begins |text|. "Best" means "greatest number |
| 242 // of components". This may return NULL if no prefix begins |text|. | 195 // of components". This may return NULL if no prefix begins |text|. |
| 243 // | 196 // |
| 244 // |prefix_suffix| (which may be empty) is appended to every attempted | 197 // |prefix_suffix| (which may be empty) is appended to every attempted |
| 245 // prefix. This is useful when you need to figure out the innermost match | 198 // prefix. This is useful when you need to figure out the innermost match |
| 246 // for some user input in a URL. | 199 // for some user input in a URL. |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 // parameter itself is freed once it's no longer needed. The only reason we | 264 // parameter itself is freed once it's no longer needed. The only reason we |
| 312 // keep this member is so we can set the cancel bit on it. | 265 // keep this member is so we can set the cancel bit on it. |
| 313 HistoryURLProviderParams* params_; | 266 HistoryURLProviderParams* params_; |
| 314 | 267 |
| 315 // Only used by unittests; if non-empty, overrides accept-languages in the | 268 // Only used by unittests; if non-empty, overrides accept-languages in the |
| 316 // profile's pref system. | 269 // profile's pref system. |
| 317 std::string languages_; | 270 std::string languages_; |
| 318 }; | 271 }; |
| 319 | 272 |
| 320 #endif // CHROME_BROWSER_AUTOCOMPLETE_HISTORY_URL_PROVIDER_H_ | 273 #endif // CHROME_BROWSER_AUTOCOMPLETE_HISTORY_URL_PROVIDER_H_ |
| OLD | NEW |