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

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: don't remove from server 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 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
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_) { 873 if (client_) {
874 // TODO(vadimt): Remove ScopedProfile below once crbug.com/422460 is fixed. 874 // TODO(vadimt): Remove ScopedProfile below once crbug.com/422460 is fixed.
875 tracked_objects::ScopedProfile tracking_profile3( 875 tracked_objects::ScopedProfile tracking_profile3(
876 FROM_HERE_WITH_EXPLICIT_FUNCTION( 876 FROM_HERE_WITH_EXPLICIT_FUNCTION(
877 "422460 TemplateURLService::OnWebDataServiceRequestDone 3")); 877 "422460 TemplateURLService::OnWebDataServiceRequestDone 3"));
878 878
879 // We used to store omnibox extensions keywords. Now they are't persisted.
880 TemplateURLVector template_urls_no_extensions;
879 // Restore extension info of loaded TemplateURLs. 881 // Restore extension info of loaded TemplateURLs.
880 for (size_t i = 0; i < template_urls.size(); ++i) { 882 for (size_t i = 0; i < template_urls.size(); ++i) {
881 DCHECK(!template_urls[i]->extension_info_); 883 DCHECK(!template_urls[i]->extension_info_);
882 client_->RestoreExtensionInfoIfNecessary(template_urls[i]); 884 client_->RestoreExtensionInfoIfNecessary(template_urls[i]);
885 if (template_urls[i]->GetType() == TemplateURL::NORMAL) {
886 template_urls_no_extensions.push_back(template_urls[i]);
887 } else {
888 web_data_service_->RemoveKeyword(template_urls[i]->id());
889 delete template_urls[i];
890 }
883 } 891 }
892 template_urls.swap(template_urls_no_extensions);
884 } 893 }
885 894
886 KeywordWebDataService::BatchModeScoper scoper(web_data_service_.get()); 895 KeywordWebDataService::BatchModeScoper scoper(web_data_service_.get());
887 896
888 { 897 {
889 // TODO(vadimt): Remove ScopedProfile below once crbug.com/422460 is fixed. 898 // TODO(vadimt): Remove ScopedProfile below once crbug.com/422460 is fixed.
890 tracked_objects::ScopedProfile tracking_profile4( 899 tracked_objects::ScopedProfile tracking_profile4(
891 FROM_HERE_WITH_EXPLICIT_FUNCTION( 900 FROM_HERE_WITH_EXPLICIT_FUNCTION(
892 "422460 TemplateURLService::OnWebDataServiceRequestDone 4")); 901 "422460 TemplateURLService::OnWebDataServiceRequestDone 4"));
893 902
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
992 syncer::ModelType type) const { 1001 syncer::ModelType type) const {
993 DCHECK_EQ(syncer::SEARCH_ENGINES, type); 1002 DCHECK_EQ(syncer::SEARCH_ENGINES, type);
994 1003
995 syncer::SyncDataList current_data; 1004 syncer::SyncDataList current_data;
996 for (TemplateURLVector::const_iterator iter = template_urls_.begin(); 1005 for (TemplateURLVector::const_iterator iter = template_urls_.begin();
997 iter != template_urls_.end(); ++iter) { 1006 iter != template_urls_.end(); ++iter) {
998 // We don't sync keywords managed by policy. 1007 // We don't sync keywords managed by policy.
999 if ((*iter)->created_by_policy()) 1008 if ((*iter)->created_by_policy())
1000 continue; 1009 continue;
1001 // We don't sync extension-controlled search engines. 1010 // We don't sync extension-controlled search engines.
1002 if ((*iter)->GetType() == TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION) 1011 if ((*iter)->GetType() != TemplateURL::NORMAL)
1003 continue; 1012 continue;
1004 current_data.push_back(CreateSyncDataFromTemplateURL(**iter)); 1013 current_data.push_back(CreateSyncDataFromTemplateURL(**iter));
1005 } 1014 }
1006 1015
1007 return current_data; 1016 return current_data;
1008 } 1017 }
1009 1018
1010 syncer::SyncError TemplateURLService::ProcessSyncChanges( 1019 syncer::SyncError TemplateURLService::ProcessSyncChanges(
1011 const tracked_objects::Location& from_here, 1020 const tracked_objects::Location& from_here,
1012 const syncer::SyncChangeList& change_list) { 1021 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 1034 // 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. 1035 // origins so we can tell what exactly caused a DSP change.
1027 base::AutoReset<DefaultSearchChangeOrigin> change_origin(&dsp_change_origin_, 1036 base::AutoReset<DefaultSearchChangeOrigin> change_origin(&dsp_change_origin_,
1028 DSP_CHANGE_SYNC_UNINTENTIONAL); 1037 DSP_CHANGE_SYNC_UNINTENTIONAL);
1029 1038
1030 KeywordWebDataService::BatchModeScoper scoper(web_data_service_.get()); 1039 KeywordWebDataService::BatchModeScoper scoper(web_data_service_.get());
1031 1040
1032 syncer::SyncChangeList new_changes; 1041 syncer::SyncChangeList new_changes;
1033 syncer::SyncError error; 1042 syncer::SyncError error;
1034 for (syncer::SyncChangeList::const_iterator iter = change_list.begin(); 1043 for (syncer::SyncChangeList::const_iterator iter = change_list.begin();
1035 iter != change_list.end(); ++iter) { 1044 iter != change_list.end(); ++iter) {
1036 DCHECK_EQ(syncer::SEARCH_ENGINES, iter->sync_data().GetDataType()); 1045 DCHECK_EQ(syncer::SEARCH_ENGINES, iter->sync_data().GetDataType());
1037 1046
1038 std::string guid = 1047 std::string guid =
1039 iter->sync_data().GetSpecifics().search_engine().sync_guid(); 1048 iter->sync_data().GetSpecifics().search_engine().sync_guid();
1040 TemplateURL* existing_turl = GetTemplateURLForGUID(guid); 1049 TemplateURL* existing_turl = GetTemplateURLForGUID(guid);
1041 scoped_ptr<TemplateURL> turl(CreateTemplateURLFromTemplateURLAndSyncData( 1050 scoped_ptr<TemplateURL> turl(CreateTemplateURLFromTemplateURLAndSyncData(
1042 prefs_, search_terms_data(), existing_turl, iter->sync_data(), 1051 client_.get(), prefs_, search_terms_data(), existing_turl,
1043 &new_changes)); 1052 iter->sync_data(), &new_changes));
1044 if (!turl.get()) 1053 if (!turl.get())
1045 continue; 1054 continue;
1046 1055
1047 // Explicitly don't check for conflicts against extension keywords; in this 1056 // 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 1057 // case the functions which modify the keyword map know how to handle the
1049 // conflicts. 1058 // conflicts.
1050 // TODO(mpcomplete): If we allow editing extension keywords, then those will 1059 // TODO(mpcomplete): If we allow editing extension keywords, then those will
1051 // need to undergo conflict resolution. 1060 // need to undergo conflict resolution.
1052 TemplateURL* existing_keyword_turl = 1061 TemplateURL* existing_keyword_turl =
1053 FindNonExtensionTemplateURLForKeyword(turl->keyword()); 1062 FindNonExtensionTemplateURLForKeyword(turl->keyword());
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
1187 SyncDataMap sync_data_map = CreateGUIDToSyncDataMap(initial_sync_data); 1196 SyncDataMap sync_data_map = CreateGUIDToSyncDataMap(initial_sync_data);
1188 1197
1189 KeywordWebDataService::BatchModeScoper scoper(web_data_service_.get()); 1198 KeywordWebDataService::BatchModeScoper scoper(web_data_service_.get());
1190 1199
1191 merge_result.set_num_items_before_association(local_data_map.size()); 1200 merge_result.set_num_items_before_association(local_data_map.size());
1192 for (SyncDataMap::const_iterator iter = sync_data_map.begin(); 1201 for (SyncDataMap::const_iterator iter = sync_data_map.begin();
1193 iter != sync_data_map.end(); ++iter) { 1202 iter != sync_data_map.end(); ++iter) {
1194 TemplateURL* local_turl = GetTemplateURLForGUID(iter->first); 1203 TemplateURL* local_turl = GetTemplateURLForGUID(iter->first);
1195 scoped_ptr<TemplateURL> sync_turl( 1204 scoped_ptr<TemplateURL> sync_turl(
1196 CreateTemplateURLFromTemplateURLAndSyncData( 1205 CreateTemplateURLFromTemplateURLAndSyncData(
1197 prefs_, search_terms_data(), local_turl, iter->second, 1206 client_.get(), prefs_, search_terms_data(), local_turl,
1198 &new_changes)); 1207 iter->second, &new_changes));
1199 if (!sync_turl.get()) 1208 if (!sync_turl.get())
1200 continue; 1209 continue;
1201 1210
1202 if (pre_sync_deletes_.find(sync_turl->sync_guid()) != 1211 if (pre_sync_deletes_.find(sync_turl->sync_guid()) !=
1203 pre_sync_deletes_.end()) { 1212 pre_sync_deletes_.end()) {
1204 // This entry was deleted before the initial sync began (possibly through 1213 // This entry was deleted before the initial sync began (possibly through
1205 // preprocessing in TemplateURLService's loading code). Ignore it and send 1214 // preprocessing in TemplateURLService's loading code). Ignore it and send
1206 // an ACTION_DELETE up to the server. 1215 // an ACTION_DELETE up to the server.
1207 new_changes.push_back( 1216 new_changes.push_back(
1208 syncer::SyncChange(FROM_HERE, 1217 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]); 1361 se_specifics->add_alternate_urls(turl.alternate_urls()[i]);
1353 se_specifics->set_search_terms_replacement_key( 1362 se_specifics->set_search_terms_replacement_key(
1354 turl.search_terms_replacement_key()); 1363 turl.search_terms_replacement_key());
1355 1364
1356 return syncer::SyncData::CreateLocalData(se_specifics->sync_guid(), 1365 return syncer::SyncData::CreateLocalData(se_specifics->sync_guid(),
1357 se_specifics->keyword(), 1366 se_specifics->keyword(),
1358 specifics); 1367 specifics);
1359 } 1368 }
1360 1369
1361 // static 1370 // static
1362 TemplateURL* TemplateURLService::CreateTemplateURLFromTemplateURLAndSyncData( 1371 scoped_ptr<TemplateURL>
1372 TemplateURLService::CreateTemplateURLFromTemplateURLAndSyncData(
1373 TemplateURLServiceClient* client,
1363 PrefService* prefs, 1374 PrefService* prefs,
1364 const SearchTermsData& search_terms_data, 1375 const SearchTermsData& search_terms_data,
1365 TemplateURL* existing_turl, 1376 TemplateURL* existing_turl,
1366 const syncer::SyncData& sync_data, 1377 const syncer::SyncData& sync_data,
1367 syncer::SyncChangeList* change_list) { 1378 syncer::SyncChangeList* change_list) {
1368 DCHECK(change_list); 1379 DCHECK(change_list);
1369 1380
1370 sync_pb::SearchEngineSpecifics specifics = 1381 sync_pb::SearchEngineSpecifics specifics =
1371 sync_data.GetSpecifics().search_engine(); 1382 sync_data.GetSpecifics().search_engine();
1372 1383
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1417 bool deduped = DeDupeEncodings(&data.input_encodings); 1428 bool deduped = DeDupeEncodings(&data.input_encodings);
1418 data.date_created = base::Time::FromInternalValue(specifics.date_created()); 1429 data.date_created = base::Time::FromInternalValue(specifics.date_created());
1419 data.last_modified = base::Time::FromInternalValue(specifics.last_modified()); 1430 data.last_modified = base::Time::FromInternalValue(specifics.last_modified());
1420 data.prepopulate_id = specifics.prepopulate_id(); 1431 data.prepopulate_id = specifics.prepopulate_id();
1421 data.sync_guid = specifics.sync_guid(); 1432 data.sync_guid = specifics.sync_guid();
1422 data.alternate_urls.clear(); 1433 data.alternate_urls.clear();
1423 for (int i = 0; i < specifics.alternate_urls_size(); ++i) 1434 for (int i = 0; i < specifics.alternate_urls_size(); ++i)
1424 data.alternate_urls.push_back(specifics.alternate_urls(i)); 1435 data.alternate_urls.push_back(specifics.alternate_urls(i));
1425 data.search_terms_replacement_key = specifics.search_terms_replacement_key(); 1436 data.search_terms_replacement_key = specifics.search_terms_replacement_key();
1426 1437
1427 TemplateURL* turl = new TemplateURL(data); 1438 scoped_ptr<TemplateURL> turl(new TemplateURL(data));
1428 // If this TemplateURL matches a built-in prepopulated template URL, it's 1439 // 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. 1440 // possible that sync is trying to modify fields that should not be touched.
1430 // Revert these fields to the built-in values. 1441 // Revert these fields to the built-in values.
1431 UpdateTemplateURLIfPrepopulated(turl, prefs); 1442 UpdateTemplateURLIfPrepopulated(turl.get(), prefs);
1432 DCHECK_NE(TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION, turl->GetType()); 1443
1444 // The omnibox keywords aren't synced anymore.
Peter Kasting 2014/11/04 19:11:56 How about this: We used to sync keywords associat
vasilii 2014/11/05 18:04:50 Done.
1445 DCHECK(client);
1446 client->RestoreExtensionInfoIfNecessary(turl.get());
1447 if (turl->GetType() == TemplateURL::OMNIBOX_API_EXTENSION)
1448 return NULL;
1449
1450 DCHECK_EQ(TemplateURL::NORMAL, turl->GetType());
1433 if (reset_keyword || deduped) { 1451 if (reset_keyword || deduped) {
1434 if (reset_keyword) 1452 if (reset_keyword)
1435 turl->ResetKeywordIfNecessary(search_terms_data, true); 1453 turl->ResetKeywordIfNecessary(search_terms_data, true);
1436 syncer::SyncData sync_data = CreateSyncDataFromTemplateURL(*turl); 1454 syncer::SyncData sync_data = CreateSyncDataFromTemplateURL(*turl);
1437 change_list->push_back(syncer::SyncChange(FROM_HERE, 1455 change_list->push_back(syncer::SyncChange(FROM_HERE,
1438 syncer::SyncChange::ACTION_UPDATE, 1456 syncer::SyncChange::ACTION_UPDATE,
1439 sync_data)); 1457 sync_data));
1440 } else if (turl->IsGoogleSearchURLWithReplaceableKeyword(search_terms_data)) { 1458 } else if (turl->IsGoogleSearchURLWithReplaceableKeyword(search_terms_data)) {
1441 if (!existing_turl) { 1459 if (!existing_turl) {
1442 // We're adding a new TemplateURL that uses the Google base URL, so set 1460 // We're adding a new TemplateURL that uses the Google base URL, so set
1443 // its keyword appropriately for the local environment. 1461 // its keyword appropriately for the local environment.
1444 turl->ResetKeywordIfNecessary(search_terms_data, false); 1462 turl->ResetKeywordIfNecessary(search_terms_data, false);
1445 } else if (existing_turl->IsGoogleSearchURLWithReplaceableKeyword( 1463 } else if (existing_turl->IsGoogleSearchURLWithReplaceableKeyword(
1446 search_terms_data)) { 1464 search_terms_data)) {
1447 // Ignore keyword changes triggered by the Google base URL changing on 1465 // 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 1466 // 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 1467 // pick that up separately at the appropriate time. Otherwise, changing
1450 // the keyword here could result in having the wrong keyword for the local 1468 // the keyword here could result in having the wrong keyword for the local
1451 // environment. 1469 // environment.
1452 turl->data_.SetKeyword(existing_turl->keyword()); 1470 turl->data_.SetKeyword(existing_turl->keyword());
1453 } 1471 }
1454 } 1472 }
1455 1473
1456 return turl; 1474 return turl.Pass();
1457 } 1475 }
1458 1476
1459 // static 1477 // static
1460 SyncDataMap TemplateURLService::CreateGUIDToSyncDataMap( 1478 SyncDataMap TemplateURLService::CreateGUIDToSyncDataMap(
1461 const syncer::SyncDataList& sync_data) { 1479 const syncer::SyncDataList& sync_data) {
1462 SyncDataMap data_map; 1480 SyncDataMap data_map;
1463 for (syncer::SyncDataList::const_iterator i(sync_data.begin()); 1481 for (syncer::SyncDataList::const_iterator i(sync_data.begin());
1464 i != sync_data.end(); 1482 i != sync_data.end();
1465 ++i) 1483 ++i)
1466 data_map[i->GetSpecifics().search_engine().sync_guid()] = *i; 1484 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) && 1565 ((turl->GetType() == TemplateURL::OMNIBOX_API_EXTENSION) &&
1548 (turl->id() > best_fallback->id())))) 1566 (turl->id() > best_fallback->id()))))
1549 best_fallback = turl; 1567 best_fallback = turl;
1550 } 1568 }
1551 if (best_fallback) 1569 if (best_fallback)
1552 keyword_to_template_map_[keyword] = best_fallback; 1570 keyword_to_template_map_[keyword] = best_fallback;
1553 else 1571 else
1554 keyword_to_template_map_.erase(keyword); 1572 keyword_to_template_map_.erase(keyword);
1555 } 1573 }
1556 1574
1575 if (template_url->GetType() == TemplateURL::OMNIBOX_API_EXTENSION)
1576 return;
1577
1557 if (!template_url->sync_guid().empty()) 1578 if (!template_url->sync_guid().empty())
1558 guid_to_template_map_.erase(template_url->sync_guid()); 1579 guid_to_template_map_.erase(template_url->sync_guid());
1559 // |provider_map_| is only initialized after loading has completed. 1580 // |provider_map_| is only initialized after loading has completed.
1560 if (loaded_) { 1581 if (loaded_) {
1561 provider_map_->Remove(template_url); 1582 provider_map_->Remove(template_url);
1562 } 1583 }
1563 } 1584 }
1564 1585
1565 void TemplateURLService::AddToMaps(TemplateURL* template_url) { 1586 void TemplateURLService::AddToMaps(TemplateURL* template_url) {
1566 bool template_url_is_omnibox_api = 1587 bool template_url_is_omnibox_api =
(...skipping 10 matching lines...) Expand all
1577 // Manually-modified keywords > extension keywords > replaceable keywords 1598 // Manually-modified keywords > extension keywords > replaceable keywords
1578 // When there are multiple extensions, the last-added wins. 1599 // When there are multiple extensions, the last-added wins.
1579 bool existing_url_is_omnibox_api = 1600 bool existing_url_is_omnibox_api =
1580 existing_url->GetType() == TemplateURL::OMNIBOX_API_EXTENSION; 1601 existing_url->GetType() == TemplateURL::OMNIBOX_API_EXTENSION;
1581 DCHECK(existing_url_is_omnibox_api || template_url_is_omnibox_api); 1602 DCHECK(existing_url_is_omnibox_api || template_url_is_omnibox_api);
1582 if (existing_url_is_omnibox_api ? 1603 if (existing_url_is_omnibox_api ?
1583 !CanReplace(template_url) : CanReplace(existing_url)) 1604 !CanReplace(template_url) : CanReplace(existing_url))
1584 keyword_to_template_map_[keyword] = template_url; 1605 keyword_to_template_map_[keyword] = template_url;
1585 } 1606 }
1586 1607
1608 if (template_url_is_omnibox_api)
1609 return;
1610
1587 if (!template_url->sync_guid().empty()) 1611 if (!template_url->sync_guid().empty())
1588 guid_to_template_map_[template_url->sync_guid()] = template_url; 1612 guid_to_template_map_[template_url->sync_guid()] = template_url;
1589 // |provider_map_| is only initialized after loading has completed. 1613 // |provider_map_| is only initialized after loading has completed.
1590 if (loaded_) 1614 if (loaded_)
1591 provider_map_->Add(template_url, search_terms_data()); 1615 provider_map_->Add(template_url, search_terms_data());
1592 } 1616 }
1593 1617
1594 // Helper for partition() call in next function. 1618 // Helper for partition() call in next function.
1595 bool HasValidID(TemplateURL* t_url) { 1619 bool HasValidID(TemplateURL* t_url) {
1596 return t_url->id() != kInvalidTemplateURLID; 1620 return t_url->id() != kInvalidTemplateURLID;
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
1677 return NULL; 1701 return NULL;
1678 } 1702 }
1679 1703
1680 bool TemplateURLService::UpdateNoNotify(TemplateURL* existing_turl, 1704 bool TemplateURLService::UpdateNoNotify(TemplateURL* existing_turl,
1681 const TemplateURL& new_values) { 1705 const TemplateURL& new_values) {
1682 DCHECK(existing_turl); 1706 DCHECK(existing_turl);
1683 if (std::find(template_urls_.begin(), template_urls_.end(), existing_turl) == 1707 if (std::find(template_urls_.begin(), template_urls_.end(), existing_turl) ==
1684 template_urls_.end()) 1708 template_urls_.end())
1685 return false; 1709 return false;
1686 1710
1711 DCHECK_NE(TemplateURL::OMNIBOX_API_EXTENSION, existing_turl->GetType());
1712
1687 base::string16 old_keyword(existing_turl->keyword()); 1713 base::string16 old_keyword(existing_turl->keyword());
1688 keyword_to_template_map_.erase(old_keyword); 1714 keyword_to_template_map_.erase(old_keyword);
1689 if (!existing_turl->sync_guid().empty()) 1715 if (!existing_turl->sync_guid().empty())
1690 guid_to_template_map_.erase(existing_turl->sync_guid()); 1716 guid_to_template_map_.erase(existing_turl->sync_guid());
1691 1717
1692 // |provider_map_| is only initialized after loading has completed. 1718 // |provider_map_| is only initialized after loading has completed.
1693 if (loaded_) 1719 if (loaded_)
1694 provider_map_->Remove(existing_turl); 1720 provider_map_->Remove(existing_turl);
1695 1721
1696 TemplateURLID previous_id = existing_turl->id(); 1722 TemplateURLID previous_id = existing_turl->id();
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
2017 2043
2018 // Check whether |template_url|'s keyword conflicts with any already in the 2044 // Check whether |template_url|'s keyword conflicts with any already in the
2019 // model. Note that we can reach here during the loading phase while 2045 // model. Note that we can reach here during the loading phase while
2020 // processing the template URLs from the web data service. In this case, 2046 // processing the template URLs from the web data service. In this case,
2021 // GetTemplateURLForKeyword() will look not only at what's already in the 2047 // GetTemplateURLForKeyword() will look not only at what's already in the
2022 // model, but at the |initial_default_search_provider_|. Since this engine 2048 // model, but at the |initial_default_search_provider_|. Since this engine
2023 // will presumably also be present in the web data, we need to double-check 2049 // will presumably also be present in the web data, we need to double-check
2024 // that any "pre-existing" entries we find are actually coming from 2050 // that any "pre-existing" entries we find are actually coming from
2025 // |template_urls_|, lest we detect a "conflict" between the 2051 // |template_urls_|, lest we detect a "conflict" between the
2026 // |initial_default_search_provider_| and the web data version of itself. 2052 // |initial_default_search_provider_| and the web data version of itself.
2027 if (existing_keyword_turl && 2053 if (template_url->GetType() != TemplateURL::OMNIBOX_API_EXTENSION &&
2054 existing_keyword_turl &&
2055 existing_keyword_turl->GetType() != TemplateURL::OMNIBOX_API_EXTENSION &&
2028 (std::find(template_urls_.begin(), template_urls_.end(), 2056 (std::find(template_urls_.begin(), template_urls_.end(),
2029 existing_keyword_turl) != template_urls_.end())) { 2057 existing_keyword_turl) != template_urls_.end())) {
2030 DCHECK_NE(existing_keyword_turl, template_url); 2058 DCHECK_NE(existing_keyword_turl, template_url);
2031 // Only replace one of the TemplateURLs if they are either both extensions, 2059 // Only replace one of the TemplateURLs if they are either both extensions,
2032 // or both not extensions. 2060 // or both not extensions.
2033 bool are_same_type = existing_keyword_turl->GetType() == 2061 bool are_same_type = existing_keyword_turl->GetType() ==
2034 template_url->GetType(); 2062 template_url->GetType();
2035 if (CanReplace(existing_keyword_turl) && are_same_type) { 2063 if (CanReplace(existing_keyword_turl) && are_same_type) {
2036 RemoveNoNotify(existing_keyword_turl); 2064 RemoveNoNotify(existing_keyword_turl);
2037 } else if (CanReplace(template_url) && are_same_type) { 2065 } else if (CanReplace(template_url) && are_same_type) {
2038 delete template_url; 2066 delete template_url;
2039 return false; 2067 return false;
2040 } else { 2068 } else {
2041 base::string16 new_keyword = 2069 base::string16 new_keyword =
2042 UniquifyKeyword(*existing_keyword_turl, false); 2070 UniquifyKeyword(*existing_keyword_turl, false);
2043 ResetTemplateURLNoNotify(existing_keyword_turl, 2071 ResetTemplateURLNoNotify(existing_keyword_turl,
2044 existing_keyword_turl->short_name(), new_keyword, 2072 existing_keyword_turl->short_name(), new_keyword,
2045 existing_keyword_turl->url()); 2073 existing_keyword_turl->url());
2046 } 2074 }
2047 } 2075 }
2048 template_urls_.push_back(template_url); 2076 template_urls_.push_back(template_url);
2049 AddToMaps(template_url); 2077 AddToMaps(template_url);
2050 2078
2051 if (newly_adding && 2079 if (newly_adding &&
2052 (template_url->GetType() != 2080 (template_url->GetType() == TemplateURL::NORMAL)) {
2053 TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION)) {
2054 if (web_data_service_.get()) 2081 if (web_data_service_.get())
2055 web_data_service_->AddKeyword(template_url->data()); 2082 web_data_service_->AddKeyword(template_url->data());
2056 2083
2057 // Inform sync of the addition. Note that this will assign a GUID to 2084 // Inform sync of the addition. Note that this will assign a GUID to
2058 // template_url and add it to the guid_to_template_map_. 2085 // template_url and add it to the guid_to_template_map_.
2059 ProcessTemplateURLChange(FROM_HERE, 2086 ProcessTemplateURLChange(FROM_HERE,
2060 template_url, 2087 template_url,
2061 syncer::SyncChange::ACTION_ADD); 2088 syncer::SyncChange::ACTION_ADD);
2062 } 2089 }
2063 2090
2064 return true; 2091 return true;
2065 } 2092 }
2066 2093
2067 void TemplateURLService::RemoveNoNotify(TemplateURL* template_url) { 2094 void TemplateURLService::RemoveNoNotify(TemplateURL* template_url) {
2068 DCHECK(template_url != default_search_provider_); 2095 DCHECK(template_url != default_search_provider_);
2069 2096
2070 TemplateURLVector::iterator i = 2097 TemplateURLVector::iterator i =
2071 std::find(template_urls_.begin(), template_urls_.end(), template_url); 2098 std::find(template_urls_.begin(), template_urls_.end(), template_url);
2072 if (i == template_urls_.end()) 2099 if (i == template_urls_.end())
2073 return; 2100 return;
2074 2101
2075 RemoveFromMaps(template_url); 2102 RemoveFromMaps(template_url);
2076 2103
2077 // Remove it from the vector containing all TemplateURLs. 2104 // Remove it from the vector containing all TemplateURLs.
2078 template_urls_.erase(i); 2105 template_urls_.erase(i);
2079 2106
2080 if (template_url->GetType() != TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION) { 2107 if (template_url->GetType() == TemplateURL::NORMAL) {
2081 if (web_data_service_.get()) 2108 if (web_data_service_.get())
2082 web_data_service_->RemoveKeyword(template_url->id()); 2109 web_data_service_->RemoveKeyword(template_url->id());
2083 2110
2084 // Inform sync of the deletion. 2111 // Inform sync of the deletion.
2085 ProcessTemplateURLChange(FROM_HERE, 2112 ProcessTemplateURLChange(FROM_HERE,
2086 template_url, 2113 template_url,
2087 syncer::SyncChange::ACTION_DELETE); 2114 syncer::SyncChange::ACTION_DELETE);
2088 2115
2089 UMA_HISTOGRAM_ENUMERATION(kDeleteSyncedEngineHistogramName, 2116 UMA_HISTOGRAM_ENUMERATION(kDeleteSyncedEngineHistogramName,
2090 DELETE_ENGINE_USER_ACTION, DELETE_ENGINE_MAX); 2117 DELETE_ENGINE_USER_ACTION, DELETE_ENGINE_MAX);
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
2228 2255
2229 void TemplateURLService::ResolveSyncKeywordConflict( 2256 void TemplateURLService::ResolveSyncKeywordConflict(
2230 TemplateURL* unapplied_sync_turl, 2257 TemplateURL* unapplied_sync_turl,
2231 TemplateURL* applied_sync_turl, 2258 TemplateURL* applied_sync_turl,
2232 syncer::SyncChangeList* change_list) { 2259 syncer::SyncChangeList* change_list) {
2233 DCHECK(loaded_); 2260 DCHECK(loaded_);
2234 DCHECK(unapplied_sync_turl); 2261 DCHECK(unapplied_sync_turl);
2235 DCHECK(applied_sync_turl); 2262 DCHECK(applied_sync_turl);
2236 DCHECK(change_list); 2263 DCHECK(change_list);
2237 DCHECK_EQ(applied_sync_turl->keyword(), unapplied_sync_turl->keyword()); 2264 DCHECK_EQ(applied_sync_turl->keyword(), unapplied_sync_turl->keyword());
2238 DCHECK_NE(TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION, 2265 DCHECK_EQ(TemplateURL::NORMAL, applied_sync_turl->GetType());
2239 applied_sync_turl->GetType());
2240 2266
2241 // Both |unapplied_sync_turl| and |applied_sync_turl| are known to Sync, so 2267 // Both |unapplied_sync_turl| and |applied_sync_turl| are known to Sync, so
2242 // don't delete either of them. Instead, determine which is "better" and 2268 // don't delete either of them. Instead, determine which is "better" and
2243 // uniquify the other one, sending an update to the server for the updated 2269 // uniquify the other one, sending an update to the server for the updated
2244 // entry. 2270 // entry.
2245 const bool applied_turl_is_better = 2271 const bool applied_turl_is_better =
2246 IsLocalTemplateURLBetter(applied_sync_turl, unapplied_sync_turl); 2272 IsLocalTemplateURLBetter(applied_sync_turl, unapplied_sync_turl);
2247 TemplateURL* loser = applied_turl_is_better ? 2273 TemplateURL* loser = applied_turl_is_better ?
2248 unapplied_sync_turl : applied_sync_turl; 2274 unapplied_sync_turl : applied_sync_turl;
2249 base::string16 new_keyword = UniquifyKeyword(*loser, false); 2275 base::string16 new_keyword = UniquifyKeyword(*loser, false);
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
2340 } 2366 }
2341 2367
2342 void TemplateURLService::PatchMissingSyncGUIDs( 2368 void TemplateURLService::PatchMissingSyncGUIDs(
2343 TemplateURLVector* template_urls) { 2369 TemplateURLVector* template_urls) {
2344 DCHECK(template_urls); 2370 DCHECK(template_urls);
2345 for (TemplateURLVector::iterator i = template_urls->begin(); 2371 for (TemplateURLVector::iterator i = template_urls->begin();
2346 i != template_urls->end(); ++i) { 2372 i != template_urls->end(); ++i) {
2347 TemplateURL* template_url = *i; 2373 TemplateURL* template_url = *i;
2348 DCHECK(template_url); 2374 DCHECK(template_url);
2349 if (template_url->sync_guid().empty() && 2375 if (template_url->sync_guid().empty() &&
2350 (template_url->GetType() != 2376 (template_url->GetType() == TemplateURL::NORMAL)) {
2351 TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION)) {
2352 template_url->data_.sync_guid = base::GenerateGUID(); 2377 template_url->data_.sync_guid = base::GenerateGUID();
2353 if (web_data_service_.get()) 2378 if (web_data_service_.get())
2354 web_data_service_->UpdateKeyword(template_url->data()); 2379 web_data_service_->UpdateKeyword(template_url->data());
2355 } 2380 }
2356 } 2381 }
2357 } 2382 }
2358 2383
2359 void TemplateURLService::OnSyncedDefaultSearchProviderGUIDChanged() { 2384 void TemplateURLService::OnSyncedDefaultSearchProviderGUIDChanged() {
2360 base::AutoReset<DefaultSearchChangeOrigin> change_origin( 2385 base::AutoReset<DefaultSearchChangeOrigin> change_origin(
2361 &dsp_change_origin_, DSP_CHANGE_SYNC_PREF); 2386 &dsp_change_origin_, DSP_CHANGE_SYNC_PREF);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
2423 2448
2424 if (most_recently_intalled_default) { 2449 if (most_recently_intalled_default) {
2425 base::AutoReset<DefaultSearchChangeOrigin> change_origin( 2450 base::AutoReset<DefaultSearchChangeOrigin> change_origin(
2426 &dsp_change_origin_, DSP_CHANGE_OVERRIDE_SETTINGS_EXTENSION); 2451 &dsp_change_origin_, DSP_CHANGE_OVERRIDE_SETTINGS_EXTENSION);
2427 default_search_manager_.SetExtensionControlledDefaultSearchEngine( 2452 default_search_manager_.SetExtensionControlledDefaultSearchEngine(
2428 most_recently_intalled_default->data()); 2453 most_recently_intalled_default->data());
2429 } else { 2454 } else {
2430 default_search_manager_.ClearExtensionControlledDefaultSearchEngine(); 2455 default_search_manager_.ClearExtensionControlledDefaultSearchEngine();
2431 } 2456 }
2432 } 2457 }
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