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

Unified Diff: components/search_engines/template_url_service.cc

Issue 2067723002: [sync] Search engine shortcuts get underscores at the end after sync (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: [sync] Search engine shortcuts get underscores at the end after sync Created 4 years, 6 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: 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 65a7581695de8fc197a9cda0a25a8e6655f70d18..245c622d4a14e6c7c1ea2c7e5d449101abe7648c 100644
--- a/components/search_engines/template_url_service.cc
+++ b/components/search_engines/template_url_service.cc
@@ -2210,6 +2210,14 @@ bool TemplateURLService::IsLocalTemplateURLBetter(
local_turl== GetDefaultSearchProvider();
}
+bool TemplateURLService::IsLocalPrepopulatedTemplateURLBetter(
+ const TemplateURL* local_turl,
+ const TemplateURL* sync_turl) {
+ DCHECK(GetTemplateURLForGUID(local_turl->sync_guid()));
+ return local_turl->last_modified() > sync_turl->last_modified() ||
+ local_turl->created_by_policy();
+}
+
void TemplateURLService::ResolveSyncKeywordConflict(
TemplateURL* unapplied_sync_turl,
TemplateURL* applied_sync_turl,
@@ -2264,6 +2272,29 @@ void TemplateURLService::MergeInSyncTemplateURL(
FindNonExtensionTemplateURLForKeyword(sync_turl->keyword());
bool should_add_sync_turl = true;
+ if (!conflicting_turl) {
Peter Kasting 2016/06/14 19:21:26 Nit: Just move the body of this conditional onto t
Patrick Noland 2016/06/14 22:55:24 Done.
+ TemplateURL* conflicting_prepopulated_turl =
Peter Kasting 2016/06/14 19:21:26 Nit: Consider a comment up here that summarizes th
Nicolas Zea 2016/06/14 21:19:44 Seconded. This is fairly subtle, so would be good
Patrick Noland 2016/06/14 22:55:24 Done.
+ FindPrepopulatedTemplateURL(sync_turl->prepopulate_id());
+
+ if (conflicting_prepopulated_turl &&
+ !IsFromSync(conflicting_prepopulated_turl, sync_data) &&
+ !IsLocalPrepopulatedTemplateURLBetter(conflicting_prepopulated_turl,
+ sync_turl)) {
+ std::string guid = conflicting_prepopulated_turl->sync_guid();
+ if (conflicting_prepopulated_turl == default_search_provider_) {
+ ApplyDefaultSearchChange(&sync_turl->data(),
Nicolas Zea 2016/06/14 21:19:44 Why don't we remove the conflicting prepopulated t
Patrick Noland 2016/06/14 22:55:24 The logic in ApplyDefaultSearchChange effectively
+ DefaultSearchManager::FROM_USER);
+ merge_result->set_num_items_modified(
+ merge_result->num_items_modified() + 1);
+ } else {
+ Remove(conflicting_prepopulated_turl);
+ merge_result->set_num_items_deleted(merge_result->num_items_deleted() +
Peter Kasting 2016/06/14 19:21:26 Nit: Break after ( instead
Patrick Noland 2016/06/14 22:55:24 Done.
+ 1);
+ }
+ local_data->erase(guid);
+ }
Nicolas Zea 2016/06/14 21:19:44 To be clear, in the else clause here we're explici
Patrick Noland 2016/06/14 22:55:24 Yes. I've added a comment to this effect. The like
+ }
+
// If there was no TemplateURL in the local model that conflicts with
// |sync_turl|, skip the following preparation steps and just add |sync_turl|
// directly. Otherwise, modify |conflicting_turl| to make room for

Powered by Google App Engine
This is Rietveld 408576698