| Index: components/search_engines/template_url_service.cc
|
| diff --git a/components/search_engines/template_url_service.cc b/components/search_engines/template_url_service.cc
|
| index 20bd85539217e5d566d5f39030b567e9cf01fa3b..0c97e1f926c8401a4da167e42f2365bf96754ab4 100644
|
| --- a/components/search_engines/template_url_service.cc
|
| +++ b/components/search_engines/template_url_service.cc
|
| @@ -664,7 +664,7 @@ TemplateURLService::TemplateURLVector TemplateURLService::GetTemplateURLs() {
|
| void TemplateURLService::IncrementUsageCount(TemplateURL* url) {
|
| DCHECK(url);
|
| // Extension-controlled search engines are not persisted.
|
| - if (url->GetType() == TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION)
|
| + if (url->GetType() != TemplateURL::NORMAL)
|
| return;
|
| if (std::find(template_urls_.begin(), template_urls_.end(), url) ==
|
| template_urls_.end())
|
| @@ -870,19 +870,6 @@ void TemplateURLService::OnWebDataServiceRequestDone(
|
| &pre_sync_deletes_);
|
| }
|
|
|
| - if (client_) {
|
| - // TODO(vadimt): Remove ScopedTracker below once crbug.com/422460 is fixed.
|
| - tracked_objects::ScopedTracker tracking_profile3(
|
| - FROM_HERE_WITH_EXPLICIT_FUNCTION(
|
| - "422460 TemplateURLService::OnWebDataServiceRequestDone 3"));
|
| -
|
| - // Restore extension info of loaded TemplateURLs.
|
| - for (size_t i = 0; i < template_urls.size(); ++i) {
|
| - DCHECK(!template_urls[i]->extension_info_);
|
| - client_->RestoreExtensionInfoIfNecessary(template_urls[i]);
|
| - }
|
| - }
|
| -
|
| KeywordWebDataService::BatchModeScoper scoper(web_data_service_.get());
|
|
|
| {
|
| @@ -999,7 +986,7 @@ syncer::SyncDataList TemplateURLService::GetAllSyncData(
|
| if ((*iter)->created_by_policy())
|
| continue;
|
| // We don't sync extension-controlled search engines.
|
| - if ((*iter)->GetType() == TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION)
|
| + if ((*iter)->GetType() != TemplateURL::NORMAL)
|
| continue;
|
| current_data.push_back(CreateSyncDataFromTemplateURL(**iter));
|
| }
|
| @@ -1032,15 +1019,15 @@ syncer::SyncError TemplateURLService::ProcessSyncChanges(
|
| syncer::SyncChangeList new_changes;
|
| syncer::SyncError error;
|
| for (syncer::SyncChangeList::const_iterator iter = change_list.begin();
|
| - iter != change_list.end(); ++iter) {
|
| + iter != change_list.end(); ++iter) {
|
| DCHECK_EQ(syncer::SEARCH_ENGINES, iter->sync_data().GetDataType());
|
|
|
| std::string guid =
|
| iter->sync_data().GetSpecifics().search_engine().sync_guid();
|
| TemplateURL* existing_turl = GetTemplateURLForGUID(guid);
|
| scoped_ptr<TemplateURL> turl(CreateTemplateURLFromTemplateURLAndSyncData(
|
| - prefs_, search_terms_data(), existing_turl, iter->sync_data(),
|
| - &new_changes));
|
| + client_.get(), prefs_, search_terms_data(), existing_turl,
|
| + iter->sync_data(), &new_changes));
|
| if (!turl.get())
|
| continue;
|
|
|
| @@ -1194,8 +1181,8 @@ syncer::SyncMergeResult TemplateURLService::MergeDataAndStartSyncing(
|
| TemplateURL* local_turl = GetTemplateURLForGUID(iter->first);
|
| scoped_ptr<TemplateURL> sync_turl(
|
| CreateTemplateURLFromTemplateURLAndSyncData(
|
| - prefs_, search_terms_data(), local_turl, iter->second,
|
| - &new_changes));
|
| + client_.get(), prefs_, search_terms_data(), local_turl,
|
| + iter->second, &new_changes));
|
| if (!sync_turl.get())
|
| continue;
|
|
|
| @@ -1359,7 +1346,9 @@ syncer::SyncData TemplateURLService::CreateSyncDataFromTemplateURL(
|
| }
|
|
|
| // static
|
| -TemplateURL* TemplateURLService::CreateTemplateURLFromTemplateURLAndSyncData(
|
| +scoped_ptr<TemplateURL>
|
| +TemplateURLService::CreateTemplateURLFromTemplateURLAndSyncData(
|
| + TemplateURLServiceClient* client,
|
| PrefService* prefs,
|
| const SearchTermsData& search_terms_data,
|
| TemplateURL* existing_turl,
|
| @@ -1424,12 +1413,24 @@ TemplateURL* TemplateURLService::CreateTemplateURLFromTemplateURLAndSyncData(
|
| data.alternate_urls.push_back(specifics.alternate_urls(i));
|
| data.search_terms_replacement_key = specifics.search_terms_replacement_key();
|
|
|
| - TemplateURL* turl = new TemplateURL(data);
|
| + scoped_ptr<TemplateURL> turl(new TemplateURL(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, prefs);
|
| - DCHECK_NE(TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION, turl->GetType());
|
| + UpdateTemplateURLIfPrepopulated(turl.get(), prefs);
|
| +
|
| + // We used to sync keywords associated with omnibox extensions, but no longer
|
| + // want to. However, if we delete these keywords from sync, we'll break any
|
| + // synced old versions of Chrome which were relying on them. Instead, for now
|
| + // we simply ignore these.
|
| + // TODO(vasilii): After a few Chrome versions, change this to go ahead and
|
| + // delete these from sync.
|
| + DCHECK(client);
|
| + client->RestoreExtensionInfoIfNecessary(turl.get());
|
| + if (turl->GetType() == TemplateURL::OMNIBOX_API_EXTENSION)
|
| + return NULL;
|
| +
|
| + DCHECK_EQ(TemplateURL::NORMAL, turl->GetType());
|
| if (reset_keyword || deduped) {
|
| if (reset_keyword)
|
| turl->ResetKeywordIfNecessary(search_terms_data, true);
|
| @@ -1453,7 +1454,7 @@ TemplateURL* TemplateURLService::CreateTemplateURLFromTemplateURLAndSyncData(
|
| }
|
| }
|
|
|
| - return turl;
|
| + return turl.Pass();
|
| }
|
|
|
| // static
|
| @@ -1554,6 +1555,9 @@ void TemplateURLService::RemoveFromMaps(TemplateURL* template_url) {
|
| keyword_to_template_map_.erase(keyword);
|
| }
|
|
|
| + if (template_url->GetType() == TemplateURL::OMNIBOX_API_EXTENSION)
|
| + return;
|
| +
|
| if (!template_url->sync_guid().empty())
|
| guid_to_template_map_.erase(template_url->sync_guid());
|
| // |provider_map_| is only initialized after loading has completed.
|
| @@ -1584,6 +1588,9 @@ void TemplateURLService::AddToMaps(TemplateURL* template_url) {
|
| keyword_to_template_map_[keyword] = template_url;
|
| }
|
|
|
| + if (template_url_is_omnibox_api)
|
| + return;
|
| +
|
| if (!template_url->sync_guid().empty())
|
| guid_to_template_map_[template_url->sync_guid()] = template_url;
|
| // |provider_map_| is only initialized after loading has completed.
|
| @@ -1700,6 +1707,8 @@ bool TemplateURLService::UpdateNoNotify(TemplateURL* existing_turl,
|
| template_urls_.end())
|
| return false;
|
|
|
| + DCHECK_NE(TemplateURL::OMNIBOX_API_EXTENSION, existing_turl->GetType());
|
| +
|
| base::string16 old_keyword(existing_turl->keyword());
|
| keyword_to_template_map_.erase(old_keyword);
|
| if (!existing_turl->sync_guid().empty())
|
| @@ -2040,7 +2049,9 @@ bool TemplateURLService::AddNoNotify(TemplateURL* template_url,
|
| // that any "pre-existing" entries we find are actually coming from
|
| // |template_urls_|, lest we detect a "conflict" between the
|
| // |initial_default_search_provider_| and the web data version of itself.
|
| - if (existing_keyword_turl &&
|
| + if (template_url->GetType() != TemplateURL::OMNIBOX_API_EXTENSION &&
|
| + existing_keyword_turl &&
|
| + existing_keyword_turl->GetType() != TemplateURL::OMNIBOX_API_EXTENSION &&
|
| (std::find(template_urls_.begin(), template_urls_.end(),
|
| existing_keyword_turl) != template_urls_.end())) {
|
| DCHECK_NE(existing_keyword_turl, template_url);
|
| @@ -2065,8 +2076,7 @@ bool TemplateURLService::AddNoNotify(TemplateURL* template_url,
|
| AddToMaps(template_url);
|
|
|
| if (newly_adding &&
|
| - (template_url->GetType() !=
|
| - TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION)) {
|
| + (template_url->GetType() == TemplateURL::NORMAL)) {
|
| if (web_data_service_.get())
|
| web_data_service_->AddKeyword(template_url->data());
|
|
|
| @@ -2093,7 +2103,7 @@ void TemplateURLService::RemoveNoNotify(TemplateURL* template_url) {
|
| // Remove it from the vector containing all TemplateURLs.
|
| template_urls_.erase(i);
|
|
|
| - if (template_url->GetType() != TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION) {
|
| + if (template_url->GetType() == TemplateURL::NORMAL) {
|
| if (web_data_service_.get())
|
| web_data_service_->RemoveKeyword(template_url->id());
|
|
|
| @@ -2251,8 +2261,7 @@ void TemplateURLService::ResolveSyncKeywordConflict(
|
| DCHECK(applied_sync_turl);
|
| DCHECK(change_list);
|
| DCHECK_EQ(applied_sync_turl->keyword(), unapplied_sync_turl->keyword());
|
| - DCHECK_NE(TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION,
|
| - applied_sync_turl->GetType());
|
| + DCHECK_EQ(TemplateURL::NORMAL, applied_sync_turl->GetType());
|
|
|
| // Both |unapplied_sync_turl| and |applied_sync_turl| are known to Sync, so
|
| // don't delete either of them. Instead, determine which is "better" and
|
| @@ -2363,8 +2372,7 @@ void TemplateURLService::PatchMissingSyncGUIDs(
|
| TemplateURL* template_url = *i;
|
| DCHECK(template_url);
|
| if (template_url->sync_guid().empty() &&
|
| - (template_url->GetType() !=
|
| - TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION)) {
|
| + (template_url->GetType() == TemplateURL::NORMAL)) {
|
| template_url->data_.sync_guid = base::GenerateGUID();
|
| if (web_data_service_.get())
|
| web_data_service_->UpdateKeyword(template_url->data());
|
|
|