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