OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/search_engines/template_url_service.h" | 5 #include "chrome/browser/search_engines/template_url_service.h" |
6 | 6 |
7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/environment.h" | 9 #include "base/environment.h" |
10 #include "base/guid.h" | 10 #include "base/guid.h" |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
184 old_base_url(old_base_url) { | 184 old_base_url(old_base_url) { |
185 } | 185 } |
186 | 186 |
187 OldBaseURLSearchTermsData::~OldBaseURLSearchTermsData() { | 187 OldBaseURLSearchTermsData::~OldBaseURLSearchTermsData() { |
188 } | 188 } |
189 | 189 |
190 std::string OldBaseURLSearchTermsData::GoogleBaseURLValue() const { | 190 std::string OldBaseURLSearchTermsData::GoogleBaseURLValue() const { |
191 return old_base_url; | 191 return old_base_url; |
192 } | 192 } |
193 | 193 |
194 // Returns true if |turl|'s GUID is not found inside |sync_data|. We use this | |
195 // in MergeDataAndStartSyncing to differentiate between TemplateURLs from Sync | |
196 // and TemplateURLs that were initially local, assuming |sync_data| is the | |
197 // |initial_sync_data| parameter. | |
198 bool IsFromSync(const TemplateURL* turl, SyncDataMap& sync_data) { | |
199 return (sync_data.find(turl->sync_guid()) != sync_data.end()); | |
200 } | |
201 | |
194 } // namespace | 202 } // namespace |
195 | 203 |
196 | 204 |
197 class TemplateURLService::LessWithPrefix { | 205 class TemplateURLService::LessWithPrefix { |
198 public: | 206 public: |
199 // We want to find the set of keywords that begin with a prefix. The STL | 207 // We want to find the set of keywords that begin with a prefix. The STL |
200 // algorithms will return the set of elements that are "equal to" the | 208 // algorithms will return the set of elements that are "equal to" the |
201 // prefix, where "equal(x, y)" means "!(cmp(x, y) || cmp(y, x))". When | 209 // prefix, where "equal(x, y)" means "!(cmp(x, y) || cmp(y, x))". When |
202 // cmp() is the typical std::less<>, this results in lexicographic equality; | 210 // cmp() is the typical std::less<>, this results in lexicographic equality; |
203 // we need to extend this to mark a prefix as "not less than" a keyword it | 211 // we need to extend this to mark a prefix as "not less than" a keyword it |
(...skipping 786 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
990 Remove(existing_turl); | 998 Remove(existing_turl); |
991 } else if (iter->change_type() == syncer::SyncChange::ACTION_ADD) { | 999 } else if (iter->change_type() == syncer::SyncChange::ACTION_ADD) { |
992 if (existing_turl) { | 1000 if (existing_turl) { |
993 NOTREACHED() << "Unexpected sync change state."; | 1001 NOTREACHED() << "Unexpected sync change state."; |
994 error = sync_error_factory_->CreateAndUploadError( | 1002 error = sync_error_factory_->CreateAndUploadError( |
995 FROM_HERE, | 1003 FROM_HERE, |
996 "ProcessSyncChanges failed on ChangeType ACTION_ADD"); | 1004 "ProcessSyncChanges failed on ChangeType ACTION_ADD"); |
997 LOG(ERROR) << "Trying to add an existing TemplateURL."; | 1005 LOG(ERROR) << "Trying to add an existing TemplateURL."; |
998 continue; | 1006 continue; |
999 } | 1007 } |
1000 std::string guid = turl->sync_guid(); | 1008 const std::string guid = turl->sync_guid(); |
1001 if (!existing_keyword_turl || ResolveSyncKeywordConflict(turl.get(), | 1009 if (existing_keyword_turl) { |
1002 existing_keyword_turl, &new_changes)) { | 1010 // Resolve any conflicts so we can safely add the new entry. |
1003 // Force the local ID to kInvalidTemplateURLID so we can add it. | 1011 ResolveSyncKeywordConflict2(turl.get(), existing_keyword_turl, |
1004 TemplateURLData data(turl->data()); | 1012 &new_changes); |
1005 data.id = kInvalidTemplateURLID; | 1013 } |
1006 Add(new TemplateURL(profile_, data)); | 1014 // Force the local ID to kInvalidTemplateURLID so we can add it. |
1015 TemplateURLData data(turl->data()); | |
1016 data.id = kInvalidTemplateURLID; | |
1017 Add(new TemplateURL(profile_, data)); | |
1007 | 1018 |
1008 // Possibly set the newly added |turl| as the default search provider. | 1019 // Possibly set the newly added |turl| as the default search provider. |
1009 SetDefaultSearchProviderIfNewlySynced(guid); | 1020 SetDefaultSearchProviderIfNewlySynced(guid); |
1010 } | |
1011 } else if (iter->change_type() == syncer::SyncChange::ACTION_UPDATE) { | 1021 } else if (iter->change_type() == syncer::SyncChange::ACTION_UPDATE) { |
1012 if (!existing_turl) { | 1022 if (!existing_turl) { |
1013 NOTREACHED() << "Unexpected sync change state."; | 1023 NOTREACHED() << "Unexpected sync change state."; |
1014 error = sync_error_factory_->CreateAndUploadError( | 1024 error = sync_error_factory_->CreateAndUploadError( |
1015 FROM_HERE, | 1025 FROM_HERE, |
1016 "ProcessSyncChanges failed on ChangeType ACTION_UPDATE"); | 1026 "ProcessSyncChanges failed on ChangeType ACTION_UPDATE"); |
1017 LOG(ERROR) << "Trying to update a non-existent TemplateURL."; | 1027 LOG(ERROR) << "Trying to update a non-existent TemplateURL."; |
1018 continue; | 1028 continue; |
1019 } | 1029 } |
1020 // Possibly resolve a keyword conflict if they have the same keywords but | 1030 if (existing_keyword_turl && (existing_keyword_turl != existing_turl)) { |
1021 // are not the same entry. | 1031 // Resolve any conflicts with other entries so we can safely update the |
1022 if (existing_keyword_turl && (existing_keyword_turl != existing_turl) && | 1032 // keyword. |
1023 !ResolveSyncKeywordConflict(turl.get(), existing_keyword_turl, | 1033 ResolveSyncKeywordConflict2(turl.get(), existing_keyword_turl, |
1024 &new_changes)) { | 1034 &new_changes); |
1025 // Note that because we're processing changes, this Remove() call won't | |
1026 // generate an ACTION_DELETE; but ResolveSyncKeywordConflict() did | |
1027 // already, so we should be OK. | |
1028 Remove(existing_turl); | |
1029 continue; | |
1030 } | 1035 } |
1031 UIThreadSearchTermsData search_terms_data(existing_turl->profile()); | 1036 UIThreadSearchTermsData search_terms_data(existing_turl->profile()); |
1032 if (UpdateNoNotify(existing_turl, *turl, search_terms_data)) | 1037 if (UpdateNoNotify(existing_turl, *turl, search_terms_data)) |
1033 NotifyObservers(); | 1038 NotifyObservers(); |
1034 } else { | 1039 } else { |
1035 // We've unexpectedly received an ACTION_INVALID. | 1040 // We've unexpectedly received an ACTION_INVALID. |
1036 NOTREACHED() << "Unexpected sync change state."; | 1041 NOTREACHED() << "Unexpected sync change state."; |
1037 error = sync_error_factory_->CreateAndUploadError( | 1042 error = sync_error_factory_->CreateAndUploadError( |
1038 FROM_HERE, | 1043 FROM_HERE, |
1039 "ProcessSyncChanges received an ACTION_INVALID"); | 1044 "ProcessSyncChanges received an ACTION_INVALID"); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1107 // preprocessing in TemplateURLService's loading code). Ignore it and send | 1112 // preprocessing in TemplateURLService's loading code). Ignore it and send |
1108 // an ACTION_DELETE up to the server. | 1113 // an ACTION_DELETE up to the server. |
1109 new_changes.push_back( | 1114 new_changes.push_back( |
1110 syncer::SyncChange(FROM_HERE, | 1115 syncer::SyncChange(FROM_HERE, |
1111 syncer::SyncChange::ACTION_DELETE, | 1116 syncer::SyncChange::ACTION_DELETE, |
1112 iter->second)); | 1117 iter->second)); |
1113 continue; | 1118 continue; |
1114 } | 1119 } |
1115 | 1120 |
1116 if (local_turl) { | 1121 if (local_turl) { |
1122 DCHECK(IsFromSync(local_turl, sync_data_map)); | |
1117 // This local search engine is already synced. If the timestamp differs | 1123 // This local search engine is already synced. If the timestamp differs |
1118 // from Sync, we need to update locally or to the cloud. Note that if the | 1124 // from Sync, we need to update locally or to the cloud. Note that if the |
1119 // timestamps are equal, we touch neither. | 1125 // timestamps are equal, we touch neither. |
1120 if (sync_turl->last_modified() > local_turl->last_modified()) { | 1126 if (sync_turl->last_modified() > local_turl->last_modified()) { |
1121 // We've received an update from Sync. We should replace all synced | 1127 // We've received an update from Sync. We should replace all synced |
1122 // fields in the local TemplateURL. Note that this includes the | 1128 // fields in the local TemplateURL. Note that this includes the |
1123 // TemplateURLID and the TemplateURL may have to be reparsed. This | 1129 // TemplateURLID and the TemplateURL may have to be reparsed. This |
1124 // also makes the local data's last_modified timestamp equal to Sync's, | 1130 // also makes the local data's last_modified timestamp equal to Sync's, |
1125 // avoiding an Update on the next MergeData call. | 1131 // avoiding an Update on the next MergeData call. |
1126 UIThreadSearchTermsData search_terms_data(local_turl->profile()); | 1132 UIThreadSearchTermsData search_terms_data(local_turl->profile()); |
(...skipping 10 matching lines...) Expand all Loading... | |
1137 local_data_map.erase(iter->first); | 1143 local_data_map.erase(iter->first); |
1138 } else { | 1144 } else { |
1139 // The search engine from the cloud has not been synced locally, but there | 1145 // The search engine from the cloud has not been synced locally, but there |
1140 // might be a local search engine that is a duplicate that needs to be | 1146 // might be a local search engine that is a duplicate that needs to be |
1141 // merged. | 1147 // merged. |
1142 TemplateURL* dupe_turl = FindDuplicateOfSyncTemplateURL(*sync_turl); | 1148 TemplateURL* dupe_turl = FindDuplicateOfSyncTemplateURL(*sync_turl); |
1143 if (dupe_turl) { | 1149 if (dupe_turl) { |
1144 // Merge duplicates and remove the processed local TURL from the map. | 1150 // Merge duplicates and remove the processed local TURL from the map. |
1145 std::string old_guid = dupe_turl->sync_guid(); | 1151 std::string old_guid = dupe_turl->sync_guid(); |
1146 MergeSyncAndLocalURLDuplicates(sync_turl.release(), dupe_turl, | 1152 MergeSyncAndLocalURLDuplicates(sync_turl.release(), dupe_turl, |
1147 &new_changes); | 1153 sync_data_map, &new_changes); |
1148 local_data_map.erase(old_guid); | 1154 local_data_map.erase(old_guid); |
1149 } else { | 1155 } else { |
1150 std::string guid = sync_turl->sync_guid(); | 1156 MergeInSyncTemplateURL(sync_turl.get(), sync_data_map, &new_changes, |
Nicolas Zea
2012/07/23 20:20:52
given that this method supports finding a conflict
SteveT
2012/07/23 21:07:00
So the above method (MergeSyncAndLocalURLDuplicate
Nicolas Zea
2012/07/23 22:14:44
How is the behavior between the two different? It
SteveT
2012/07/24 14:46:30
Actually yeah, MergeInSyncTemplateURL is sort of a
| |
1151 // Keyword conflict is possible in this case. Resolve it first before | 1157 &local_data_map); |
1152 // adding the new TemplateURL. Note that we don't remove the local TURL | |
1153 // from local_data_map in this case as it may still need to be pushed to | |
1154 // the cloud. We also explicitly don't resolve conflicts against | |
1155 // extension keywords; see comments in ProcessSyncChanges(). | |
1156 TemplateURL* existing_keyword_turl = | |
1157 FindNonExtensionTemplateURLForKeyword(sync_turl->keyword()); | |
1158 if (!existing_keyword_turl || ResolveSyncKeywordConflict( | |
1159 sync_turl.get(), existing_keyword_turl, &new_changes)) { | |
1160 // Force the local ID to kInvalidTemplateURLID so we can add it. | |
1161 TemplateURLData data(sync_turl->data()); | |
1162 data.id = kInvalidTemplateURLID; | |
1163 Add(new TemplateURL(profile_, data)); | |
1164 | |
1165 // Possibly set the newly added |turl| as the default search provider. | |
1166 SetDefaultSearchProviderIfNewlySynced(guid); | |
1167 } | |
1168 } | 1158 } |
1169 } | 1159 } |
1170 } | 1160 } |
1171 | 1161 |
1172 // The remaining SyncData in local_data_map should be everything that needs to | 1162 // The remaining SyncData in local_data_map should be everything that needs to |
1173 // be pushed as ADDs to sync. | 1163 // be pushed as ADDs to sync. |
1174 for (SyncDataMap::const_iterator iter = local_data_map.begin(); | 1164 for (SyncDataMap::const_iterator iter = local_data_map.begin(); |
1175 iter != local_data_map.end(); ++iter) { | 1165 iter != local_data_map.end(); ++iter) { |
1176 new_changes.push_back( | 1166 new_changes.push_back( |
1177 syncer::SyncChange(FROM_HERE, | 1167 syncer::SyncChange(FROM_HERE, |
(...skipping 1124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2302 // This is a best-effort approach where we try to preserve the original | 2292 // This is a best-effort approach where we try to preserve the original |
2303 // keyword and let the user do what they will after our attempt. | 2293 // keyword and let the user do what they will after our attempt. |
2304 string16 keyword_candidate(turl.keyword()); | 2294 string16 keyword_candidate(turl.keyword()); |
2305 do { | 2295 do { |
2306 keyword_candidate.append(ASCIIToUTF16("_")); | 2296 keyword_candidate.append(ASCIIToUTF16("_")); |
2307 } while (GetTemplateURLForKeyword(keyword_candidate)); | 2297 } while (GetTemplateURLForKeyword(keyword_candidate)); |
2308 | 2298 |
2309 return keyword_candidate; | 2299 return keyword_candidate; |
2310 } | 2300 } |
2311 | 2301 |
2302 // Find the "better" TemplateURL based on a set of heuristics: | |
2303 // * newer last_modified timestamp. | |
2304 // * ... | |
2305 // Returns true if |turl1| is better, false otherwise. In the case of ties, | |
2306 // prefer |turl1| (return true). | |
2307 bool CompareTemplateURLs(const TemplateURL* turl1, const TemplateURL* turl2) { | |
2308 return false; | |
2309 } | |
2310 | |
2311 void TemplateURLService::MergeInSyncTemplateURL( | |
2312 TemplateURL* sync_turl, | |
2313 SyncDataMap& sync_data, | |
2314 syncer::SyncChangeList* change_list, | |
2315 SyncDataMap* initial_data) { | |
2316 DCHECK(sync_turl); | |
2317 DCHECK(!GetTemplateURLForGUID(sync_turl->sync_guid())); | |
2318 DCHECK(IsFromSync(sync_turl, sync_data)); | |
2319 | |
2320 TemplateURL* local_turl = | |
2321 FindNonExtensionTemplateURLForKeyword(sync_turl->keyword()); | |
2322 bool should_add_sync_turl = local_turl == NULL; | |
2323 | |
2324 // If there was no TemplateURL in the local model that conflicts with | |
2325 // |sync_turl|, we can skip the following preparation steps and just | |
2326 // |sync_turl| directly. | |
2327 if (!should_add_sync_turl) { | |
2328 DCHECK(local_turl); | |
2329 const bool local_is_better = | |
2330 (local_turl->last_modified() > sync_turl->last_modified()) || | |
2331 local_turl->created_by_policy() || | |
2332 (local_turl == GetDefaultSearchProvider()); | |
2333 if (IsFromSync(local_turl, sync_data)) { | |
2334 // |local_turl| was merged in earlier from Sync, so we're not allowed to | |
2335 // remove it. In this case, we want to uniquify the worse one and send | |
2336 // an update for the changed keyword to sync. We can reuse the logic from | |
2337 // ResolveSyncKeywordConflict2 for this. | |
2338 ResolveSyncKeywordConflict2(sync_turl, local_turl, change_list); | |
2339 should_add_sync_turl = true; | |
2340 } else { | |
2341 // |local_turl| is not yet known to Sync. If it is better, then we want to | |
2342 // transfer its values up to sync. Otherwise, we remove it and allow the | |
2343 // entry from Sync to overtake it in the model. | |
2344 if (local_is_better) { | |
2345 ResetTemplateURLGUID(local_turl, sync_turl->sync_guid()); | |
2346 syncer::SyncData sync_data = CreateSyncDataFromTemplateURL(*local_turl); | |
2347 change_list->push_back(syncer::SyncChange( | |
2348 FROM_HERE, | |
2349 syncer::SyncChange::ACTION_UPDATE, | |
2350 sync_data)); | |
2351 // Note that in this case we do not set |should_add_sync_turl|, since | |
2352 // we've effectively "merged" it in by updating the local entry with | |
2353 // its sync_guid. | |
2354 // TODO(stevet/reviewer): If local_turl was the DSP, should we set the | |
2355 // Synced GUID pref with the new GUID? What about in | |
Nicolas Zea
2012/07/23 20:20:52
Hmm, interesting. Preferences are associated befor
SteveT
2012/07/23 21:07:00
Oh, so we have an ordering guarantee now that Pref
Nicolas Zea
2012/07/23 22:14:44
Yeah...it's not a guarantee, given that preference
SteveT
2012/07/24 14:46:30
So the problem here isn't the local_turl losing co
Nicolas Zea
2012/07/24 19:31:47
Ah, I see. So we're in one of two states:
1) We lo
SteveT
2012/07/24 21:51:18
Yes, so in (1), pending_synced_default_change_ is
Nicolas Zea
2012/07/24 22:13:37
I don't think we should be attempting to repair an
| |
2356 // MergeSyncAndLocalURLDuplicates, where we do something similar? | |
2357 } else { | |
2358 // We guarantee that this isn't the local search provider. Otherwise, | |
2359 // local would have won. | |
2360 DCHECK(local_turl != GetDefaultSearchProvider()); | |
2361 const std::string guid = local_turl->sync_guid(); | |
2362 Remove(local_turl); | |
2363 // Also remove the entry from the initial data so that we don't push it | |
2364 // up to Sync. | |
2365 initial_data->erase(guid); | |
Nicolas Zea
2012/07/23 20:20:52
does this need to be done for the case above as we
SteveT
2012/07/23 21:07:00
Hm, yes, you're right. In either case, since local
| |
2366 should_add_sync_turl = true; | |
2367 } | |
2368 } | |
2369 } | |
2370 | |
2371 if (should_add_sync_turl) { | |
2372 const std::string guid = sync_turl->sync_guid(); | |
2373 // Force the local ID to kInvalidTemplateURLID so we can add it. | |
2374 TemplateURLData data(sync_turl->data()); | |
2375 data.id = kInvalidTemplateURLID; | |
2376 Add(new TemplateURL(profile_, data)); | |
2377 | |
2378 // Possibly set the newly added |turl| as the default search provider. | |
2379 // TODO(stevet/reviewer): Note that if this call notices a Default change, | |
2380 // it will NOT set the pref since we are currently proccessing sync changes. | |
2381 // See SetDefaultSearchProviderNoNotify. | |
2382 // We might have to detect that case ourselves and explicitly set the pref? | |
Nicolas Zea
2012/07/23 20:20:52
I'm not sure I follow; why would we want to update
SteveT
2012/07/23 21:07:00
Ah right, I was thinking about just SetDefaultSear
| |
2383 SetDefaultSearchProviderIfNewlySynced(guid); | |
2384 } | |
2385 } | |
2386 | |
2387 void TemplateURLService::ResolveSyncKeywordConflict2( | |
2388 TemplateURL* sync_turl, | |
2389 TemplateURL* local_turl, | |
Nicolas Zea
2012/07/23 20:20:52
|sync_turl| and |local_turl| don't really make sen
SteveT
2012/07/23 21:07:00
This is true, but local_turl is already located on
Nicolas Zea
2012/07/23 22:14:44
maybe unapplied_sync_turl and applied_sync_turl?
SteveT
2012/07/24 14:46:30
Sounds good. Done.
| |
2390 syncer::SyncChangeList* change_list) { | |
2391 DCHECK(loaded_); | |
2392 DCHECK(sync_turl); | |
2393 DCHECK(local_turl); | |
2394 DCHECK(change_list); | |
2395 DCHECK(local_turl->keyword() == sync_turl->keyword()); | |
2396 DCHECK(!local_turl->IsExtensionKeyword()); | |
2397 | |
2398 // Both |sync_turl| and |local_turl| are known to Sync, so don't delete | |
2399 // either of them. Instead, determine which is "better" and uniquify the other | |
2400 // one, sending an update to the server for the updated entry. | |
2401 const bool local_is_better = | |
2402 (local_turl->last_modified() > sync_turl->last_modified()) || | |
2403 local_turl->created_by_policy() || | |
2404 (local_turl == GetDefaultSearchProvider()); | |
2405 TemplateURL* loser = local_is_better ? local_turl : sync_turl; | |
2406 string16 new_keyword = UniquifyKeyword(*loser, false); | |
2407 DCHECK(!GetTemplateURLForKeyword(new_keyword)); | |
2408 syncer::SyncData sync_data = CreateSyncDataFromTemplateURL(*loser); | |
2409 change_list->push_back(syncer::SyncChange(FROM_HERE, | |
2410 syncer::SyncChange::ACTION_UPDATE, | |
2411 sync_data)); | |
2412 if (local_is_better) { | |
2413 // Just set the keyword of |sync_turl|. The caller is responsible for adding | |
2414 // or updating sync_turl in the local model. | |
2415 sync_turl->data_.SetKeyword(new_keyword); | |
2416 } else { | |
2417 // Update |local_turl| in the local model with the new keyword. | |
2418 TemplateURLData data(local_turl->data()); | |
2419 data.SetKeyword(new_keyword); | |
2420 TemplateURL new_turl(local_turl->profile(), data); | |
2421 UIThreadSearchTermsData search_terms_data(local_turl->profile()); | |
2422 if (UpdateNoNotify(local_turl, new_turl, search_terms_data)) | |
2423 NotifyObservers(); | |
2424 } | |
2425 } | |
2426 | |
2312 bool TemplateURLService::ResolveSyncKeywordConflict( | 2427 bool TemplateURLService::ResolveSyncKeywordConflict( |
2313 TemplateURL* sync_turl, | 2428 TemplateURL* sync_turl, |
2314 TemplateURL* local_turl, | 2429 TemplateURL* local_turl, |
2315 syncer::SyncChangeList* change_list) { | 2430 syncer::SyncChangeList* change_list) { |
2316 DCHECK(loaded_); | 2431 DCHECK(loaded_); |
2317 DCHECK(sync_turl); | 2432 DCHECK(sync_turl); |
2318 DCHECK(local_turl); | 2433 DCHECK(local_turl); |
2434 DCHECK(change_list); | |
2319 DCHECK(sync_turl->sync_guid() != local_turl->sync_guid()); | 2435 DCHECK(sync_turl->sync_guid() != local_turl->sync_guid()); |
2320 DCHECK(!local_turl->IsExtensionKeyword()); | 2436 DCHECK(!local_turl->IsExtensionKeyword()); |
2321 DCHECK(change_list); | |
2322 | 2437 |
2323 const bool local_is_better = | 2438 const bool local_is_better = |
2324 (local_turl->last_modified() > sync_turl->last_modified()) || | 2439 (local_turl->last_modified() > sync_turl->last_modified()) || |
2325 local_turl->created_by_policy() || | 2440 local_turl->created_by_policy() || |
2326 (local_turl == GetDefaultSearchProvider()); | 2441 (local_turl == GetDefaultSearchProvider()); |
2327 const bool can_replace_local = CanReplace(local_turl); | 2442 const bool can_replace_local = CanReplace(local_turl); |
2328 if (CanReplace(sync_turl) && (local_is_better || !can_replace_local)) { | 2443 if (CanReplace(sync_turl) && (local_is_better || !can_replace_local)) { |
2329 syncer::SyncData sync_data = CreateSyncDataFromTemplateURL(*sync_turl); | 2444 syncer::SyncData sync_data = CreateSyncDataFromTemplateURL(*sync_turl); |
2330 change_list->push_back(syncer::SyncChange(FROM_HERE, | 2445 change_list->push_back(syncer::SyncChange(FROM_HERE, |
2331 syncer::SyncChange::ACTION_DELETE, | 2446 syncer::SyncChange::ACTION_DELETE, |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2382 TemplateURL* TemplateURLService::FindDuplicateOfSyncTemplateURL( | 2497 TemplateURL* TemplateURLService::FindDuplicateOfSyncTemplateURL( |
2383 const TemplateURL& sync_turl) { | 2498 const TemplateURL& sync_turl) { |
2384 TemplateURL* existing_turl = GetTemplateURLForKeyword(sync_turl.keyword()); | 2499 TemplateURL* existing_turl = GetTemplateURLForKeyword(sync_turl.keyword()); |
2385 return existing_turl && (existing_turl->url() == sync_turl.url()) ? | 2500 return existing_turl && (existing_turl->url() == sync_turl.url()) ? |
2386 existing_turl : NULL; | 2501 existing_turl : NULL; |
2387 } | 2502 } |
2388 | 2503 |
2389 void TemplateURLService::MergeSyncAndLocalURLDuplicates( | 2504 void TemplateURLService::MergeSyncAndLocalURLDuplicates( |
2390 TemplateURL* sync_turl, | 2505 TemplateURL* sync_turl, |
2391 TemplateURL* local_turl, | 2506 TemplateURL* local_turl, |
2507 SyncDataMap& sync_data, | |
2392 syncer::SyncChangeList* change_list) { | 2508 syncer::SyncChangeList* change_list) { |
2393 DCHECK(loaded_); | 2509 DCHECK(loaded_); |
2394 DCHECK(sync_turl); | 2510 DCHECK(sync_turl); |
2395 DCHECK(local_turl); | 2511 DCHECK(local_turl); |
2396 DCHECK(change_list); | 2512 DCHECK(change_list); |
2397 scoped_ptr<TemplateURL> scoped_sync_turl(sync_turl); | 2513 scoped_ptr<TemplateURL> scoped_sync_turl(sync_turl); |
2398 if (sync_turl->last_modified() > local_turl->last_modified()) { | 2514 if (sync_turl->last_modified() > local_turl->last_modified()) { |
2399 // Fully replace local_url with Sync's copy. Note that because use Add | 2515 // Fully replace local_url with Sync's copy. Note that because use Add |
2400 // rather than ResetTemplateURL, |sync_url| is added with a fresh | 2516 // rather than ResetTemplateURL, |sync_url| is added with a fresh |
2401 // TemplateURLID. We don't need to sync the new ID back to the server since | 2517 // TemplateURLID. We don't need to sync the new ID back to the server since |
2402 // it's only relevant locally. | 2518 // it's only relevant locally. |
2403 bool delete_default = (local_turl == GetDefaultSearchProvider()); | 2519 bool delete_default = (local_turl == GetDefaultSearchProvider()); |
2404 DCHECK(!delete_default || !is_default_search_managed_); | 2520 DCHECK(!delete_default || !is_default_search_managed_); |
2405 if (delete_default) | 2521 if (delete_default) |
2406 default_search_provider_ = NULL; | 2522 default_search_provider_ = NULL; |
2407 | 2523 |
2408 // See comments in ResolveSyncKeywordConflict() regarding generating an | 2524 // See comments in ResolveSyncKeywordConflict() regarding generating an |
2409 // ACTION_DELETE manually since Remove() won't do it. | 2525 // ACTION_DELETE manually since Remove() won't do it. |
2410 syncer::SyncData sync_data = CreateSyncDataFromTemplateURL(*local_turl); | 2526 if (IsFromSync(local_turl, sync_data)) { |
Nicolas Zea
2012/07/23 20:20:52
I don't think we want to delete the local turl if
SteveT
2012/07/23 21:07:00
Hm yeah, this is actually wrong.
What happens und
Nicolas Zea
2012/07/23 22:14:44
Yeah, I think that's the right approach.
SteveT
2012/07/24 14:46:30
Oops, when I said "roll the logic into ResolveSync
| |
2411 change_list->push_back(syncer::SyncChange(FROM_HERE, | 2527 syncer::SyncData sync_data = CreateSyncDataFromTemplateURL(*local_turl); |
2412 syncer::SyncChange::ACTION_DELETE, | 2528 change_list->push_back(syncer::SyncChange(FROM_HERE, |
2413 sync_data)); | 2529 syncer::SyncChange::ACTION_DELETE, |
2530 sync_data)); | |
2531 } | |
2414 Remove(local_turl); | 2532 Remove(local_turl); |
2415 | 2533 |
2416 // Force the local ID to kInvalidTemplateURLID so we can add it. | 2534 // Force the local ID to kInvalidTemplateURLID so we can add it. |
2417 sync_turl->data_.id = kInvalidTemplateURLID; | 2535 sync_turl->data_.id = kInvalidTemplateURLID; |
2418 Add(scoped_sync_turl.release()); | 2536 Add(scoped_sync_turl.release()); |
2419 if (delete_default) | 2537 if (delete_default) |
2420 SetDefaultSearchProvider(sync_turl); | 2538 SetDefaultSearchProvider(sync_turl); |
2421 } else { | 2539 } else { |
2422 // Change the local TURL's GUID to the server's GUID and push an update to | 2540 // Change the local TURL's GUID to the server's GUID and push an update to |
2423 // Sync. This ensures that the rest of local_url's fields are sync'd up to | 2541 // Sync. This ensures that the rest of local_url's fields are sync'd up to |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2473 // TODO(mpcomplete): If we allow editing extension keywords, then those | 2591 // TODO(mpcomplete): If we allow editing extension keywords, then those |
2474 // should be persisted to disk and synced. | 2592 // should be persisted to disk and synced. |
2475 if (template_url->sync_guid().empty() && | 2593 if (template_url->sync_guid().empty() && |
2476 !template_url->IsExtensionKeyword()) { | 2594 !template_url->IsExtensionKeyword()) { |
2477 template_url->data_.sync_guid = base::GenerateGUID(); | 2595 template_url->data_.sync_guid = base::GenerateGUID(); |
2478 if (service_.get()) | 2596 if (service_.get()) |
2479 service_->UpdateKeyword(template_url->data()); | 2597 service_->UpdateKeyword(template_url->data()); |
2480 } | 2598 } |
2481 } | 2599 } |
2482 } | 2600 } |
OLD | NEW |