Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(478)

Unified Diff: chrome/browser/autocomplete/history_url_provider.cc

Issue 321243003: Omnibox: Add Field Trial to Create UWYT When Inlining (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/autocomplete/history_url_provider.h ('k') | chrome/browser/omnibox/omnibox_field_trial.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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(&params->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,
« no previous file with comments | « chrome/browser/autocomplete/history_url_provider.h ('k') | chrome/browser/omnibox/omnibox_field_trial.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698