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..fedde5c444ae1f152d38d4e9308f1e36d01555d0 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" |
@@ -628,7 +629,6 @@ void TemplateURLService::SetDefaultSearchProvider(TemplateURL* url) { |
TemplateURL* TemplateURLService::GetDefaultSearchProvider() { |
if (loaded_ && !load_failed_) |
return default_search_provider_; |
- |
// We're not loaded, rely on the default search provider stored in prefs. |
return initial_default_search_provider_.get(); |
} |
@@ -1316,6 +1316,10 @@ TemplateURL* TemplateURLService::CreateTemplateURLFromTemplateURLAndSyncData( |
data.search_terms_replacement_key = specifics.search_terms_replacement_key(); |
TemplateURL* turl = new TemplateURL(profile, data); |
+ // If this TemplateURL matches a built-in prepopulated template URL, it's |
+ // possible that sync is trying to modify fields that should not be touched. |
+ // Revert these fields to the built-in values. |
+ UpdateTemplateURLIfPrepopulated(turl, profile); |
DCHECK(!turl->IsExtensionKeyword()); |
if (reset_keyword || deduped) { |
if (reset_keyword) |
@@ -1756,6 +1760,7 @@ bool TemplateURLService::UpdateNoNotify( |
TemplateURLID previous_id = existing_turl->id(); |
existing_turl->CopyFrom(new_values); |
existing_turl->data_.id = previous_id; |
+ |
UIThreadSearchTermsData new_search_terms_data(profile_); |
provider_map_->Add(existing_turl, new_search_terms_data); |
@@ -1805,6 +1810,28 @@ bool TemplateURLService::UpdateNoNotify( |
return true; |
} |
+// static |
+void TemplateURLService::UpdateTemplateURLIfPrepopulated( |
+ TemplateURL* template_url, |
+ Profile* profile) { |
+ 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 +2162,6 @@ bool TemplateURLService::SetDefaultSearchProviderNoNotify(TemplateURL* url) { |
bool TemplateURLService::AddNoNotify(TemplateURL* template_url, |
bool newly_adding) { |
DCHECK(template_url); |
- |
if (newly_adding) { |
DCHECK_EQ(kInvalidTemplateURLID, template_url->id()); |
DCHECK(std::find(template_urls_.begin(), template_urls_.end(), |