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

Unified Diff: chrome/browser/search_engines/template_url_service.cc

Issue 12084076: Ensure post-sync TemplateURL of prepopulated engines use built-in version. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Revised approach, see bug description Created 7 years, 11 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
Index: chrome/browser/search_engines/template_url_service.cc
diff --git a/chrome/browser/search_engines/template_url_service.cc b/chrome/browser/search_engines/template_url_service.cc
index bd754ec4a885599c28d50b5fdd76ac2e102f1a66..e98d56048c1bedfe492dd37686ea300f4269e7f4 100644
--- a/chrome/browser/search_engines/template_url_service.cc
+++ b/chrome/browser/search_engines/template_url_service.cc
@@ -10,6 +10,7 @@
#include "base/environment.h"
#include "base/guid.h"
#include "base/i18n/case_conversion.h"
+#include "base/memory/scoped_vector.h"
#include "base/metrics/histogram.h"
#include "base/stl_util.h"
#include "base/string_number_conversions.h"
@@ -1756,6 +1757,8 @@ bool TemplateURLService::UpdateNoNotify(
TemplateURLID previous_id = existing_turl->id();
existing_turl->CopyFrom(new_values);
existing_turl->data_.id = previous_id;
+ UpdateTemplateURLIfPrepopulated(existing_turl);
+
UIThreadSearchTermsData new_search_terms_data(profile_);
provider_map_->Add(existing_turl, new_search_terms_data);
@@ -1805,6 +1808,26 @@ bool TemplateURLService::UpdateNoNotify(
return true;
}
+void TemplateURLService::UpdateTemplateURLIfPrepopulated(
+ TemplateURL* template_url) {
+ int prepopulate_id = template_url->prepopulate_id();
+ if (template_url->prepopulate_id() == 0)
+ return;
+
+ ScopedVector<TemplateURL> prepopulated_urls;
+ size_t default_search_index;
+ TemplateURLPrepopulateData::GetPrepopulatedEngines(profile_,
+ &prepopulated_urls.get(), &default_search_index);
+
+ for (size_t i = 0; i < prepopulated_urls.size(); ++i) {
+ if (prepopulated_urls[i]->prepopulate_id() == prepopulate_id) {
+ MergeIntoPrepopulatedEngineData(&prepopulated_urls[i]->data_,
+ template_url);
+ template_url->CopyFrom(*prepopulated_urls[i]);
+ }
+ }
+}
+
PrefService* TemplateURLService::GetPrefs() {
return profile_ ? profile_->GetPrefs() : NULL;
}
@@ -2135,7 +2158,7 @@ bool TemplateURLService::SetDefaultSearchProviderNoNotify(TemplateURL* url) {
bool TemplateURLService::AddNoNotify(TemplateURL* template_url,
bool newly_adding) {
DCHECK(template_url);
-
+ UpdateTemplateURLIfPrepopulated(template_url);
if (newly_adding) {
DCHECK_EQ(kInvalidTemplateURLID, template_url->id());
DCHECK(std::find(template_urls_.begin(), template_urls_.end(),

Powered by Google App Engine
This is Rietveld 408576698