Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/app_list/search/mixer.h" | 5 #include "ui/app_list/search/mixer.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "ui/app_list/search_provider.h" | 13 #include "ui/app_list/search_provider.h" |
| 14 #include "ui/app_list/search_result.h" | 14 #include "ui/app_list/search_result.h" |
| 15 | 15 |
| 16 namespace app_list { | 16 namespace app_list { |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 // Maximum number of results to show. | 20 // Maximum number of results to show. |
| 21 const size_t kMaxResults = 6; | 21 const size_t kMaxResults = 6; |
| 22 const size_t kMaxMainGroupResults = 4; | 22 const size_t kMaxMainGroupResults = 4; |
| 23 const size_t kMaxWebstoreResults = 2; | 23 const size_t kMaxWebstoreResults = 2; |
| 24 const size_t kMaxPeopleResults = 2; | 24 const size_t kMaxPeopleResults = 2; |
| 25 const size_t kMaxSuggestionsResults = 4; | |
|
Mathieu
2014/12/03 21:01:31
App launcher folks: I'm not sure any of this is ne
| |
| 25 | 26 |
| 26 // A value to indicate no max number of results limit. | 27 // A value to indicate no max number of results limit. |
| 27 const size_t kNoMaxResultsLimit = 0; | 28 const size_t kNoMaxResultsLimit = 0; |
| 28 | 29 |
| 29 void UpdateResult(const SearchResult& source, SearchResult* target) { | 30 void UpdateResult(const SearchResult& source, SearchResult* target) { |
| 30 target->set_title(source.title()); | 31 target->set_title(source.title()); |
| 31 target->set_title_tags(source.title_tags()); | 32 target->set_title_tags(source.title_tags()); |
| 32 target->set_details(source.details()); | 33 target->set_details(source.details()); |
| 33 target->set_details_tags(source.details_tags()); | 34 target->set_details_tags(source.details_tags()); |
| 34 } | 35 } |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 120 : ui_results_(ui_results) { | 121 : ui_results_(ui_results) { |
| 121 } | 122 } |
| 122 Mixer::~Mixer() { | 123 Mixer::~Mixer() { |
| 123 } | 124 } |
| 124 | 125 |
| 125 void Mixer::Init() { | 126 void Mixer::Init() { |
| 126 groups_[MAIN_GROUP].reset(new Group(kMaxMainGroupResults, 3.0)); | 127 groups_[MAIN_GROUP].reset(new Group(kMaxMainGroupResults, 3.0)); |
| 127 groups_[OMNIBOX_GROUP].reset(new Group(kNoMaxResultsLimit, 2.0)); | 128 groups_[OMNIBOX_GROUP].reset(new Group(kNoMaxResultsLimit, 2.0)); |
| 128 groups_[WEBSTORE_GROUP].reset(new Group(kMaxWebstoreResults, 1.0)); | 129 groups_[WEBSTORE_GROUP].reset(new Group(kMaxWebstoreResults, 1.0)); |
| 129 groups_[PEOPLE_GROUP].reset(new Group(kMaxPeopleResults, 0.0)); | 130 groups_[PEOPLE_GROUP].reset(new Group(kMaxPeopleResults, 0.0)); |
| 131 groups_[SUGGESTIONS_GROUP].reset(new Group(kMaxSuggestionsResults, 2.0)); | |
| 130 } | 132 } |
| 131 | 133 |
| 132 void Mixer::AddProviderToGroup(GroupId group, SearchProvider* provider) { | 134 void Mixer::AddProviderToGroup(GroupId group, SearchProvider* provider) { |
| 133 groups_[group]->AddProvider(provider); | 135 groups_[group]->AddProvider(provider); |
| 134 } | 136 } |
| 135 | 137 |
| 136 void Mixer::MixAndPublish(const KnownResults& known_results) { | 138 void Mixer::MixAndPublish(const KnownResults& known_results) { |
| 137 FetchResults(known_results); | 139 FetchResults(known_results); |
| 138 | 140 |
| 139 SortedResults results; | 141 SortedResults results; |
| 140 results.reserve(kMaxResults); | 142 results.reserve(kMaxResults); |
| 141 | 143 |
| 142 const Group& main_group = *groups_[MAIN_GROUP]; | 144 const Group& main_group = *groups_[MAIN_GROUP]; |
| 143 const Group& omnibox_group = *groups_[OMNIBOX_GROUP]; | 145 const Group& omnibox_group = *groups_[OMNIBOX_GROUP]; |
| 144 const Group& webstore_group = *groups_[WEBSTORE_GROUP]; | 146 const Group& webstore_group = *groups_[WEBSTORE_GROUP]; |
| 145 const Group& people_group = *groups_[PEOPLE_GROUP]; | 147 const Group& people_group = *groups_[PEOPLE_GROUP]; |
| 148 const Group& suggestions_group = *groups_[SUGGESTIONS_GROUP]; | |
| 146 | 149 |
| 147 // Adds main group and web store results first. | 150 // Adds main group and web store results first. |
| 148 results.insert(results.end(), main_group.results().begin(), | 151 results.insert(results.end(), main_group.results().begin(), |
| 149 main_group.results().end()); | 152 main_group.results().end()); |
| 150 results.insert(results.end(), webstore_group.results().begin(), | 153 results.insert(results.end(), webstore_group.results().begin(), |
| 151 webstore_group.results().end()); | 154 webstore_group.results().end()); |
| 152 results.insert(results.end(), people_group.results().begin(), | 155 results.insert(results.end(), people_group.results().begin(), |
| 153 people_group.results().end()); | 156 people_group.results().end()); |
| 157 results.insert(results.end(), suggestions_group.results().begin(), | |
| 158 suggestions_group.results().end()); | |
| 154 | 159 |
| 155 // Collapse duplicate apps from local and web store. | 160 // Collapse duplicate apps from local and web store. |
| 156 RemoveDuplicates(&results); | 161 RemoveDuplicates(&results); |
| 157 | 162 |
| 158 // Fill the remaining slots with omnibox results. Always add at least one | 163 // Fill the remaining slots with omnibox results. Always add at least one |
| 159 // omnibox result (even if there are no more slots; if we over-fill the | 164 // omnibox result (even if there are no more slots; if we over-fill the |
| 160 // vector, the web store and people results will be removed in a later step). | 165 // vector, the web store and people results will be removed in a later step). |
| 161 const size_t omnibox_results = | 166 const size_t omnibox_results = |
| 162 std::min(omnibox_group.results().size(), | 167 std::min(omnibox_group.results().size(), |
| 163 results.size() < kMaxResults ? kMaxResults - results.size() : 1); | 168 results.size() < kMaxResults ? kMaxResults - results.size() : 1); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 241 | 246 |
| 242 results->swap(final); | 247 results->swap(final); |
| 243 } | 248 } |
| 244 | 249 |
| 245 void Mixer::FetchResults(const KnownResults& known_results) { | 250 void Mixer::FetchResults(const KnownResults& known_results) { |
| 246 for (const auto& item : groups_) | 251 for (const auto& item : groups_) |
| 247 item.second->FetchResults(known_results); | 252 item.second->FetchResults(known_results); |
| 248 } | 253 } |
| 249 | 254 |
| 250 } // namespace app_list | 255 } // namespace app_list |
| OLD | NEW |