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

Side by Side Diff: components/search_engines/template_url_service.cc

Issue 684493002: Don't persist and sync omnibox extension keywords. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nit Created 6 years, 1 month 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 646 matching lines...) Expand 10 before | Expand all | Expand 10 after
657 AddExtensionControlledTURL(url, info.Pass()); 657 AddExtensionControlledTURL(url, info.Pass());
658 } 658 }
659 659
660 TemplateURLService::TemplateURLVector TemplateURLService::GetTemplateURLs() { 660 TemplateURLService::TemplateURLVector TemplateURLService::GetTemplateURLs() {
661 return template_urls_; 661 return template_urls_;
662 } 662 }
663 663
664 void TemplateURLService::IncrementUsageCount(TemplateURL* url) { 664 void TemplateURLService::IncrementUsageCount(TemplateURL* url) {
665 DCHECK(url); 665 DCHECK(url);
666 // Extension-controlled search engines are not persisted. 666 // Extension-controlled search engines are not persisted.
667 if (url->GetType() == TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION) 667 if (url->GetType() != TemplateURL::NORMAL)
668 return; 668 return;
669 if (std::find(template_urls_.begin(), template_urls_.end(), url) == 669 if (std::find(template_urls_.begin(), template_urls_.end(), url) ==
670 template_urls_.end()) 670 template_urls_.end())
671 return; 671 return;
672 ++url->data_.usage_count; 672 ++url->data_.usage_count;
673 673
674 if (web_data_service_.get()) 674 if (web_data_service_.get())
675 web_data_service_->UpdateKeyword(url->data()); 675 web_data_service_->UpdateKeyword(url->data());
676 } 676 }
677 677
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
863 prefs_, 863 prefs_,
864 &template_urls, 864 &template_urls,
865 (default_search_provider_source_ == DefaultSearchManager::FROM_USER) 865 (default_search_provider_source_ == DefaultSearchManager::FROM_USER)
866 ? initial_default_search_provider_.get() 866 ? initial_default_search_provider_.get()
867 : NULL, 867 : NULL,
868 search_terms_data(), 868 search_terms_data(),
869 &new_resource_keyword_version, 869 &new_resource_keyword_version,
870 &pre_sync_deletes_); 870 &pre_sync_deletes_);
871 } 871 }
872 872
873 if (client_) {
874 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422460 is fixed.
875 tracked_objects::ScopedTracker tracking_profile3(
876 FROM_HERE_WITH_EXPLICIT_FUNCTION(
877 "422460 TemplateURLService::OnWebDataServiceRequestDone 3"));
878
879 // Restore extension info of loaded TemplateURLs.
880 for (size_t i = 0; i < template_urls.size(); ++i) {
881 DCHECK(!template_urls[i]->extension_info_);
882 client_->RestoreExtensionInfoIfNecessary(template_urls[i]);
883 }
884 }
885
886 KeywordWebDataService::BatchModeScoper scoper(web_data_service_.get()); 873 KeywordWebDataService::BatchModeScoper scoper(web_data_service_.get());
887 874
888 { 875 {
889 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422460 is fixed. 876 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422460 is fixed.
890 tracked_objects::ScopedTracker tracking_profile4( 877 tracked_objects::ScopedTracker tracking_profile4(
891 FROM_HERE_WITH_EXPLICIT_FUNCTION( 878 FROM_HERE_WITH_EXPLICIT_FUNCTION(
892 "422460 TemplateURLService::OnWebDataServiceRequestDone 4")); 879 "422460 TemplateURLService::OnWebDataServiceRequestDone 4"));
893 880
894 PatchMissingSyncGUIDs(&template_urls); 881 PatchMissingSyncGUIDs(&template_urls);
895 882
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
992 syncer::ModelType type) const { 979 syncer::ModelType type) const {
993 DCHECK_EQ(syncer::SEARCH_ENGINES, type); 980 DCHECK_EQ(syncer::SEARCH_ENGINES, type);
994 981
995 syncer::SyncDataList current_data; 982 syncer::SyncDataList current_data;
996 for (TemplateURLVector::const_iterator iter = template_urls_.begin(); 983 for (TemplateURLVector::const_iterator iter = template_urls_.begin();
997 iter != template_urls_.end(); ++iter) { 984 iter != template_urls_.end(); ++iter) {
998 // We don't sync keywords managed by policy. 985 // We don't sync keywords managed by policy.
999 if ((*iter)->created_by_policy()) 986 if ((*iter)->created_by_policy())
1000 continue; 987 continue;
1001 // We don't sync extension-controlled search engines. 988 // We don't sync extension-controlled search engines.
1002 if ((*iter)->GetType() == TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION) 989 if ((*iter)->GetType() != TemplateURL::NORMAL)
1003 continue; 990 continue;
1004 current_data.push_back(CreateSyncDataFromTemplateURL(**iter)); 991 current_data.push_back(CreateSyncDataFromTemplateURL(**iter));
1005 } 992 }
1006 993
1007 return current_data; 994 return current_data;
1008 } 995 }
1009 996
1010 syncer::SyncError TemplateURLService::ProcessSyncChanges( 997 syncer::SyncError TemplateURLService::ProcessSyncChanges(
1011 const tracked_objects::Location& from_here, 998 const tracked_objects::Location& from_here,
1012 const syncer::SyncChangeList& change_list) { 999 const syncer::SyncChangeList& change_list) {
(...skipping 12 matching lines...) Expand all
1025 // As we move through Sync Code, we may set this to increasingly specific 1012 // As we move through Sync Code, we may set this to increasingly specific
1026 // origins so we can tell what exactly caused a DSP change. 1013 // origins so we can tell what exactly caused a DSP change.
1027 base::AutoReset<DefaultSearchChangeOrigin> change_origin(&dsp_change_origin_, 1014 base::AutoReset<DefaultSearchChangeOrigin> change_origin(&dsp_change_origin_,
1028 DSP_CHANGE_SYNC_UNINTENTIONAL); 1015 DSP_CHANGE_SYNC_UNINTENTIONAL);
1029 1016
1030 KeywordWebDataService::BatchModeScoper scoper(web_data_service_.get()); 1017 KeywordWebDataService::BatchModeScoper scoper(web_data_service_.get());
1031 1018
1032 syncer::SyncChangeList new_changes; 1019 syncer::SyncChangeList new_changes;
1033 syncer::SyncError error; 1020 syncer::SyncError error;
1034 for (syncer::SyncChangeList::const_iterator iter = change_list.begin(); 1021 for (syncer::SyncChangeList::const_iterator iter = change_list.begin();
1035 iter != change_list.end(); ++iter) { 1022 iter != change_list.end(); ++iter) {
1036 DCHECK_EQ(syncer::SEARCH_ENGINES, iter->sync_data().GetDataType()); 1023 DCHECK_EQ(syncer::SEARCH_ENGINES, iter->sync_data().GetDataType());
1037 1024
1038 std::string guid = 1025 std::string guid =
1039 iter->sync_data().GetSpecifics().search_engine().sync_guid(); 1026 iter->sync_data().GetSpecifics().search_engine().sync_guid();
1040 TemplateURL* existing_turl = GetTemplateURLForGUID(guid); 1027 TemplateURL* existing_turl = GetTemplateURLForGUID(guid);
1041 scoped_ptr<TemplateURL> turl(CreateTemplateURLFromTemplateURLAndSyncData( 1028 scoped_ptr<TemplateURL> turl(CreateTemplateURLFromTemplateURLAndSyncData(
1042 prefs_, search_terms_data(), existing_turl, iter->sync_data(), 1029 client_.get(), prefs_, search_terms_data(), existing_turl,
1043 &new_changes)); 1030 iter->sync_data(), &new_changes));
1044 if (!turl.get()) 1031 if (!turl.get())
1045 continue; 1032 continue;
1046 1033
1047 // Explicitly don't check for conflicts against extension keywords; in this 1034 // Explicitly don't check for conflicts against extension keywords; in this
1048 // case the functions which modify the keyword map know how to handle the 1035 // case the functions which modify the keyword map know how to handle the
1049 // conflicts. 1036 // conflicts.
1050 // TODO(mpcomplete): If we allow editing extension keywords, then those will 1037 // TODO(mpcomplete): If we allow editing extension keywords, then those will
1051 // need to undergo conflict resolution. 1038 // need to undergo conflict resolution.
1052 TemplateURL* existing_keyword_turl = 1039 TemplateURL* existing_keyword_turl =
1053 FindNonExtensionTemplateURLForKeyword(turl->keyword()); 1040 FindNonExtensionTemplateURLForKeyword(turl->keyword());
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
1187 SyncDataMap sync_data_map = CreateGUIDToSyncDataMap(initial_sync_data); 1174 SyncDataMap sync_data_map = CreateGUIDToSyncDataMap(initial_sync_data);
1188 1175
1189 KeywordWebDataService::BatchModeScoper scoper(web_data_service_.get()); 1176 KeywordWebDataService::BatchModeScoper scoper(web_data_service_.get());
1190 1177
1191 merge_result.set_num_items_before_association(local_data_map.size()); 1178 merge_result.set_num_items_before_association(local_data_map.size());
1192 for (SyncDataMap::const_iterator iter = sync_data_map.begin(); 1179 for (SyncDataMap::const_iterator iter = sync_data_map.begin();
1193 iter != sync_data_map.end(); ++iter) { 1180 iter != sync_data_map.end(); ++iter) {
1194 TemplateURL* local_turl = GetTemplateURLForGUID(iter->first); 1181 TemplateURL* local_turl = GetTemplateURLForGUID(iter->first);
1195 scoped_ptr<TemplateURL> sync_turl( 1182 scoped_ptr<TemplateURL> sync_turl(
1196 CreateTemplateURLFromTemplateURLAndSyncData( 1183 CreateTemplateURLFromTemplateURLAndSyncData(
1197 prefs_, search_terms_data(), local_turl, iter->second, 1184 client_.get(), prefs_, search_terms_data(), local_turl,
1198 &new_changes)); 1185 iter->second, &new_changes));
1199 if (!sync_turl.get()) 1186 if (!sync_turl.get())
1200 continue; 1187 continue;
1201 1188
1202 if (pre_sync_deletes_.find(sync_turl->sync_guid()) != 1189 if (pre_sync_deletes_.find(sync_turl->sync_guid()) !=
1203 pre_sync_deletes_.end()) { 1190 pre_sync_deletes_.end()) {
1204 // This entry was deleted before the initial sync began (possibly through 1191 // This entry was deleted before the initial sync began (possibly through
1205 // preprocessing in TemplateURLService's loading code). Ignore it and send 1192 // preprocessing in TemplateURLService's loading code). Ignore it and send
1206 // an ACTION_DELETE up to the server. 1193 // an ACTION_DELETE up to the server.
1207 new_changes.push_back( 1194 new_changes.push_back(
1208 syncer::SyncChange(FROM_HERE, 1195 syncer::SyncChange(FROM_HERE,
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
1352 se_specifics->add_alternate_urls(turl.alternate_urls()[i]); 1339 se_specifics->add_alternate_urls(turl.alternate_urls()[i]);
1353 se_specifics->set_search_terms_replacement_key( 1340 se_specifics->set_search_terms_replacement_key(
1354 turl.search_terms_replacement_key()); 1341 turl.search_terms_replacement_key());
1355 1342
1356 return syncer::SyncData::CreateLocalData(se_specifics->sync_guid(), 1343 return syncer::SyncData::CreateLocalData(se_specifics->sync_guid(),
1357 se_specifics->keyword(), 1344 se_specifics->keyword(),
1358 specifics); 1345 specifics);
1359 } 1346 }
1360 1347
1361 // static 1348 // static
1362 TemplateURL* TemplateURLService::CreateTemplateURLFromTemplateURLAndSyncData( 1349 scoped_ptr<TemplateURL>
1350 TemplateURLService::CreateTemplateURLFromTemplateURLAndSyncData(
1351 TemplateURLServiceClient* client,
1363 PrefService* prefs, 1352 PrefService* prefs,
1364 const SearchTermsData& search_terms_data, 1353 const SearchTermsData& search_terms_data,
1365 TemplateURL* existing_turl, 1354 TemplateURL* existing_turl,
1366 const syncer::SyncData& sync_data, 1355 const syncer::SyncData& sync_data,
1367 syncer::SyncChangeList* change_list) { 1356 syncer::SyncChangeList* change_list) {
1368 DCHECK(change_list); 1357 DCHECK(change_list);
1369 1358
1370 sync_pb::SearchEngineSpecifics specifics = 1359 sync_pb::SearchEngineSpecifics specifics =
1371 sync_data.GetSpecifics().search_engine(); 1360 sync_data.GetSpecifics().search_engine();
1372 1361
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1417 bool deduped = DeDupeEncodings(&data.input_encodings); 1406 bool deduped = DeDupeEncodings(&data.input_encodings);
1418 data.date_created = base::Time::FromInternalValue(specifics.date_created()); 1407 data.date_created = base::Time::FromInternalValue(specifics.date_created());
1419 data.last_modified = base::Time::FromInternalValue(specifics.last_modified()); 1408 data.last_modified = base::Time::FromInternalValue(specifics.last_modified());
1420 data.prepopulate_id = specifics.prepopulate_id(); 1409 data.prepopulate_id = specifics.prepopulate_id();
1421 data.sync_guid = specifics.sync_guid(); 1410 data.sync_guid = specifics.sync_guid();
1422 data.alternate_urls.clear(); 1411 data.alternate_urls.clear();
1423 for (int i = 0; i < specifics.alternate_urls_size(); ++i) 1412 for (int i = 0; i < specifics.alternate_urls_size(); ++i)
1424 data.alternate_urls.push_back(specifics.alternate_urls(i)); 1413 data.alternate_urls.push_back(specifics.alternate_urls(i));
1425 data.search_terms_replacement_key = specifics.search_terms_replacement_key(); 1414 data.search_terms_replacement_key = specifics.search_terms_replacement_key();
1426 1415
1427 TemplateURL* turl = new TemplateURL(data); 1416 scoped_ptr<TemplateURL> turl(new TemplateURL(data));
1428 // If this TemplateURL matches a built-in prepopulated template URL, it's 1417 // If this TemplateURL matches a built-in prepopulated template URL, it's
1429 // possible that sync is trying to modify fields that should not be touched. 1418 // possible that sync is trying to modify fields that should not be touched.
1430 // Revert these fields to the built-in values. 1419 // Revert these fields to the built-in values.
1431 UpdateTemplateURLIfPrepopulated(turl, prefs); 1420 UpdateTemplateURLIfPrepopulated(turl.get(), prefs);
1432 DCHECK_NE(TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION, turl->GetType()); 1421
1422 // We used to sync keywords associated with omnibox extensions, but no longer
1423 // want to. However, if we delete these keywords from sync, we'll break any
1424 // synced old versions of Chrome which were relying on them. Instead, for now
1425 // we simply ignore these.
1426 // TODO(vasilii): After a few Chrome versions, change this to go ahead and
1427 // delete these from sync.
1428 DCHECK(client);
1429 client->RestoreExtensionInfoIfNecessary(turl.get());
1430 if (turl->GetType() == TemplateURL::OMNIBOX_API_EXTENSION)
1431 return NULL;
1432
1433 DCHECK_EQ(TemplateURL::NORMAL, turl->GetType());
1433 if (reset_keyword || deduped) { 1434 if (reset_keyword || deduped) {
1434 if (reset_keyword) 1435 if (reset_keyword)
1435 turl->ResetKeywordIfNecessary(search_terms_data, true); 1436 turl->ResetKeywordIfNecessary(search_terms_data, true);
1436 syncer::SyncData sync_data = CreateSyncDataFromTemplateURL(*turl); 1437 syncer::SyncData sync_data = CreateSyncDataFromTemplateURL(*turl);
1437 change_list->push_back(syncer::SyncChange(FROM_HERE, 1438 change_list->push_back(syncer::SyncChange(FROM_HERE,
1438 syncer::SyncChange::ACTION_UPDATE, 1439 syncer::SyncChange::ACTION_UPDATE,
1439 sync_data)); 1440 sync_data));
1440 } else if (turl->IsGoogleSearchURLWithReplaceableKeyword(search_terms_data)) { 1441 } else if (turl->IsGoogleSearchURLWithReplaceableKeyword(search_terms_data)) {
1441 if (!existing_turl) { 1442 if (!existing_turl) {
1442 // We're adding a new TemplateURL that uses the Google base URL, so set 1443 // We're adding a new TemplateURL that uses the Google base URL, so set
1443 // its keyword appropriately for the local environment. 1444 // its keyword appropriately for the local environment.
1444 turl->ResetKeywordIfNecessary(search_terms_data, false); 1445 turl->ResetKeywordIfNecessary(search_terms_data, false);
1445 } else if (existing_turl->IsGoogleSearchURLWithReplaceableKeyword( 1446 } else if (existing_turl->IsGoogleSearchURLWithReplaceableKeyword(
1446 search_terms_data)) { 1447 search_terms_data)) {
1447 // Ignore keyword changes triggered by the Google base URL changing on 1448 // Ignore keyword changes triggered by the Google base URL changing on
1448 // another client. If the base URL changes in this client as well, we'll 1449 // another client. If the base URL changes in this client as well, we'll
1449 // pick that up separately at the appropriate time. Otherwise, changing 1450 // pick that up separately at the appropriate time. Otherwise, changing
1450 // the keyword here could result in having the wrong keyword for the local 1451 // the keyword here could result in having the wrong keyword for the local
1451 // environment. 1452 // environment.
1452 turl->data_.SetKeyword(existing_turl->keyword()); 1453 turl->data_.SetKeyword(existing_turl->keyword());
1453 } 1454 }
1454 } 1455 }
1455 1456
1456 return turl; 1457 return turl.Pass();
1457 } 1458 }
1458 1459
1459 // static 1460 // static
1460 SyncDataMap TemplateURLService::CreateGUIDToSyncDataMap( 1461 SyncDataMap TemplateURLService::CreateGUIDToSyncDataMap(
1461 const syncer::SyncDataList& sync_data) { 1462 const syncer::SyncDataList& sync_data) {
1462 SyncDataMap data_map; 1463 SyncDataMap data_map;
1463 for (syncer::SyncDataList::const_iterator i(sync_data.begin()); 1464 for (syncer::SyncDataList::const_iterator i(sync_data.begin());
1464 i != sync_data.end(); 1465 i != sync_data.end();
1465 ++i) 1466 ++i)
1466 data_map[i->GetSpecifics().search_engine().sync_guid()] = *i; 1467 data_map[i->GetSpecifics().search_engine().sync_guid()] = *i;
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
1547 ((turl->GetType() == TemplateURL::OMNIBOX_API_EXTENSION) && 1548 ((turl->GetType() == TemplateURL::OMNIBOX_API_EXTENSION) &&
1548 (turl->id() > best_fallback->id())))) 1549 (turl->id() > best_fallback->id()))))
1549 best_fallback = turl; 1550 best_fallback = turl;
1550 } 1551 }
1551 if (best_fallback) 1552 if (best_fallback)
1552 keyword_to_template_map_[keyword] = best_fallback; 1553 keyword_to_template_map_[keyword] = best_fallback;
1553 else 1554 else
1554 keyword_to_template_map_.erase(keyword); 1555 keyword_to_template_map_.erase(keyword);
1555 } 1556 }
1556 1557
1558 if (template_url->GetType() == TemplateURL::OMNIBOX_API_EXTENSION)
1559 return;
1560
1557 if (!template_url->sync_guid().empty()) 1561 if (!template_url->sync_guid().empty())
1558 guid_to_template_map_.erase(template_url->sync_guid()); 1562 guid_to_template_map_.erase(template_url->sync_guid());
1559 // |provider_map_| is only initialized after loading has completed. 1563 // |provider_map_| is only initialized after loading has completed.
1560 if (loaded_) { 1564 if (loaded_) {
1561 provider_map_->Remove(template_url); 1565 provider_map_->Remove(template_url);
1562 } 1566 }
1563 } 1567 }
1564 1568
1565 void TemplateURLService::AddToMaps(TemplateURL* template_url) { 1569 void TemplateURLService::AddToMaps(TemplateURL* template_url) {
1566 bool template_url_is_omnibox_api = 1570 bool template_url_is_omnibox_api =
(...skipping 10 matching lines...) Expand all
1577 // Manually-modified keywords > extension keywords > replaceable keywords 1581 // Manually-modified keywords > extension keywords > replaceable keywords
1578 // When there are multiple extensions, the last-added wins. 1582 // When there are multiple extensions, the last-added wins.
1579 bool existing_url_is_omnibox_api = 1583 bool existing_url_is_omnibox_api =
1580 existing_url->GetType() == TemplateURL::OMNIBOX_API_EXTENSION; 1584 existing_url->GetType() == TemplateURL::OMNIBOX_API_EXTENSION;
1581 DCHECK(existing_url_is_omnibox_api || template_url_is_omnibox_api); 1585 DCHECK(existing_url_is_omnibox_api || template_url_is_omnibox_api);
1582 if (existing_url_is_omnibox_api ? 1586 if (existing_url_is_omnibox_api ?
1583 !CanReplace(template_url) : CanReplace(existing_url)) 1587 !CanReplace(template_url) : CanReplace(existing_url))
1584 keyword_to_template_map_[keyword] = template_url; 1588 keyword_to_template_map_[keyword] = template_url;
1585 } 1589 }
1586 1590
1591 if (template_url_is_omnibox_api)
1592 return;
1593
1587 if (!template_url->sync_guid().empty()) 1594 if (!template_url->sync_guid().empty())
1588 guid_to_template_map_[template_url->sync_guid()] = template_url; 1595 guid_to_template_map_[template_url->sync_guid()] = template_url;
1589 // |provider_map_| is only initialized after loading has completed. 1596 // |provider_map_| is only initialized after loading has completed.
1590 if (loaded_) 1597 if (loaded_)
1591 provider_map_->Add(template_url, search_terms_data()); 1598 provider_map_->Add(template_url, search_terms_data());
1592 } 1599 }
1593 1600
1594 // Helper for partition() call in next function. 1601 // Helper for partition() call in next function.
1595 bool HasValidID(TemplateURL* t_url) { 1602 bool HasValidID(TemplateURL* t_url) {
1596 return t_url->id() != kInvalidTemplateURLID; 1603 return t_url->id() != kInvalidTemplateURLID;
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
1693 return NULL; 1700 return NULL;
1694 } 1701 }
1695 1702
1696 bool TemplateURLService::UpdateNoNotify(TemplateURL* existing_turl, 1703 bool TemplateURLService::UpdateNoNotify(TemplateURL* existing_turl,
1697 const TemplateURL& new_values) { 1704 const TemplateURL& new_values) {
1698 DCHECK(existing_turl); 1705 DCHECK(existing_turl);
1699 if (std::find(template_urls_.begin(), template_urls_.end(), existing_turl) == 1706 if (std::find(template_urls_.begin(), template_urls_.end(), existing_turl) ==
1700 template_urls_.end()) 1707 template_urls_.end())
1701 return false; 1708 return false;
1702 1709
1710 DCHECK_NE(TemplateURL::OMNIBOX_API_EXTENSION, existing_turl->GetType());
1711
1703 base::string16 old_keyword(existing_turl->keyword()); 1712 base::string16 old_keyword(existing_turl->keyword());
1704 keyword_to_template_map_.erase(old_keyword); 1713 keyword_to_template_map_.erase(old_keyword);
1705 if (!existing_turl->sync_guid().empty()) 1714 if (!existing_turl->sync_guid().empty())
1706 guid_to_template_map_.erase(existing_turl->sync_guid()); 1715 guid_to_template_map_.erase(existing_turl->sync_guid());
1707 1716
1708 // |provider_map_| is only initialized after loading has completed. 1717 // |provider_map_| is only initialized after loading has completed.
1709 if (loaded_) 1718 if (loaded_)
1710 provider_map_->Remove(existing_turl); 1719 provider_map_->Remove(existing_turl);
1711 1720
1712 TemplateURLID previous_id = existing_turl->id(); 1721 TemplateURLID previous_id = existing_turl->id();
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
2033 2042
2034 // Check whether |template_url|'s keyword conflicts with any already in the 2043 // Check whether |template_url|'s keyword conflicts with any already in the
2035 // model. Note that we can reach here during the loading phase while 2044 // model. Note that we can reach here during the loading phase while
2036 // processing the template URLs from the web data service. In this case, 2045 // processing the template URLs from the web data service. In this case,
2037 // GetTemplateURLForKeyword() will look not only at what's already in the 2046 // GetTemplateURLForKeyword() will look not only at what's already in the
2038 // model, but at the |initial_default_search_provider_|. Since this engine 2047 // model, but at the |initial_default_search_provider_|. Since this engine
2039 // will presumably also be present in the web data, we need to double-check 2048 // will presumably also be present in the web data, we need to double-check
2040 // that any "pre-existing" entries we find are actually coming from 2049 // that any "pre-existing" entries we find are actually coming from
2041 // |template_urls_|, lest we detect a "conflict" between the 2050 // |template_urls_|, lest we detect a "conflict" between the
2042 // |initial_default_search_provider_| and the web data version of itself. 2051 // |initial_default_search_provider_| and the web data version of itself.
2043 if (existing_keyword_turl && 2052 if (template_url->GetType() != TemplateURL::OMNIBOX_API_EXTENSION &&
2053 existing_keyword_turl &&
2054 existing_keyword_turl->GetType() != TemplateURL::OMNIBOX_API_EXTENSION &&
2044 (std::find(template_urls_.begin(), template_urls_.end(), 2055 (std::find(template_urls_.begin(), template_urls_.end(),
2045 existing_keyword_turl) != template_urls_.end())) { 2056 existing_keyword_turl) != template_urls_.end())) {
2046 DCHECK_NE(existing_keyword_turl, template_url); 2057 DCHECK_NE(existing_keyword_turl, template_url);
2047 // Only replace one of the TemplateURLs if they are either both extensions, 2058 // Only replace one of the TemplateURLs if they are either both extensions,
2048 // or both not extensions. 2059 // or both not extensions.
2049 bool are_same_type = existing_keyword_turl->GetType() == 2060 bool are_same_type = existing_keyword_turl->GetType() ==
2050 template_url->GetType(); 2061 template_url->GetType();
2051 if (CanReplace(existing_keyword_turl) && are_same_type) { 2062 if (CanReplace(existing_keyword_turl) && are_same_type) {
2052 RemoveNoNotify(existing_keyword_turl); 2063 RemoveNoNotify(existing_keyword_turl);
2053 } else if (CanReplace(template_url) && are_same_type) { 2064 } else if (CanReplace(template_url) && are_same_type) {
2054 delete template_url; 2065 delete template_url;
2055 return false; 2066 return false;
2056 } else { 2067 } else {
2057 base::string16 new_keyword = 2068 base::string16 new_keyword =
2058 UniquifyKeyword(*existing_keyword_turl, false); 2069 UniquifyKeyword(*existing_keyword_turl, false);
2059 ResetTemplateURLNoNotify(existing_keyword_turl, 2070 ResetTemplateURLNoNotify(existing_keyword_turl,
2060 existing_keyword_turl->short_name(), new_keyword, 2071 existing_keyword_turl->short_name(), new_keyword,
2061 existing_keyword_turl->url()); 2072 existing_keyword_turl->url());
2062 } 2073 }
2063 } 2074 }
2064 template_urls_.push_back(template_url); 2075 template_urls_.push_back(template_url);
2065 AddToMaps(template_url); 2076 AddToMaps(template_url);
2066 2077
2067 if (newly_adding && 2078 if (newly_adding &&
2068 (template_url->GetType() != 2079 (template_url->GetType() == TemplateURL::NORMAL)) {
2069 TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION)) {
2070 if (web_data_service_.get()) 2080 if (web_data_service_.get())
2071 web_data_service_->AddKeyword(template_url->data()); 2081 web_data_service_->AddKeyword(template_url->data());
2072 2082
2073 // Inform sync of the addition. Note that this will assign a GUID to 2083 // Inform sync of the addition. Note that this will assign a GUID to
2074 // template_url and add it to the guid_to_template_map_. 2084 // template_url and add it to the guid_to_template_map_.
2075 ProcessTemplateURLChange(FROM_HERE, 2085 ProcessTemplateURLChange(FROM_HERE,
2076 template_url, 2086 template_url,
2077 syncer::SyncChange::ACTION_ADD); 2087 syncer::SyncChange::ACTION_ADD);
2078 } 2088 }
2079 2089
2080 return true; 2090 return true;
2081 } 2091 }
2082 2092
2083 void TemplateURLService::RemoveNoNotify(TemplateURL* template_url) { 2093 void TemplateURLService::RemoveNoNotify(TemplateURL* template_url) {
2084 DCHECK(template_url != default_search_provider_); 2094 DCHECK(template_url != default_search_provider_);
2085 2095
2086 TemplateURLVector::iterator i = 2096 TemplateURLVector::iterator i =
2087 std::find(template_urls_.begin(), template_urls_.end(), template_url); 2097 std::find(template_urls_.begin(), template_urls_.end(), template_url);
2088 if (i == template_urls_.end()) 2098 if (i == template_urls_.end())
2089 return; 2099 return;
2090 2100
2091 RemoveFromMaps(template_url); 2101 RemoveFromMaps(template_url);
2092 2102
2093 // Remove it from the vector containing all TemplateURLs. 2103 // Remove it from the vector containing all TemplateURLs.
2094 template_urls_.erase(i); 2104 template_urls_.erase(i);
2095 2105
2096 if (template_url->GetType() != TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION) { 2106 if (template_url->GetType() == TemplateURL::NORMAL) {
2097 if (web_data_service_.get()) 2107 if (web_data_service_.get())
2098 web_data_service_->RemoveKeyword(template_url->id()); 2108 web_data_service_->RemoveKeyword(template_url->id());
2099 2109
2100 // Inform sync of the deletion. 2110 // Inform sync of the deletion.
2101 ProcessTemplateURLChange(FROM_HERE, 2111 ProcessTemplateURLChange(FROM_HERE,
2102 template_url, 2112 template_url,
2103 syncer::SyncChange::ACTION_DELETE); 2113 syncer::SyncChange::ACTION_DELETE);
2104 2114
2105 UMA_HISTOGRAM_ENUMERATION(kDeleteSyncedEngineHistogramName, 2115 UMA_HISTOGRAM_ENUMERATION(kDeleteSyncedEngineHistogramName,
2106 DELETE_ENGINE_USER_ACTION, DELETE_ENGINE_MAX); 2116 DELETE_ENGINE_USER_ACTION, DELETE_ENGINE_MAX);
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
2244 2254
2245 void TemplateURLService::ResolveSyncKeywordConflict( 2255 void TemplateURLService::ResolveSyncKeywordConflict(
2246 TemplateURL* unapplied_sync_turl, 2256 TemplateURL* unapplied_sync_turl,
2247 TemplateURL* applied_sync_turl, 2257 TemplateURL* applied_sync_turl,
2248 syncer::SyncChangeList* change_list) { 2258 syncer::SyncChangeList* change_list) {
2249 DCHECK(loaded_); 2259 DCHECK(loaded_);
2250 DCHECK(unapplied_sync_turl); 2260 DCHECK(unapplied_sync_turl);
2251 DCHECK(applied_sync_turl); 2261 DCHECK(applied_sync_turl);
2252 DCHECK(change_list); 2262 DCHECK(change_list);
2253 DCHECK_EQ(applied_sync_turl->keyword(), unapplied_sync_turl->keyword()); 2263 DCHECK_EQ(applied_sync_turl->keyword(), unapplied_sync_turl->keyword());
2254 DCHECK_NE(TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION, 2264 DCHECK_EQ(TemplateURL::NORMAL, applied_sync_turl->GetType());
2255 applied_sync_turl->GetType());
2256 2265
2257 // Both |unapplied_sync_turl| and |applied_sync_turl| are known to Sync, so 2266 // Both |unapplied_sync_turl| and |applied_sync_turl| are known to Sync, so
2258 // don't delete either of them. Instead, determine which is "better" and 2267 // don't delete either of them. Instead, determine which is "better" and
2259 // uniquify the other one, sending an update to the server for the updated 2268 // uniquify the other one, sending an update to the server for the updated
2260 // entry. 2269 // entry.
2261 const bool applied_turl_is_better = 2270 const bool applied_turl_is_better =
2262 IsLocalTemplateURLBetter(applied_sync_turl, unapplied_sync_turl); 2271 IsLocalTemplateURLBetter(applied_sync_turl, unapplied_sync_turl);
2263 TemplateURL* loser = applied_turl_is_better ? 2272 TemplateURL* loser = applied_turl_is_better ?
2264 unapplied_sync_turl : applied_sync_turl; 2273 unapplied_sync_turl : applied_sync_turl;
2265 base::string16 new_keyword = UniquifyKeyword(*loser, false); 2274 base::string16 new_keyword = UniquifyKeyword(*loser, false);
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
2356 } 2365 }
2357 2366
2358 void TemplateURLService::PatchMissingSyncGUIDs( 2367 void TemplateURLService::PatchMissingSyncGUIDs(
2359 TemplateURLVector* template_urls) { 2368 TemplateURLVector* template_urls) {
2360 DCHECK(template_urls); 2369 DCHECK(template_urls);
2361 for (TemplateURLVector::iterator i = template_urls->begin(); 2370 for (TemplateURLVector::iterator i = template_urls->begin();
2362 i != template_urls->end(); ++i) { 2371 i != template_urls->end(); ++i) {
2363 TemplateURL* template_url = *i; 2372 TemplateURL* template_url = *i;
2364 DCHECK(template_url); 2373 DCHECK(template_url);
2365 if (template_url->sync_guid().empty() && 2374 if (template_url->sync_guid().empty() &&
2366 (template_url->GetType() != 2375 (template_url->GetType() == TemplateURL::NORMAL)) {
2367 TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION)) {
2368 template_url->data_.sync_guid = base::GenerateGUID(); 2376 template_url->data_.sync_guid = base::GenerateGUID();
2369 if (web_data_service_.get()) 2377 if (web_data_service_.get())
2370 web_data_service_->UpdateKeyword(template_url->data()); 2378 web_data_service_->UpdateKeyword(template_url->data());
2371 } 2379 }
2372 } 2380 }
2373 } 2381 }
2374 2382
2375 void TemplateURLService::OnSyncedDefaultSearchProviderGUIDChanged() { 2383 void TemplateURLService::OnSyncedDefaultSearchProviderGUIDChanged() {
2376 base::AutoReset<DefaultSearchChangeOrigin> change_origin( 2384 base::AutoReset<DefaultSearchChangeOrigin> change_origin(
2377 &dsp_change_origin_, DSP_CHANGE_SYNC_PREF); 2385 &dsp_change_origin_, DSP_CHANGE_SYNC_PREF);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
2439 2447
2440 if (most_recently_intalled_default) { 2448 if (most_recently_intalled_default) {
2441 base::AutoReset<DefaultSearchChangeOrigin> change_origin( 2449 base::AutoReset<DefaultSearchChangeOrigin> change_origin(
2442 &dsp_change_origin_, DSP_CHANGE_OVERRIDE_SETTINGS_EXTENSION); 2450 &dsp_change_origin_, DSP_CHANGE_OVERRIDE_SETTINGS_EXTENSION);
2443 default_search_manager_.SetExtensionControlledDefaultSearchEngine( 2451 default_search_manager_.SetExtensionControlledDefaultSearchEngine(
2444 most_recently_intalled_default->data()); 2452 most_recently_intalled_default->data());
2445 } else { 2453 } else {
2446 default_search_manager_.ClearExtensionControlledDefaultSearchEngine(); 2454 default_search_manager_.ClearExtensionControlledDefaultSearchEngine();
2447 } 2455 }
2448 } 2456 }
OLDNEW
« no previous file with comments | « components/search_engines/template_url_service.h ('k') | components/search_engines/template_url_service_sync_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698