summaryrefslogtreecommitdiffstats
path: root/chrome/browser/autocomplete/history_contents_provider.cc
diff options
context:
space:
mode:
authorpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-12 17:38:33 +0000
committerpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-12 17:38:33 +0000
commitffaf78a76172755b47a12c408656818d05232b85 (patch)
tree40a385fee1c04574e34ae66e89a817761982d527 /chrome/browser/autocomplete/history_contents_provider.cc
parentc1602a9988ef421b9773dc03da40c6bf184d22a1 (diff)
downloadchromium_src-ffaf78a76172755b47a12c408656818d05232b85.zip
chromium_src-ffaf78a76172755b47a12c408656818d05232b85.tar.gz
chromium_src-ffaf78a76172755b47a12c408656818d05232b85.tar.bz2
Omnibox metrics logging patch splitout, part 1: Random miscellaneous small style and similar changes. In one or two cases the motivation is not obvious without looking at the original patch.
Review URL: http://codereview.chromium.org/10822 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@5261 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/autocomplete/history_contents_provider.cc')
-rw-r--r--chrome/browser/autocomplete/history_contents_provider.cc33
1 files changed, 18 insertions, 15 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();