Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(181)

Unified Diff: chrome/browser/ui/app_list/search/mixer.cc

Issue 372843003: Add unit test for Mixer::Publish. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comment, fix an address comparison that was missed Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/app_list/search/mixer.h ('k') | chrome/browser/ui/app_list/search/mixer_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..7ea8fb460820121c7bd645c0a0e89583a5acd97f 100644
--- a/chrome/browser/ui/app_list/search/mixer.cc
+++ b/chrome/browser/ui/app_list/search/mixer.cc
@@ -25,74 +25,19 @@ 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;
- final.reserve(results->size());
-
- std::set<std::string> id_set;
- for (SortedResults::iterator it = results->begin();
- it != results->end();
- ++it) {
- const std::string& id = it->result->id();
- if (id_set.find(id) != id_set.end())
- continue;
-
- id_set.insert(id);
- final.push_back(*it);
- }
+} // namespace
- results->swap(final);
+Mixer::SortData::SortData() : result(NULL), score(0.0) {
}
-// 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;
-
- 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);
+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 +171,50 @@ void Mixer::MixAndPublish(const KnownResults& known_results) {
Publish(results, ui_results_);
}
+void Mixer::Publish(const SortedResults& 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::RemoveDuplicates(SortedResults* results) {
+ SortedResults final;
+ final.reserve(results->size());
+
+ std::set<std::string> id_set;
+ for (SortedResults::iterator it = results->begin(); it != results->end();
+ ++it) {
+ const std::string& id = it->result->id();
+ if (id_set.find(id) != id_set.end())
+ continue;
+
+ id_set.insert(id);
+ final.push_back(*it);
+ }
+
+ results->swap(final);
+}
+
void Mixer::FetchResults(const KnownResults& known_results) {
for (Groups::iterator group_it = groups_.begin();
group_it != groups_.end();
« no previous file with comments | « chrome/browser/ui/app_list/search/mixer.h ('k') | chrome/browser/ui/app_list/search/mixer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698