| Index: chrome/browser/autocomplete/history_url_provider.cc
|
| diff --git a/chrome/browser/autocomplete/history_url_provider.cc b/chrome/browser/autocomplete/history_url_provider.cc
|
| index 8e78b366f0930b578021fd35385678e7a9762348..caab80b40e5fc90a179ae12375ed700f5969e989 100644
|
| --- a/chrome/browser/autocomplete/history_url_provider.cc
|
| +++ b/chrome/browser/autocomplete/history_url_provider.cc
|
| @@ -374,6 +374,9 @@ HistoryURLProvider::VisitClassifier::VisitClassifier(
|
| : provider_(provider),
|
| db_(db),
|
| type_(INVALID) {
|
| + if (!db_)
|
| + return;
|
| +
|
| const GURL& url = input.canonicalized_url();
|
| // Detect email addresses. These cases will look like "http://user@site/",
|
| // and because the history backend strips auth creds, we'll get a bogus exact
|
| @@ -523,7 +526,7 @@ void HistoryURLProvider::Start(const AutocompleteInput& input,
|
| if (url_db) {
|
| DoAutocomplete(NULL, url_db, params.get());
|
| matches_.clear();
|
| - PromoteMatchIfNecessary(*params);
|
| + PromoteMatchesIfNecessary(*params);
|
| UpdateStarredStateOfMatches();
|
| // NOTE: We don't reset |params| here since at least the |promote_type|
|
| // field on it will be read by the second pass -- see comments in
|
| @@ -715,20 +718,9 @@ void HistoryURLProvider::DoAutocomplete(history::HistoryBackend* backend,
|
| SortAndDedupMatches(¶ms->matches);
|
|
|
| // Try to create a shorter suggestion from the best match.
|
| - // We allow the what you typed match to be displayed when there's a reasonable
|
| - // chance the user actually cares:
|
| - // * Their input can be opened as a URL, and
|
| - // * We parsed the input as a URL, or it starts with an explicit "http:" or
|
| - // "https:".
|
| - // Otherwise, this is just low-quality noise. In the cases where we've parsed
|
| - // as UNKNOWN, we'll still show an accidental search infobar if need be.
|
| VisitClassifier classifier(this, params->input, db);
|
| - bool have_what_you_typed_match =
|
| - (params->input.type() != metrics::OmniboxInputType::QUERY) &&
|
| - ((params->input.type() != metrics::OmniboxInputType::UNKNOWN) ||
|
| - (classifier.type() == VisitClassifier::UNVISITED_INTRANET) ||
|
| - !params->trim_http ||
|
| - (AutocompleteInput::NumNonHostComponents(params->input.parts()) > 0));
|
| + const bool have_what_you_typed_match =
|
| + HaveWhatYouTypedMatch(classifier, *params);
|
| const bool have_shorter_suggestion_suitable_for_inline_autocomplete =
|
| PromoteOrCreateShorterSuggestion(db, have_what_you_typed_match, params);
|
|
|
| @@ -782,15 +774,26 @@ void HistoryURLProvider::DoAutocomplete(history::HistoryBackend* backend,
|
| }
|
| }
|
|
|
| -void HistoryURLProvider::PromoteMatchIfNecessary(
|
| +void HistoryURLProvider::PromoteMatchesIfNecessary(
|
| const HistoryURLProviderParams& params) {
|
| - if (params.promote_type == HistoryURLProviderParams::NEITHER)
|
| - return;
|
| - matches_.push_back(
|
| - (params.promote_type == HistoryURLProviderParams::WHAT_YOU_TYPED_MATCH) ?
|
| - params.what_you_typed_match :
|
| - HistoryMatchToACMatch(params, 0, INLINE_AUTOCOMPLETE,
|
| - CalculateRelevance(INLINE_AUTOCOMPLETE, 0)));
|
| + if (params.promote_type == HistoryURLProviderParams::FRONT_HISTORY_MATCH) {
|
| + matches_.push_back(HistoryMatchToACMatch(params, 0, INLINE_AUTOCOMPLETE,
|
| + CalculateRelevance(INLINE_AUTOCOMPLETE, 0)));
|
| + if (OmniboxFieldTrial::AddUWYTMatchEvenIfPromotedURLs()) {
|
| + HistoryService* const history_service =
|
| + HistoryServiceFactory::GetForProfile(profile_,
|
| + Profile::EXPLICIT_ACCESS);
|
| + if (history_service &&
|
| + HaveWhatYouTypedMatch(VisitClassifier(
|
| + this, params.input, history_service->InMemoryDatabase()),
|
| + params)) {
|
| + matches_.push_back(params.what_you_typed_match);
|
| + }
|
| + }
|
| + } else if (params.promote_type ==
|
| + HistoryURLProviderParams::WHAT_YOU_TYPED_MATCH) {
|
| + matches_.push_back(params.what_you_typed_match);
|
| + }
|
| }
|
|
|
| void HistoryURLProvider::QueryComplete(
|
| @@ -811,7 +814,7 @@ void HistoryURLProvider::QueryComplete(
|
| // match in it, whereas |params->matches| will be empty.
|
| if (!params->failed) {
|
| matches_.clear();
|
| - PromoteMatchIfNecessary(*params);
|
| + PromoteMatchesIfNecessary(*params);
|
|
|
| // Determine relevance of highest scoring match, if any.
|
| int relevance = matches_.empty() ?
|
| @@ -843,6 +846,24 @@ void HistoryURLProvider::QueryComplete(
|
| listener_->OnProviderUpdate(true);
|
| }
|
|
|
| +// static
|
| +bool HistoryURLProvider::HaveWhatYouTypedMatch(
|
| + const VisitClassifier& classifier,
|
| + const HistoryURLProviderParams& params) {
|
| + // We consider the what you typed match to be eligible to be displayed when
|
| + // there's a reasonable chance the user actually cares:
|
| + // * Their input can be opened as a URL, and
|
| + // * We parsed the input as a URL, or it starts with an explicit "http:" or
|
| + // "https:".
|
| + // Otherwise, this is just low-quality noise. In the cases where we've parsed
|
| + // as UNKNOWN, we'll still show an accidental search infobar if need be.
|
| + return (params.input.type() != metrics::OmniboxInputType::QUERY) &&
|
| + ((params.input.type() != metrics::OmniboxInputType::UNKNOWN) ||
|
| + (classifier.type() == VisitClassifier::UNVISITED_INTRANET) ||
|
| + !params.trim_http ||
|
| + (AutocompleteInput::NumNonHostComponents(params.input.parts()) > 0));
|
| +}
|
| +
|
| bool HistoryURLProvider::FixupExactSuggestion(
|
| history::URLDatabase* db,
|
| const VisitClassifier& classifier,
|
|
|