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);
......
...@@ -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