| 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..89ca6329c17e8891363c2b0c257e0b809577c18d 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,15 +1316,18 @@ 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)
|
| turl->ResetKeywordIfNecessary(true);
|
| syncer::SyncData sync_data = CreateSyncDataFromTemplateURL(*turl);
|
| - change_list->push_back(
|
| - syncer::SyncChange(FROM_HERE,
|
| - syncer::SyncChange::ACTION_UPDATE,
|
| - sync_data));
|
| + change_list->push_back(syncer::SyncChange(FROM_HERE,
|
| + syncer::SyncChange::ACTION_UPDATE,
|
| + sync_data));
|
| } else if (turl->IsGoogleSearchURLWithReplaceableKeyword()) {
|
| if (!existing_turl) {
|
| // We're adding a new TemplateURL that uses the Google base URL, so set
|
| @@ -1805,6 +1808,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;
|
| }
|
|
|