summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-04 14:19:37 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-04 14:19:37 +0000
commitea3b9a5037ff9bb3b927a4d57cdfaab835e636db (patch)
treee92390617210619762c398db1a66e32762ac86b4 /chrome
parent7a4557d5ebc81fb3c99ae511d5a64b8543ec8b2f (diff)
downloadchromium_src-ea3b9a5037ff9bb3b927a4d57cdfaab835e636db.zip
chromium_src-ea3b9a5037ff9bb3b927a4d57cdfaab835e636db.tar.gz
chromium_src-ea3b9a5037ff9bb3b927a4d57cdfaab835e636db.tar.bz2
Makes the search provider not return results that look like URLs.
BUG=77065 TEST=see bug, also covered by unit test R=pkasting@chromium.org Review URL: http://codereview.chromium.org/6711087 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@80308 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/autocomplete/autocomplete.cc32
-rw-r--r--chrome/browser/autocomplete/autocomplete.h36
-rw-r--r--chrome/browser/autocomplete/autocomplete_browsertest.cc5
-rw-r--r--chrome/browser/autocomplete/autocomplete_classifier.cc4
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit.cc3
-rw-r--r--chrome/browser/autocomplete/autocomplete_result_unittest.cc4
-rw-r--r--chrome/browser/autocomplete/autocomplete_unittest.cc16
-rw-r--r--chrome/browser/autocomplete/builtin_provider.cc3
-rw-r--r--chrome/browser/autocomplete/history_contents_provider.cc12
-rw-r--r--chrome/browser/autocomplete/history_contents_provider_unittest.cc22
-rw-r--r--chrome/browser/autocomplete/history_quick_provider_unittest.cc3
-rw-r--r--chrome/browser/autocomplete/history_url_provider.cc2
-rw-r--r--chrome/browser/autocomplete/history_url_provider_unittest.cc7
-rw-r--r--chrome/browser/autocomplete/keyword_provider.cc6
-rw-r--r--chrome/browser/autocomplete/keyword_provider_unittest.cc2
-rw-r--r--chrome/browser/autocomplete/search_provider.cc39
-rw-r--r--chrome/browser/autocomplete/search_provider.h4
-rw-r--r--chrome/browser/autocomplete/search_provider_unittest.cc41
-rw-r--r--chrome/browser/extensions/extension_omnibox_apitest.cc15
-rw-r--r--chrome/browser/ui/webui/options/browser_options_handler.cc4
20 files changed, 178 insertions, 82 deletions
diff --git a/chrome/browser/autocomplete/autocomplete.cc b/chrome/browser/autocomplete/autocomplete.cc
index 1f4a10e..101f373 100644
--- a/chrome/browser/autocomplete/autocomplete.cc
+++ b/chrome/browser/autocomplete/autocomplete.cc
@@ -51,7 +51,7 @@ AutocompleteInput::AutocompleteInput()
prevent_inline_autocomplete_(false),
prefer_keyword_(false),
allow_exact_keyword_match_(true),
- synchronous_only_(false) {
+ matches_requested_(ALL_MATCHES) {
}
AutocompleteInput::AutocompleteInput(const string16& text,
@@ -59,14 +59,14 @@ AutocompleteInput::AutocompleteInput(const string16& text,
bool prevent_inline_autocomplete,
bool prefer_keyword,
bool allow_exact_keyword_match,
- bool synchronous_only)
+ MatchesRequested matches_requested)
: original_text_(text),
desired_tld_(desired_tld),
initial_prevent_inline_autocomplete_(prevent_inline_autocomplete),
prevent_inline_autocomplete_(prevent_inline_autocomplete),
prefer_keyword_(prefer_keyword),
allow_exact_keyword_match_(allow_exact_keyword_match),
- synchronous_only_(synchronous_only) {
+ matches_requested_(matches_requested) {
// Trim whitespace from edges of input; don't inline autocomplete if there
// was trailing whitespace.
if (TrimWhitespace(text, TRIM_ALL, &text_) & TRIM_TRAILING)
@@ -464,7 +464,7 @@ bool AutocompleteInput::Equals(const AutocompleteInput& other) const {
(scheme_ == other.scheme_) &&
(prevent_inline_autocomplete_ == other.prevent_inline_autocomplete_) &&
(prefer_keyword_ == other.prefer_keyword_) &&
- (synchronous_only_ == other.synchronous_only_);
+ (matches_requested_ == other.matches_requested_);
}
void AutocompleteInput::Clear() {
@@ -826,16 +826,18 @@ void AutocompleteController::SetProfile(Profile* profile) {
// different profile.
}
-void AutocompleteController::Start(const string16& text,
- const string16& desired_tld,
- bool prevent_inline_autocomplete,
- bool prefer_keyword,
- bool allow_exact_keyword_match,
- bool synchronous_only) {
+void AutocompleteController::Start(
+ const string16& text,
+ const string16& desired_tld,
+ bool prevent_inline_autocomplete,
+ bool prefer_keyword,
+ bool allow_exact_keyword_match,
+ AutocompleteInput::MatchesRequested matches_requested) {
const string16 old_input_text(input_.text());
- const bool old_synchronous_only = input_.synchronous_only();
+ const AutocompleteInput::MatchesRequested old_matches_requested =
+ input_.matches_requested();
input_ = AutocompleteInput(text, desired_tld, prevent_inline_autocomplete,
- prefer_keyword, allow_exact_keyword_match, synchronous_only);
+ prefer_keyword, allow_exact_keyword_match, matches_requested);
// See if we can avoid rerunning autocomplete when the query hasn't changed
// much. When the user presses or releases the ctrl key, the desired_tld
@@ -847,7 +849,7 @@ void AutocompleteController::Start(const string16& text,
// NOTE: This comes after constructing |input_| above since that construction
// can change the text string (e.g. by stripping off a leading '?').
const bool minimal_changes = (input_.text() == old_input_text) &&
- (input_.synchronous_only() == old_synchronous_only);
+ (input_.matches_requested() == old_matches_requested);
expire_timer_.Stop();
@@ -857,10 +859,10 @@ void AutocompleteController::Start(const string16& text,
for (ACProviders::iterator i(providers_.begin()); i != providers_.end();
++i) {
(*i)->Start(input_, minimal_changes);
- if (synchronous_only)
+ if (matches_requested != AutocompleteInput::ALL_MATCHES)
DCHECK((*i)->done());
}
- if (!synchronous_only && text.size() < 6) {
+ if (matches_requested == AutocompleteInput::ALL_MATCHES && text.size() < 6) {
base::TimeTicks end_time = base::TimeTicks::Now();
std::string name = "Omnibox.QueryTime." + base::IntToString(text.size());
scoped_refptr<base::Histogram> counter = base::Histogram::FactoryGet(
diff --git a/chrome/browser/autocomplete/autocomplete.h b/chrome/browser/autocomplete/autocomplete.h
index cf0152f..d1809d3 100644
--- a/chrome/browser/autocomplete/autocomplete.h
+++ b/chrome/browser/autocomplete/autocomplete.h
@@ -185,13 +185,30 @@ class AutocompleteInput {
FORCED_QUERY, // Input forced to be a query by an initial '?'
};
+ // Enumeration of the possible match query types. Callers who only need some
+ // of the matches for a particular input can get answers more quickly by
+ // specifying that upfront.
+ enum MatchesRequested {
+ // Only the best match in the whole result set matters. Providers should at
+ // most return synchronously-available matches, and if possible do even less
+ // work, so that it's safe to ask for these repeatedly in the course of one
+ // higher-level "synchronous" query.
+ BEST_MATCH,
+
+ // Only synchronous matches should be returned.
+ SYNCHRONOUS_MATCHES,
+
+ // All matches should be fetched.
+ ALL_MATCHES,
+ };
+
AutocompleteInput();
AutocompleteInput(const string16& text,
const string16& desired_tld,
bool prevent_inline_autocomplete,
bool prefer_keyword,
bool allow_exact_keyword_match,
- bool synchronous_only);
+ MatchesRequested matches_requested);
~AutocompleteInput();
// If type is |FORCED_QUERY| and |text| starts with '?', it is removed.
@@ -282,11 +299,8 @@ class AutocompleteInput {
// keyword search, even if the input is "<keyword> <search string>".
bool allow_exact_keyword_match() const { return allow_exact_keyword_match_; }
- // Returns whether providers should avoid scheduling asynchronous work. If
- // this is true, providers should stop after returning all the
- // synchronously-available matches. This also means any in-progress
- // asynchronous work should be canceled, so no later callbacks are fired.
- bool synchronous_only() const { return synchronous_only_; }
+ // See description of enum for details.
+ MatchesRequested matches_requested() const { return matches_requested_; }
// operator==() by another name.
bool Equals(const AutocompleteInput& other) const;
@@ -306,7 +320,7 @@ class AutocompleteInput {
bool prevent_inline_autocomplete_;
bool prefer_keyword_;
bool allow_exact_keyword_match_;
- bool synchronous_only_;
+ MatchesRequested matches_requested_;
};
// AutocompleteProvider -------------------------------------------------------
@@ -611,9 +625,9 @@ class AutocompleteController : public ACProviderListener {
// in a page and telling the browser to search for it or navigate to it. This
// parameter only applies to substituting keywords.
- // If |synchronous_only| is true, the controller asks the providers to only
- // return matches which are synchronously available, which should mean that
- // all providers will be done immediately.
+ // If |matches_requested| is BEST_MATCH or SYNCHRONOUS_MATCHES the controller
+ // asks the providers to only return matches which are synchronously
+ // available, which should mean that all providers will be done immediately.
//
// The controller calls AutocompleteControllerDelegate::OnResultChanged() from
// inside this call at least once. If matches are available later on that
@@ -625,7 +639,7 @@ class AutocompleteController : public ACProviderListener {
bool prevent_inline_autocomplete,
bool prefer_keyword,
bool allow_exact_keyword_match,
- bool synchronous_only);
+ AutocompleteInput::MatchesRequested matches_requested);
// Cancels the current query, ensuring there will be no future notifications
// fired. If new matches have come in since the most recent notification was
diff --git a/chrome/browser/autocomplete/autocomplete_browsertest.cc b/chrome/browser/autocomplete/autocomplete_browsertest.cc
index 3238e43..b115277 100644
--- a/chrome/browser/autocomplete/autocomplete_browsertest.cc
+++ b/chrome/browser/autocomplete/autocomplete_browsertest.cc
@@ -106,8 +106,9 @@ IN_PROC_BROWSER_TEST_F(AutocompleteBrowserTest, MAYBE_Autocomplete) {
AutocompleteController* autocomplete_controller = GetAutocompleteController();
{
- autocomplete_controller->Start(ASCIIToUTF16("chrome"), string16(),
- true, false, true, true);
+ autocomplete_controller->Start(
+ ASCIIToUTF16("chrome"), string16(), true, false, true,
+ AutocompleteInput::SYNCHRONOUS_MATCHES);
EXPECT_TRUE(autocomplete_controller->done());
EXPECT_TRUE(location_bar->GetInputString().empty());
diff --git a/chrome/browser/autocomplete/autocomplete_classifier.cc b/chrome/browser/autocomplete/autocomplete_classifier.cc
index ad9e2d7..98d1780 100644
--- a/chrome/browser/autocomplete/autocomplete_classifier.cc
+++ b/chrome/browser/autocomplete/autocomplete_classifier.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -21,7 +21,7 @@ void AutocompleteClassifier::Classify(const string16& text,
AutocompleteMatch* match,
GURL* alternate_nav_url) {
controller_->Start(text, desired_tld, true, false, allow_exact_keyword_match,
- true);
+ AutocompleteInput::BEST_MATCH);
DCHECK(controller_->done());
const AutocompleteResult& result = controller_->result();
if (result.empty()) {
diff --git a/chrome/browser/autocomplete/autocomplete_edit.cc b/chrome/browser/autocomplete/autocomplete_edit.cc
index 418c362..f853f95 100644
--- a/chrome/browser/autocomplete/autocomplete_edit.cc
+++ b/chrome/browser/autocomplete/autocomplete_edit.cc
@@ -392,7 +392,8 @@ void AutocompleteEditModel::StartAutocomplete(
prevent_inline_autocomplete || just_deleted_text_ ||
(has_selected_text && inline_autocomplete_text_.empty()) ||
(paste_state_ != NONE), keyword_is_selected,
- keyword_is_selected || allow_exact_keyword_match_, false);
+ keyword_is_selected || allow_exact_keyword_match_,
+ AutocompleteInput::ALL_MATCHES);
}
void AutocompleteEditModel::StopAutocomplete() {
diff --git a/chrome/browser/autocomplete/autocomplete_result_unittest.cc b/chrome/browser/autocomplete/autocomplete_result_unittest.cc
index fe94c73..0fbdcba 100644
--- a/chrome/browser/autocomplete/autocomplete_result_unittest.cc
+++ b/chrome/browser/autocomplete/autocomplete_result_unittest.cc
@@ -93,7 +93,7 @@ void AutocompleteResultTest::RunCopyOldMatchesTest(
const TestData* current, size_t current_size,
const TestData* expected, size_t expected_size) {
AutocompleteInput input(ASCIIToUTF16("a"), string16(), false, false, false,
- false);
+ AutocompleteInput::ALL_MATCHES);
ACMatches last_matches;
PopulateAutocompleteMatches(last, last_size, &last_matches);
@@ -125,7 +125,7 @@ TEST_F(AutocompleteResultTest, Swap) {
ACMatches matches;
AutocompleteMatch match;
AutocompleteInput input(ASCIIToUTF16("a"), string16(), false, false, false,
- false);
+ AutocompleteInput::ALL_MATCHES);
matches.push_back(match);
r1.AppendMatches(matches);
r1.SortAndCull(input);
diff --git a/chrome/browser/autocomplete/autocomplete_unittest.cc b/chrome/browser/autocomplete/autocomplete_unittest.cc
index d30b7b7..9d0f7c1 100644
--- a/chrome/browser/autocomplete/autocomplete_unittest.cc
+++ b/chrome/browser/autocomplete/autocomplete_unittest.cc
@@ -68,7 +68,7 @@ void TestProvider::Start(const AutocompleteInput& input,
// Generate one result synchronously, the rest later.
AddResults(0, 1);
- if (!input.synchronous_only()) {
+ if (input.matches_requested() == AutocompleteInput::ALL_MATCHES) {
done_ = false;
MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(
this, &TestProvider::Run));
@@ -203,7 +203,8 @@ void AutocompleteProviderTest::
void AutocompleteProviderTest::RunTest() {
result_.Reset();
- controller_->Start(ASCIIToUTF16("a"), string16(), true, false, true, false);
+ controller_->Start(ASCIIToUTF16("a"), string16(), true, false, true,
+ AutocompleteInput::ALL_MATCHES);
// The message loop will terminate when all autocomplete input has been
// collected.
@@ -217,7 +218,8 @@ void AutocompleteProviderTest::RunExactKeymatchTest(
// match should thus be a keyword match iff |allow_exact_keyword_match| is
// true.
controller_->Start(ASCIIToUTF16("k test"), string16(), true, false,
- allow_exact_keyword_match, true);
+ allow_exact_keyword_match,
+ AutocompleteInput::SYNCHRONOUS_MATCHES);
EXPECT_TRUE(controller_->done());
// ResetControllerWithKeywordAndSearchProviders() adds the keyword provider
// first, then the search provider. So if the default match is a keyword
@@ -359,7 +361,7 @@ TEST_F(AutocompleteTest, InputType) {
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(input_cases); ++i) {
SCOPED_TRACE(input_cases[i].input);
AutocompleteInput input(input_cases[i].input, string16(), true, false,
- true, false);
+ true, AutocompleteInput::ALL_MATCHES);
EXPECT_EQ(input_cases[i].type, input.type());
}
}
@@ -375,7 +377,7 @@ TEST_F(AutocompleteTest, InputTypeWithDesiredTLD) {
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(input_cases); ++i) {
AutocompleteInput input(input_cases[i].input, ASCIIToUTF16("com"), true,
- false, true, false);
+ false, true, AutocompleteInput::ALL_MATCHES);
EXPECT_EQ(input_cases[i].type, input.type()) << "Input: " <<
input_cases[i].input;
}
@@ -385,7 +387,7 @@ TEST_F(AutocompleteTest, InputTypeWithDesiredTLD) {
// crash. As long as the test completes without crashing, we're fine.
TEST_F(AutocompleteTest, InputCrash) {
AutocompleteInput input(WideToUTF16(L"\uff65@s"), string16(), true, false,
- true, false);
+ true, AutocompleteInput::ALL_MATCHES);
}
// Test comparing matches relevance.
@@ -455,7 +457,7 @@ TEST(AutocompleteInput, ParseForEmphasizeComponent) {
&scheme,
&host);
AutocompleteInput input(input_cases[i].input, string16(), true, false,
- true, false);
+ true, AutocompleteInput::ALL_MATCHES);
EXPECT_EQ(input_cases[i].scheme.begin, scheme.begin) << "Input: " <<
input_cases[i].input;
EXPECT_EQ(input_cases[i].scheme.len, scheme.len) << "Input: " <<
diff --git a/chrome/browser/autocomplete/builtin_provider.cc b/chrome/browser/autocomplete/builtin_provider.cc
index 3ea4946..96843cf 100644
--- a/chrome/browser/autocomplete/builtin_provider.cc
+++ b/chrome/browser/autocomplete/builtin_provider.cc
@@ -28,7 +28,8 @@ void BuiltinProvider::Start(const AutocompleteInput& input,
matches_.clear();
if ((input.type() == AutocompleteInput::INVALID) ||
(input.type() == AutocompleteInput::FORCED_QUERY) ||
- (input.type() == AutocompleteInput::QUERY))
+ (input.type() == AutocompleteInput::QUERY) ||
+ (input.matches_requested() == AutocompleteInput::BEST_MATCH))
return;
for (Builtins::const_iterator i(builtins_.begin());
(i != builtins_.end()) && (matches_.size() < kMaxMatches); ++i) {
diff --git a/chrome/browser/autocomplete/history_contents_provider.cc b/chrome/browser/autocomplete/history_contents_provider.cc
index 91c3078..71336b0 100644
--- a/chrome/browser/autocomplete/history_contents_provider.cc
+++ b/chrome/browser/autocomplete/history_contents_provider.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -87,6 +87,12 @@ void HistoryContentsProvider::Start(const AutocompleteInput& input,
return;
}
+ if (input.matches_requested() == AutocompleteInput::BEST_MATCH) {
+ // None of our results are applicable for best match.
+ Stop();
+ return;
+ }
+
// Change input type so matches will be marked up properly.
input_type_ = input.type();
trim_http_ = !HasHTTPScheme(input.text());
@@ -105,7 +111,7 @@ void HistoryContentsProvider::Start(const AutocompleteInput& input,
// allowed to keep running it, do so, and when it finishes, its results will
// get marked up for this new input. In synchronous_only mode, cancel the
// history query.
- if (input.synchronous_only()) {
+ if (input.matches_requested() != AutocompleteInput::ALL_MATCHES) {
done_ = true;
request_consumer_.CancelAllRequests();
}
@@ -125,7 +131,7 @@ void HistoryContentsProvider::Start(const AutocompleteInput& input,
// Convert the bookmark results.
ConvertResults();
- if (!input.synchronous_only()) {
+ if (input.matches_requested() == AutocompleteInput::ALL_MATCHES) {
HistoryService* history =
profile_->GetHistoryService(Profile::EXPLICIT_ACCESS);
if (history) {
diff --git a/chrome/browser/autocomplete/history_contents_provider_unittest.cc b/chrome/browser/autocomplete/history_contents_provider_unittest.cc
index f4665b2..296117c 100644
--- a/chrome/browser/autocomplete/history_contents_provider_unittest.cc
+++ b/chrome/browser/autocomplete/history_contents_provider_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -45,7 +45,7 @@ class HistoryContentsProviderTest : public TestingBrowserProcessTest,
// When we're waiting for asynchronous messages, we have to spin the message
// loop. This will be exited in the OnProviderUpdate function when complete.
- if (!input.synchronous_only())
+ if (input.matches_requested() == AutocompleteInput::ALL_MATCHES)
MessageLoop::current()->Run();
}
@@ -108,7 +108,7 @@ class HistoryContentsProviderTest : public TestingBrowserProcessTest,
TEST_F(HistoryContentsProviderTest, Body) {
AutocompleteInput input(ASCIIToUTF16("FOO"), string16(), true, false, true,
- false);
+ AutocompleteInput::ALL_MATCHES);
RunQuery(input, false);
// The results should be the first two pages, in decreasing order.
@@ -122,7 +122,7 @@ TEST_F(HistoryContentsProviderTest, Body) {
TEST_F(HistoryContentsProviderTest, Title) {
AutocompleteInput input(ASCIIToUTF16("PAGEONE"), string16(), true, false,
- true, false);
+ true, AutocompleteInput::ALL_MATCHES);
RunQuery(input, false);
// The results should be the first two pages.
@@ -139,14 +139,14 @@ TEST_F(HistoryContentsProviderTest, MinimalChanges) {
// A minimal changes request when there have been no real queries should
// give us no results.
AutocompleteInput sync_input(ASCIIToUTF16("PAGEONE"), string16(), true, false,
- true, true);
+ true, AutocompleteInput::SYNCHRONOUS_MATCHES);
RunQuery(sync_input, true);
const ACMatches& m1 = matches();
EXPECT_EQ(0U, m1.size());
// Now do a "regular" query to get the results.
AutocompleteInput async_input(ASCIIToUTF16("PAGEONE"), string16(), true,
- false, true, false);
+ false, true, AutocompleteInput::ALL_MATCHES);
RunQuery(async_input, false);
const ACMatches& m2 = matches();
EXPECT_EQ(2U, m2.size());
@@ -170,7 +170,7 @@ TEST_F(HistoryContentsProviderTest, Bookmarks) {
// Ask for synchronous. This should only get the bookmark.
AutocompleteInput sync_input(ASCIIToUTF16("bar"), string16(), true, false,
- true, true);
+ true, AutocompleteInput::SYNCHRONOUS_MATCHES);
RunQuery(sync_input, false);
const ACMatches& m1 = matches();
ASSERT_EQ(1U, m1.size());
@@ -180,7 +180,7 @@ TEST_F(HistoryContentsProviderTest, Bookmarks) {
// Ask for async. We should get the bookmark immediately.
AutocompleteInput async_input(ASCIIToUTF16("bar"), string16(), true, false,
- true, false);
+ true, AutocompleteInput::ALL_MATCHES);
provider()->Start(async_input, false);
const ACMatches& m2 = matches();
ASSERT_EQ(1U, m2.size());
@@ -203,7 +203,7 @@ TEST_F(HistoryContentsProviderTest, Bookmarks) {
// Tests that history is deleted properly.
TEST_F(HistoryContentsProviderTest, DeleteMatch) {
AutocompleteInput input(ASCIIToUTF16("bar"), string16(), true, false, true,
- false);
+ AutocompleteInput::ALL_MATCHES);
RunQuery(input, false);
// Query; the result should be the third page.
@@ -228,7 +228,7 @@ TEST_F(HistoryContentsProviderTest, DeleteStarredMatch) {
// Get the match to delete its history
AutocompleteInput input(ASCIIToUTF16("bar"), string16(), true, false, true,
- false);
+ AutocompleteInput::ALL_MATCHES);
RunQuery(input, false);
const ACMatches& m = matches();
ASSERT_EQ(1U, m.size());
@@ -239,7 +239,7 @@ TEST_F(HistoryContentsProviderTest, DeleteStarredMatch) {
// Run a query that would only match history (but the history is deleted)
AutocompleteInput you_input(ASCIIToUTF16("you"), string16(), true, false,
- true, false);
+ true, AutocompleteInput::ALL_MATCHES);
RunQuery(you_input, false);
EXPECT_EQ(0U, matches().size());
diff --git a/chrome/browser/autocomplete/history_quick_provider_unittest.cc b/chrome/browser/autocomplete/history_quick_provider_unittest.cc
index 38ed75c..5e577b1 100644
--- a/chrome/browser/autocomplete/history_quick_provider_unittest.cc
+++ b/chrome/browser/autocomplete/history_quick_provider_unittest.cc
@@ -177,7 +177,8 @@ void HistoryQuickProviderTest::RunTest(const string16 text,
std::sort(expected_urls.begin(), expected_urls.end());
MessageLoop::current()->RunAllPending();
- AutocompleteInput input(text, string16(), false, false, true, false);
+ AutocompleteInput input(text, string16(), false, false, true,
+ AutocompleteInput::ALL_MATCHES);
provider_->Start(input, false);
EXPECT_TRUE(provider_->done());
diff --git a/chrome/browser/autocomplete/history_url_provider.cc b/chrome/browser/autocomplete/history_url_provider.cc
index 65a60f5..545f98a 100644
--- a/chrome/browser/autocomplete/history_url_provider.cc
+++ b/chrome/browser/autocomplete/history_url_provider.cc
@@ -631,7 +631,7 @@ void HistoryURLProvider::RunAutocompletePasses(
// Pass 2: Ask the history service to call us back on the history thread,
// where we can read the full on-disk DB.
- if (!input.synchronous_only()) {
+ if (input.matches_requested() == AutocompleteInput::ALL_MATCHES) {
done_ = false;
params_ = params.release(); // This object will be destroyed in
// QueryComplete() once we're done with it.
diff --git a/chrome/browser/autocomplete/history_url_provider_unittest.cc b/chrome/browser/autocomplete/history_url_provider_unittest.cc
index bd29d09..89df897 100644
--- a/chrome/browser/autocomplete/history_url_provider_unittest.cc
+++ b/chrome/browser/autocomplete/history_url_provider_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -188,7 +188,7 @@ void HistoryURLProviderTest::RunTest(const string16 text,
const std::string* expected_urls,
size_t num_results) {
AutocompleteInput input(text, desired_tld, prevent_inline_autocomplete,
- false, true, false);
+ false, true, AutocompleteInput::ALL_MATCHES);
autocomplete_->Start(input, false);
if (!autocomplete_->done())
MessageLoop::current()->Run();
@@ -202,7 +202,8 @@ void HistoryURLProviderTest::RunTest(const string16 text,
void HistoryURLProviderTest::RunAdjustOffsetTest(const string16 text,
size_t expected_offset) {
- AutocompleteInput input(text, string16(), false, false, true, false);
+ AutocompleteInput input(text, string16(), false, false, true,
+ AutocompleteInput::ALL_MATCHES);
autocomplete_->Start(input, false);
if (!autocomplete_->done())
MessageLoop::current()->Run();
diff --git a/chrome/browser/autocomplete/keyword_provider.cc b/chrome/browser/autocomplete/keyword_provider.cc
index 138c689..99ea49c 100644
--- a/chrome/browser/autocomplete/keyword_provider.cc
+++ b/chrome/browser/autocomplete/keyword_provider.cc
@@ -185,7 +185,8 @@ void KeywordProvider::Start(const AutocompleteInput& input,
i != keyword_matches.end(); ) {
const TemplateURL* template_url(model->GetTemplateURLForKeyword(*i));
if (profile_ &&
- !input.synchronous_only() && template_url->IsExtensionKeyword()) {
+ input.matches_requested() == AutocompleteInput::ALL_MATCHES &&
+ template_url->IsExtensionKeyword()) {
ExtensionService* service = profile_->GetExtensionService();
const Extension* extension = service->GetExtensionById(
template_url->GetExtensionId(), false);
@@ -215,7 +216,8 @@ void KeywordProvider::Start(const AutocompleteInput& input,
remaining_input, -1));
if (profile_ &&
- !input.synchronous_only() && template_url->IsExtensionKeyword()) {
+ input.matches_requested() == AutocompleteInput::ALL_MATCHES &&
+ template_url->IsExtensionKeyword()) {
if (template_url->GetExtensionId() != current_keyword_extension_id_)
MaybeEndExtensionKeywordMode();
if (current_keyword_extension_id_.empty())
diff --git a/chrome/browser/autocomplete/keyword_provider_unittest.cc b/chrome/browser/autocomplete/keyword_provider_unittest.cc
index 37922ba..dbf9636 100644
--- a/chrome/browser/autocomplete/keyword_provider_unittest.cc
+++ b/chrome/browser/autocomplete/keyword_provider_unittest.cc
@@ -67,7 +67,7 @@ void KeywordProviderTest::RunTest(
ACMatches matches;
for (int i = 0; i < num_cases; ++i) {
AutocompleteInput input(keyword_cases[i].input, string16(), true,
- false, true, false);
+ false, true, AutocompleteInput::ALL_MATCHES);
kw_provider_->Start(input, false);
EXPECT_TRUE(kw_provider_->done());
matches = kw_provider_->matches();
diff --git a/chrome/browser/autocomplete/search_provider.cc b/chrome/browser/autocomplete/search_provider.cc
index 8263aa9..5cb873b 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"
@@ -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
@@ -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,22 @@ 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 that if the user has typed the whole term, we don't need to do
+ // anything special, since the "What you typed" history match will outrank
+ // us; bypassing this case also prevents the Classify() call below from
+ // recursing infinitely.
+ if (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 +683,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) {
diff --git a/chrome/browser/autocomplete/search_provider.h b/chrome/browser/autocomplete/search_provider.h
index 5ae50cc..982cf75 100644
--- a/chrome/browser/autocomplete/search_provider.h
+++ b/chrome/browser/autocomplete/search_provider.h
@@ -233,8 +233,10 @@ class SearchProvider : public AutocompleteProvider,
// algorithms for the different types of matches.
int CalculateRelevanceForWhatYouTyped() const;
// |time| is the time at which this query was last seen. |is_keyword| is true
- // if the search is from the keyword provider.
+ // if the search is from the keyword provider. |looks_like_url| is true if the
+ // search term would be treated as a URL if typed into the omnibox.
int CalculateRelevanceForHistory(const base::Time& time,
+ bool looks_like_url,
bool is_keyword) const;
// |result_number| is the index of the suggestion in the result set from the
// server; the best suggestion is suggestion number 0. |is_keyword| is true
diff --git a/chrome/browser/autocomplete/search_provider_unittest.cc b/chrome/browser/autocomplete/search_provider_unittest.cc
index a9a0996..4f9b104 100644
--- a/chrome/browser/autocomplete/search_provider_unittest.cc
+++ b/chrome/browser/autocomplete/search_provider_unittest.cc
@@ -178,7 +178,7 @@ void SearchProviderTest::QueryForInput(const string16& text,
bool minimal_changes) {
// Start a query.
AutocompleteInput input(text, string16(), prevent_inline_autocomplete,
- false, true, false);
+ false, true, AutocompleteInput::ALL_MATCHES);
provider_->Start(input, minimal_changes);
// RunAllPending so that the task scheduled by SearchProvider to create the
@@ -453,3 +453,42 @@ TEST_F(SearchProviderTest, DifferingText) {
AutocompleteMatch instant_match = FindMatchWithDestination(instant_url);
EXPECT_FALSE(instant_match.destination_url.is_empty());
}
+
+TEST_F(SearchProviderTest, DontAutocompleteURLLikeTerms) {
+ profile_.CreateAutocompleteClassifier();
+ string16 term(ASCIIToUTF16("docs.google.com"));
+ HistoryService* history =
+ profile_.GetHistoryService(Profile::EXPLICIT_ACCESS);
+ GURL url = GURL(default_t_url_->url()->ReplaceSearchTerms(
+ *default_t_url_, term, 0, string16()));
+ history->AddPageWithDetails(
+ url, string16(), 1, 1, base::Time::Now(), false, history::SOURCE_BROWSED);
+ history->SetKeywordSearchTermsForURL(url, default_t_url_->id(), term);
+
+ // Add the term as a url.
+ history->AddPageWithDetails(
+ GURL("http://docs.google.com"), string16(), 1, 1, base::Time::Now(),
+ false, history::SOURCE_BROWSED);
+
+ profile_.BlockUntilHistoryProcessesPendingRequests();
+
+ QueryForInput(ASCIIToUTF16("docs"), false, false);
+
+ // Wait until history and the suggest query complete.
+ profile_.BlockUntilHistoryProcessesPendingRequests();
+ ASSERT_NO_FATAL_FAILURE(FinishDefaultSuggestQuery());
+
+ // Provider should be done.
+ EXPECT_TRUE(provider_->done());
+
+ // There should be two matches, one for what you typed, the other for
+ // 'docs.google.com'. The search term should have a lower priority than the
+ // what you typed match.
+ ASSERT_EQ(2u, provider_->matches().size());
+ AutocompleteMatch term_match = FindMatchWithDestination(url);
+ GURL what_you_typed_url = GURL(default_t_url_->url()->ReplaceSearchTerms(
+ *default_t_url_, ASCIIToUTF16("docs"), 0, string16()));
+ AutocompleteMatch what_you_typed_match =
+ FindMatchWithDestination(what_you_typed_url);
+ EXPECT_GT(what_you_typed_match.relevance, term_match.relevance);
+}
diff --git a/chrome/browser/extensions/extension_omnibox_apitest.cc b/chrome/browser/extensions/extension_omnibox_apitest.cc
index ca9ce2c..16ae174 100644
--- a/chrome/browser/extensions/extension_omnibox_apitest.cc
+++ b/chrome/browser/extensions/extension_omnibox_apitest.cc
@@ -89,8 +89,9 @@ IN_PROC_BROWSER_TEST_F(OmniboxApiTest, MAYBE_Basic) {
// Test that our extension's keyword is suggested to us when we partially type
// it.
{
- autocomplete_controller->Start(ASCIIToUTF16("keywor"), string16(),
- true, false, true, false);
+ autocomplete_controller->Start(
+ ASCIIToUTF16("keywor"), string16(), true, false, true,
+ AutocompleteInput::ALL_MATCHES);
WaitForAutocompleteDone(autocomplete_controller);
EXPECT_TRUE(autocomplete_controller->done());
@@ -114,8 +115,9 @@ IN_PROC_BROWSER_TEST_F(OmniboxApiTest, MAYBE_Basic) {
// Test that our extension can send suggestions back to us.
{
- autocomplete_controller->Start(ASCIIToUTF16("keyword suggestio"),
- string16(), true, false, true, false);
+ autocomplete_controller->Start(
+ ASCIIToUTF16("keyword suggestio"), string16(), true, false, true,
+ AutocompleteInput::ALL_MATCHES);
WaitForAutocompleteDone(autocomplete_controller);
EXPECT_TRUE(autocomplete_controller->done());
@@ -178,8 +180,9 @@ IN_PROC_BROWSER_TEST_F(OmniboxApiTest, MAYBE_Basic) {
{
ResultCatcher catcher;
- autocomplete_controller->Start(ASCIIToUTF16("keyword command"), string16(),
- true, false, true, false);
+ autocomplete_controller->Start(
+ ASCIIToUTF16("keyword command"), string16(), true, false, true,
+ AutocompleteInput::ALL_MATCHES);
location_bar->AcceptInput();
EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
}
diff --git a/chrome/browser/ui/webui/options/browser_options_handler.cc b/chrome/browser/ui/webui/options/browser_options_handler.cc
index 13bd75d..0ea970c 100644
--- a/chrome/browser/ui/webui/options/browser_options_handler.cc
+++ b/chrome/browser/ui/webui/options/browser_options_handler.cc
@@ -413,8 +413,8 @@ void BrowserOptionsHandler::RequestAutocompleteSuggestions(
CHECK_EQ(args->GetSize(), 1U);
CHECK(args->GetString(0, &input));
- autocomplete_controller_->Start(input, string16(),
- true, false, false, false);
+ autocomplete_controller_->Start(input, string16(), true, false, false,
+ AutocompleteInput::ALL_MATCHES);
}
void BrowserOptionsHandler::OnResultChanged(bool default_match_changed) {