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

Side by Side Diff: ui/app_list/search/mixer.cc

Issue 898273002: app_list::SearchResult: Duplicate() is const. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix. Created 5 years, 10 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 unified diff | Download patch
OLDNEW
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 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 for (size_t i = 0; i < ui_results->item_count(); ++i) { 199 for (size_t i = 0; i < ui_results->item_count(); ++i) {
200 SearchResult* ui_result = ui_results->GetItemAt(i); 200 SearchResult* ui_result = ui_results->GetItemAt(i);
201 ui_results_map[ui_result->id()] = ui_result; 201 ui_results_map[ui_result->id()] = ui_result;
202 } 202 }
203 // We have to erase all results at once so that observers are notified with 203 // We have to erase all results at once so that observers are notified with
204 // meaningful indexes. 204 // meaningful indexes.
205 ui_results->RemoveAll(); 205 ui_results->RemoveAll();
206 206
207 // Add items back to |ui_results| in the order of |new_results|. 207 // Add items back to |ui_results| in the order of |new_results|.
208 for (size_t i = 0; i < new_results.size(); ++i) { 208 for (size_t i = 0; i < new_results.size(); ++i) {
209 SearchResult* new_result = new_results[i].result; 209 const SearchResult& new_result = *new_results[i].result;
210 IdToResultMap::const_iterator ui_result_it = 210 IdToResultMap::const_iterator ui_result_it =
211 ui_results_map.find(new_result->id()); 211 ui_results_map.find(new_result.id());
212 if (ui_result_it != ui_results_map.end()) { 212 if (ui_result_it != ui_results_map.end()) {
213 // Update and use the old result if it exists. 213 // Update and use the old result if it exists.
214 SearchResult* ui_result = ui_result_it->second; 214 SearchResult* ui_result = ui_result_it->second;
215 UpdateResult(*new_result, ui_result); 215 UpdateResult(new_result, ui_result);
216 216
217 // |ui_results| takes back ownership from |ui_results_map| here. 217 // |ui_results| takes back ownership from |ui_results_map| here.
218 ui_results->Add(ui_result); 218 ui_results->Add(ui_result);
219 219
220 // Remove the item from the map so that it ends up only with unused 220 // Remove the item from the map so that it ends up only with unused
221 // results. 221 // results.
222 ui_results_map.erase(ui_result->id()); 222 ui_results_map.erase(ui_result->id());
223 } else { 223 } else {
224 // Copy the result from |new_results| otherwise. 224 // Copy the result from |new_results| otherwise.
225 ui_results->Add(new_result->Duplicate().release()); 225 ui_results->Add(new_result.Duplicate().release());
226 } 226 }
227 } 227 }
228 228
229 // Delete the results remaining in the map as they are not in the new results. 229 // Delete the results remaining in the map as they are not in the new results.
230 for (IdToResultMap::const_iterator ui_result_it = ui_results_map.begin(); 230 for (IdToResultMap::const_iterator ui_result_it = ui_results_map.begin();
231 ui_result_it != ui_results_map.end(); 231 ui_result_it != ui_results_map.end();
232 ++ui_result_it) { 232 ++ui_result_it) {
233 delete ui_result_it->second; 233 delete ui_result_it->second;
234 } 234 }
235 } 235 }
(...skipping 16 matching lines...) Expand all
252 results->swap(final); 252 results->swap(final);
253 } 253 }
254 254
255 void Mixer::FetchResults(bool is_voice_query, 255 void Mixer::FetchResults(bool is_voice_query,
256 const KnownResults& known_results) { 256 const KnownResults& known_results) {
257 for (const auto& item : groups_) 257 for (const auto& item : groups_)
258 item.second->FetchResults(is_voice_query, known_results); 258 item.second->FetchResults(is_voice_query, known_results);
259 } 259 }
260 260
261 } // namespace app_list 261 } // namespace app_list
OLDNEW
« no previous file with comments | « chrome/browser/ui/app_list/search/webstore/webstore_result.cc ('k') | ui/app_list/search/mixer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698