Commit ccc03dcd authored by jiangj@opera.com's avatar jiangj@opera.com

Pass AutocompleteProvider::kMaxMatches to InMemoryURLIndex

The only client of InMemoryURLIndex::HistoryItemsForTerms is
//chrome/browser/autocomplete/history_quick_provider.cc which has access
to the constant. So pass the constant to the history component instead
of having the dependency.

BUG=374730
TBR=thakis  // For OWNERS at chrome/browser/autocomplete/history_quick_provider.cc

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@273072 0039d316-1c4b-4281-b951-d872f2087c98
parent 373f4acf
...@@ -103,7 +103,8 @@ void HistoryQuickProvider::DoAutocomplete() { ...@@ -103,7 +103,8 @@ void HistoryQuickProvider::DoAutocomplete() {
// Get the matching URLs from the DB. // Get the matching URLs from the DB.
ScoredHistoryMatches matches = GetIndex()->HistoryItemsForTerms( ScoredHistoryMatches matches = GetIndex()->HistoryItemsForTerms(
autocomplete_input_.text(), autocomplete_input_.text(),
autocomplete_input_.cursor_position()); autocomplete_input_.cursor_position(),
AutocompleteProvider::kMaxMatches);
if (matches.empty()) if (matches.empty())
return; return;
......
...@@ -16,7 +16,6 @@ include_rules = [ ...@@ -16,7 +16,6 @@ include_rules = [
# Do not add to the list of temporarily-allowed dependencies below, # Do not add to the list of temporarily-allowed dependencies below,
# and please do not introduce more #includes of these files. # and please do not introduce more #includes of these files.
"!chrome/browser/autocomplete/autocomplete_match.h", "!chrome/browser/autocomplete/autocomplete_match.h",
"!chrome/browser/autocomplete/autocomplete_provider.h",
"!chrome/browser/autocomplete/autocomplete_result.h", "!chrome/browser/autocomplete/autocomplete_result.h",
"!chrome/browser/autocomplete/history_provider_util.h", "!chrome/browser/autocomplete/history_provider_util.h",
"!chrome/browser/autocomplete/history_url_provider.h", "!chrome/browser/autocomplete/history_url_provider.h",
......
...@@ -160,10 +160,12 @@ bool InMemoryURLIndex::GetCacheFilePath(base::FilePath* file_path) { ...@@ -160,10 +160,12 @@ bool InMemoryURLIndex::GetCacheFilePath(base::FilePath* file_path) {
ScoredHistoryMatches InMemoryURLIndex::HistoryItemsForTerms( ScoredHistoryMatches InMemoryURLIndex::HistoryItemsForTerms(
const base::string16& term_string, const base::string16& term_string,
size_t cursor_position) { size_t cursor_position,
size_t max_matches) {
return private_data_->HistoryItemsForTerms( return private_data_->HistoryItemsForTerms(
term_string, term_string,
cursor_position, cursor_position,
max_matches,
languages_, languages_,
BookmarkModelFactory::GetForProfile(profile_)); BookmarkModelFactory::GetForProfile(profile_));
} }
......
...@@ -117,9 +117,11 @@ class InMemoryURLIndex : public content::NotificationObserver, ...@@ -117,9 +117,11 @@ class InMemoryURLIndex : public content::NotificationObserver,
// URLIndexPrivateData class. For a complete description of this function // URLIndexPrivateData class. For a complete description of this function
// refer to that class. If |cursor_position| is base::string16::npos, the // refer to that class. If |cursor_position| is base::string16::npos, the
// function doesn't do anything special with the cursor; this is equivalent // function doesn't do anything special with the cursor; this is equivalent
// to the cursor being at the end. // to the cursor being at the end. In total, |max_matches| of items will be
// returned in the |ScoredHistoryMatches| vector.
ScoredHistoryMatches HistoryItemsForTerms(const base::string16& term_string, ScoredHistoryMatches HistoryItemsForTerms(const base::string16& term_string,
size_t cursor_position); size_t cursor_position,
size_t max_matches);
// Deletes the index entry, if any, for the given |url|. // Deletes the index entry, if any, for the given |url|.
void DeleteURL(const GURL& url); void DeleteURL(const GURL& url);
......
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "chrome/browser/autocomplete/autocomplete_provider.h"
#include "chrome/browser/bookmarks/bookmark_model_factory.h" #include "chrome/browser/bookmarks/bookmark_model_factory.h"
#include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/history/history_backend.h" #include "chrome/browser/history/history_backend.h"
...@@ -38,6 +37,10 @@ ...@@ -38,6 +37,10 @@
using base::ASCIIToUTF16; using base::ASCIIToUTF16;
using content::BrowserThread; using content::BrowserThread;
namespace {
const size_t kMaxMatches = 3;
} // namespace
// The test version of the history url database table ('url') is contained in // The test version of the history url database table ('url') is contained in
// a database file created from a text file('url_history_provider_test.db.txt'). // a database file created from a text file('url_history_provider_test.db.txt').
// The only difference between this table and a live 'urls' table from a // The only difference between this table and a live 'urls' table from a
...@@ -447,7 +450,7 @@ TEST_F(LimitedInMemoryURLIndexTest, Initialization) { ...@@ -447,7 +450,7 @@ TEST_F(LimitedInMemoryURLIndexTest, Initialization) {
TEST_F(InMemoryURLIndexTest, Retrieval) { TEST_F(InMemoryURLIndexTest, Retrieval) {
// See if a very specific term gives a single result. // See if a very specific term gives a single result.
ScoredHistoryMatches matches = url_index_->HistoryItemsForTerms( ScoredHistoryMatches matches = url_index_->HistoryItemsForTerms(
ASCIIToUTF16("DrudgeReport"), base::string16::npos); ASCIIToUTF16("DrudgeReport"), base::string16::npos, kMaxMatches);
ASSERT_EQ(1U, matches.size()); ASSERT_EQ(1U, matches.size());
// Verify that we got back the result we expected. // Verify that we got back the result we expected.
...@@ -458,8 +461,8 @@ TEST_F(InMemoryURLIndexTest, Retrieval) { ...@@ -458,8 +461,8 @@ TEST_F(InMemoryURLIndexTest, Retrieval) {
// Make sure a trailing space prevents inline-ability but still results // Make sure a trailing space prevents inline-ability but still results
// in the expected result. // in the expected result.
matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("DrudgeReport "), matches = url_index_->HistoryItemsForTerms(
base::string16::npos); ASCIIToUTF16("DrudgeReport "), base::string16::npos, kMaxMatches);
ASSERT_EQ(1U, matches.size()); ASSERT_EQ(1U, matches.size());
EXPECT_EQ(5, matches[0].url_info.id()); EXPECT_EQ(5, matches[0].url_info.id());
EXPECT_EQ("http://drudgereport.com/", matches[0].url_info.url().spec()); EXPECT_EQ("http://drudgereport.com/", matches[0].url_info.url().spec());
...@@ -467,15 +470,15 @@ TEST_F(InMemoryURLIndexTest, Retrieval) { ...@@ -467,15 +470,15 @@ TEST_F(InMemoryURLIndexTest, Retrieval) {
EXPECT_FALSE(matches[0].can_inline()); EXPECT_FALSE(matches[0].can_inline());
// Search which should result in multiple results. // Search which should result in multiple results.
matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("drudge"), matches = url_index_->HistoryItemsForTerms(
base::string16::npos); ASCIIToUTF16("drudge"), base::string16::npos, kMaxMatches);
ASSERT_EQ(2U, matches.size()); ASSERT_EQ(2U, matches.size());
// The results should be in descending score order. // The results should be in descending score order.
EXPECT_GE(matches[0].raw_score(), matches[1].raw_score()); EXPECT_GE(matches[0].raw_score(), matches[1].raw_score());
// Search which should result in nearly perfect result. // Search which should result in nearly perfect result.
matches = url_index_->HistoryItemsForTerms( matches = url_index_->HistoryItemsForTerms(
ASCIIToUTF16("Nearly Perfect Result"), base::string16::npos); ASCIIToUTF16("Nearly Perfect Result"), base::string16::npos, kMaxMatches);
ASSERT_EQ(1U, matches.size()); ASSERT_EQ(1U, matches.size());
// The results should have a very high score. // The results should have a very high score.
EXPECT_GT(matches[0].raw_score(), 900); EXPECT_GT(matches[0].raw_score(), 900);
...@@ -487,8 +490,8 @@ TEST_F(InMemoryURLIndexTest, Retrieval) { ...@@ -487,8 +490,8 @@ TEST_F(InMemoryURLIndexTest, Retrieval) {
EXPECT_FALSE(matches[0].can_inline()); EXPECT_FALSE(matches[0].can_inline());
// Search which should result in very poor result. // Search which should result in very poor result.
matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("qui c"), matches = url_index_->HistoryItemsForTerms(
base::string16::npos); ASCIIToUTF16("qui c"), base::string16::npos, kMaxMatches);
ASSERT_EQ(1U, matches.size()); ASSERT_EQ(1U, matches.size());
// The results should have a poor score. // The results should have a poor score.
EXPECT_LT(matches[0].raw_score(), 500); EXPECT_LT(matches[0].raw_score(), 500);
...@@ -500,15 +503,15 @@ TEST_F(InMemoryURLIndexTest, Retrieval) { ...@@ -500,15 +503,15 @@ TEST_F(InMemoryURLIndexTest, Retrieval) {
EXPECT_FALSE(matches[0].can_inline()); EXPECT_FALSE(matches[0].can_inline());
// Search which will match at the end of an URL with encoded characters. // Search which will match at the end of an URL with encoded characters.
matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("Mice"), matches = url_index_->HistoryItemsForTerms(
base::string16::npos); ASCIIToUTF16("Mice"), base::string16::npos, kMaxMatches);
ASSERT_EQ(1U, matches.size()); ASSERT_EQ(1U, matches.size());
EXPECT_EQ(30, matches[0].url_info.id()); EXPECT_EQ(30, matches[0].url_info.id());
EXPECT_FALSE(matches[0].can_inline()); EXPECT_FALSE(matches[0].can_inline());
// Check that URLs are not escaped an escape time. // Check that URLs are not escaped an escape time.
matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("1% wikipedia"), matches = url_index_->HistoryItemsForTerms(
base::string16::npos); ASCIIToUTF16("1% wikipedia"), base::string16::npos, kMaxMatches);
ASSERT_EQ(1U, matches.size()); ASSERT_EQ(1U, matches.size());
EXPECT_EQ(35, matches[0].url_info.id()); EXPECT_EQ(35, matches[0].url_info.id());
EXPECT_EQ("http://en.wikipedia.org/wiki/1%25_rule_(Internet_culture)", EXPECT_EQ("http://en.wikipedia.org/wiki/1%25_rule_(Internet_culture)",
...@@ -516,8 +519,8 @@ TEST_F(InMemoryURLIndexTest, Retrieval) { ...@@ -516,8 +519,8 @@ TEST_F(InMemoryURLIndexTest, Retrieval) {
// Verify that a single term can appear multiple times in the URL and as long // Verify that a single term can appear multiple times in the URL and as long
// as one starts the URL it is still inlined. // as one starts the URL it is still inlined.
matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("fubar"), matches = url_index_->HistoryItemsForTerms(
base::string16::npos); ASCIIToUTF16("fubar"), base::string16::npos, kMaxMatches);
ASSERT_EQ(1U, matches.size()); ASSERT_EQ(1U, matches.size());
EXPECT_EQ(34, matches[0].url_info.id()); EXPECT_EQ(34, matches[0].url_info.id());
EXPECT_EQ("http://fubarfubarandfubar.com/", matches[0].url_info.url().spec()); EXPECT_EQ("http://fubarfubarandfubar.com/", matches[0].url_info.url().spec());
...@@ -529,16 +532,18 @@ TEST_F(InMemoryURLIndexTest, Retrieval) { ...@@ -529,16 +532,18 @@ TEST_F(InMemoryURLIndexTest, Retrieval) {
TEST_F(InMemoryURLIndexTest, CursorPositionRetrieval) { TEST_F(InMemoryURLIndexTest, CursorPositionRetrieval) {
// See if a very specific term with no cursor gives an empty result. // See if a very specific term with no cursor gives an empty result.
ScoredHistoryMatches matches = url_index_->HistoryItemsForTerms( ScoredHistoryMatches matches = url_index_->HistoryItemsForTerms(
ASCIIToUTF16("DrudReport"), base::string16::npos); ASCIIToUTF16("DrudReport"), base::string16::npos, kMaxMatches);
ASSERT_EQ(0U, matches.size()); ASSERT_EQ(0U, matches.size());
// The same test with the cursor at the end should give an empty result. // The same test with the cursor at the end should give an empty result.
matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("DrudReport"), 10u); matches = url_index_->HistoryItemsForTerms(
ASCIIToUTF16("DrudReport"), 10u, kMaxMatches);
ASSERT_EQ(0U, matches.size()); ASSERT_EQ(0U, matches.size());
// If the cursor is between Drud and Report, we should find the desired // If the cursor is between Drud and Report, we should find the desired
// result. // result.
matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("DrudReport"), 4u); matches = url_index_->HistoryItemsForTerms(
ASCIIToUTF16("DrudReport"), 4u, kMaxMatches);
ASSERT_EQ(1U, matches.size()); ASSERT_EQ(1U, matches.size());
EXPECT_EQ("http://drudgereport.com/", matches[0].url_info.url().spec()); EXPECT_EQ("http://drudgereport.com/", matches[0].url_info.url().spec());
EXPECT_EQ(ASCIIToUTF16("DRUDGE REPORT 2010"), matches[0].url_info.title()); EXPECT_EQ(ASCIIToUTF16("DRUDGE REPORT 2010"), matches[0].url_info.title());
...@@ -546,18 +551,18 @@ TEST_F(InMemoryURLIndexTest, CursorPositionRetrieval) { ...@@ -546,18 +551,18 @@ TEST_F(InMemoryURLIndexTest, CursorPositionRetrieval) {
// Now check multi-word inputs. No cursor should fail to find a // Now check multi-word inputs. No cursor should fail to find a
// result on this input. // result on this input.
matches = url_index_->HistoryItemsForTerms( matches = url_index_->HistoryItemsForTerms(
ASCIIToUTF16("MORTGAGERATE DROPS"), base::string16::npos); ASCIIToUTF16("MORTGAGERATE DROPS"), base::string16::npos, kMaxMatches);
ASSERT_EQ(0U, matches.size()); ASSERT_EQ(0U, matches.size());
// Ditto with cursor at end. // Ditto with cursor at end.
matches = url_index_->HistoryItemsForTerms( matches = url_index_->HistoryItemsForTerms(
ASCIIToUTF16("MORTGAGERATE DROPS"), 18u); ASCIIToUTF16("MORTGAGERATE DROPS"), 18u, kMaxMatches);
ASSERT_EQ(0U, matches.size()); ASSERT_EQ(0U, matches.size());
// If the cursor is between MORTAGE And RATE, we should find the // If the cursor is between MORTAGE And RATE, we should find the
// desired result. // desired result.
matches = url_index_->HistoryItemsForTerms( matches = url_index_->HistoryItemsForTerms(
ASCIIToUTF16("MORTGAGERATE DROPS"), 8u); ASCIIToUTF16("MORTGAGERATE DROPS"), 8u, kMaxMatches);
ASSERT_EQ(1U, matches.size()); ASSERT_EQ(1U, matches.size());
EXPECT_EQ("http://www.reuters.com/article/idUSN0839880620100708", EXPECT_EQ("http://www.reuters.com/article/idUSN0839880620100708",
matches[0].url_info.url().spec()); matches[0].url_info.url().spec());
...@@ -569,69 +574,67 @@ TEST_F(InMemoryURLIndexTest, CursorPositionRetrieval) { ...@@ -569,69 +574,67 @@ TEST_F(InMemoryURLIndexTest, CursorPositionRetrieval) {
TEST_F(InMemoryURLIndexTest, URLPrefixMatching) { TEST_F(InMemoryURLIndexTest, URLPrefixMatching) {
// "drudgere" - found, can inline // "drudgere" - found, can inline
ScoredHistoryMatches matches = url_index_->HistoryItemsForTerms( ScoredHistoryMatches matches = url_index_->HistoryItemsForTerms(
ASCIIToUTF16("drudgere"), base::string16::npos); ASCIIToUTF16("drudgere"), base::string16::npos, kMaxMatches);
ASSERT_EQ(1U, matches.size()); ASSERT_EQ(1U, matches.size());
EXPECT_TRUE(matches[0].can_inline()); EXPECT_TRUE(matches[0].can_inline());
// "drudgere" - found, can inline // "drudgere" - found, can inline
matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("drudgere"), matches = url_index_->HistoryItemsForTerms(
base::string16::npos); ASCIIToUTF16("drudgere"), base::string16::npos, kMaxMatches);
ASSERT_EQ(1U, matches.size()); ASSERT_EQ(1U, matches.size());
EXPECT_TRUE(matches[0].can_inline()); EXPECT_TRUE(matches[0].can_inline());
// "www.atdmt" - not found // "www.atdmt" - not found
matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("www.atdmt"), matches = url_index_->HistoryItemsForTerms(
base::string16::npos); ASCIIToUTF16("www.atdmt"), base::string16::npos, kMaxMatches);
EXPECT_EQ(0U, matches.size()); EXPECT_EQ(0U, matches.size());
// "atdmt" - found, cannot inline // "atdmt" - found, cannot inline
matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("atdmt"), matches = url_index_->HistoryItemsForTerms(
base::string16::npos); ASCIIToUTF16("atdmt"), base::string16::npos, kMaxMatches);
ASSERT_EQ(1U, matches.size()); ASSERT_EQ(1U, matches.size());
EXPECT_FALSE(matches[0].can_inline()); EXPECT_FALSE(matches[0].can_inline());
// "view.atdmt" - found, can inline // "view.atdmt" - found, can inline
matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("view.atdmt"), matches = url_index_->HistoryItemsForTerms(
base::string16::npos); ASCIIToUTF16("view.atdmt"), base::string16::npos, kMaxMatches);
ASSERT_EQ(1U, matches.size()); ASSERT_EQ(1U, matches.size());
EXPECT_TRUE(matches[0].can_inline()); EXPECT_TRUE(matches[0].can_inline());
// "view.atdmt" - found, can inline // "view.atdmt" - found, can inline
matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("view.atdmt"), matches = url_index_->HistoryItemsForTerms(
base::string16::npos); ASCIIToUTF16("view.atdmt"), base::string16::npos, kMaxMatches);
ASSERT_EQ(1U, matches.size()); ASSERT_EQ(1U, matches.size());
EXPECT_TRUE(matches[0].can_inline()); EXPECT_TRUE(matches[0].can_inline());
// "cnn.com" - found, can inline // "cnn.com" - found, can inline
matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("cnn.com"), matches = url_index_->HistoryItemsForTerms(
base::string16::npos); ASCIIToUTF16("cnn.com"), base::string16::npos, kMaxMatches);
ASSERT_EQ(2U, matches.size()); ASSERT_EQ(2U, matches.size());
// One match should be inline-able, the other not. // One match should be inline-able, the other not.
EXPECT_TRUE(matches[0].can_inline() != matches[1].can_inline()); EXPECT_TRUE(matches[0].can_inline() != matches[1].can_inline());
// "www.cnn.com" - found, can inline // "www.cnn.com" - found, can inline
matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("www.cnn.com"), matches = url_index_->HistoryItemsForTerms(
base::string16::npos); ASCIIToUTF16("www.cnn.com"), base::string16::npos, kMaxMatches);
ASSERT_EQ(1U, matches.size()); ASSERT_EQ(1U, matches.size());
EXPECT_TRUE(matches[0].can_inline()); EXPECT_TRUE(matches[0].can_inline());
// "ww.cnn.com" - found because we allow mid-term matches in hostnames // "ww.cnn.com" - found because we allow mid-term matches in hostnames
matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("ww.cnn.com"), matches = url_index_->HistoryItemsForTerms(
base::string16::npos); ASCIIToUTF16("ww.cnn.com"), base::string16::npos, kMaxMatches);
ASSERT_EQ(1U, matches.size()); ASSERT_EQ(1U, matches.size());
// "www.cnn.com" - found, can inline // "www.cnn.com" - found, can inline
matches = matches = url_index_->HistoryItemsForTerms(
url_index_->HistoryItemsForTerms(ASCIIToUTF16("www.cnn.com"), ASCIIToUTF16("www.cnn.com"), base::string16::npos, kMaxMatches);
base::string16::npos);
ASSERT_EQ(1U, matches.size()); ASSERT_EQ(1U, matches.size());
EXPECT_TRUE(matches[0].can_inline()); EXPECT_TRUE(matches[0].can_inline());
// "tp://www.cnn.com" - not found because we don't allow tp as a mid-term // "tp://www.cnn.com" - not found because we don't allow tp as a mid-term
// match // match
matches = matches = url_index_->HistoryItemsForTerms(
url_index_->HistoryItemsForTerms(ASCIIToUTF16("tp://www.cnn.com"), ASCIIToUTF16("tp://www.cnn.com"), base::string16::npos, kMaxMatches);
base::string16::npos);
ASSERT_EQ(0U, matches.size()); ASSERT_EQ(0U, matches.size());
} }
...@@ -641,13 +644,13 @@ TEST_F(InMemoryURLIndexTest, ProperStringMatching) { ...@@ -641,13 +644,13 @@ TEST_F(InMemoryURLIndexTest, ProperStringMatching) {
// "atdmt.view" - not found // "atdmt.view" - not found
// "view.atdmt" - found // "view.atdmt" - found
ScoredHistoryMatches matches = url_index_->HistoryItemsForTerms( ScoredHistoryMatches matches = url_index_->HistoryItemsForTerms(
ASCIIToUTF16("atdmt view"), base::string16::npos); ASCIIToUTF16("atdmt view"), base::string16::npos, kMaxMatches);
ASSERT_EQ(1U, matches.size()); ASSERT_EQ(1U, matches.size());
matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("atdmt.view"), matches = url_index_->HistoryItemsForTerms(
base::string16::npos); ASCIIToUTF16("atdmt.view"), base::string16::npos, kMaxMatches);
ASSERT_EQ(0U, matches.size()); ASSERT_EQ(0U, matches.size());
matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("view.atdmt"), matches = url_index_->HistoryItemsForTerms(
base::string16::npos); ASCIIToUTF16("view.atdmt"), base::string16::npos, kMaxMatches);
ASSERT_EQ(1U, matches.size()); ASSERT_EQ(1U, matches.size());
} }
...@@ -659,15 +662,14 @@ TEST_F(InMemoryURLIndexTest, HugeResultSet) { ...@@ -659,15 +662,14 @@ TEST_F(InMemoryURLIndexTest, HugeResultSet) {
EXPECT_TRUE(UpdateURL(new_row)); EXPECT_TRUE(UpdateURL(new_row));
} }
ScoredHistoryMatches matches = ScoredHistoryMatches matches = url_index_->HistoryItemsForTerms(
url_index_->HistoryItemsForTerms(ASCIIToUTF16("b"), base::string16::npos); ASCIIToUTF16("b"), base::string16::npos, kMaxMatches);
URLIndexPrivateData& private_data(*GetPrivateData()); URLIndexPrivateData& private_data(*GetPrivateData());
ASSERT_EQ(AutocompleteProvider::kMaxMatches, matches.size()); ASSERT_EQ(kMaxMatches, matches.size());
// There are 7 matches already in the database. // There are 7 matches already in the database.
ASSERT_EQ(1008U, private_data.pre_filter_item_count_); ASSERT_EQ(1008U, private_data.pre_filter_item_count_);
ASSERT_EQ(500U, private_data.post_filter_item_count_); ASSERT_EQ(500U, private_data.post_filter_item_count_);
ASSERT_EQ(AutocompleteProvider::kMaxMatches, ASSERT_EQ(kMaxMatches, private_data.post_scoring_item_count_);
private_data.post_scoring_item_count_);
} }
TEST_F(InMemoryURLIndexTest, TitleSearch) { TEST_F(InMemoryURLIndexTest, TitleSearch) {
...@@ -676,7 +678,7 @@ TEST_F(InMemoryURLIndexTest, TitleSearch) { ...@@ -676,7 +678,7 @@ TEST_F(InMemoryURLIndexTest, TitleSearch) {
// Ensure title is being searched. // Ensure title is being searched.
ScoredHistoryMatches matches = url_index_->HistoryItemsForTerms( ScoredHistoryMatches matches = url_index_->HistoryItemsForTerms(
ASCIIToUTF16("MORTGAGE RATE DROPS"), base::string16::npos); ASCIIToUTF16("MORTGAGE RATE DROPS"), base::string16::npos, kMaxMatches);
ASSERT_EQ(1U, matches.size()); ASSERT_EQ(1U, matches.size());
// Verify that we got back the result we expected. // Verify that we got back the result we expected.
...@@ -692,8 +694,8 @@ TEST_F(InMemoryURLIndexTest, TitleChange) { ...@@ -692,8 +694,8 @@ TEST_F(InMemoryURLIndexTest, TitleChange) {
// Verify current title terms retrieves desired item. // Verify current title terms retrieves desired item.
base::string16 original_terms = base::string16 original_terms =
ASCIIToUTF16("lebronomics could high taxes influence"); ASCIIToUTF16("lebronomics could high taxes influence");
ScoredHistoryMatches matches = ScoredHistoryMatches matches = url_index_->HistoryItemsForTerms(
url_index_->HistoryItemsForTerms(original_terms, base::string16::npos); original_terms, base::string16::npos, kMaxMatches);
ASSERT_EQ(1U, matches.size()); ASSERT_EQ(1U, matches.size());
// Verify that we got back the result we expected. // Verify that we got back the result we expected.
...@@ -708,7 +710,8 @@ TEST_F(InMemoryURLIndexTest, TitleChange) { ...@@ -708,7 +710,8 @@ TEST_F(InMemoryURLIndexTest, TitleChange) {
// Verify new title terms retrieves nothing. // Verify new title terms retrieves nothing.
base::string16 new_terms = ASCIIToUTF16("does eat oats little lambs ivy"); base::string16 new_terms = ASCIIToUTF16("does eat oats little lambs ivy");
matches = url_index_->HistoryItemsForTerms(new_terms, base::string16::npos); matches = url_index_->HistoryItemsForTerms(
new_terms, base::string16::npos, kMaxMatches);
ASSERT_EQ(0U, matches.size()); ASSERT_EQ(0U, matches.size());
// Update the row. // Update the row.
...@@ -716,42 +719,42 @@ TEST_F(InMemoryURLIndexTest, TitleChange) { ...@@ -716,42 +719,42 @@ TEST_F(InMemoryURLIndexTest, TitleChange) {
EXPECT_TRUE(UpdateURL(old_row)); EXPECT_TRUE(UpdateURL(old_row));
// Verify we get the row using the new terms but not the original terms. // Verify we get the row using the new terms but not the original terms.
matches = url_index_->HistoryItemsForTerms(new_terms, base::string16::npos); matches = url_index_->HistoryItemsForTerms(
new_terms, base::string16::npos, kMaxMatches);
ASSERT_EQ(1U, matches.size()); ASSERT_EQ(1U, matches.size());
EXPECT_EQ(expected_id, matches[0].url_info.id()); EXPECT_EQ(expected_id, matches[0].url_info.id());
matches = matches = url_index_->HistoryItemsForTerms(
url_index_->HistoryItemsForTerms(original_terms, base::string16::npos); original_terms, base::string16::npos, kMaxMatches);
ASSERT_EQ(0U, matches.size()); ASSERT_EQ(0U, matches.size());
} }
TEST_F(InMemoryURLIndexTest, NonUniqueTermCharacterSets) { TEST_F(InMemoryURLIndexTest, NonUniqueTermCharacterSets) {
// The presence of duplicate characters should succeed. Exercise by cycling // The presence of duplicate characters should succeed. Exercise by cycling
// through a string with several duplicate characters. // through a string with several duplicate characters.
ScoredHistoryMatches matches = ScoredHistoryMatches matches = url_index_->HistoryItemsForTerms(
url_index_->HistoryItemsForTerms(ASCIIToUTF16("ABRA"), ASCIIToUTF16("ABRA"), base::string16::npos, kMaxMatches);
base::string16::npos);
ASSERT_EQ(1U, matches.size()); ASSERT_EQ(1U, matches.size());
EXPECT_EQ(28, matches[0].url_info.id()); EXPECT_EQ(28, matches[0].url_info.id());
EXPECT_EQ("http://www.ddj.com/windows/184416623", EXPECT_EQ("http://www.ddj.com/windows/184416623",
matches[0].url_info.url().spec()); matches[0].url_info.url().spec());
matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("ABRACAD"), matches = url_index_->HistoryItemsForTerms(
base::string16::npos); ASCIIToUTF16("ABRACAD"), base::string16::npos, kMaxMatches);
ASSERT_EQ(1U, matches.size()); ASSERT_EQ(1U, matches.size());
EXPECT_EQ(28, matches[0].url_info.id()); EXPECT_EQ(28, matches[0].url_info.id());
matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("ABRACADABRA"), matches = url_index_->HistoryItemsForTerms(
base::string16::npos); ASCIIToUTF16("ABRACADABRA"), base::string16::npos, kMaxMatches);
ASSERT_EQ(1U, matches.size()); ASSERT_EQ(1U, matches.size());
EXPECT_EQ(28, matches[0].url_info.id()); EXPECT_EQ(28, matches[0].url_info.id());
matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("ABRACADABR"), matches = url_index_->HistoryItemsForTerms(
base::string16::npos); ASCIIToUTF16("ABRACADABR"), base::string16::npos, kMaxMatches);
ASSERT_EQ(1U, matches.size()); ASSERT_EQ(1U, matches.size());
EXPECT_EQ(28, matches[0].url_info.id()); EXPECT_EQ(28, matches[0].url_info.id());
matches = url_index_->HistoryItemsForTerms(ASCIIToUTF16("ABRACA"), matches = url_index_->HistoryItemsForTerms(
base::string16::npos); ASCIIToUTF16("ABRACA"), base::string16::npos, kMaxMatches);
ASSERT_EQ(1U, matches.size()); ASSERT_EQ(1U, matches.size());
EXPECT_EQ(28, matches[0].url_info.id()); EXPECT_EQ(28, matches[0].url_info.id());
} }
...@@ -772,21 +775,23 @@ TEST_F(InMemoryURLIndexTest, TypedCharacterCaching) { ...@@ -772,21 +775,23 @@ TEST_F(InMemoryURLIndexTest, TypedCharacterCaching) {
// Simulate typing "r" giving "r" in the simulated omnibox. The results for // Simulate typing "r" giving "r" in the simulated omnibox. The results for
// 'r' will be not cached because it is only 1 character long. // 'r' will be not cached because it is only 1 character long.
url_index_->HistoryItemsForTerms(ASCIIToUTF16("r"), base::string16::npos); url_index_->HistoryItemsForTerms(
ASCIIToUTF16("r"), base::string16::npos, kMaxMatches);
EXPECT_EQ(0U, cache.size()); EXPECT_EQ(0U, cache.size());
// Simulate typing "re" giving "r re" in the simulated omnibox. // Simulate typing "re" giving "r re" in the simulated omnibox.
// 're' should be cached at this point but not 'r' as it is a single // 're' should be cached at this point but not 'r' as it is a single
// character. // character.
url_index_->HistoryItemsForTerms(ASCIIToUTF16("r re"), base::string16::npos); url_index_->HistoryItemsForTerms(
ASCIIToUTF16("r re"), base::string16::npos, kMaxMatches);
ASSERT_EQ(1U, cache.size()); ASSERT_EQ(1U, cache.size());
CheckTerm(cache, ASCIIToUTF16("re")); CheckTerm(cache, ASCIIToUTF16("re"));
// Simulate typing "reco" giving "r re reco" in the simulated omnibox. // Simulate typing "reco" giving "r re reco" in the simulated omnibox.
// 're' and 'reco' should be cached at this point but not 'r' as it is a // 're' and 'reco' should be cached at this point but not 'r' as it is a
// single character. // single character.
url_index_->HistoryItemsForTerms(ASCIIToUTF16("r re reco"), url_index_->HistoryItemsForTerms(
base::string16::npos); ASCIIToUTF16("r re reco"), base::string16::npos, kMaxMatches);
ASSERT_EQ(2U, cache.size()); ASSERT_EQ(2U, cache.size());
CheckTerm(cache, ASCIIToUTF16("re")); CheckTerm(cache, ASCIIToUTF16("re"));
CheckTerm(cache, ASCIIToUTF16("reco")); CheckTerm(cache, ASCIIToUTF16("reco"));
...@@ -794,20 +799,21 @@ TEST_F(InMemoryURLIndexTest, TypedCharacterCaching) { ...@@ -794,20 +799,21 @@ TEST_F(InMemoryURLIndexTest, TypedCharacterCaching) {
// Simulate typing "mort". // Simulate typing "mort".
// Since we now have only one search term, the cached results for 're' and // Since we now have only one search term, the cached results for 're' and
// 'reco' should be purged, giving us only 1 item in the cache (for 'mort'). // 'reco' should be purged, giving us only 1 item in the cache (for 'mort').
url_index_->HistoryItemsForTerms(ASCIIToUTF16("mort"), base::string16::npos); url_index_->HistoryItemsForTerms(
ASCIIToUTF16("mort"), base::string16::npos, kMaxMatches);
ASSERT_EQ(1U, cache.size()); ASSERT_EQ(1U, cache.size());
CheckTerm(cache, ASCIIToUTF16("mort")); CheckTerm(cache, ASCIIToUTF16("mort"));
// Simulate typing "reco" giving "mort reco" in the simulated omnibox. // Simulate typing "reco" giving "mort reco" in the simulated omnibox.
url_index_->HistoryItemsForTerms(ASCIIToUTF16("mort reco"), url_index_->HistoryItemsForTerms(
base::string16::npos); ASCIIToUTF16("mort reco"), base::string16::npos, kMaxMatches);
ASSERT_EQ(2U, cache.size()); ASSERT_EQ(2U, cache.size());
CheckTerm(cache, ASCIIToUTF16("mort")); CheckTerm(cache, ASCIIToUTF16("mort"));
CheckTerm(cache, ASCIIToUTF16("reco")); CheckTerm(cache, ASCIIToUTF16("reco"));
// Simulate a <DELETE> by removing the 'reco' and adding back the 'rec'. // Simulate a <DELETE> by removing the 'reco' and adding back the 'rec'.
url_index_->HistoryItemsForTerms(ASCIIToUTF16("mort rec"), url_index_->HistoryItemsForTerms(
base::string16::npos); ASCIIToUTF16("mort rec"), base::string16::npos, kMaxMatches);
ASSERT_EQ(2U, cache.size()); ASSERT_EQ(2U, cache.size());
CheckTerm(cache, ASCIIToUTF16("mort")); CheckTerm(cache, ASCIIToUTF16("mort"));
CheckTerm(cache, ASCIIToUTF16("rec")); CheckTerm(cache, ASCIIToUTF16("rec"));
...@@ -819,7 +825,8 @@ TEST_F(InMemoryURLIndexTest, AddNewRows) { ...@@ -819,7 +825,8 @@ TEST_F(InMemoryURLIndexTest, AddNewRows) {
// Newly created URLRows get a last_visit time of 'right now' so it should // Newly created URLRows get a last_visit time of 'right now' so it should
// qualify as a quick result candidate. // qualify as a quick result candidate.
EXPECT_TRUE(url_index_->HistoryItemsForTerms( EXPECT_TRUE(url_index_->HistoryItemsForTerms(
ASCIIToUTF16("brokeandalone"), base::string16::npos).empty()); ASCIIToUTF16("brokeandalone"), base::string16::npos, kMaxMatches)
.empty());
// Add a new row. // Add a new row.
URLRow new_row(GURL("http://www.brokeandaloneinmanitoba.com/"), new_row_id++); URLRow new_row(GURL("http://www.brokeandaloneinmanitoba.com/"), new_row_id++);
...@@ -828,13 +835,13 @@ TEST_F(InMemoryURLIndexTest, AddNewRows) { ...@@ -828,13 +835,13 @@ TEST_F(InMemoryURLIndexTest, AddNewRows) {
// Verify that we can retrieve it. // Verify that we can retrieve it.
EXPECT_EQ(1U, url_index_->HistoryItemsForTerms( EXPECT_EQ(1U, url_index_->HistoryItemsForTerms(
ASCIIToUTF16("brokeandalone"), base::string16::npos).size()); ASCIIToUTF16("brokeandalone"), base::string16::npos, kMaxMatches).size());
// Add it again just to be sure that is harmless and that it does not update // Add it again just to be sure that is harmless and that it does not update
// the index. // the index.
EXPECT_FALSE(UpdateURL(new_row)); EXPECT_FALSE(UpdateURL(new_row));
EXPECT_EQ(1U, url_index_->HistoryItemsForTerms( EXPECT_EQ(1U, url_index_->HistoryItemsForTerms(
ASCIIToUTF16("brokeandalone"), base::string16::npos).size()); ASCIIToUTF16("brokeandalone"), base::string16::npos, kMaxMatches).size());
// Make up an URL that does not qualify and try to add it. // Make up an URL that does not qualify and try to add it.
URLRow unqualified_row(GURL("http://www.brokeandaloneinmanitoba.com/"), URLRow unqualified_row(GURL("http://www.brokeandaloneinmanitoba.com/"),
...@@ -844,13 +851,13 @@ TEST_F(InMemoryURLIndexTest, AddNewRows) { ...@@ -844,13 +851,13 @@ TEST_F(InMemoryURLIndexTest, AddNewRows) {
TEST_F(InMemoryURLIndexTest, DeleteRows) { TEST_F(InMemoryURLIndexTest, DeleteRows) {
ScoredHistoryMatches matches = url_index_->HistoryItemsForTerms( ScoredHistoryMatches matches = url_index_->HistoryItemsForTerms(
ASCIIToUTF16("DrudgeReport"), base::string16::npos); ASCIIToUTF16("DrudgeReport"), base::string16::npos, kMaxMatches);
ASSERT_EQ(1U, matches.size()); ASSERT_EQ(1U, matches.size());
// Delete the URL then search again. // Delete the URL then search again.
EXPECT_TRUE(DeleteURL(matches[0].url_info.url())); EXPECT_TRUE(DeleteURL(matches[0].url_info.url()));
EXPECT_TRUE(url_index_->HistoryItemsForTerms( EXPECT_TRUE(url_index_->HistoryItemsForTerms(
ASCIIToUTF16("DrudgeReport"), base::string16::npos).empty()); ASCIIToUTF16("DrudgeReport"), base::string16::npos, kMaxMatches).empty());
// Make up an URL that does not exist in the database and delete it. // Make up an URL that does not exist in the database and delete it.
GURL url("http://www.hokeypokey.com/putyourrightfootin.html"); GURL url("http://www.hokeypokey.com/putyourrightfootin.html");
...@@ -859,7 +866,7 @@ TEST_F(InMemoryURLIndexTest, DeleteRows) { ...@@ -859,7 +866,7 @@ TEST_F(InMemoryURLIndexTest, DeleteRows) {
TEST_F(InMemoryURLIndexTest, ExpireRow) { TEST_F(InMemoryURLIndexTest, ExpireRow) {
ScoredHistoryMatches matches = url_index_->HistoryItemsForTerms( ScoredHistoryMatches matches = url_index_->HistoryItemsForTerms(
ASCIIToUTF16("DrudgeReport"), base::string16::npos); ASCIIToUTF16("DrudgeReport"), base::string16::npos, kMaxMatches);
ASSERT_EQ(1U, matches.size()); ASSERT_EQ(1U, matches.size());
// Determine the row id for the result, remember that id, broadcast a // Determine the row id for the result, remember that id, broadcast a
...@@ -871,7 +878,7 @@ TEST_F(InMemoryURLIndexTest, ExpireRow) { ...@@ -871,7 +878,7 @@ TEST_F(InMemoryURLIndexTest, ExpireRow) {
content::Source<InMemoryURLIndexTest>(this), content::Source<InMemoryURLIndexTest>(this),
content::Details<history::HistoryDetails>(&deleted_details)); content::Details<history::HistoryDetails>(&deleted_details));
EXPECT_TRUE(url_index_->HistoryItemsForTerms( EXPECT_TRUE(url_index_->HistoryItemsForTerms(
ASCIIToUTF16("DrudgeReport"), base::string16::npos).empty()); ASCIIToUTF16("DrudgeReport"), base::string16::npos, kMaxMatches).empty());
} }
TEST_F(InMemoryURLIndexTest, WhitelistedURLs) { TEST_F(InMemoryURLIndexTest, WhitelistedURLs) {
......
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "chrome/browser/autocomplete/autocomplete_provider.h"
#include "chrome/browser/history/history_database.h" #include "chrome/browser/history/history_database.h"
#include "chrome/browser/history/history_db_task.h" #include "chrome/browser/history/history_db_task.h"
#include "chrome/browser/history/history_service.h" #include "chrome/browser/history/history_service.h"
...@@ -150,6 +149,7 @@ URLIndexPrivateData::URLIndexPrivateData() ...@@ -150,6 +149,7 @@ URLIndexPrivateData::URLIndexPrivateData()
ScoredHistoryMatches URLIndexPrivateData::HistoryItemsForTerms( ScoredHistoryMatches URLIndexPrivateData::HistoryItemsForTerms(
base::string16 search_string, base::string16 search_string,
size_t cursor_position, size_t cursor_position,
size_t max_matches,
const std::string& languages, const std::string& languages,
BookmarkService* bookmark_service) { BookmarkService* bookmark_service) {
// If cursor position is set and useful (not at either end of the // If cursor position is set and useful (not at either end of the
...@@ -246,14 +246,14 @@ ScoredHistoryMatches URLIndexPrivateData::HistoryItemsForTerms( ...@@ -246,14 +246,14 @@ ScoredHistoryMatches URLIndexPrivateData::HistoryItemsForTerms(
AddHistoryMatch(*this, languages, bookmark_service, lower_raw_string, AddHistoryMatch(*this, languages, bookmark_service, lower_raw_string,
lower_raw_terms, base::Time::Now())).ScoredMatches(); lower_raw_terms, base::Time::Now())).ScoredMatches();
// Select and sort only the top kMaxMatches results. // Select and sort only the top |max_matches| results.
if (scored_items.size() > AutocompleteProvider::kMaxMatches) { if (scored_items.size() > max_matches) {
std::partial_sort(scored_items.begin(), std::partial_sort(scored_items.begin(),
scored_items.begin() + scored_items.begin() +
AutocompleteProvider::kMaxMatches, max_matches,
scored_items.end(), scored_items.end(),
ScoredHistoryMatch::MatchScoreGreater); ScoredHistoryMatch::MatchScoreGreater);
scored_items.resize(AutocompleteProvider::kMaxMatches); scored_items.resize(max_matches);
} else { } else {
std::sort(scored_items.begin(), scored_items.end(), std::sort(scored_items.begin(), scored_items.end(),
ScoredHistoryMatch::MatchScoreGreater); ScoredHistoryMatch::MatchScoreGreater);
......
...@@ -65,9 +65,12 @@ class URLIndexPrivateData ...@@ -65,9 +65,12 @@ class URLIndexPrivateData
// |kItemsToScoreLimit| limit) will be retained and used for subsequent calls // |kItemsToScoreLimit| limit) will be retained and used for subsequent calls
// to this function. |bookmark_service| is used to boost a result's score if // to this function. |bookmark_service| is used to boost a result's score if
// its URL is referenced by one or more of the user's bookmarks. |languages| // its URL is referenced by one or more of the user's bookmarks. |languages|
// is used to help parse/format the URLs in the history index. // is used to help parse/format the URLs in the history index. In total,
// |max_matches| of items will be returned in the |ScoredHistoryMatches|
// vector.
ScoredHistoryMatches HistoryItemsForTerms(base::string16 term_string, ScoredHistoryMatches HistoryItemsForTerms(base::string16 term_string,
size_t cursor_position, size_t cursor_position,
size_t max_matches,
const std::string& languages, const std::string& languages,
BookmarkService* bookmark_service); BookmarkService* bookmark_service);
......
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