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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/search_engines/template_url_service.h" 5 #include "components/search_engines/template_url_service.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/auto_reset.h" 10 #include "base/auto_reset.h"
(...skipping 2192 matching lines...) Expand 10 before | Expand all | Expand 10 after
2203 2203
2204 bool TemplateURLService::IsLocalTemplateURLBetter( 2204 bool TemplateURLService::IsLocalTemplateURLBetter(
2205 const TemplateURL* local_turl, 2205 const TemplateURL* local_turl,
2206 const TemplateURL* sync_turl) { 2206 const TemplateURL* sync_turl) {
2207 DCHECK(GetTemplateURLForGUID(local_turl->sync_guid())); 2207 DCHECK(GetTemplateURLForGUID(local_turl->sync_guid()));
2208 return local_turl->last_modified() > sync_turl->last_modified() || 2208 return local_turl->last_modified() > sync_turl->last_modified() ||
2209 local_turl->created_by_policy() || 2209 local_turl->created_by_policy() ||
2210 local_turl== GetDefaultSearchProvider(); 2210 local_turl== GetDefaultSearchProvider();
2211 } 2211 }
2212 2212
2213 bool TemplateURLService::IsLocalPrepopulatedTemplateURLBetter(
2214 const TemplateURL* local_turl,
2215 const TemplateURL* sync_turl) {
2216 DCHECK(GetTemplateURLForGUID(local_turl->sync_guid()));
2217 return local_turl->last_modified() > sync_turl->last_modified() ||
2218 local_turl->created_by_policy();
2219 }
2220
2213 void TemplateURLService::ResolveSyncKeywordConflict( 2221 void TemplateURLService::ResolveSyncKeywordConflict(
2214 TemplateURL* unapplied_sync_turl, 2222 TemplateURL* unapplied_sync_turl,
2215 TemplateURL* applied_sync_turl, 2223 TemplateURL* applied_sync_turl,
2216 syncer::SyncChangeList* change_list) { 2224 syncer::SyncChangeList* change_list) {
2217 DCHECK(loaded_); 2225 DCHECK(loaded_);
2218 DCHECK(unapplied_sync_turl); 2226 DCHECK(unapplied_sync_turl);
2219 DCHECK(applied_sync_turl); 2227 DCHECK(applied_sync_turl);
2220 DCHECK(change_list); 2228 DCHECK(change_list);
2221 DCHECK_EQ(applied_sync_turl->keyword(), unapplied_sync_turl->keyword()); 2229 DCHECK_EQ(applied_sync_turl->keyword(), unapplied_sync_turl->keyword());
2222 DCHECK_EQ(TemplateURL::NORMAL, applied_sync_turl->GetType()); 2230 DCHECK_EQ(TemplateURL::NORMAL, applied_sync_turl->GetType());
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
2257 SyncDataMap* local_data, 2265 SyncDataMap* local_data,
2258 syncer::SyncMergeResult* merge_result) { 2266 syncer::SyncMergeResult* merge_result) {
2259 DCHECK(sync_turl); 2267 DCHECK(sync_turl);
2260 DCHECK(!GetTemplateURLForGUID(sync_turl->sync_guid())); 2268 DCHECK(!GetTemplateURLForGUID(sync_turl->sync_guid()));
2261 DCHECK(IsFromSync(sync_turl, sync_data)); 2269 DCHECK(IsFromSync(sync_turl, sync_data));
2262 2270
2263 TemplateURL* conflicting_turl = 2271 TemplateURL* conflicting_turl =
2264 FindNonExtensionTemplateURLForKeyword(sync_turl->keyword()); 2272 FindNonExtensionTemplateURLForKeyword(sync_turl->keyword());
2265 bool should_add_sync_turl = true; 2273 bool should_add_sync_turl = true;
2266 2274
2275 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.
2276 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.
2277 FindPrepopulatedTemplateURL(sync_turl->prepopulate_id());
2278
2279 if (conflicting_prepopulated_turl &&
2280 !IsFromSync(conflicting_prepopulated_turl, sync_data) &&
2281 !IsLocalPrepopulatedTemplateURLBetter(conflicting_prepopulated_turl,
2282 sync_turl)) {
2283 std::string guid = conflicting_prepopulated_turl->sync_guid();
2284 if (conflicting_prepopulated_turl == default_search_provider_) {
2285 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
2286 DefaultSearchManager::FROM_USER);
2287 merge_result->set_num_items_modified(
2288 merge_result->num_items_modified() + 1);
2289 } else {
2290 Remove(conflicting_prepopulated_turl);
2291 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.
2292 1);
2293 }
2294 local_data->erase(guid);
2295 }
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
2296 }
2297
2267 // If there was no TemplateURL in the local model that conflicts with 2298 // If there was no TemplateURL in the local model that conflicts with
2268 // |sync_turl|, skip the following preparation steps and just add |sync_turl| 2299 // |sync_turl|, skip the following preparation steps and just add |sync_turl|
2269 // directly. Otherwise, modify |conflicting_turl| to make room for 2300 // directly. Otherwise, modify |conflicting_turl| to make room for
2270 // |sync_turl|. 2301 // |sync_turl|.
2271 if (conflicting_turl) { 2302 if (conflicting_turl) {
2272 if (IsFromSync(conflicting_turl, sync_data)) { 2303 if (IsFromSync(conflicting_turl, sync_data)) {
2273 // |conflicting_turl| is already known to Sync, so we're not allowed to 2304 // |conflicting_turl| is already known to Sync, so we're not allowed to
2274 // remove it. In this case, we want to uniquify the worse one and send an 2305 // remove it. In this case, we want to uniquify the worse one and send an
2275 // update for the changed keyword to sync. We can reuse the logic from 2306 // update for the changed keyword to sync. We can reuse the logic from
2276 // ResolveSyncKeywordConflict for this. 2307 // ResolveSyncKeywordConflict for this.
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
2434 2465
2435 if (most_recently_intalled_default) { 2466 if (most_recently_intalled_default) {
2436 base::AutoReset<DefaultSearchChangeOrigin> change_origin( 2467 base::AutoReset<DefaultSearchChangeOrigin> change_origin(
2437 &dsp_change_origin_, DSP_CHANGE_OVERRIDE_SETTINGS_EXTENSION); 2468 &dsp_change_origin_, DSP_CHANGE_OVERRIDE_SETTINGS_EXTENSION);
2438 default_search_manager_.SetExtensionControlledDefaultSearchEngine( 2469 default_search_manager_.SetExtensionControlledDefaultSearchEngine(
2439 most_recently_intalled_default->data()); 2470 most_recently_intalled_default->data());
2440 } else { 2471 } else {
2441 default_search_manager_.ClearExtensionControlledDefaultSearchEngine(); 2472 default_search_manager_.ClearExtensionControlledDefaultSearchEngine();
2442 } 2473 }
2443 } 2474 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698