Chromium Code Reviews| 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 #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 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 81 // request. This can happen frequently when the user is typing quickly. In | 81 // request. This can happen frequently when the user is typing quickly. In |
| 82 // this case, the main thread sets params_->cancel, which the background thread | 82 // this case, the main thread sets params_->cancel, which the background thread |
| 83 // checks periodically. If it finds the flag set, it stops what it's doing | 83 // checks periodically. If it finds the flag set, it stops what it's doing |
| 84 // immediately and calls back to the main thread. (We don't delete the params | 84 // immediately and calls back to the main thread. (We don't delete the params |
| 85 // on the history thread, because we should only do that when we can safely | 85 // on the history thread, because we should only do that when we can safely |
| 86 // NULL out params_, and that must be done on the main thread.) | 86 // NULL out params_, and that must be done on the main thread.) |
| 87 | 87 |
| 88 // Used to communicate autocomplete parameters between threads via the history | 88 // Used to communicate autocomplete parameters between threads via the history |
| 89 // service. | 89 // service. |
| 90 struct HistoryURLProviderParams { | 90 struct HistoryURLProviderParams { |
| 91 enum PromoteType { | |
|
Mark P
2014/06/18 18:23:45
nit: comment
Peter Kasting
2014/06/18 20:38:30
I couldn't think of anything to put here that wasn
Mark P
2014/06/19 03:53:13
Then perhaps say "See comments by declaration of |
Peter Kasting
2014/06/19 20:55:22
Done.
| |
| 92 WHAT_YOU_TYPED_MATCH, | |
| 93 FRONT_HISTORY_MATCH, | |
| 94 NEITHER, | |
| 95 }; | |
| 96 | |
| 91 HistoryURLProviderParams(const AutocompleteInput& input, | 97 HistoryURLProviderParams(const AutocompleteInput& input, |
| 92 bool trim_http, | 98 bool trim_http, |
| 93 const AutocompleteMatch& what_you_typed_match, | 99 const AutocompleteMatch& what_you_typed_match, |
| 94 const std::string& languages, | 100 const std::string& languages, |
| 95 TemplateURL* default_search_provider, | 101 TemplateURL* default_search_provider, |
| 96 const SearchTermsData& search_terms_data); | 102 const SearchTermsData& search_terms_data); |
| 97 ~HistoryURLProviderParams(); | 103 ~HistoryURLProviderParams(); |
| 98 | 104 |
| 99 base::MessageLoop* message_loop; | 105 base::MessageLoop* message_loop; |
| 100 | 106 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 118 // running queries that are no longer needed. Since we don't care if we run | 124 // running queries that are no longer needed. Since we don't care if we run |
| 119 // the extra queries, the lack of signaling is not a problem. | 125 // the extra queries, the lack of signaling is not a problem. |
| 120 base::CancellationFlag cancel_flag; | 126 base::CancellationFlag cancel_flag; |
| 121 | 127 |
| 122 // Set by ExecuteWithDB() on the history thread when the query could not be | 128 // Set by ExecuteWithDB() on the history thread when the query could not be |
| 123 // performed because the history system failed to properly init the database. | 129 // performed because the history system failed to properly init the database. |
| 124 // If this is set when the main thread is called back, it avoids changing | 130 // If this is set when the main thread is called back, it avoids changing |
| 125 // |matches_| at all, so it won't delete the default match Start() creates. | 131 // |matches_| at all, so it won't delete the default match Start() creates. |
| 126 bool failed; | 132 bool failed; |
| 127 | 133 |
| 128 // List of matches written by the history thread. We keep this separate list | 134 // List of matches written by DoAutocomplete(). Upon its return the provider |
| 129 // to avoid having the main thread read the provider's matches while the | 135 // converts this list to ACMatches and places them in |matches_|. |
| 130 // history thread is manipulating them. The provider copies this list back | 136 history::HistoryMatches matches; |
| 131 // to matches_ on the main thread in QueryComplete(). | 137 |
| 132 ACMatches matches; | 138 // 1 if the what you typed match appears as a known history entry, 0 |
| 139 // otherwise. | |
| 140 size_t exact_suggestion; | |
|
Mark P
2014/06/18 18:23:45
nit: (in a later changelist, perhaps)
I've always
Peter Kasting
2014/06/18 20:38:30
Me too. I figured out a way to change this to a b
| |
| 141 | |
| 142 // Tells the provider whether to promote the what you typed match, the first | |
| 143 // element of |matches|, or neither as the first AutocompleteMatch. | |
|
Mark P
2014/06/18 18:23:45
By convention, what is this set to if the first el
Peter Kasting
2014/06/18 20:38:30
Added comments about this.
| |
| 144 PromoteType promote_type; | |
| 133 | 145 |
| 134 // Languages we should pass to gfx::GetCleanStringFromUrl. | 146 // Languages we should pass to gfx::GetCleanStringFromUrl. |
| 135 std::string languages; | 147 std::string languages; |
| 136 | 148 |
| 137 // When true, we should avoid calling SuggestExactInput(). | |
| 138 bool dont_suggest_exact_input; | |
| 139 | |
| 140 // The default search provider and search terms data necessary to cull results | 149 // The default search provider and search terms data necessary to cull results |
| 141 // that correspond to searches (on the default engine). These can only be | 150 // that correspond to searches (on the default engine). These can only be |
| 142 // obtained on the UI thread, so we have to copy them into here to pass them | 151 // obtained on the UI thread, so we have to copy them into here to pass them |
| 143 // to the history thread. We use a scoped_ptr<TemplateURL> for the DSP since | 152 // to the history thread. We use a scoped_ptr<TemplateURL> for the DSP since |
| 144 // TemplateURLs can't be copied by value. We use a scoped_ptr<SearchTermsData> | 153 // TemplateURLs can't be copied by value. We use a scoped_ptr<SearchTermsData> |
| 145 // so that we can store a snapshot of the SearchTermsData accessible from the | 154 // so that we can store a snapshot of the SearchTermsData accessible from the |
| 146 // history thread. | 155 // history thread. |
| 147 scoped_ptr<TemplateURL> default_search_provider; | 156 scoped_ptr<TemplateURL> default_search_provider; |
| 148 scoped_ptr<SearchTermsData> search_terms_data; | 157 scoped_ptr<SearchTermsData> search_terms_data; |
| 149 | 158 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 166 | 175 |
| 167 // HistoryProvider: | 176 // HistoryProvider: |
| 168 virtual void Start(const AutocompleteInput& input, | 177 virtual void Start(const AutocompleteInput& input, |
| 169 bool minimal_changes) OVERRIDE; | 178 bool minimal_changes) OVERRIDE; |
| 170 virtual void Stop(bool clear_cached_results) OVERRIDE; | 179 virtual void Stop(bool clear_cached_results) OVERRIDE; |
| 171 | 180 |
| 172 // Returns a match representing a navigation to |destination_url| given user | 181 // Returns a match representing a navigation to |destination_url| given user |
| 173 // input of |text|. |trim_http| controls whether the match's |fill_into_edit| | 182 // input of |text|. |trim_http| controls whether the match's |fill_into_edit| |
| 174 // and |contents| should have any HTTP scheme stripped off, and should not be | 183 // and |contents| should have any HTTP scheme stripped off, and should not be |
| 175 // set to true if |text| contains an http prefix. | 184 // set to true if |text| contains an http prefix. |
| 176 // NOTE: This does not set the relevance of the returned match, as different | 185 // NOTES: This does not set the relevance of the returned match, as different |
| 177 // callers want different behavior. Callers must set this manually. | 186 // callers want different behavior. Callers must set this manually. |
| 187 // This function should only be called on the UI thread. | |
| 178 AutocompleteMatch SuggestExactInput(const base::string16& text, | 188 AutocompleteMatch SuggestExactInput(const base::string16& text, |
| 179 const GURL& destination_url, | 189 const GURL& destination_url, |
| 180 bool trim_http); | 190 bool trim_http); |
| 181 | 191 |
| 182 // Runs the history query on the history thread, called by the history | 192 // Runs the history query on the history thread, called by the history |
| 183 // system. The history database MAY BE NULL in which case it is not | 193 // system. The history database MAY BE NULL in which case it is not |
| 184 // available and we should return no data. Also schedules returning the | 194 // available and we should return no data. Also schedules returning the |
| 185 // results to the main thread | 195 // results to the main thread |
| 186 void ExecuteWithDB(history::HistoryBackend* backend, | 196 void ExecuteWithDB(history::HistoryBackend* backend, |
| 187 history::URLDatabase* db, | 197 history::URLDatabase* db, |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 213 const base::string16& input_text, | 223 const base::string16& input_text, |
| 214 const base::string16& description); | 224 const base::string16& description); |
| 215 | 225 |
| 216 // Actually runs the autocomplete job on the given database, which is | 226 // Actually runs the autocomplete job on the given database, which is |
| 217 // guaranteed not to be NULL. Used by both autocomplete passes, and therefore | 227 // guaranteed not to be NULL. Used by both autocomplete passes, and therefore |
| 218 // called on multiple different threads (though not simultaneously). | 228 // called on multiple different threads (though not simultaneously). |
| 219 void DoAutocomplete(history::HistoryBackend* backend, | 229 void DoAutocomplete(history::HistoryBackend* backend, |
| 220 history::URLDatabase* db, | 230 history::URLDatabase* db, |
| 221 HistoryURLProviderParams* params); | 231 HistoryURLProviderParams* params); |
| 222 | 232 |
| 233 // Clears |matches_|, then may promote either the what you typed match or | |
| 234 // first history match in |params| to the front of |matches_|, depending on | |
| 235 // the value of params->promote_type. | |
|
Mark P
2014/06/18 18:23:44
Clearing matches seems like an odd initial/side ef
Peter Kasting
2014/06/18 20:38:30
It is. I did it because both callers wanted it so
| |
| 236 void PromoteMatchIfNecessary(const HistoryURLProviderParams& params); | |
| 237 | |
| 223 // Dispatches the results to the autocomplete controller. Called on the | 238 // Dispatches the results to the autocomplete controller. Called on the |
| 224 // main thread by ExecuteWithDB when the results are available. | 239 // main thread by ExecuteWithDB when the results are available. |
| 225 // Frees params_gets_deleted on exit. | 240 // Frees params_gets_deleted on exit. |
| 226 void QueryComplete(HistoryURLProviderParams* params_gets_deleted); | 241 void QueryComplete(HistoryURLProviderParams* params_gets_deleted); |
| 227 | 242 |
| 228 // Looks up the info for params->what_you_typed_match in the DB. If found, | 243 // Looks up the info for params->what_you_typed_match in the DB. If found, |
| 229 // fills in the title, promotes the match's priority to that of an inline | 244 // fills in the title, promotes the match's priority to that of an inline |
| 230 // autocomplete match (maybe it should be slightly better?), and places it on | 245 // autocomplete match (maybe it should be slightly better?), and places it on |
| 231 // the front of |matches| (so we pick the right matches to throw away when | 246 // the front of params->matches (so we pick the right matches to throw away |
| 232 // culling redirects to/from it). Returns whether a match was promoted. | 247 // when culling redirects to/from it). Returns whether a match was promoted. |
| 233 bool FixupExactSuggestion(history::URLDatabase* db, | 248 bool FixupExactSuggestion(history::URLDatabase* db, |
| 234 const VisitClassifier& classifier, | 249 const VisitClassifier& classifier, |
| 235 HistoryURLProviderParams* params, | 250 HistoryURLProviderParams* params) const; |
| 236 history::HistoryMatches* matches) const; | |
| 237 | 251 |
| 238 // Helper function for FixupExactSuggestion, this returns true if the input | 252 // Helper function for FixupExactSuggestion, this returns true if the input |
| 239 // corresponds to some intranet URL where the user has previously visited the | 253 // corresponds to some intranet URL where the user has previously visited the |
| 240 // host in question. In this case the input should be treated as a URL. | 254 // host in question. In this case the input should be treated as a URL. |
| 241 bool CanFindIntranetURL(history::URLDatabase* db, | 255 bool CanFindIntranetURL(history::URLDatabase* db, |
| 242 const AutocompleteInput& input) const; | 256 const AutocompleteInput& input) const; |
| 243 | 257 |
| 244 // Determines if |match| is suitable for inline autocomplete. If so, promotes | |
| 245 // the match. Returns whether |match| was promoted. | |
| 246 bool PromoteMatchForInlineAutocomplete(const history::HistoryMatch& match, | |
| 247 HistoryURLProviderParams* params); | |
| 248 | |
| 249 // Sees if a shorter version of the best match should be created, and if so | 258 // Sees if a shorter version of the best match should be created, and if so |
| 250 // places it at the front of |matches|. This can suggest history URLs that | 259 // places it at the front of params->matches. This can suggest history URLs |
| 251 // are prefixes of the best match (if they've been visited enough, compared to | 260 // that are prefixes of the best match (if they've been visited enough, |
| 252 // the best match), or create host-only suggestions even when they haven't | 261 // compared to the best match), or create host-only suggestions even when they |
| 253 // been visited before: if the user visited http://example.com/asdf once, | 262 // haven't been visited before: if the user visited http://example.com/asdf |
| 254 // we'll suggest http://example.com/ even if they've never been to it. | 263 // once, we'll suggest http://example.com/ even if they've never been to it. |
| 255 void PromoteOrCreateShorterSuggestion( | 264 void PromoteOrCreateShorterSuggestion( |
| 256 history::URLDatabase* db, | 265 history::URLDatabase* db, |
| 257 const HistoryURLProviderParams& params, | |
| 258 bool have_what_you_typed_match, | 266 bool have_what_you_typed_match, |
| 259 history::HistoryMatches* matches); | 267 HistoryURLProviderParams* params); |
| 260 | 268 |
| 261 // Removes results that have been rarely typed or visited, and not any time | 269 // Removes results that have been rarely typed or visited, and not any time |
| 262 // recently. The exact parameters for this heuristic can be found in the | 270 // recently. The exact parameters for this heuristic can be found in the |
| 263 // function body. Also culls results corresponding to queries from the default | 271 // function body. Also culls results corresponding to queries from the default |
| 264 // search engine. These are low-quality, difficult-to-understand matches for | 272 // search engine. These are low-quality, difficult-to-understand matches for |
| 265 // users, and the SearchProvider should surface past queries in a better way | 273 // users, and the SearchProvider should surface past queries in a better way |
| 266 // anyway. | 274 // anyway. |
| 267 void CullPoorMatches(const HistoryURLProviderParams& params, | 275 void CullPoorMatches(HistoryURLProviderParams* params) const; |
| 268 history::HistoryMatches* matches) const; | |
| 269 | 276 |
| 270 // Removes results that redirect to each other, leaving at most |max_results| | 277 // Removes results that redirect to each other, leaving at most |max_results| |
| 271 // results. | 278 // results. |
| 272 void CullRedirects(history::HistoryBackend* backend, | 279 void CullRedirects(history::HistoryBackend* backend, |
| 273 history::HistoryMatches* matches, | 280 history::HistoryMatches* matches, |
| 274 size_t max_results) const; | 281 size_t max_results) const; |
| 275 | 282 |
| 276 // Helper function for CullRedirects, this removes all but the first | 283 // Helper function for CullRedirects, this removes all but the first |
| 277 // occurance of [any of the set of strings in |remove|] from the |matches| | 284 // occurance of [any of the set of strings in |remove|] from the |matches| |
| 278 // list. | 285 // list. |
| 279 // | 286 // |
| 280 // The return value is the index of the item that is after the item in the | 287 // The return value is the index of the item that is after the item in the |
| 281 // input identified by |source_index|. If |source_index| or an item before | 288 // input identified by |source_index|. If |source_index| or an item before |
| 282 // is removed, the next item will be shifted, and this allows the caller to | 289 // is removed, the next item will be shifted, and this allows the caller to |
| 283 // pick up on the next one when this happens. | 290 // pick up on the next one when this happens. |
| 284 size_t RemoveSubsequentMatchesOf(history::HistoryMatches* matches, | 291 size_t RemoveSubsequentMatchesOf(history::HistoryMatches* matches, |
| 285 size_t source_index, | 292 size_t source_index, |
| 286 const std::vector<GURL>& remove) const; | 293 const std::vector<GURL>& remove) const; |
| 287 | 294 |
| 288 // Converts a line from the database into an autocomplete match for display. | 295 // Converts a specified |match_number| from params.matches into an |
| 289 // If experimental scoring is enabled, the final relevance score might be | 296 // autocomplete match for display. If experimental scoring is enabled, the |
| 290 // different from the given |relevance|. | 297 // final relevance score might be different from the given |relevance|. |
| 298 // NOTE: This function should only be called on the UI thread. | |
| 291 AutocompleteMatch HistoryMatchToACMatch( | 299 AutocompleteMatch HistoryMatchToACMatch( |
| 292 const HistoryURLProviderParams& params, | 300 const HistoryURLProviderParams& params, |
| 293 const history::HistoryMatch& history_match, | 301 size_t match_number, |
| 294 MatchType match_type, | 302 MatchType match_type, |
| 295 int relevance); | 303 int relevance); |
| 296 | 304 |
| 297 // Params for the current query. The provider should not free this directly; | 305 // Params for the current query. The provider should not free this directly; |
| 298 // instead, it is passed as a parameter through the history backend, and the | 306 // instead, it is passed as a parameter through the history backend, and the |
| 299 // parameter itself is freed once it's no longer needed. The only reason we | 307 // parameter itself is freed once it's no longer needed. The only reason we |
| 300 // keep this member is so we can set the cancel bit on it. | 308 // keep this member is so we can set the cancel bit on it. |
| 301 HistoryURLProviderParams* params_; | 309 HistoryURLProviderParams* params_; |
| 302 | 310 |
| 303 // Params controlling experimental behavior of this provider. | 311 // Params controlling experimental behavior of this provider. |
| 304 HUPScoringParams scoring_params_; | 312 HUPScoringParams scoring_params_; |
| 305 | 313 |
| 306 // If true, HistoryURL provider should lookup and cull redirects. If | 314 // If true, HistoryURL provider should lookup and cull redirects. If |
| 307 // false, it returns matches that may be redirects to each other and | 315 // false, it returns matches that may be redirects to each other and |
| 308 // simply hopes the default AutoCompleteController behavior to remove | 316 // simply hopes the default AutoCompleteController behavior to remove |
| 309 // URLs that are likely duplicates (http://google.com <-> | 317 // URLs that are likely duplicates (http://google.com <-> |
| 310 // https://www.google.com/, etc.) will do a good enough job. | 318 // https://www.google.com/, etc.) will do a good enough job. |
| 311 bool cull_redirects_; | 319 bool cull_redirects_; |
| 312 | 320 |
| 313 // Used in PromoteOrCreateShorterSuggestion(). If true, we may create | 321 // Used in PromoteOrCreateShorterSuggestion(). If true, we may create |
| 314 // shorter suggestions even when they haven't been visited before: | 322 // shorter suggestions even when they haven't been visited before: |
| 315 // if the user visited http://example.com/asdf once, we'll suggest | 323 // if the user visited http://example.com/asdf once, we'll suggest |
| 316 // http://example.com/ even if they've never been to it. | 324 // http://example.com/ even if they've never been to it. |
| 317 bool create_shorter_match_; | 325 bool create_shorter_match_; |
| 318 | 326 |
| 319 DISALLOW_COPY_AND_ASSIGN(HistoryURLProvider); | 327 DISALLOW_COPY_AND_ASSIGN(HistoryURLProvider); |
| 320 }; | 328 }; |
| 321 | 329 |
| 322 #endif // CHROME_BROWSER_AUTOCOMPLETE_HISTORY_URL_PROVIDER_H_ | 330 #endif // CHROME_BROWSER_AUTOCOMPLETE_HISTORY_URL_PROVIDER_H_ |
| OLD | NEW |