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

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

Issue 10690128: Reland r145993. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 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 | Annotate | Revision Log
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/guid.h" 10 #include "base/guid.h"
(...skipping 961 matching lines...) Expand 10 before | Expand all | Expand 10 after
972 // may try to continually delete the resurrected entry. 972 // may try to continually delete the resurrected entry.
973 string16 updated_keyword = UniquifyKeyword(*existing_turl, true); 973 string16 updated_keyword = UniquifyKeyword(*existing_turl, true);
974 TemplateURLData data(existing_turl->data()); 974 TemplateURLData data(existing_turl->data());
975 data.SetKeyword(updated_keyword); 975 data.SetKeyword(updated_keyword);
976 TemplateURL new_turl(existing_turl->profile(), data); 976 TemplateURL new_turl(existing_turl->profile(), data);
977 UIThreadSearchTermsData search_terms_data(existing_turl->profile()); 977 UIThreadSearchTermsData search_terms_data(existing_turl->profile());
978 if (UpdateNoNotify(existing_turl, new_turl, search_terms_data)) 978 if (UpdateNoNotify(existing_turl, new_turl, search_terms_data))
979 NotifyObservers(); 979 NotifyObservers();
980 980
981 syncer::SyncData sync_data = CreateSyncDataFromTemplateURL(new_turl); 981 syncer::SyncData sync_data = CreateSyncDataFromTemplateURL(new_turl);
982 new_changes.push_back( 982 new_changes.push_back(syncer::SyncChange(FROM_HERE,
983 syncer::SyncChange(syncer::SyncChange::ACTION_ADD, sync_data)); 983 syncer::SyncChange::ACTION_ADD,
984 sync_data));
984 // Ignore the delete attempt. This means we never end up reseting the 985 // Ignore the delete attempt. This means we never end up reseting the
985 // default search provider due to an ACTION_DELETE from sync. 986 // default search provider due to an ACTION_DELETE from sync.
986 continue; 987 continue;
987 } 988 }
988 989
989 Remove(existing_turl); 990 Remove(existing_turl);
990 } else if (iter->change_type() == syncer::SyncChange::ACTION_ADD) { 991 } else if (iter->change_type() == syncer::SyncChange::ACTION_ADD) {
991 if (existing_turl) { 992 if (existing_turl) {
992 NOTREACHED() << "Unexpected sync change state."; 993 NOTREACHED() << "Unexpected sync change state.";
993 error = sync_error_factory_->CreateAndUploadError( 994 error = sync_error_factory_->CreateAndUploadError(
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
1099 iter->second, &new_changes)); 1100 iter->second, &new_changes));
1100 if (!sync_turl.get()) 1101 if (!sync_turl.get())
1101 continue; 1102 continue;
1102 1103
1103 if (pre_sync_deletes_.find(sync_turl->sync_guid()) != 1104 if (pre_sync_deletes_.find(sync_turl->sync_guid()) !=
1104 pre_sync_deletes_.end()) { 1105 pre_sync_deletes_.end()) {
1105 // This entry was deleted before the initial sync began (possibly through 1106 // This entry was deleted before the initial sync began (possibly through
1106 // preprocessing in TemplateURLService's loading code). Ignore it and send 1107 // preprocessing in TemplateURLService's loading code). Ignore it and send
1107 // an ACTION_DELETE up to the server. 1108 // an ACTION_DELETE up to the server.
1108 new_changes.push_back( 1109 new_changes.push_back(
1109 syncer::SyncChange(syncer::SyncChange::ACTION_DELETE, 1110 syncer::SyncChange(FROM_HERE,
1111 syncer::SyncChange::ACTION_DELETE,
1110 iter->second)); 1112 iter->second));
1111 continue; 1113 continue;
1112 } 1114 }
1113 1115
1114 if (local_turl) { 1116 if (local_turl) {
1115 // This local search engine is already synced. If the timestamp differs 1117 // This local search engine is already synced. If the timestamp differs
1116 // from Sync, we need to update locally or to the cloud. Note that if the 1118 // from Sync, we need to update locally or to the cloud. Note that if the
1117 // timestamps are equal, we touch neither. 1119 // timestamps are equal, we touch neither.
1118 if (sync_turl->last_modified() > local_turl->last_modified()) { 1120 if (sync_turl->last_modified() > local_turl->last_modified()) {
1119 // We've received an update from Sync. We should replace all synced 1121 // We've received an update from Sync. We should replace all synced
1120 // fields in the local TemplateURL. Note that this includes the 1122 // fields in the local TemplateURL. Note that this includes the
1121 // TemplateURLID and the TemplateURL may have to be reparsed. This 1123 // TemplateURLID and the TemplateURL may have to be reparsed. This
1122 // also makes the local data's last_modified timestamp equal to Sync's, 1124 // also makes the local data's last_modified timestamp equal to Sync's,
1123 // avoiding an Update on the next MergeData call. 1125 // avoiding an Update on the next MergeData call.
1124 UIThreadSearchTermsData search_terms_data(local_turl->profile()); 1126 UIThreadSearchTermsData search_terms_data(local_turl->profile());
1125 if (UpdateNoNotify(local_turl, *sync_turl, search_terms_data)) 1127 if (UpdateNoNotify(local_turl, *sync_turl, search_terms_data))
1126 NotifyObservers(); 1128 NotifyObservers();
1127 } else if (sync_turl->last_modified() < local_turl->last_modified()) { 1129 } else if (sync_turl->last_modified() < local_turl->last_modified()) {
1128 // Otherwise, we know we have newer data, so update Sync with our 1130 // Otherwise, we know we have newer data, so update Sync with our
1129 // data fields. 1131 // data fields.
1130 new_changes.push_back( 1132 new_changes.push_back(
1131 syncer::SyncChange(syncer::SyncChange::ACTION_UPDATE, 1133 syncer::SyncChange(FROM_HERE,
1132 local_data_map[local_turl->sync_guid()])); 1134 syncer::SyncChange::ACTION_UPDATE,
1135 local_data_map[local_turl->sync_guid()]));
1133 } 1136 }
1134 local_data_map.erase(iter->first); 1137 local_data_map.erase(iter->first);
1135 } else { 1138 } else {
1136 // The search engine from the cloud has not been synced locally, but there 1139 // The search engine from the cloud has not been synced locally, but there
1137 // might be a local search engine that is a duplicate that needs to be 1140 // might be a local search engine that is a duplicate that needs to be
1138 // merged. 1141 // merged.
1139 TemplateURL* dupe_turl = FindDuplicateOfSyncTemplateURL(*sync_turl); 1142 TemplateURL* dupe_turl = FindDuplicateOfSyncTemplateURL(*sync_turl);
1140 if (dupe_turl) { 1143 if (dupe_turl) {
1141 // Merge duplicates and remove the processed local TURL from the map. 1144 // Merge duplicates and remove the processed local TURL from the map.
1142 std::string old_guid = dupe_turl->sync_guid(); 1145 std::string old_guid = dupe_turl->sync_guid();
(...skipping 21 matching lines...) Expand all
1164 } 1167 }
1165 } 1168 }
1166 } 1169 }
1167 } 1170 }
1168 1171
1169 // The remaining SyncData in local_data_map should be everything that needs to 1172 // The remaining SyncData in local_data_map should be everything that needs to
1170 // be pushed as ADDs to sync. 1173 // be pushed as ADDs to sync.
1171 for (SyncDataMap::const_iterator iter = local_data_map.begin(); 1174 for (SyncDataMap::const_iterator iter = local_data_map.begin();
1172 iter != local_data_map.end(); ++iter) { 1175 iter != local_data_map.end(); ++iter) {
1173 new_changes.push_back( 1176 new_changes.push_back(
1174 syncer::SyncChange(syncer::SyncChange::ACTION_ADD, iter->second)); 1177 syncer::SyncChange(FROM_HERE,
1178 syncer::SyncChange::ACTION_ADD,
1179 iter->second));
1175 } 1180 }
1176 1181
1177 // Do some post-processing on the change list to ensure that we are sending 1182 // Do some post-processing on the change list to ensure that we are sending
1178 // valid changes to sync_processor_. 1183 // valid changes to sync_processor_.
1179 PruneSyncChanges(&sync_data_map, &new_changes); 1184 PruneSyncChanges(&sync_data_map, &new_changes);
1180 1185
1181 syncer::SyncError error = 1186 syncer::SyncError error =
1182 sync_processor_->ProcessSyncChanges(FROM_HERE, new_changes); 1187 sync_processor_->ProcessSyncChanges(FROM_HERE, new_changes);
1183 if (error.IsSet()) 1188 if (error.IsSet())
1184 return error; 1189 return error;
1185 1190
1186 // The ACTION_DELETEs from this set are processed. Empty it so we don't try to 1191 // The ACTION_DELETEs from this set are processed. Empty it so we don't try to
1187 // reuse them on the next call to MergeDataAndStartSyncing. 1192 // reuse them on the next call to MergeDataAndStartSyncing.
1188 pre_sync_deletes_.clear(); 1193 pre_sync_deletes_.clear();
1189 1194
1190 models_associated_ = true; 1195 models_associated_ = true;
1191 return syncer::SyncError(); 1196 return syncer::SyncError();
1192 } 1197 }
1193 1198
1194 void TemplateURLService::StopSyncing(syncer::ModelType type) { 1199 void TemplateURLService::StopSyncing(syncer::ModelType type) {
1195 DCHECK_EQ(type, syncer::SEARCH_ENGINES); 1200 DCHECK_EQ(type, syncer::SEARCH_ENGINES);
1196 models_associated_ = false; 1201 models_associated_ = false;
1197 sync_processor_.reset(); 1202 sync_processor_.reset();
1198 sync_error_factory_.reset(); 1203 sync_error_factory_.reset();
1199 } 1204 }
1200 1205
1201 void TemplateURLService::ProcessTemplateURLChange( 1206 void TemplateURLService::ProcessTemplateURLChange(
1207 const tracked_objects::Location& from_here,
1202 const TemplateURL* turl, 1208 const TemplateURL* turl,
1203 syncer::SyncChange::SyncChangeType type) { 1209 syncer::SyncChange::SyncChangeType type) {
1204 DCHECK_NE(type, syncer::SyncChange::ACTION_INVALID); 1210 DCHECK_NE(type, syncer::SyncChange::ACTION_INVALID);
1205 DCHECK(turl); 1211 DCHECK(turl);
1206 1212
1207 if (!models_associated_) 1213 if (!models_associated_)
1208 return; // Not syncing. 1214 return; // Not syncing.
1209 1215
1210 if (processing_syncer_changes_) 1216 if (processing_syncer_changes_)
1211 return; // These are changes originating from us. Ignore. 1217 return; // These are changes originating from us. Ignore.
1212 1218
1213 // Avoid syncing Extension keywords. 1219 // Avoid syncing Extension keywords.
1214 // TODO(mpcomplete): If we allow editing extension keywords, then those should 1220 // TODO(mpcomplete): If we allow editing extension keywords, then those should
1215 // be persisted to disk and synced. 1221 // be persisted to disk and synced.
1216 if (turl->IsExtensionKeyword()) 1222 if (turl->IsExtensionKeyword())
1217 return; 1223 return;
1218 1224
1219 // Avoid syncing keywords managed by policy. 1225 // Avoid syncing keywords managed by policy.
1220 if (turl->created_by_policy()) 1226 if (turl->created_by_policy())
1221 return; 1227 return;
1222 1228
1223 syncer::SyncChangeList changes; 1229 syncer::SyncChangeList changes;
1224 1230
1225 syncer::SyncData sync_data = CreateSyncDataFromTemplateURL(*turl); 1231 syncer::SyncData sync_data = CreateSyncDataFromTemplateURL(*turl);
1226 changes.push_back(syncer::SyncChange(type, sync_data)); 1232 changes.push_back(syncer::SyncChange(from_here,
1233 type,
1234 sync_data));
1227 1235
1228 sync_processor_->ProcessSyncChanges(FROM_HERE, changes); 1236 sync_processor_->ProcessSyncChanges(FROM_HERE, changes);
1229 } 1237 }
1230 1238
1231 // static 1239 // static
1232 syncer::SyncData TemplateURLService::CreateSyncDataFromTemplateURL( 1240 syncer::SyncData TemplateURLService::CreateSyncDataFromTemplateURL(
1233 const TemplateURL& turl) { 1241 const TemplateURL& turl) {
1234 sync_pb::EntitySpecifics specifics; 1242 sync_pb::EntitySpecifics specifics;
1235 sync_pb::SearchEngineSpecifics* se_specifics = 1243 sync_pb::SearchEngineSpecifics* se_specifics =
1236 specifics.mutable_search_engine(); 1244 specifics.mutable_search_engine();
(...skipping 24 matching lines...) Expand all
1261 syncer::SyncChangeList* change_list) { 1269 syncer::SyncChangeList* change_list) {
1262 DCHECK(change_list); 1270 DCHECK(change_list);
1263 1271
1264 sync_pb::SearchEngineSpecifics specifics = 1272 sync_pb::SearchEngineSpecifics specifics =
1265 sync_data.GetSpecifics().search_engine(); 1273 sync_data.GetSpecifics().search_engine();
1266 1274
1267 // Past bugs might have caused either of these fields to be empty. Just 1275 // Past bugs might have caused either of these fields to be empty. Just
1268 // delete this data off the server. 1276 // delete this data off the server.
1269 if (specifics.url().empty() || specifics.sync_guid().empty()) { 1277 if (specifics.url().empty() || specifics.sync_guid().empty()) {
1270 change_list->push_back( 1278 change_list->push_back(
1271 syncer::SyncChange(syncer::SyncChange::ACTION_DELETE, sync_data)); 1279 syncer::SyncChange(FROM_HERE,
1280 syncer::SyncChange::ACTION_DELETE,
1281 sync_data));
1272 return NULL; 1282 return NULL;
1273 } 1283 }
1274 1284
1275 TemplateURLData data(existing_turl ? 1285 TemplateURLData data(existing_turl ?
1276 existing_turl->data() : TemplateURLData()); 1286 existing_turl->data() : TemplateURLData());
1277 data.short_name = UTF8ToUTF16(specifics.short_name()); 1287 data.short_name = UTF8ToUTF16(specifics.short_name());
1278 data.originating_url = GURL(specifics.originating_url()); 1288 data.originating_url = GURL(specifics.originating_url());
1279 string16 keyword(UTF8ToUTF16(specifics.keyword())); 1289 string16 keyword(UTF8ToUTF16(specifics.keyword()));
1280 // NOTE: Once this code has shipped in a couple of stable releases, we can 1290 // NOTE: Once this code has shipped in a couple of stable releases, we can
1281 // probably remove the migration portion, comment out the 1291 // probably remove the migration portion, comment out the
(...skipping 22 matching lines...) Expand all
1304 data.prepopulate_id = specifics.prepopulate_id(); 1314 data.prepopulate_id = specifics.prepopulate_id();
1305 data.sync_guid = specifics.sync_guid(); 1315 data.sync_guid = specifics.sync_guid();
1306 1316
1307 TemplateURL* turl = new TemplateURL(profile, data); 1317 TemplateURL* turl = new TemplateURL(profile, data);
1308 DCHECK(!turl->IsExtensionKeyword()); 1318 DCHECK(!turl->IsExtensionKeyword());
1309 if (reset_keyword || deduped) { 1319 if (reset_keyword || deduped) {
1310 if (reset_keyword) 1320 if (reset_keyword)
1311 turl->ResetKeywordIfNecessary(true); 1321 turl->ResetKeywordIfNecessary(true);
1312 syncer::SyncData sync_data = CreateSyncDataFromTemplateURL(*turl); 1322 syncer::SyncData sync_data = CreateSyncDataFromTemplateURL(*turl);
1313 change_list->push_back( 1323 change_list->push_back(
1314 syncer::SyncChange(syncer::SyncChange::ACTION_UPDATE, sync_data)); 1324 syncer::SyncChange(FROM_HERE,
1325 syncer::SyncChange::ACTION_UPDATE,
1326 sync_data));
1315 } else if (turl->IsGoogleSearchURLWithReplaceableKeyword()) { 1327 } else if (turl->IsGoogleSearchURLWithReplaceableKeyword()) {
1316 if (!existing_turl) { 1328 if (!existing_turl) {
1317 // We're adding a new TemplateURL that uses the Google base URL, so set 1329 // We're adding a new TemplateURL that uses the Google base URL, so set
1318 // its keyword appropriately for the local environment. 1330 // its keyword appropriately for the local environment.
1319 turl->ResetKeywordIfNecessary(false); 1331 turl->ResetKeywordIfNecessary(false);
1320 } else if (existing_turl->IsGoogleSearchURLWithReplaceableKeyword()) { 1332 } else if (existing_turl->IsGoogleSearchURLWithReplaceableKeyword()) {
1321 // Ignore keyword changes triggered by the Google base URL changing on 1333 // Ignore keyword changes triggered by the Google base URL changing on
1322 // another client. If the base URL changes in this client as well, we'll 1334 // another client. If the base URL changes in this client as well, we'll
1323 // pick that up separately at the appropriate time. Otherwise, changing 1335 // pick that up separately at the appropriate time. Otherwise, changing
1324 // the keyword here could result in having the wrong keyword for the local 1336 // the keyword here could result in having the wrong keyword for the local
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
1760 } 1772 }
1761 } 1773 }
1762 } 1774 }
1763 if (!existing_turl->sync_guid().empty()) 1775 if (!existing_turl->sync_guid().empty())
1764 guid_to_template_map_[existing_turl->sync_guid()] = existing_turl; 1776 guid_to_template_map_[existing_turl->sync_guid()] = existing_turl;
1765 1777
1766 if (service_.get()) 1778 if (service_.get())
1767 service_->UpdateKeyword(existing_turl->data()); 1779 service_->UpdateKeyword(existing_turl->data());
1768 1780
1769 // Inform sync of the update. 1781 // Inform sync of the update.
1770 ProcessTemplateURLChange(existing_turl, syncer::SyncChange::ACTION_UPDATE); 1782 ProcessTemplateURLChange(FROM_HERE,
1783 existing_turl,
1784 syncer::SyncChange::ACTION_UPDATE);
1771 1785
1772 if (default_search_provider_ == existing_turl) { 1786 if (default_search_provider_ == existing_turl) {
1773 bool success = SetDefaultSearchProviderNoNotify(existing_turl); 1787 bool success = SetDefaultSearchProviderNoNotify(existing_turl);
1774 DCHECK(success); 1788 DCHECK(success);
1775 } 1789 }
1776 return true; 1790 return true;
1777 } 1791 }
1778 1792
1779 PrefService* TemplateURLService::GetPrefs() { 1793 PrefService* TemplateURLService::GetPrefs() {
1780 return profile_ ? profile_->GetPrefs() : NULL; 1794 return profile_ ? profile_->GetPrefs() : NULL;
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
2091 GetPrefs()->SetString(prefs::kSyncedDefaultSearchProviderGUID, 2105 GetPrefs()->SetString(prefs::kSyncedDefaultSearchProviderGUID,
2092 url->sync_guid()); 2106 url->sync_guid());
2093 } 2107 }
2094 } 2108 }
2095 2109
2096 if (service_.get()) 2110 if (service_.get())
2097 service_->SetDefaultSearchProvider(url); 2111 service_->SetDefaultSearchProvider(url);
2098 2112
2099 // Inform sync the change to the show_in_default_list flag. 2113 // Inform sync the change to the show_in_default_list flag.
2100 if (url) 2114 if (url)
2101 ProcessTemplateURLChange(url, syncer::SyncChange::ACTION_UPDATE); 2115 ProcessTemplateURLChange(FROM_HERE,
2116 url,
2117 syncer::SyncChange::ACTION_UPDATE);
2102 return true; 2118 return true;
2103 } 2119 }
2104 2120
2105 bool TemplateURLService::AddNoNotify(TemplateURL* template_url, 2121 bool TemplateURLService::AddNoNotify(TemplateURL* template_url,
2106 bool newly_adding) { 2122 bool newly_adding) {
2107 DCHECK(template_url); 2123 DCHECK(template_url);
2108 2124
2109 if (newly_adding) { 2125 if (newly_adding) {
2110 DCHECK_EQ(kInvalidTemplateURLID, template_url->id()); 2126 DCHECK_EQ(kInvalidTemplateURLID, template_url->id());
2111 DCHECK(std::find(template_urls_.begin(), template_urls_.end(), 2127 DCHECK(std::find(template_urls_.begin(), template_urls_.end(),
(...skipping 28 matching lines...) Expand all
2140 if (newly_adding) { 2156 if (newly_adding) {
2141 // Don't persist extension keywords to disk. They'll get re-added on each 2157 // Don't persist extension keywords to disk. They'll get re-added on each
2142 // launch as the extensions are loaded. 2158 // launch as the extensions are loaded.
2143 // TODO(mpcomplete): If we allow editing extension keywords, then those 2159 // TODO(mpcomplete): If we allow editing extension keywords, then those
2144 // should be persisted to disk and synced. 2160 // should be persisted to disk and synced.
2145 if (service_.get() && !template_url->IsExtensionKeyword()) 2161 if (service_.get() && !template_url->IsExtensionKeyword())
2146 service_->AddKeyword(template_url->data()); 2162 service_->AddKeyword(template_url->data());
2147 2163
2148 // Inform sync of the addition. Note that this will assign a GUID to 2164 // Inform sync of the addition. Note that this will assign a GUID to
2149 // template_url and add it to the guid_to_template_map_. 2165 // template_url and add it to the guid_to_template_map_.
2150 ProcessTemplateURLChange(template_url, syncer::SyncChange::ACTION_ADD); 2166 ProcessTemplateURLChange(FROM_HERE,
2167 template_url,
2168 syncer::SyncChange::ACTION_ADD);
2151 } 2169 }
2152 2170
2153 return true; 2171 return true;
2154 } 2172 }
2155 2173
2156 void TemplateURLService::RemoveNoNotify(TemplateURL* template_url) { 2174 void TemplateURLService::RemoveNoNotify(TemplateURL* template_url) {
2157 TemplateURLVector::iterator i = 2175 TemplateURLVector::iterator i =
2158 std::find(template_urls_.begin(), template_urls_.end(), template_url); 2176 std::find(template_urls_.begin(), template_urls_.end(), template_url);
2159 if (i == template_urls_.end()) 2177 if (i == template_urls_.end())
2160 return; 2178 return;
2161 2179
2162 if (template_url == default_search_provider_) { 2180 if (template_url == default_search_provider_) {
2163 // Should never delete the default search provider. 2181 // Should never delete the default search provider.
2164 NOTREACHED(); 2182 NOTREACHED();
2165 return; 2183 return;
2166 } 2184 }
2167 2185
2168 RemoveFromMaps(template_url); 2186 RemoveFromMaps(template_url);
2169 2187
2170 // Remove it from the vector containing all TemplateURLs. 2188 // Remove it from the vector containing all TemplateURLs.
2171 template_urls_.erase(i); 2189 template_urls_.erase(i);
2172 2190
2173 // Extension keywords are not persisted. 2191 // Extension keywords are not persisted.
2174 // TODO(mpcomplete): If we allow editing extension keywords, then those should 2192 // TODO(mpcomplete): If we allow editing extension keywords, then those should
2175 // be persisted to disk and synced. 2193 // be persisted to disk and synced.
2176 if (service_.get() && !template_url->IsExtensionKeyword()) 2194 if (service_.get() && !template_url->IsExtensionKeyword())
2177 service_->RemoveKeyword(template_url->id()); 2195 service_->RemoveKeyword(template_url->id());
2178 2196
2179 // Inform sync of the deletion. 2197 // Inform sync of the deletion.
2180 ProcessTemplateURLChange(template_url, syncer::SyncChange::ACTION_DELETE); 2198 ProcessTemplateURLChange(FROM_HERE,
2199 template_url,
2200 syncer::SyncChange::ACTION_DELETE);
2181 2201
2182 if (profile_) { 2202 if (profile_) {
2183 content::Source<Profile> source(profile_); 2203 content::Source<Profile> source(profile_);
2184 TemplateURLID id = template_url->id(); 2204 TemplateURLID id = template_url->id();
2185 content::NotificationService::current()->Notify( 2205 content::NotificationService::current()->Notify(
2186 chrome::NOTIFICATION_TEMPLATE_URL_REMOVED, 2206 chrome::NOTIFICATION_TEMPLATE_URL_REMOVED,
2187 source, 2207 source,
2188 content::Details<TemplateURLID>(&id)); 2208 content::Details<TemplateURLID>(&id));
2189 } 2209 }
2190 2210
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
2300 DCHECK(!local_turl->IsExtensionKeyword()); 2320 DCHECK(!local_turl->IsExtensionKeyword());
2301 DCHECK(change_list); 2321 DCHECK(change_list);
2302 2322
2303 const bool local_is_better = 2323 const bool local_is_better =
2304 (local_turl->last_modified() > sync_turl->last_modified()) || 2324 (local_turl->last_modified() > sync_turl->last_modified()) ||
2305 local_turl->created_by_policy() || 2325 local_turl->created_by_policy() ||
2306 (local_turl == GetDefaultSearchProvider()); 2326 (local_turl == GetDefaultSearchProvider());
2307 const bool can_replace_local = CanReplace(local_turl); 2327 const bool can_replace_local = CanReplace(local_turl);
2308 if (CanReplace(sync_turl) && (local_is_better || !can_replace_local)) { 2328 if (CanReplace(sync_turl) && (local_is_better || !can_replace_local)) {
2309 syncer::SyncData sync_data = CreateSyncDataFromTemplateURL(*sync_turl); 2329 syncer::SyncData sync_data = CreateSyncDataFromTemplateURL(*sync_turl);
2310 change_list->push_back( 2330 change_list->push_back(syncer::SyncChange(FROM_HERE,
2311 syncer::SyncChange(syncer::SyncChange::ACTION_DELETE, sync_data)); 2331 syncer::SyncChange::ACTION_DELETE,
2332 sync_data));
2312 return false; 2333 return false;
2313 } 2334 }
2314 if (can_replace_local) { 2335 if (can_replace_local) {
2315 // Since we're processing sync changes, the upcoming Remove() won't generate 2336 // Since we're processing sync changes, the upcoming Remove() won't generate
2316 // an ACTION_DELETE. We need to do it manually to keep the server in sync 2337 // an ACTION_DELETE. We need to do it manually to keep the server in sync
2317 // with us. Note that if we're being called from 2338 // with us. Note that if we're being called from
2318 // MergeDataAndStartSyncing(), and this TemplateURL was pre-existing rather 2339 // MergeDataAndStartSyncing(), and this TemplateURL was pre-existing rather
2319 // than having just been brought down, then this is wrong, because the 2340 // than having just been brought down, then this is wrong, because the
2320 // server doesn't yet know about this entity; but in this case, 2341 // server doesn't yet know about this entity; but in this case,
2321 // PruneSyncChanges() will prune out the ACTION_DELETE we create here. 2342 // PruneSyncChanges() will prune out the ACTION_DELETE we create here.
2322 syncer::SyncData sync_data = CreateSyncDataFromTemplateURL(*local_turl); 2343 syncer::SyncData sync_data = CreateSyncDataFromTemplateURL(*local_turl);
2323 change_list->push_back( 2344 change_list->push_back(syncer::SyncChange(FROM_HERE,
2324 syncer::SyncChange(syncer::SyncChange::ACTION_DELETE, sync_data)); 2345 syncer::SyncChange::ACTION_DELETE,
2346 sync_data));
2325 Remove(local_turl); 2347 Remove(local_turl);
2326 } else if (local_is_better) { 2348 } else if (local_is_better) {
2327 string16 new_keyword = UniquifyKeyword(*sync_turl, false); 2349 string16 new_keyword = UniquifyKeyword(*sync_turl, false);
2328 DCHECK(!GetTemplateURLForKeyword(new_keyword)); 2350 DCHECK(!GetTemplateURLForKeyword(new_keyword));
2329 sync_turl->data_.SetKeyword(new_keyword); 2351 sync_turl->data_.SetKeyword(new_keyword);
2330 // If we update the cloud TURL, we need to push an update back to sync 2352 // If we update the cloud TURL, we need to push an update back to sync
2331 // informing it that something has changed. 2353 // informing it that something has changed.
2332 syncer::SyncData sync_data = CreateSyncDataFromTemplateURL(*sync_turl); 2354 syncer::SyncData sync_data = CreateSyncDataFromTemplateURL(*sync_turl);
2333 change_list->push_back( 2355 change_list->push_back(syncer::SyncChange(FROM_HERE,
2334 syncer::SyncChange(syncer::SyncChange::ACTION_UPDATE, sync_data)); 2356 syncer::SyncChange::ACTION_UPDATE,
2357 sync_data));
2335 } else { 2358 } else {
2336 string16 new_keyword = UniquifyKeyword(*local_turl, false); 2359 string16 new_keyword = UniquifyKeyword(*local_turl, false);
2337 TemplateURLData data(local_turl->data()); 2360 TemplateURLData data(local_turl->data());
2338 data.SetKeyword(new_keyword); 2361 data.SetKeyword(new_keyword);
2339 TemplateURL new_turl(local_turl->profile(), data); 2362 TemplateURL new_turl(local_turl->profile(), data);
2340 UIThreadSearchTermsData search_terms_data(local_turl->profile()); 2363 UIThreadSearchTermsData search_terms_data(local_turl->profile());
2341 if (UpdateNoNotify(local_turl, new_turl, search_terms_data)) 2364 if (UpdateNoNotify(local_turl, new_turl, search_terms_data))
2342 NotifyObservers(); 2365 NotifyObservers();
2343 // Since we're processing sync changes, the UpdateNoNotify() above didn't 2366 // Since we're processing sync changes, the UpdateNoNotify() above didn't
2344 // generate an ACTION_UPDATE. We need to do it manually to keep the server 2367 // generate an ACTION_UPDATE. We need to do it manually to keep the server
2345 // in sync with us. Note that if we're being called from 2368 // in sync with us. Note that if we're being called from
2346 // MergeDataAndStartSyncing(), and this TemplateURL was pre-existing rather 2369 // MergeDataAndStartSyncing(), and this TemplateURL was pre-existing rather
2347 // than having just been brought down, then this is wrong, because the 2370 // than having just been brought down, then this is wrong, because the
2348 // server won't know about this entity until it processes the ACTION_ADD our 2371 // server won't know about this entity until it processes the ACTION_ADD our
2349 // caller will later generate; but in this case, PruneSyncChanges() will 2372 // caller will later generate; but in this case, PruneSyncChanges() will
2350 // prune out the ACTION_UPDATE we create here. 2373 // prune out the ACTION_UPDATE we create here.
2351 syncer::SyncData sync_data = CreateSyncDataFromTemplateURL(*local_turl); 2374 syncer::SyncData sync_data = CreateSyncDataFromTemplateURL(*local_turl);
2352 change_list->push_back( 2375 change_list->push_back(syncer::SyncChange(FROM_HERE,
2353 syncer::SyncChange(syncer::SyncChange::ACTION_UPDATE, sync_data)); 2376 syncer::SyncChange::ACTION_UPDATE,
2377 sync_data));
2354 } 2378 }
2355 return true; 2379 return true;
2356 } 2380 }
2357 2381
2358 TemplateURL* TemplateURLService::FindDuplicateOfSyncTemplateURL( 2382 TemplateURL* TemplateURLService::FindDuplicateOfSyncTemplateURL(
2359 const TemplateURL& sync_turl) { 2383 const TemplateURL& sync_turl) {
2360 TemplateURL* existing_turl = GetTemplateURLForKeyword(sync_turl.keyword()); 2384 TemplateURL* existing_turl = GetTemplateURLForKeyword(sync_turl.keyword());
2361 return existing_turl && (existing_turl->url() == sync_turl.url()) ? 2385 return existing_turl && (existing_turl->url() == sync_turl.url()) ?
2362 existing_turl : NULL; 2386 existing_turl : NULL;
2363 } 2387 }
(...skipping 13 matching lines...) Expand all
2377 // TemplateURLID. We don't need to sync the new ID back to the server since 2401 // TemplateURLID. We don't need to sync the new ID back to the server since
2378 // it's only relevant locally. 2402 // it's only relevant locally.
2379 bool delete_default = (local_turl == GetDefaultSearchProvider()); 2403 bool delete_default = (local_turl == GetDefaultSearchProvider());
2380 DCHECK(!delete_default || !is_default_search_managed_); 2404 DCHECK(!delete_default || !is_default_search_managed_);
2381 if (delete_default) 2405 if (delete_default)
2382 default_search_provider_ = NULL; 2406 default_search_provider_ = NULL;
2383 2407
2384 // See comments in ResolveSyncKeywordConflict() regarding generating an 2408 // See comments in ResolveSyncKeywordConflict() regarding generating an
2385 // ACTION_DELETE manually since Remove() won't do it. 2409 // ACTION_DELETE manually since Remove() won't do it.
2386 syncer::SyncData sync_data = CreateSyncDataFromTemplateURL(*local_turl); 2410 syncer::SyncData sync_data = CreateSyncDataFromTemplateURL(*local_turl);
2387 change_list->push_back( 2411 change_list->push_back(syncer::SyncChange(FROM_HERE,
2388 syncer::SyncChange(syncer::SyncChange::ACTION_DELETE, sync_data)); 2412 syncer::SyncChange::ACTION_DELETE,
2413 sync_data));
2389 Remove(local_turl); 2414 Remove(local_turl);
2390 2415
2391 // Force the local ID to kInvalidTemplateURLID so we can add it. 2416 // Force the local ID to kInvalidTemplateURLID so we can add it.
2392 sync_turl->data_.id = kInvalidTemplateURLID; 2417 sync_turl->data_.id = kInvalidTemplateURLID;
2393 Add(scoped_sync_turl.release()); 2418 Add(scoped_sync_turl.release());
2394 if (delete_default) 2419 if (delete_default)
2395 SetDefaultSearchProvider(sync_turl); 2420 SetDefaultSearchProvider(sync_turl);
2396 } else { 2421 } else {
2397 // Change the local TURL's GUID to the server's GUID and push an update to 2422 // Change the local TURL's GUID to the server's GUID and push an update to
2398 // Sync. This ensures that the rest of local_url's fields are sync'd up to 2423 // Sync. This ensures that the rest of local_url's fields are sync'd up to
2399 // the server, and the next time local_url is synced, it is recognized by 2424 // the server, and the next time local_url is synced, it is recognized by
2400 // having the same GUID. 2425 // having the same GUID.
2401 ResetTemplateURLGUID(local_turl, sync_turl->sync_guid()); 2426 ResetTemplateURLGUID(local_turl, sync_turl->sync_guid());
2402 syncer::SyncData sync_data = CreateSyncDataFromTemplateURL(*local_turl); 2427 syncer::SyncData sync_data = CreateSyncDataFromTemplateURL(*local_turl);
2403 change_list->push_back( 2428 change_list->push_back(syncer::SyncChange(FROM_HERE,
2404 syncer::SyncChange(syncer::SyncChange::ACTION_UPDATE, sync_data)); 2429 syncer::SyncChange::ACTION_UPDATE,
2430 sync_data));
2405 } 2431 }
2406 } 2432 }
2407 2433
2408 void TemplateURLService::SetDefaultSearchProviderIfNewlySynced( 2434 void TemplateURLService::SetDefaultSearchProviderIfNewlySynced(
2409 const std::string& guid) { 2435 const std::string& guid) {
2410 // If we're not syncing or if default search is managed by policy, ignore. 2436 // If we're not syncing or if default search is managed by policy, ignore.
2411 if (!sync_processor_.get() || is_default_search_managed_) 2437 if (!sync_processor_.get() || is_default_search_managed_)
2412 return; 2438 return;
2413 2439
2414 PrefService* prefs = GetPrefs(); 2440 PrefService* prefs = GetPrefs();
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
2447 // TODO(mpcomplete): If we allow editing extension keywords, then those 2473 // TODO(mpcomplete): If we allow editing extension keywords, then those
2448 // should be persisted to disk and synced. 2474 // should be persisted to disk and synced.
2449 if (template_url->sync_guid().empty() && 2475 if (template_url->sync_guid().empty() &&
2450 !template_url->IsExtensionKeyword()) { 2476 !template_url->IsExtensionKeyword()) {
2451 template_url->data_.sync_guid = base::GenerateGUID(); 2477 template_url->data_.sync_guid = base::GenerateGUID();
2452 if (service_.get()) 2478 if (service_.get())
2453 service_->UpdateKeyword(template_url->data()); 2479 service_->UpdateKeyword(template_url->data());
2454 } 2480 }
2455 } 2481 }
2456 } 2482 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698