diff options
author | sky@google.com <sky@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-10-08 15:22:34 +0000 |
---|---|---|
committer | sky@google.com <sky@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-10-08 15:22:34 +0000 |
commit | fda28420d4964c01a7396be1c88695557c1d51b3 (patch) | |
tree | 5d1f89fde4db34f463e640dfefc5fa6aef65d6cf /chrome/browser/template_url_model.cc | |
parent | 544545cd1e7c5697c7610a33dd2c94b2d7d1cfb0 (diff) | |
download | chromium_src-fda28420d4964c01a7396be1c88695557c1d51b3.zip chromium_src-fda28420d4964c01a7396be1c88695557c1d51b3.tar.gz chromium_src-fda28420d4964c01a7396be1c88695557c1d51b3.tar.bz2 |
Fixes crasher in TemplateURLModel that occurred when the db had
multiple keywords with the same prepopulate id. We had this for
Hungary.
BUG=3192
TEST=make sure you don't see any problems with keywords.
Review URL: http://codereview.chromium.org/6284
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@3008 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/template_url_model.cc')
-rw-r--r-- | chrome/browser/template_url_model.cc | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/chrome/browser/template_url_model.cc b/chrome/browser/template_url_model.cc index c93da96..ca0cedf 100644 --- a/chrome/browser/template_url_model.cc +++ b/chrome/browser/template_url_model.cc @@ -602,9 +602,18 @@ void TemplateURLModel::OnWebDataServiceRequestDone( // Compiler won't convert std::vector<TemplateURL*> to // std::vector<const TemplateURL*>. - SetTemplateURLs( + std::vector<const TemplateURL*> template_urls = *reinterpret_cast<std::vector<const TemplateURL*>* >( - &keyword_result.keywords)); + &keyword_result.keywords); + const int resource_keyword_version = + TemplateURLPrepopulateData::GetDataVersion(); + if (keyword_result.builtin_keyword_version != resource_keyword_version) { + // There should never be duplicate TemplateURLs. We had a bug such that + // duplicate TemplateURLs existed for one locale. As such we invoke + // RemoveDuplicatePrepopulateIDs to nuke the duplicates. + RemoveDuplicatePrepopulateIDs(&template_urls); + } + SetTemplateURLs(template_urls); if (keyword_result.default_search_provider_id) { // See if we can find the default search provider. @@ -617,8 +626,6 @@ void TemplateURLModel::OnWebDataServiceRequestDone( } } - const int resource_keyword_version = - TemplateURLPrepopulateData::GetDataVersion(); if (keyword_result.builtin_keyword_version != resource_keyword_version) { MergeEnginesFromPrepopulateData(); service_->SetBuiltinKeywordVersion(resource_keyword_version); @@ -649,6 +656,28 @@ void TemplateURLModel::OnWebDataServiceRequestDone( NotifyLoaded(); } +void TemplateURLModel::RemoveDuplicatePrepopulateIDs( + std::vector<const TemplateURL*>* urls) { + std::set<int> ids; + for (std::vector<const TemplateURL*>::iterator i = urls->begin(); + i != urls->end(); ) { + int prepopulate_id = (*i)->prepopulate_id(); + if (prepopulate_id) { + if (ids.find(prepopulate_id) != ids.end()) { + if (service_.get()) + service_->RemoveKeyword(**i); + delete *i; + i = urls->erase(i); + } else { + ids.insert(prepopulate_id); + ++i; + } + } else { + ++i; + } + } +} + void TemplateURLModel::Observe(NotificationType type, const NotificationSource& source, const NotificationDetails& details) { @@ -721,6 +750,7 @@ void TemplateURLModel::MergeEnginesFromPrepopulateData() { loaded_urls[i]->set_short_name(existing_url->short_name()); } Replace(existing_url, loaded_urls[i]); + id_to_turl[t_url->prepopulate_id()] = loaded_urls[i]; } else { Add(loaded_urls[i]); } |