summaryrefslogtreecommitdiffstats
path: root/chrome/browser/autocomplete
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/autocomplete')
-rw-r--r--chrome/browser/autocomplete/history_contents_provider.cc33
-rw-r--r--chrome/browser/autocomplete/keyword_provider.cc2
-rw-r--r--chrome/browser/autocomplete/search_provider.cc4
3 files changed, 21 insertions, 18 deletions
diff --git a/chrome/browser/autocomplete/history_contents_provider.cc b/chrome/browser/autocomplete/history_contents_provider.cc
index 9c50bd3..1d3ed28 100644
--- a/chrome/browser/autocomplete/history_contents_provider.cc
+++ b/chrome/browser/autocomplete/history_contents_provider.cc
@@ -22,6 +22,11 @@ const int kDaysToSearch = 30;
// a single result. It allows the results to be sorted and processed without
// modifying the larger and slower results structure.
struct MatchReference {
+ MatchReference(const history::URLResult* result, int relevance)
+ : result(result),
+ relevance(relevance) {
+ }
+
const history::URLResult* result;
int relevance; // Score of relevance computed by CalculateRelevance.
};
@@ -144,9 +149,7 @@ void HistoryContentsProvider::ConvertResults() {
std::vector<MatchReference> result_refs;
result_refs.reserve(results_.size());
for (size_t i = 0; i < results_.size(); i++) {
- MatchReference ref;
- ref.result = &results_[i];
- ref.relevance = CalculateRelevance(*ref.result);
+ MatchReference ref(&results_[i], CalculateRelevance(results_[i]));
result_refs.push_back(ref);
}
@@ -180,6 +183,10 @@ void HistoryContentsProvider::ConvertResults() {
matches_[i].relevance = -matches_[i].relevance;
}
+static bool MatchInTitle(const history::URLResult& result) {
+ return !result.title_match_positions().empty();
+}
+
AutocompleteMatch HistoryContentsProvider::ResultToMatch(
const history::URLResult& result,
int score) {
@@ -227,8 +234,8 @@ void HistoryContentsProvider::ClassifyDescription(
int HistoryContentsProvider::CalculateRelevance(
const history::URLResult& result) {
- bool in_title = !!result.title_match_positions().size();
- bool is_starred =
+ const bool in_title = MatchInTitle(result);
+ const bool is_starred =
(profile_->GetBookmarkModel() &&
profile_->GetBookmarkModel()->IsBookmarked(result.url()));
@@ -236,22 +243,18 @@ int HistoryContentsProvider::CalculateRelevance(
case AutocompleteInput::UNKNOWN:
case AutocompleteInput::REQUESTED_URL:
if (is_starred) {
- return in_title ? 1000 + star_title_count_++ :
- 550 + star_contents_count_++;
- } else {
- return in_title ? 700 + title_count_++ :
- 500 + contents_count_++;
+ return in_title ?
+ (1000 + star_title_count_++) : (550 + star_contents_count_++);
}
+ return in_title ? (700 + title_count_++) : (500 + contents_count_++);
case AutocompleteInput::QUERY:
case AutocompleteInput::FORCED_QUERY:
if (is_starred) {
- return in_title ? 1200 + star_title_count_++ :
- 750 + star_contents_count_++;
- } else {
- return in_title ? 900 + title_count_++ :
- 700 + contents_count_++;
+ return in_title ?
+ (1200 + star_title_count_++) : (750 + star_contents_count_++);
}
+ return in_title ? (900 + title_count_++) : (700 + contents_count_++);
default:
NOTREACHED();
diff --git a/chrome/browser/autocomplete/keyword_provider.cc b/chrome/browser/autocomplete/keyword_provider.cc
index 4674d85..7c9f55b 100644
--- a/chrome/browser/autocomplete/keyword_provider.cc
+++ b/chrome/browser/autocomplete/keyword_provider.cc
@@ -227,7 +227,7 @@ int KeywordProvider::CalculateRelevance(AutocompleteInput::Type type,
}
AutocompleteMatch KeywordProvider::CreateAutocompleteMatch(
- TemplateURLModel *model,
+ TemplateURLModel* model,
const std::wstring keyword,
const AutocompleteInput& input,
size_t prefix_length,
diff --git a/chrome/browser/autocomplete/search_provider.cc b/chrome/browser/autocomplete/search_provider.cc
index b7b260e..96fd52f 100644
--- a/chrome/browser/autocomplete/search_provider.cc
+++ b/chrome/browser/autocomplete/search_provider.cc
@@ -360,11 +360,11 @@ void SearchProvider::ConvertResultsToAutocompleteMatches() {
for (MatchMap::const_iterator i(map.begin()); i != map.end(); ++i)
matches_.push_back(i->second);
- if (navigation_results_.size()) {
+ if (!navigation_results_.empty()) {
// TODO(kochi): http://b/1170574 We add only one results for navigational
// suggestions. If we can get more useful information about the score,
// consider adding more results.
- matches_.push_back(NavigationToMatch(navigation_results_[0],
+ matches_.push_back(NavigationToMatch(navigation_results_.front(),
CalculateRelevanceForNavigation(0)));
}