Commit be23f89a authored by pkasting@chromium.org's avatar pkasting@chromium.org

Don't call AutocompleteInput::Parse() on a background thread, part 2.

This changes HistoryURLProviderParams from holding an ACMatches object to
holding a HistoryMatches object; the HistoryMatches will no longer be fixed up
in DoAutocomplete(), but rather after it returns control to the UI thread.

The majority of this change is mechanical, but some nontrivial changes have to
be made to DoAutocomplete() to account for how the "promote" action it could
previously take must also happen on the UI thread.  Therefore the |params|
object also has to gain a few members to allow the post-DoAutocomplete() code to
do promotion correctly.

BUG=376199
TEST=none
R=mpearson@chromium.org

Review URL: https://codereview.chromium.org/333273009

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@278558 0039d316-1c4b-4281-b951-d872f2087c98
parent c1bc01d8
...@@ -12,8 +12,7 @@ HistoryMatch::HistoryMatch() ...@@ -12,8 +12,7 @@ HistoryMatch::HistoryMatch()
: url_info(), : url_info(),
input_location(base::string16::npos), input_location(base::string16::npos),
match_in_scheme(false), match_in_scheme(false),
innermost_match(true), innermost_match(true) {
promoted(false) {
} }
HistoryMatch::HistoryMatch(const URLRow& url_info, HistoryMatch::HistoryMatch(const URLRow& url_info,
...@@ -23,8 +22,7 @@ HistoryMatch::HistoryMatch(const URLRow& url_info, ...@@ -23,8 +22,7 @@ HistoryMatch::HistoryMatch(const URLRow& url_info,
: url_info(url_info), : url_info(url_info),
input_location(input_location), input_location(input_location),
match_in_scheme(match_in_scheme), match_in_scheme(match_in_scheme),
innermost_match(innermost_match), innermost_match(innermost_match) {
promoted(false) {
} }
bool HistoryMatch::EqualsGURL(const HistoryMatch& h, const GURL& url) { bool HistoryMatch::EqualsGURL(const HistoryMatch& h, const GURL& url) {
......
...@@ -50,10 +50,6 @@ struct HistoryMatch { ...@@ -50,10 +50,6 @@ struct HistoryMatch {
// "x", no scheme in our prefix list (or "www.") begins with x, so all // "x", no scheme in our prefix list (or "www.") begins with x, so all
// matches are, vacuously, "innermost matches". // matches are, vacuously, "innermost matches".
bool innermost_match; bool innermost_match;
// When sorting, all promoted matches should appear before all non-promoted
// matches, regardless of other properties of the match.
bool promoted;
}; };
typedef std::deque<HistoryMatch> HistoryMatches; typedef std::deque<HistoryMatch> HistoryMatches;
......
...@@ -88,6 +88,13 @@ class URLDatabase; ...@@ -88,6 +88,13 @@ class URLDatabase;
// Used to communicate autocomplete parameters between threads via the history // Used to communicate autocomplete parameters between threads via the history
// service. // service.
struct HistoryURLProviderParams { struct HistoryURLProviderParams {
// See comments on |promote_type| below.
enum PromoteType {
WHAT_YOU_TYPED_MATCH,
FRONT_HISTORY_MATCH,
NEITHER,
};
HistoryURLProviderParams(const AutocompleteInput& input, HistoryURLProviderParams(const AutocompleteInput& input,
bool trim_http, bool trim_http,
const AutocompleteMatch& what_you_typed_match, const AutocompleteMatch& what_you_typed_match,
...@@ -125,18 +132,33 @@ struct HistoryURLProviderParams { ...@@ -125,18 +132,33 @@ struct HistoryURLProviderParams {
// |matches_| at all, so it won't delete the default match Start() creates. // |matches_| at all, so it won't delete the default match Start() creates.
bool failed; bool failed;
// List of matches written by the history thread. We keep this separate list // List of matches written by DoAutocomplete(). Upon its return the provider
// to avoid having the main thread read the provider's matches while the // converts this list to ACMatches and places them in |matches_|.
// history thread is manipulating them. The provider copies this list back history::HistoryMatches matches;
// to matches_ on the main thread in QueryComplete().
ACMatches matches; // True if the suggestion for exactly what the user typed appears as a known
// URL in the user's history. In this case, this will also be the first match
// in |matches|.
//
// NOTE: There are some complications related to keeping things consistent
// between passes and how we deal with intranet URLs, which are too complex to
// explain here; see the implementations of DoAutocomplete() and
// FixupExactSuggestion() for specific comments.
bool exact_suggestion_is_in_history;
// Tells the provider whether to promote the what you typed match, the first
// element of |matches|, or neither as the first AutocompleteMatch. If
// |exact_suggestion_is_in_history| is true (and thus "the what you typed
// match" and "the first element of |matches|" represent the same thing), this
// will be set to WHAT_YOU_TYPED_MATCH.
//
// NOTE: The second pass of DoAutocomplete() checks what the first pass set
// this to. See comments in DoAutocomplete().
PromoteType promote_type;
// Languages we should pass to gfx::GetCleanStringFromUrl. // Languages we should pass to gfx::GetCleanStringFromUrl.
std::string languages; std::string languages;
// When true, we should avoid calling SuggestExactInput().
bool dont_suggest_exact_input;
// The default search provider and search terms data necessary to cull results // The default search provider and search terms data necessary to cull results
// that correspond to searches (on the default engine). These can only be // that correspond to searches (on the default engine). These can only be
// obtained on the UI thread, so we have to copy them into here to pass them // obtained on the UI thread, so we have to copy them into here to pass them
...@@ -173,8 +195,9 @@ class HistoryURLProvider : public HistoryProvider { ...@@ -173,8 +195,9 @@ class HistoryURLProvider : public HistoryProvider {
// input of |text|. |trim_http| controls whether the match's |fill_into_edit| // input of |text|. |trim_http| controls whether the match's |fill_into_edit|
// and |contents| should have any HTTP scheme stripped off, and should not be // and |contents| should have any HTTP scheme stripped off, and should not be
// set to true if |text| contains an http prefix. // set to true if |text| contains an http prefix.
// NOTE: This does not set the relevance of the returned match, as different // NOTES: This does not set the relevance of the returned match, as different
// callers want different behavior. Callers must set this manually. // callers want different behavior. Callers must set this manually.
// This function should only be called on the UI thread.
AutocompleteMatch SuggestExactInput(const base::string16& text, AutocompleteMatch SuggestExactInput(const base::string16& text,
const GURL& destination_url, const GURL& destination_url,
bool trim_http); bool trim_http);
...@@ -220,6 +243,11 @@ class HistoryURLProvider : public HistoryProvider { ...@@ -220,6 +243,11 @@ class HistoryURLProvider : public HistoryProvider {
history::URLDatabase* db, history::URLDatabase* db,
HistoryURLProviderParams* params); HistoryURLProviderParams* params);
// May promote either the what you typed match or first history match in
// params->matches to the front of |matches_|, depending on the value of
// params->promote_type.
void PromoteMatchIfNecessary(const HistoryURLProviderParams& params);
// Dispatches the results to the autocomplete controller. Called on the // Dispatches the results to the autocomplete controller. Called on the
// main thread by ExecuteWithDB when the results are available. // main thread by ExecuteWithDB when the results are available.
// Frees params_gets_deleted on exit. // Frees params_gets_deleted on exit.
...@@ -228,12 +256,11 @@ class HistoryURLProvider : public HistoryProvider { ...@@ -228,12 +256,11 @@ class HistoryURLProvider : public HistoryProvider {
// Looks up the info for params->what_you_typed_match in the DB. If found, // Looks up the info for params->what_you_typed_match in the DB. If found,
// fills in the title, promotes the match's priority to that of an inline // fills in the title, promotes the match's priority to that of an inline
// autocomplete match (maybe it should be slightly better?), and places it on // autocomplete match (maybe it should be slightly better?), and places it on
// the front of |matches| (so we pick the right matches to throw away when // the front of params->matches (so we pick the right matches to throw away
// culling redirects to/from it). Returns whether a match was promoted. // when culling redirects to/from it). Returns whether a match was promoted.
bool FixupExactSuggestion(history::URLDatabase* db, bool FixupExactSuggestion(history::URLDatabase* db,
const VisitClassifier& classifier, const VisitClassifier& classifier,
HistoryURLProviderParams* params, HistoryURLProviderParams* params) const;
history::HistoryMatches* matches) const;
// Helper function for FixupExactSuggestion, this returns true if the input // Helper function for FixupExactSuggestion, this returns true if the input
// corresponds to some intranet URL where the user has previously visited the // corresponds to some intranet URL where the user has previously visited the
...@@ -241,22 +268,18 @@ class HistoryURLProvider : public HistoryProvider { ...@@ -241,22 +268,18 @@ class HistoryURLProvider : public HistoryProvider {
bool CanFindIntranetURL(history::URLDatabase* db, bool CanFindIntranetURL(history::URLDatabase* db,
const AutocompleteInput& input) const; const AutocompleteInput& input) const;
// Determines if |match| is suitable for inline autocomplete. If so, promotes
// the match. Returns whether |match| was promoted.
bool PromoteMatchForInlineAutocomplete(const history::HistoryMatch& match,
HistoryURLProviderParams* params);
// Sees if a shorter version of the best match should be created, and if so // Sees if a shorter version of the best match should be created, and if so
// places it at the front of |matches|. This can suggest history URLs that // places it at the front of params->matches. This can suggest history URLs
// are prefixes of the best match (if they've been visited enough, compared to // that are prefixes of the best match (if they've been visited enough,
// the best match), or create host-only suggestions even when they haven't // compared to the best match), or create host-only suggestions even when they
// been visited before: if the user visited http://example.com/asdf once, // haven't been visited before: if the user visited http://example.com/asdf
// we'll suggest http://example.com/ even if they've never been to it. // once, we'll suggest http://example.com/ even if they've never been to it.
void PromoteOrCreateShorterSuggestion( // Returns true if a match was successfully created/promoted that we're
// willing to inline autocomplete.
bool PromoteOrCreateShorterSuggestion(
history::URLDatabase* db, history::URLDatabase* db,
const HistoryURLProviderParams& params,
bool have_what_you_typed_match, bool have_what_you_typed_match,
history::HistoryMatches* matches); HistoryURLProviderParams* params);
// Removes results that have been rarely typed or visited, and not any time // Removes results that have been rarely typed or visited, and not any time
// recently. The exact parameters for this heuristic can be found in the // recently. The exact parameters for this heuristic can be found in the
...@@ -264,8 +287,7 @@ class HistoryURLProvider : public HistoryProvider { ...@@ -264,8 +287,7 @@ class HistoryURLProvider : public HistoryProvider {
// search engine. These are low-quality, difficult-to-understand matches for // search engine. These are low-quality, difficult-to-understand matches for
// users, and the SearchProvider should surface past queries in a better way // users, and the SearchProvider should surface past queries in a better way
// anyway. // anyway.
void CullPoorMatches(const HistoryURLProviderParams& params, void CullPoorMatches(HistoryURLProviderParams* params) const;
history::HistoryMatches* matches) const;
// Removes results that redirect to each other, leaving at most |max_results| // Removes results that redirect to each other, leaving at most |max_results|
// results. // results.
...@@ -285,12 +307,13 @@ class HistoryURLProvider : public HistoryProvider { ...@@ -285,12 +307,13 @@ class HistoryURLProvider : public HistoryProvider {
size_t source_index, size_t source_index,
const std::vector<GURL>& remove) const; const std::vector<GURL>& remove) const;
// Converts a line from the database into an autocomplete match for display. // Converts a specified |match_number| from params.matches into an
// If experimental scoring is enabled, the final relevance score might be // autocomplete match for display. If experimental scoring is enabled, the
// different from the given |relevance|. // final relevance score might be different from the given |relevance|.
// NOTE: This function should only be called on the UI thread.
AutocompleteMatch HistoryMatchToACMatch( AutocompleteMatch HistoryMatchToACMatch(
const HistoryURLProviderParams& params, const HistoryURLProviderParams& params,
const history::HistoryMatch& history_match, size_t match_number,
MatchType match_type, MatchType match_type,
int relevance); int relevance);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment