summaryrefslogtreecommitdiffstats
path: root/chrome/browser/autocomplete/search_provider.cc
diff options
context:
space:
mode:
authorKristian Monsen <kristianm@google.com>2011-06-28 21:49:31 +0100
committerKristian Monsen <kristianm@google.com>2011-07-08 17:55:00 +0100
commitddb351dbec246cf1fab5ec20d2d5520909041de1 (patch)
tree158e3fb57bdcac07c7f1e767fde3c70687c9fbb1 /chrome/browser/autocomplete/search_provider.cc
parent6b92e04f5f151c896e3088e86f70db7081009308 (diff)
downloadexternal_chromium-ddb351dbec246cf1fab5ec20d2d5520909041de1.zip
external_chromium-ddb351dbec246cf1fab5ec20d2d5520909041de1.tar.gz
external_chromium-ddb351dbec246cf1fab5ec20d2d5520909041de1.tar.bz2
Merge Chromium at r12.0.742.93: Initial merge by git
Change-Id: Ic5ee2fec31358bbee305f7e915442377bfa6cda6
Diffstat (limited to 'chrome/browser/autocomplete/search_provider.cc')
-rw-r--r--chrome/browser/autocomplete/search_provider.cc49
1 files changed, 38 insertions, 11 deletions
diff --git a/chrome/browser/autocomplete/search_provider.cc b/chrome/browser/autocomplete/search_provider.cc
index ed308bb..589b31a 100644
--- a/chrome/browser/autocomplete/search_provider.cc
+++ b/chrome/browser/autocomplete/search_provider.cc
@@ -12,6 +12,7 @@
#include "base/message_loop.h"
#include "base/string16.h"
#include "base/utf_string_conversions.h"
+#include "chrome/browser/autocomplete/autocomplete_classifier.h"
#include "chrome/browser/autocomplete/keyword_provider.h"
#include "chrome/browser/autocomplete/autocomplete_match.h"
#include "chrome/browser/google/google_util.h"
@@ -22,9 +23,9 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/history/in_memory_database.h"
#include "chrome/browser/search_engines/template_url_model.h"
-#include "chrome/common/json_value_serializer.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h"
+#include "content/common/json_value_serializer.h"
#include "googleurl/src/url_util.h"
#include "grit/generated_resources.h"
#include "net/base/escape.h"
@@ -133,7 +134,8 @@ void SearchProvider::Start(const AutocompleteInput& input,
bool minimal_changes) {
matches_.clear();
- instant_finalized_ = input.synchronous_only();
+ instant_finalized_ =
+ (input.matches_requested() != AutocompleteInput::ALL_MATCHES);
// Can't return search/suggest results for bogus input or without a profile.
if (!profile_ || (input.type() == AutocompleteInput::INVALID)) {
@@ -326,14 +328,16 @@ void SearchProvider::StartOrStopSuggestQuery(bool minimal_changes) {
// have its results, or are allowed to keep running it, just do that, rather
// than starting a new query.
if (minimal_changes &&
- (have_suggest_results_ || (!done_ && !input_.synchronous_only())))
+ (have_suggest_results_ ||
+ (!done_ &&
+ input_.matches_requested() == AutocompleteInput::ALL_MATCHES)))
return;
// We can't keep running any previous query, so halt it.
StopSuggest();
// We can't start a new query if we're only allowed synchronous results.
- if (input_.synchronous_only())
+ if (input_.matches_requested() != AutocompleteInput::ALL_MATCHES)
return;
// We'll have at least one pending fetch. Set it to 1 now, but the value is
@@ -349,7 +353,7 @@ void SearchProvider::StartOrStopSuggestQuery(bool minimal_changes) {
}
bool SearchProvider::IsQuerySuitableForSuggest() const {
- // Don't run Suggest when off the record, the engine doesn't support it, or
+ // Don't run Suggest in incognito mode, the engine doesn't support it, or
// the user has disabled it.
if (profile_->IsOffTheRecord() ||
(!providers_.valid_suggest_for_keyword_provider() &&
@@ -601,6 +605,7 @@ void SearchProvider::AddHistoryResultsToMap(const HistoryResults& results,
int did_not_accept_suggestion,
MatchMap* map) {
int last_relevance = 0;
+ AutocompleteClassifier* classifier = profile_->GetAutocompleteClassifier();
for (HistoryResults::const_iterator i(results.begin()); i != results.end();
++i) {
// History returns results sorted for us. We force the relevance to decrease
@@ -611,7 +616,28 @@ void SearchProvider::AddHistoryResultsToMap(const HistoryResults& results,
// be random.
// This uses >= to handle the case where 3 or more results have the same
// relevance.
- int relevance = CalculateRelevanceForHistory(i->time, is_keyword);
+ bool term_looks_like_url = false;
+ // Don't autocomplete search terms that would normally be treated as URLs
+ // when typed. For example, if the user searched for google.com and types
+ // goog, don't autocomplete to the search term google.com. Otherwise, the
+ // input will look like a URL but act like a search, which is confusing.
+ // NOTE: We don't check this in the following cases:
+ // * When inline autocomplete is disabled, we won't be inline
+ // autocompleting this term, so we don't need to worry about confusion as
+ // much. This also prevents calling Classify() again from inside the
+ // classifier (which will corrupt state and likely crash), since the
+ // classifier always disabled inline autocomplete.
+ // * When the user has typed the whole term, the "what you typed" history
+ // match will outrank us for URL-like inputs anyway, so we need not do
+ // anything special.
+ if (!input_.prevent_inline_autocomplete() && classifier &&
+ i->term != input_.text()) {
+ AutocompleteMatch match;
+ classifier->Classify(i->term, string16(), false, &match, NULL);
+ term_looks_like_url = match.transition == PageTransition::TYPED;
+ }
+ int relevance = CalculateRelevanceForHistory(i->time, term_looks_like_url,
+ is_keyword);
if (i != results.begin() && relevance >= last_relevance)
relevance = last_relevance - 1;
last_relevance = relevance;
@@ -663,18 +689,19 @@ int SearchProvider::CalculateRelevanceForWhatYouTyped() const {
}
int SearchProvider::CalculateRelevanceForHistory(const Time& time,
+ bool looks_like_url,
bool is_keyword) const {
// The relevance of past searches falls off over time. There are two distinct
// equations used. If the first equation is used (searches to the primary
- // provider with a type other than URL) the score starts at 1399 and falls to
- // 1300. If the second equation is used the relevance of a search 15 minutes
- // ago is discounted about 50 points, while the relevance of a search two
- // weeks ago is discounted about 450 points.
+ // provider with a type other than URL that don't autocomplete to a url) the
+ // score starts at 1399 and falls to 1300. If the second equation is used the
+ // relevance of a search 15 minutes ago is discounted about 50 points, while
+ // the relevance of a search two weeks ago is discounted about 450 points.
double elapsed_time = std::max((Time::Now() - time).InSecondsF(), 0.);
if (providers_.is_primary_provider(is_keyword) &&
input_.type() != AutocompleteInput::URL &&
- !input_.prevent_inline_autocomplete()) {
+ !input_.prevent_inline_autocomplete() && !looks_like_url) {
// Searches with the past two days get a different curve.
const double autocomplete_time= 2 * 24 * 60 * 60;
if (elapsed_time < autocomplete_time) {