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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 84 // checks periodically. If it finds the flag set, it stops what it's doing | 84 // checks periodically. If it finds the flag set, it stops what it's doing |
| 85 // immediately and calls back to the main thread. (We don't delete the params | 85 // immediately and calls back to the main thread. (We don't delete the params |
| 86 // on the history thread, because we should only do that when we can safely | 86 // on the history thread, because we should only do that when we can safely |
| 87 // NULL out params_, and that must be done on the main thread.) | 87 // NULL out params_, and that must be done on the main thread.) |
| 88 | 88 |
| 89 // Used to communicate autocomplete parameters between threads via the history | 89 // Used to communicate autocomplete parameters between threads via the history |
| 90 // service. | 90 // service. |
| 91 struct HistoryURLProviderParams { | 91 struct HistoryURLProviderParams { |
| 92 HistoryURLProviderParams(const AutocompleteInput& input, | 92 HistoryURLProviderParams(const AutocompleteInput& input, |
| 93 bool trim_http, | 93 bool trim_http, |
| 94 const AutocompleteMatch& what_you_typed_match, | |
| 94 const std::string& languages, | 95 const std::string& languages, |
| 95 TemplateURL* default_search_provider, | 96 TemplateURL* default_search_provider, |
| 96 const SearchTermsData& search_terms_data); | 97 const SearchTermsData& search_terms_data); |
| 97 ~HistoryURLProviderParams(); | 98 ~HistoryURLProviderParams(); |
| 98 | 99 |
| 99 base::MessageLoop* message_loop; | 100 base::MessageLoop* message_loop; |
| 100 | 101 |
| 101 // A copy of the autocomplete input. We need the copy since this object will | 102 // A copy of the autocomplete input. We need the copy since this object will |
| 102 // live beyond the original query while it runs on the history thread. | 103 // live beyond the original query while it runs on the history thread. |
| 103 AutocompleteInput input; | 104 AutocompleteInput input; |
| 104 | 105 |
| 105 // Should inline autocompletion be disabled? This is initalized from | 106 // Should inline autocompletion be disabled? This is initalized from |
| 106 // |input.prevent_inline_autocomplete()|, but set to false is the input | 107 // |input.prevent_inline_autocomplete()|, but set to false is the input |
| 107 // contains trailing white space. | 108 // contains trailing white space. |
| 108 bool prevent_inline_autocomplete; | 109 bool prevent_inline_autocomplete; |
| 109 | 110 |
| 110 // Set when "http://" should be trimmed from the beginning of the URLs. | 111 // Set when "http://" should be trimmed from the beginning of the URLs. |
| 111 bool trim_http; | 112 bool trim_http; |
| 112 | 113 |
| 114 // A match corresponding to what the user typed. | |
| 115 AutocompleteMatch what_you_typed_match; | |
| 116 | |
| 113 // Set by the main thread to cancel this request. If this flag is set when | 117 // Set by the main thread to cancel this request. If this flag is set when |
| 114 // the query runs, the query will be abandoned. This allows us to avoid | 118 // the query runs, the query will be abandoned. This allows us to avoid |
| 115 // running queries that are no longer needed. Since we don't care if we run | 119 // running queries that are no longer needed. Since we don't care if we run |
| 116 // the extra queries, the lack of signaling is not a problem. | 120 // the extra queries, the lack of signaling is not a problem. |
| 117 base::CancellationFlag cancel_flag; | 121 base::CancellationFlag cancel_flag; |
| 118 | 122 |
| 119 // Set by ExecuteWithDB() on the history thread when the query could not be | 123 // Set by ExecuteWithDB() on the history thread when the query could not be |
| 120 // performed because the history system failed to properly init the database. | 124 // performed because the history system failed to properly init the database. |
| 121 // If this is set when the main thread is called back, it avoids changing | 125 // If this is set when the main thread is called back, it avoids changing |
| 122 // |matches_| at all, so it won't delete the default match Start() creates. | 126 // |matches_| at all, so it won't delete the default match Start() creates. |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 215 // called on multiple different threads (though not simultaneously). | 219 // called on multiple different threads (though not simultaneously). |
| 216 void DoAutocomplete(history::HistoryBackend* backend, | 220 void DoAutocomplete(history::HistoryBackend* backend, |
| 217 history::URLDatabase* db, | 221 history::URLDatabase* db, |
| 218 HistoryURLProviderParams* params); | 222 HistoryURLProviderParams* params); |
| 219 | 223 |
| 220 // Dispatches the results to the autocomplete controller. Called on the | 224 // Dispatches the results to the autocomplete controller. Called on the |
| 221 // main thread by ExecuteWithDB when the results are available. | 225 // main thread by ExecuteWithDB when the results are available. |
| 222 // Frees params_gets_deleted on exit. | 226 // Frees params_gets_deleted on exit. |
| 223 void QueryComplete(HistoryURLProviderParams* params_gets_deleted); | 227 void QueryComplete(HistoryURLProviderParams* params_gets_deleted); |
| 224 | 228 |
| 225 // Given a |match| containing the "what you typed" suggestion created by | 229 // Given a |match| containing the "what you typed" suggestion created by |
|
Mark P
2014/06/17 17:43:25
This comment needs to be slightly revised.
Peter Kasting
2014/06/17 20:39:48
Done.
| |
| 226 // SuggestExactInput(), looks up its info in the DB. If found, fills in the | 230 // SuggestExactInput(), looks up its info in the DB. If found, fills in the |
| 227 // title from the DB, promotes the match's priority to that of an inline | 231 // title from the DB, promotes the match's priority to that of an inline |
| 228 // autocomplete match (maybe it should be slightly better?), and places it on | 232 // autocomplete match (maybe it should be slightly better?), and places it on |
| 229 // the front of |matches| (so we pick the right matches to throw away | 233 // the front of |matches| (so we pick the right matches to throw away |
| 230 // when culling redirects to/from it). Returns whether a match was promoted. | 234 // when culling redirects to/from it). Returns whether a match was promoted. |
| 231 bool FixupExactSuggestion(history::URLDatabase* db, | 235 bool FixupExactSuggestion(history::URLDatabase* db, |
| 232 const AutocompleteInput& input, | |
| 233 const VisitClassifier& classifier, | 236 const VisitClassifier& classifier, |
| 234 AutocompleteMatch* match, | 237 HistoryURLProviderParams* params, |
| 235 history::HistoryMatches* matches) const; | 238 history::HistoryMatches* matches) const; |
| 236 | 239 |
| 237 // Helper function for FixupExactSuggestion, this returns true if the input | 240 // Helper function for FixupExactSuggestion, this returns true if the input |
| 238 // corresponds to some intranet URL where the user has previously visited the | 241 // corresponds to some intranet URL where the user has previously visited the |
| 239 // host in question. In this case the input should be treated as a URL. | 242 // host in question. In this case the input should be treated as a URL. |
| 240 bool CanFindIntranetURL(history::URLDatabase* db, | 243 bool CanFindIntranetURL(history::URLDatabase* db, |
| 241 const AutocompleteInput& input) const; | 244 const AutocompleteInput& input) const; |
| 242 | 245 |
| 243 // Determines if |match| is suitable for inline autocomplete. If so, and if | 246 // Determines if |match| is suitable for inline autocomplete. If so, promotes |
| 244 // |params| is non-NULL, promotes the match. Returns whether |match| is | 247 // the match. Returns whether |match| was promoted. |
| 245 // suitable for inline autocomplete. | |
| 246 bool PromoteMatchForInlineAutocomplete(const history::HistoryMatch& match, | 248 bool PromoteMatchForInlineAutocomplete(const history::HistoryMatch& match, |
| 247 HistoryURLProviderParams* params); | 249 HistoryURLProviderParams* params); |
| 248 | 250 |
| 249 // Sees if a shorter version of the best match should be created, and if so | 251 // 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 | 252 // places it at the front of |matches|. This can suggest history URLs that |
| 251 // are prefixes of the best match (if they've been visited enough, compared to | 253 // are prefixes of the best match (if they've been visited enough, compared to |
| 252 // the best match), or create host-only suggestions even when they haven't | 254 // the best match), or create host-only suggestions even when they haven't |
| 253 // been visited before: if the user visited http://example.com/asdf once, | 255 // been visited before: if the user visited http://example.com/asdf once, |
| 254 // we'll suggest http://example.com/ even if they've never been to it. | 256 // we'll suggest http://example.com/ even if they've never been to it. |
| 255 void PromoteOrCreateShorterSuggestion( | 257 void PromoteOrCreateShorterSuggestion( |
| 256 history::URLDatabase* db, | 258 history::URLDatabase* db, |
| 257 const HistoryURLProviderParams& params, | 259 const HistoryURLProviderParams& params, |
| 258 bool have_what_you_typed_match, | 260 bool have_what_you_typed_match, |
| 259 const AutocompleteMatch& what_you_typed_match, | |
| 260 history::HistoryMatches* matches); | 261 history::HistoryMatches* matches); |
| 261 | 262 |
| 262 // Removes results that have been rarely typed or visited, and not any time | 263 // Removes results that have been rarely typed or visited, and not any time |
| 263 // recently. The exact parameters for this heuristic can be found in the | 264 // recently. The exact parameters for this heuristic can be found in the |
| 264 // function body. Also culls results corresponding to queries from the default | 265 // function body. Also culls results corresponding to queries from the default |
| 265 // search engine. These are low-quality, difficult-to-understand matches for | 266 // search engine. These are low-quality, difficult-to-understand matches for |
| 266 // users, and the SearchProvider should surface past queries in a better way | 267 // users, and the SearchProvider should surface past queries in a better way |
| 267 // anyway. | 268 // anyway. |
| 268 void CullPoorMatches(const HistoryURLProviderParams& params, | 269 void CullPoorMatches(const HistoryURLProviderParams& params, |
| 269 history::HistoryMatches* matches) const; | 270 history::HistoryMatches* matches) const; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 314 // Used in PromoteOrCreateShorterSuggestion(). If true, we may create | 315 // Used in PromoteOrCreateShorterSuggestion(). If true, we may create |
| 315 // shorter suggestions even when they haven't been visited before: | 316 // shorter suggestions even when they haven't been visited before: |
| 316 // if the user visited http://example.com/asdf once, we'll suggest | 317 // if the user visited http://example.com/asdf once, we'll suggest |
| 317 // http://example.com/ even if they've never been to it. | 318 // http://example.com/ even if they've never been to it. |
| 318 bool create_shorter_match_; | 319 bool create_shorter_match_; |
| 319 | 320 |
| 320 DISALLOW_COPY_AND_ASSIGN(HistoryURLProvider); | 321 DISALLOW_COPY_AND_ASSIGN(HistoryURLProvider); |
| 321 }; | 322 }; |
| 322 | 323 |
| 323 #endif // CHROME_BROWSER_AUTOCOMPLETE_HISTORY_URL_PROVIDER_H_ | 324 #endif // CHROME_BROWSER_AUTOCOMPLETE_HISTORY_URL_PROVIDER_H_ |
| OLD | NEW |