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

Side by Side Diff: chrome/browser/search_engines/template_url_service.cc

Issue 10384188: Ensure that TemplateURLs removed by prepopulate search engine merging is also removed from Sync. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: removed AddPreSyncDeletedGUIDForTesting; test empty set; merge to TOT Created 8 years, 7 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 (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/i18n/case_conversion.h" 10 #include "base/i18n/case_conversion.h"
(...skipping 595 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 606
607 // initial_default_search_provider_ is only needed before we've finished 607 // initial_default_search_provider_ is only needed before we've finished
608 // loading. Now that we've loaded we can nuke it. 608 // loading. Now that we've loaded we can nuke it.
609 initial_default_search_provider_.reset(); 609 initial_default_search_provider_.reset();
610 is_default_search_managed_ = false; 610 is_default_search_managed_ = false;
611 611
612 TemplateURLVector template_urls; 612 TemplateURLVector template_urls;
613 TemplateURL* default_search_provider = NULL; 613 TemplateURL* default_search_provider = NULL;
614 int new_resource_keyword_version = 0; 614 int new_resource_keyword_version = 0;
615 GetSearchProvidersUsingKeywordResult(*result, service_.get(), profile_, 615 GetSearchProvidersUsingKeywordResult(*result, service_.get(), profile_,
616 &template_urls, &default_search_provider, &new_resource_keyword_version); 616 &template_urls, &default_search_provider, &new_resource_keyword_version,
617 &pre_sync_deletes_);
617 618
618 bool database_specified_a_default = (default_search_provider != NULL); 619 bool database_specified_a_default = (default_search_provider != NULL);
619 620
620 // Check if default search provider is now managed. 621 // Check if default search provider is now managed.
621 scoped_ptr<TemplateURL> default_from_prefs; 622 scoped_ptr<TemplateURL> default_from_prefs;
622 LoadDefaultSearchProviderFromPrefs(&default_from_prefs, 623 LoadDefaultSearchProviderFromPrefs(&default_from_prefs,
623 &is_default_search_managed_); 624 &is_default_search_managed_);
624 625
625 // Check if the default search provider has been changed in Web Data by 626 // Check if the default search provider has been changed in Web Data by
626 // another program. No immediate action is performed because the default 627 // another program. No immediate action is performed because the default
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
972 973
973 for (SyncDataMap::const_iterator iter = sync_data_map.begin(); 974 for (SyncDataMap::const_iterator iter = sync_data_map.begin();
974 iter != sync_data_map.end(); ++iter) { 975 iter != sync_data_map.end(); ++iter) {
975 TemplateURL* local_turl = GetTemplateURLForGUID(iter->first); 976 TemplateURL* local_turl = GetTemplateURLForGUID(iter->first);
976 scoped_ptr<TemplateURL> sync_turl( 977 scoped_ptr<TemplateURL> sync_turl(
977 CreateTemplateURLFromTemplateURLAndSyncData(profile_, local_turl, 978 CreateTemplateURLFromTemplateURLAndSyncData(profile_, local_turl,
978 iter->second, &new_changes)); 979 iter->second, &new_changes));
979 if (!sync_turl.get()) 980 if (!sync_turl.get())
980 continue; 981 continue;
981 982
983 if (pre_sync_deletes_.find(sync_turl->sync_guid()) !=
984 pre_sync_deletes_.end()) {
985 // This entry was deleted before the initial sync began (possibly through
986 // preprocessing in TemplateURLService's loading code). Ignore it and send
987 // an ACTION_DELETE up to the server.
988 new_changes.push_back(SyncChange(SyncChange::ACTION_DELETE,
989 iter->second));
990 continue;
991 }
992
982 if (local_turl) { 993 if (local_turl) {
983 // This local search engine is already synced. If the timestamp differs 994 // This local search engine is already synced. If the timestamp differs
984 // from Sync, we need to update locally or to the cloud. Note that if the 995 // from Sync, we need to update locally or to the cloud. Note that if the
985 // timestamps are equal, we touch neither. 996 // timestamps are equal, we touch neither.
986 if (sync_turl->last_modified() > local_turl->last_modified()) { 997 if (sync_turl->last_modified() > local_turl->last_modified()) {
987 // We've received an update from Sync. We should replace all synced 998 // We've received an update from Sync. We should replace all synced
988 // fields in the local TemplateURL. Note that this includes the 999 // fields in the local TemplateURL. Note that this includes the
989 // TemplateURLID and the TemplateURL may have to be reparsed. This 1000 // TemplateURLID and the TemplateURL may have to be reparsed. This
990 // also makes the local data's last_modified timestamp equal to Sync's, 1001 // also makes the local data's last_modified timestamp equal to Sync's,
991 // avoiding an Update on the next MergeData call. 1002 // avoiding an Update on the next MergeData call.
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1041 } 1052 }
1042 1053
1043 // Do some post-processing on the change list to ensure that we are sending 1054 // Do some post-processing on the change list to ensure that we are sending
1044 // valid changes to sync_processor_. 1055 // valid changes to sync_processor_.
1045 PruneSyncChanges(&sync_data_map, &new_changes); 1056 PruneSyncChanges(&sync_data_map, &new_changes);
1046 1057
1047 SyncError error = sync_processor_->ProcessSyncChanges(FROM_HERE, new_changes); 1058 SyncError error = sync_processor_->ProcessSyncChanges(FROM_HERE, new_changes);
1048 if (error.IsSet()) 1059 if (error.IsSet())
1049 return error; 1060 return error;
1050 1061
1062 // The ACTION_DELETEs from this set are processed. Empty it so we don't try to
1063 // reuse them on the next call to MergeDataAndStartSyncing.
1064 pre_sync_deletes_.clear();
1065
1051 models_associated_ = true; 1066 models_associated_ = true;
1052 return SyncError(); 1067 return SyncError();
1053 } 1068 }
1054 1069
1055 void TemplateURLService::StopSyncing(syncable::ModelType type) { 1070 void TemplateURLService::StopSyncing(syncable::ModelType type) {
1056 DCHECK_EQ(type, syncable::SEARCH_ENGINES); 1071 DCHECK_EQ(type, syncable::SEARCH_ENGINES);
1057 models_associated_ = false; 1072 models_associated_ = false;
1058 sync_processor_.reset(); 1073 sync_processor_.reset();
1059 sync_error_factory_.reset(); 1074 sync_error_factory_.reset();
1060 } 1075 }
(...skipping 1177 matching lines...) Expand 10 before | Expand all | Expand 10 after
2238 // TODO(mpcomplete): If we allow editing extension keywords, then those 2253 // TODO(mpcomplete): If we allow editing extension keywords, then those
2239 // should be persisted to disk and synced. 2254 // should be persisted to disk and synced.
2240 if (template_url->sync_guid().empty() && 2255 if (template_url->sync_guid().empty() &&
2241 !template_url->IsExtensionKeyword()) { 2256 !template_url->IsExtensionKeyword()) {
2242 template_url->data_.sync_guid = guid::GenerateGUID(); 2257 template_url->data_.sync_guid = guid::GenerateGUID();
2243 if (service_.get()) 2258 if (service_.get())
2244 service_->UpdateKeyword(template_url->data()); 2259 service_->UpdateKeyword(template_url->data());
2245 } 2260 }
2246 } 2261 }
2247 } 2262 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698