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> |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 | 204 |
205 // Add items back to |ui_results| in the order of |new_results|. | 205 // Add items back to |ui_results| in the order of |new_results|. |
206 for (const SortData& sort_data : new_results) { | 206 for (const SortData& sort_data : new_results) { |
207 const SearchResult& new_result = *sort_data.result; | 207 const SearchResult& new_result = *sort_data.result; |
208 IdToResultMap::const_iterator ui_result_it = | 208 IdToResultMap::const_iterator ui_result_it = |
209 ui_results_map.find(new_result.id()); | 209 ui_results_map.find(new_result.id()); |
210 if (ui_result_it != ui_results_map.end()) { | 210 if (ui_result_it != ui_results_map.end()) { |
211 // Update and use the old result if it exists. | 211 // Update and use the old result if it exists. |
212 SearchResult* ui_result = ui_result_it->second; | 212 SearchResult* ui_result = ui_result_it->second; |
213 UpdateResult(new_result, ui_result); | 213 UpdateResult(new_result, ui_result); |
| 214 ui_result->set_relevance(sort_data.score); |
214 | 215 |
215 // |ui_results| takes back ownership from |ui_results_map| here. | 216 // |ui_results| takes back ownership from |ui_results_map| here. |
216 ui_results->Add(ui_result); | 217 ui_results->Add(ui_result); |
217 | 218 |
218 // Remove the item from the map so that it ends up only with unused | 219 // Remove the item from the map so that it ends up only with unused |
219 // results. | 220 // results. |
220 ui_results_map.erase(ui_result->id()); | 221 ui_results_map.erase(ui_result->id()); |
221 } else { | 222 } else { |
| 223 scoped_ptr<SearchResult> result_copy = new_result.Duplicate(); |
| 224 result_copy->set_relevance(sort_data.score); |
222 // Copy the result from |new_results| otherwise. | 225 // Copy the result from |new_results| otherwise. |
223 ui_results->Add(new_result.Duplicate().release()); | 226 ui_results->Add(result_copy.release()); |
224 } | 227 } |
225 } | 228 } |
226 | 229 |
227 // Delete the results remaining in the map as they are not in the new results. | 230 // Delete the results remaining in the map as they are not in the new results. |
228 for (const auto& ui_result : ui_results_map) { | 231 for (const auto& ui_result : ui_results_map) { |
229 delete ui_result.second; | 232 delete ui_result.second; |
230 } | 233 } |
231 } | 234 } |
232 | 235 |
233 void Mixer::RemoveDuplicates(SortedResults* results) { | 236 void Mixer::RemoveDuplicates(SortedResults* results) { |
(...skipping 13 matching lines...) Expand all Loading... |
247 results->swap(final); | 250 results->swap(final); |
248 } | 251 } |
249 | 252 |
250 void Mixer::FetchResults(bool is_voice_query, | 253 void Mixer::FetchResults(bool is_voice_query, |
251 const KnownResults& known_results) { | 254 const KnownResults& known_results) { |
252 for (const auto& item : groups_) | 255 for (const auto& item : groups_) |
253 item.second->FetchResults(is_voice_query, known_results); | 256 item.second->FetchResults(is_voice_query, known_results); |
254 } | 257 } |
255 | 258 |
256 } // namespace app_list | 259 } // namespace app_list |
OLD | NEW |