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

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 2185 matching lines...) Expand 10 before | Expand all | Expand 10 after
2196 base::string16 keyword_candidate(turl.keyword()); 2196 base::string16 keyword_candidate(turl.keyword());
2197 do { 2197 do {
2198 keyword_candidate.append(base::ASCIIToUTF16("_")); 2198 keyword_candidate.append(base::ASCIIToUTF16("_"));
2199 } while (GetTemplateURLForKeyword(keyword_candidate)); 2199 } while (GetTemplateURLForKeyword(keyword_candidate));
2200 2200
2201 return keyword_candidate; 2201 return keyword_candidate;
2202 } 2202 }
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 bool prefer_local_default) {
2207 DCHECK(GetTemplateURLForGUID(local_turl->sync_guid())); 2208 DCHECK(GetTemplateURLForGUID(local_turl->sync_guid()));
2208 return local_turl->last_modified() > sync_turl->last_modified() || 2209 return local_turl->last_modified() > sync_turl->last_modified() ||
2209 local_turl->created_by_policy() || 2210 local_turl->created_by_policy() ||
2210 local_turl== GetDefaultSearchProvider(); 2211 (prefer_local_default && local_turl == GetDefaultSearchProvider());
2211 } 2212 }
2212 2213
2213 void TemplateURLService::ResolveSyncKeywordConflict( 2214 void TemplateURLService::ResolveSyncKeywordConflict(
2214 TemplateURL* unapplied_sync_turl, 2215 TemplateURL* unapplied_sync_turl,
2215 TemplateURL* applied_sync_turl, 2216 TemplateURL* applied_sync_turl,
2216 syncer::SyncChangeList* change_list) { 2217 syncer::SyncChangeList* change_list) {
2217 DCHECK(loaded_); 2218 DCHECK(loaded_);
2218 DCHECK(unapplied_sync_turl); 2219 DCHECK(unapplied_sync_turl);
2219 DCHECK(applied_sync_turl); 2220 DCHECK(applied_sync_turl);
2220 DCHECK(change_list); 2221 DCHECK(change_list);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
2257 SyncDataMap* local_data, 2258 SyncDataMap* local_data,
2258 syncer::SyncMergeResult* merge_result) { 2259 syncer::SyncMergeResult* merge_result) {
2259 DCHECK(sync_turl); 2260 DCHECK(sync_turl);
2260 DCHECK(!GetTemplateURLForGUID(sync_turl->sync_guid())); 2261 DCHECK(!GetTemplateURLForGUID(sync_turl->sync_guid()));
2261 DCHECK(IsFromSync(sync_turl, sync_data)); 2262 DCHECK(IsFromSync(sync_turl, sync_data));
2262 2263
2263 TemplateURL* conflicting_turl = 2264 TemplateURL* conflicting_turl =
2264 FindNonExtensionTemplateURLForKeyword(sync_turl->keyword()); 2265 FindNonExtensionTemplateURLForKeyword(sync_turl->keyword());
2265 bool should_add_sync_turl = true; 2266 bool should_add_sync_turl = true;
2266 2267
2267 // If there was no TemplateURL in the local model that conflicts with 2268 // Resolve conflicts with local TemplateURLs.
2268 // |sync_turl|, skip the following preparation steps and just add |sync_turl|
2269 // directly. Otherwise, modify |conflicting_turl| to make room for
2270 // |sync_turl|.
2271 if (conflicting_turl) { 2269 if (conflicting_turl) {
2270 // Modify |conflicting_turl| to make room for |sync_turl|.
2272 if (IsFromSync(conflicting_turl, sync_data)) { 2271 if (IsFromSync(conflicting_turl, sync_data)) {
2273 // |conflicting_turl| is already known to Sync, so we're not allowed to 2272 // |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 2273 // 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 2274 // update for the changed keyword to sync. We can reuse the logic from
2276 // ResolveSyncKeywordConflict for this. 2275 // ResolveSyncKeywordConflict for this.
2277 ResolveSyncKeywordConflict(sync_turl, conflicting_turl, change_list); 2276 ResolveSyncKeywordConflict(sync_turl, conflicting_turl, change_list);
2278 merge_result->set_num_items_modified( 2277 merge_result->set_num_items_modified(
2279 merge_result->num_items_modified() + 1); 2278 merge_result->num_items_modified() + 1);
2280 } else { 2279 } else {
2281 // |conflicting_turl| is not yet known to Sync. If it is better, then we 2280 // |conflicting_turl| is not yet known to Sync. If it is better, then we
(...skipping 17 matching lines...) Expand all
2299 // local would have won. 2298 // local would have won.
2300 DCHECK(conflicting_turl != GetDefaultSearchProvider()); 2299 DCHECK(conflicting_turl != GetDefaultSearchProvider());
2301 Remove(conflicting_turl); 2300 Remove(conflicting_turl);
2302 merge_result->set_num_items_deleted( 2301 merge_result->set_num_items_deleted(
2303 merge_result->num_items_deleted() + 1); 2302 merge_result->num_items_deleted() + 1);
2304 } 2303 }
2305 // This TemplateURL was either removed or overwritten in the local model. 2304 // This TemplateURL was either removed or overwritten in the local model.
2306 // Remove the entry from the local data so it isn't pushed up to Sync. 2305 // Remove the entry from the local data so it isn't pushed up to Sync.
2307 local_data->erase(guid); 2306 local_data->erase(guid);
2308 } 2307 }
2308 } else {
2309 // Check for a turl with a conflicting prepopulate_id.
Peter Kasting 2016/06/14 23:48:39 Nit: I generally try to say TemplateURL instead of
2310 TemplateURL* conflicting_prepopulated_turl =
2311 FindPrepopulatedTemplateURL(sync_turl->prepopulate_id());
2312
2313 // If there's a conflicting prepopulated turl that's not a keyword conflict
2314 // then |sync_turl| has likely been user-modified. We give |sync_turl|
2315 // precdence if it's been modified more recently and the local turl isn't
Peter Kasting 2016/06/14 23:48:39 Nit: precedence
2316 // yet known to sync. This can override the default search engine, since if
2317 // it didn't, we could end up with two distinct default search engines.
Peter Kasting 2016/06/14 23:48:39 Nit: This sentence seems a bit misleading (Templat
2318 // If we can't safely remove or merge the local turl, we'll leave both turls
2319 // alone.
2320 if (conflicting_prepopulated_turl &&
2321 !IsFromSync(conflicting_prepopulated_turl, sync_data) &&
2322 !IsLocalTemplateURLBetter(conflicting_prepopulated_turl, sync_turl,
2323 false)) {
2324 // Remove or modify |conflicting_prepopulated_turl| to make room for
2325 // |sync_turl|.
Peter Kasting 2016/06/14 23:48:39 Nit: Is this comment strictly accurate for the fir
2326 std::string guid = conflicting_prepopulated_turl->sync_guid();
2327 if (conflicting_prepopulated_turl == default_search_provider_) {
2328 ApplyDefaultSearchChange(&sync_turl->data(),
2329 DefaultSearchManager::FROM_USER);
2330 merge_result->set_num_items_modified(
2331 merge_result->num_items_modified() + 1);
2332 } else {
2333 Remove(conflicting_prepopulated_turl);
2334 merge_result->set_num_items_deleted(merge_result->num_items_deleted() +
2335 1);
2336 }
2337 // Remove the local data so it isn't written to sync.
2338 local_data->erase(guid);
2339 }
2309 } 2340 }
2310 2341
2311 if (should_add_sync_turl) { 2342 if (should_add_sync_turl) {
2312 // Force the local ID to kInvalidTemplateURLID so we can add it. 2343 // Force the local ID to kInvalidTemplateURLID so we can add it.
2313 TemplateURLData data(sync_turl->data()); 2344 TemplateURLData data(sync_turl->data());
2314 data.id = kInvalidTemplateURLID; 2345 data.id = kInvalidTemplateURLID;
2315 TemplateURL* added = new TemplateURL(data); 2346 TemplateURL* added = new TemplateURL(data);
2316 base::AutoReset<DefaultSearchChangeOrigin> change_origin( 2347 base::AutoReset<DefaultSearchChangeOrigin> change_origin(
2317 &dsp_change_origin_, DSP_CHANGE_SYNC_ADD); 2348 &dsp_change_origin_, DSP_CHANGE_SYNC_ADD);
2318 if (Add(added)) 2349 if (Add(added))
(...skipping 115 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