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

Unified Diff: ios/chrome/browser/search_engines/search_engines_util.cc

Issue 2307663002: Remove ScopedVector from search_engines. (Closed)
Patch Set: devlin Created 4 years, 3 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 | « components/search_engines/util.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/chrome/browser/search_engines/search_engines_util.cc
diff --git a/ios/chrome/browser/search_engines/search_engines_util.cc b/ios/chrome/browser/search_engines/search_engines_util.cc
index afd94e08553005eccf9f5fb042e2d90789c2a787..5ec1c0e75d2379122d01b5965c666f13a5e9fd69 100644
--- a/ios/chrome/browser/search_engines/search_engines_util.cc
+++ b/ios/chrome/browser/search_engines/search_engines_util.cc
@@ -28,7 +28,7 @@ void UpdateSearchEngine(TemplateURLService* service) {
DCHECK(service->loaded());
std::vector<TemplateURL*> old_engines = service->GetTemplateURLs();
size_t default_engine;
- ScopedVector<TemplateURLData> new_engines =
+ std::vector<std::unique_ptr<TemplateURLData>> new_engines =
TemplateURLPrepopulateData::GetPrepopulatedEngines(nullptr,
&default_engine);
DCHECK(default_engine == 0);
@@ -39,8 +39,8 @@ void UpdateSearchEngine(TemplateURLService* service) {
// It is not possible to add all the new ones first, because the service gets
// confused when a prepopulated engine is there more than once.
// Instead, this will in a first pass makes google as the default engine. In
- // a second pass, it will remove all other search engine. At last, in a third
- // pass, it will add all new engine but google.
+ // a second pass, it will remove all other search engines. At last, in a third
+ // pass, it will add all new engines but google.
for (auto* engine : old_engines) {
if (engine->prepopulate_id() == kGoogleEnginePrepopulatedId)
service->SetUserSelectedDefaultSearchProvider(engine);
@@ -49,15 +49,9 @@ void UpdateSearchEngine(TemplateURLService* service) {
if (engine->prepopulate_id() != kGoogleEnginePrepopulatedId)
service->Remove(engine);
}
- ScopedVector<TemplateURLData>::iterator it = new_engines.begin();
- while (it != new_engines.end()) {
- if ((*it)->prepopulate_id != kGoogleEnginePrepopulatedId) {
- // service->Add takes ownership on Added TemplateURL.
- service->Add(base::MakeUnique<TemplateURL>(**it));
- it = new_engines.weak_erase(it);
droger 2016/09/02 08:34:26 If I understand correctly this was a memory leak.
Avi (use Gerrit) 2016/09/02 14:39:38 Yes, this was a memory leak; we were constructing
- } else {
- ++it;
- }
+ for (const auto& engine : new_engines) {
+ if (engine->prepopulate_id != kGoogleEnginePrepopulatedId)
+ service->Add(base::MakeUnique<TemplateURL>(*engine));
}
}
« no previous file with comments | « components/search_engines/util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698