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