Index: chrome/browser/ui/app_list/search/mixer.cc |
diff --git a/chrome/browser/ui/app_list/search/mixer.cc b/chrome/browser/ui/app_list/search/mixer.cc |
index 6a737713492183c446f450610d0811731f52e34c..144079ea7aa970d250e15e8ca8c35b667706b3be 100644 |
--- a/chrome/browser/ui/app_list/search/mixer.cc |
+++ b/chrome/browser/ui/app_list/search/mixer.cc |
@@ -16,6 +16,8 @@ namespace app_list { |
namespace { |
+typedef std::vector<Mixer::SortData> SortedResults; |
+ |
// Maximum number of results to show. |
const size_t kMaxResults = 6; |
const size_t kMaxMainGroupResults = 4; |
@@ -25,27 +27,6 @@ const size_t kMaxPeopleResults = 2; |
// A value to indicate no max number of results limit. |
const size_t kNoMaxResultsLimit = 0; |
-// Used for sorting and mixing results. |
-struct SortData { |
- SortData() |
- : result(NULL), |
- score(0.0) { |
- } |
- SortData(ChromeSearchResult* result, double score) |
- : result(result), |
- score(score) { |
- } |
- |
- bool operator<(const SortData& other) const { |
- // This data precedes (less than) |other| if it has higher score. |
- return score > other.score; |
- } |
- |
- ChromeSearchResult* result; // Not owned. |
- double score; |
-}; |
-typedef std::vector<SortData> SortedResults; |
- |
// Removes duplicates from |results|. |
void RemoveDuplicates(SortedResults* results) { |
SortedResults final; |
@@ -66,33 +47,19 @@ void RemoveDuplicates(SortedResults* results) { |
results->swap(final); |
} |
-// Publishes the given |results| to |ui_results|. Reuse existing ones to avoid |
-// flickering. |
-void Publish(const SortedResults& results, |
- AppListModel::SearchResults* ui_results) { |
- for (size_t i = 0; i < results.size(); ++i) { |
- ChromeSearchResult* result = results[i].result; |
+} // namespace |
- ChromeSearchResult* ui_result = i < ui_results->item_count() ? |
- static_cast<ChromeSearchResult*>(ui_results->GetItemAt(i)) : NULL; |
- if (ui_result && ui_result->id() == result->id()) { |
- ui_result->set_title(result->title()); |
- ui_result->set_title_tags(result->title_tags()); |
- ui_result->set_details(result->details()); |
- ui_result->set_details_tags(result->details_tags()); |
- ui_results->NotifyItemsChanged(i, 1); |
- } else { |
- if (ui_result) |
- ui_results->DeleteAt(i); |
- ui_results->AddAt(i, result->Duplicate().release()); |
- } |
- } |
+Mixer::SortData::SortData() : result(NULL), score(0.0) { |
+} |
- while (ui_results->item_count() > results.size()) |
- ui_results->DeleteAt(ui_results->item_count() - 1); |
+Mixer::SortData::SortData(ChromeSearchResult* result, double score) |
+ : result(result), score(score) { |
} |
-} // namespace |
+bool Mixer::SortData::operator<(const SortData& other) const { |
+ // This data precedes (less than) |other| if it has higher score. |
+ return score > other.score; |
+} |
// Used to group relevant providers together fox mixing their results. |
class Mixer::Group { |
@@ -226,6 +193,32 @@ void Mixer::MixAndPublish(const KnownResults& known_results) { |
Publish(results, ui_results_); |
} |
+void Mixer::Publish(const std::vector<SortData>& results, |
+ AppListModel::SearchResults* ui_results) { |
+ for (size_t i = 0; i < results.size(); ++i) { |
+ ChromeSearchResult* result = results[i].result; |
+ |
+ ChromeSearchResult* ui_result = |
+ i < ui_results->item_count() |
+ ? static_cast<ChromeSearchResult*>(ui_results->GetItemAt(i)) |
+ : NULL; |
+ if (ui_result && ui_result->id() == result->id()) { |
+ ui_result->set_title(result->title()); |
+ ui_result->set_title_tags(result->title_tags()); |
+ ui_result->set_details(result->details()); |
+ ui_result->set_details_tags(result->details_tags()); |
+ ui_results->NotifyItemsChanged(i, 1); |
+ } else { |
+ if (ui_result) |
+ ui_results->DeleteAt(i); |
+ ui_results->AddAt(i, result->Duplicate().release()); |
+ } |
+ } |
+ |
+ while (ui_results->item_count() > results.size()) |
+ ui_results->DeleteAt(ui_results->item_count() - 1); |
+} |
+ |
void Mixer::FetchResults(const KnownResults& known_results) { |
for (Groups::iterator group_it = groups_.begin(); |
group_it != groups_.end(); |