| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/search_engines/template_url_service.h" | 5 #include "chrome/browser/search_engines/template_url_service.h" |
| 6 | 6 |
| 7 #include <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 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 | 420 |
| 421 // Remove leading "www.". | 421 // Remove leading "www.". |
| 422 result = net::StripWWW(result); | 422 result = net::StripWWW(result); |
| 423 | 423 |
| 424 // Remove trailing "/". | 424 // Remove trailing "/". |
| 425 return (result.length() > 0 && result[result.length() - 1] == '/') ? | 425 return (result.length() > 0 && result[result.length() - 1] == '/') ? |
| 426 result.substr(0, result.length() - 1) : result; | 426 result.substr(0, result.length() - 1) : result; |
| 427 } | 427 } |
| 428 | 428 |
| 429 // static | 429 // static |
| 430 GURL TemplateURLService::GenerateSearchURL(TemplateURL* t_url) { | 430 GURL TemplateURLService::GenerateSearchURL( |
| 431 DCHECK(t_url); | |
| 432 UIThreadSearchTermsData search_terms_data(t_url->profile()); | |
| 433 return GenerateSearchURLUsingTermsData(t_url, search_terms_data); | |
| 434 } | |
| 435 | |
| 436 // static | |
| 437 GURL TemplateURLService::GenerateSearchURLUsingTermsData( | |
| 438 const TemplateURL* t_url, | 431 const TemplateURL* t_url, |
| 439 const SearchTermsData& search_terms_data) { | 432 const SearchTermsData& search_terms_data) { |
| 440 DCHECK(t_url); | 433 DCHECK(t_url); |
| 441 | 434 |
| 442 const TemplateURLRef& search_ref = t_url->url_ref(); | 435 const TemplateURLRef& search_ref = t_url->url_ref(); |
| 443 if (!search_ref.IsValid(search_terms_data)) | 436 if (!search_ref.IsValid(search_terms_data)) |
| 444 return GURL(); | 437 return GURL(); |
| 445 | 438 |
| 446 if (!search_ref.SupportsReplacement(search_terms_data)) | 439 if (!search_ref.SupportsReplacement(search_terms_data)) |
| 447 return GURL(t_url->url()); | 440 return GURL(t_url->url()); |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 606 if (elem != guid_to_template_map_.end()) | 599 if (elem != guid_to_template_map_.end()) |
| 607 return elem->second; | 600 return elem->second; |
| 608 return (!loaded_ && | 601 return (!loaded_ && |
| 609 initial_default_search_provider_.get() && | 602 initial_default_search_provider_.get() && |
| 610 (initial_default_search_provider_->sync_guid() == sync_guid)) ? | 603 (initial_default_search_provider_->sync_guid() == sync_guid)) ? |
| 611 initial_default_search_provider_.get() : NULL; | 604 initial_default_search_provider_.get() : NULL; |
| 612 } | 605 } |
| 613 | 606 |
| 614 TemplateURL* TemplateURLService::GetTemplateURLForHost( | 607 TemplateURL* TemplateURLService::GetTemplateURLForHost( |
| 615 const std::string& host) { | 608 const std::string& host) { |
| 616 if (loaded_) { | 609 if (loaded_) |
| 617 TemplateURL* t_url = provider_map_->GetTemplateURLForHost(host); | 610 return provider_map_->GetTemplateURLForHost(host); |
| 618 if (t_url) | 611 TemplateURL* initial_dsp = initial_default_search_provider_.get(); |
| 619 return t_url; | 612 if (!initial_dsp) |
| 620 } | 613 return NULL; |
| 621 return (!loaded_ && | 614 return (GenerateSearchURL(initial_dsp, search_terms_data()).host() == host) ? |
| 622 initial_default_search_provider_.get() && | 615 initial_dsp : NULL; |
| 623 (GenerateSearchURL(initial_default_search_provider_.get()).host() == | |
| 624 host)) ? initial_default_search_provider_.get() : NULL; | |
| 625 } | 616 } |
| 626 | 617 |
| 627 bool TemplateURLService::Add(TemplateURL* template_url) { | 618 bool TemplateURLService::Add(TemplateURL* template_url) { |
| 628 WebDataService::KeywordBatchModeScoper keyword_scoper(service_.get()); | 619 WebDataService::KeywordBatchModeScoper keyword_scoper(service_.get()); |
| 629 if (!AddNoNotify(template_url, true)) | 620 if (!AddNoNotify(template_url, true)) |
| 630 return false; | 621 return false; |
| 631 NotifyObservers(); | 622 NotifyObservers(); |
| 632 return true; | 623 return true; |
| 633 } | 624 } |
| 634 | 625 |
| 635 void TemplateURLService::AddAndSetProfile(TemplateURL* template_url, | |
| 636 Profile* profile) { | |
| 637 template_url->profile_ = profile; | |
| 638 Add(template_url); | |
| 639 } | |
| 640 | |
| 641 void TemplateURLService::AddWithOverrides(TemplateURL* template_url, | 626 void TemplateURLService::AddWithOverrides(TemplateURL* template_url, |
| 642 const base::string16& short_name, | 627 const base::string16& short_name, |
| 643 const base::string16& keyword, | 628 const base::string16& keyword, |
| 644 const std::string& url) { | 629 const std::string& url) { |
| 645 DCHECK(!keyword.empty()); | 630 DCHECK(!keyword.empty()); |
| 646 DCHECK(!url.empty()); | 631 DCHECK(!url.empty()); |
| 647 template_url->data_.short_name = short_name; | 632 template_url->data_.short_name = short_name; |
| 648 template_url->data_.SetKeyword(keyword); | 633 template_url->data_.SetKeyword(keyword); |
| 649 template_url->SetURL(url); | 634 template_url->SetURL(url); |
| 650 Add(template_url); | 635 Add(template_url); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 709 base::Time created_before) { | 694 base::Time created_before) { |
| 710 GURL o(origin.GetOrigin()); | 695 GURL o(origin.GetOrigin()); |
| 711 bool should_notify = false; | 696 bool should_notify = false; |
| 712 WebDataService::KeywordBatchModeScoper keyword_scoper(service_.get()); | 697 WebDataService::KeywordBatchModeScoper keyword_scoper(service_.get()); |
| 713 for (size_t i = 0; i < template_urls_.size();) { | 698 for (size_t i = 0; i < template_urls_.size();) { |
| 714 if (template_urls_[i]->date_created() >= created_after && | 699 if (template_urls_[i]->date_created() >= created_after && |
| 715 (created_before.is_null() || | 700 (created_before.is_null() || |
| 716 template_urls_[i]->date_created() < created_before) && | 701 template_urls_[i]->date_created() < created_before) && |
| 717 CanReplace(template_urls_[i]) && | 702 CanReplace(template_urls_[i]) && |
| 718 (o.is_empty() || | 703 (o.is_empty() || |
| 719 GenerateSearchURL(template_urls_[i]).GetOrigin() == o)) { | 704 GenerateSearchURL(template_urls_[i], |
| 705 search_terms_data()).GetOrigin() == o)) { |
| 720 RemoveNoNotify(template_urls_[i]); | 706 RemoveNoNotify(template_urls_[i]); |
| 721 should_notify = true; | 707 should_notify = true; |
| 722 } else { | 708 } else { |
| 723 ++i; | 709 ++i; |
| 724 } | 710 } |
| 725 } | 711 } |
| 726 if (should_notify) | 712 if (should_notify) |
| 727 NotifyObservers(); | 713 NotifyObservers(); |
| 728 } | 714 } |
| 729 | 715 |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 851 | 837 |
| 852 // Remove items. | 838 // Remove items. |
| 853 for (std::vector<TemplateURL*>::iterator i = actions.removed_engines.begin(); | 839 for (std::vector<TemplateURL*>::iterator i = actions.removed_engines.begin(); |
| 854 i < actions.removed_engines.end(); ++i) | 840 i < actions.removed_engines.end(); ++i) |
| 855 RemoveNoNotify(*i); | 841 RemoveNoNotify(*i); |
| 856 | 842 |
| 857 // Edit items. | 843 // Edit items. |
| 858 for (EditedEngines::iterator i(actions.edited_engines.begin()); | 844 for (EditedEngines::iterator i(actions.edited_engines.begin()); |
| 859 i < actions.edited_engines.end(); ++i) { | 845 i < actions.edited_engines.end(); ++i) { |
| 860 UIThreadSearchTermsData search_terms_data(profile()); | 846 UIThreadSearchTermsData search_terms_data(profile()); |
| 861 TemplateURL new_values(profile(), i->second); | 847 TemplateURL new_values(i->second); |
| 862 UpdateNoNotify(i->first, new_values, search_terms_data); | 848 UpdateNoNotify(i->first, new_values, search_terms_data); |
| 863 } | 849 } |
| 864 | 850 |
| 865 // Add items. | 851 // Add items. |
| 866 for (std::vector<TemplateURLData>::const_iterator i = | 852 for (std::vector<TemplateURLData>::const_iterator i = |
| 867 actions.added_engines.begin(); | 853 actions.added_engines.begin(); |
| 868 i < actions.added_engines.end(); | 854 i < actions.added_engines.end(); |
| 869 ++i) { | 855 ++i) { |
| 870 AddNoNotify(new TemplateURL(profile_, *i), true); | 856 AddNoNotify(new TemplateURL(*i), true); |
| 871 } | 857 } |
| 872 | 858 |
| 873 base::AutoReset<DefaultSearchChangeOrigin> change_origin( | 859 base::AutoReset<DefaultSearchChangeOrigin> change_origin( |
| 874 &dsp_change_origin_, DSP_CHANGE_PROFILE_RESET); | 860 &dsp_change_origin_, DSP_CHANGE_PROFILE_RESET); |
| 875 | 861 |
| 876 default_search_manager_.ClearUserSelectedDefaultSearchEngine(); | 862 default_search_manager_.ClearUserSelectedDefaultSearchEngine(); |
| 877 | 863 |
| 878 if (!default_search_provider_) { | 864 if (!default_search_provider_) { |
| 879 // If the default search provider came from a user pref we would have been | 865 // If the default search provider came from a user pref we would have been |
| 880 // notified of the new (fallback-provided) value in | 866 // notified of the new (fallback-provided) value in |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1097 // not ideal, but it prevents a far more severe bug where the default is | 1083 // not ideal, but it prevents a far more severe bug where the default is |
| 1098 // unexpectedly swapped to something else. The user can safely delete | 1084 // unexpectedly swapped to something else. The user can safely delete |
| 1099 // the extra entry again later, if they choose. Most users who do not | 1085 // the extra entry again later, if they choose. Most users who do not |
| 1100 // look at the search engines UI will not notice this. | 1086 // look at the search engines UI will not notice this. |
| 1101 // Note that we append a special character to the end of the keyword in | 1087 // Note that we append a special character to the end of the keyword in |
| 1102 // an attempt to avoid a ping-poinging situation where receiving clients | 1088 // an attempt to avoid a ping-poinging situation where receiving clients |
| 1103 // may try to continually delete the resurrected entry. | 1089 // may try to continually delete the resurrected entry. |
| 1104 base::string16 updated_keyword = UniquifyKeyword(*existing_turl, true); | 1090 base::string16 updated_keyword = UniquifyKeyword(*existing_turl, true); |
| 1105 TemplateURLData data(existing_turl->data()); | 1091 TemplateURLData data(existing_turl->data()); |
| 1106 data.SetKeyword(updated_keyword); | 1092 data.SetKeyword(updated_keyword); |
| 1107 TemplateURL new_turl(existing_turl->profile(), data); | 1093 TemplateURL new_turl(data); |
| 1108 UIThreadSearchTermsData search_terms_data(existing_turl->profile()); | 1094 if (UpdateNoNotify(existing_turl, new_turl, search_terms_data())) |
| 1109 if (UpdateNoNotify(existing_turl, new_turl, search_terms_data)) | |
| 1110 NotifyObservers(); | 1095 NotifyObservers(); |
| 1111 | 1096 |
| 1112 syncer::SyncData sync_data = CreateSyncDataFromTemplateURL(new_turl); | 1097 syncer::SyncData sync_data = CreateSyncDataFromTemplateURL(new_turl); |
| 1113 new_changes.push_back(syncer::SyncChange(FROM_HERE, | 1098 new_changes.push_back(syncer::SyncChange(FROM_HERE, |
| 1114 syncer::SyncChange::ACTION_ADD, | 1099 syncer::SyncChange::ACTION_ADD, |
| 1115 sync_data)); | 1100 sync_data)); |
| 1116 // Ignore the delete attempt. This means we never end up resetting the | 1101 // Ignore the delete attempt. This means we never end up resetting the |
| 1117 // default search provider due to an ACTION_DELETE from sync. | 1102 // default search provider due to an ACTION_DELETE from sync. |
| 1118 continue; | 1103 continue; |
| 1119 } | 1104 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1130 if (existing_keyword_turl) { | 1115 if (existing_keyword_turl) { |
| 1131 // Resolve any conflicts so we can safely add the new entry. | 1116 // Resolve any conflicts so we can safely add the new entry. |
| 1132 ResolveSyncKeywordConflict(turl.get(), existing_keyword_turl, | 1117 ResolveSyncKeywordConflict(turl.get(), existing_keyword_turl, |
| 1133 &new_changes); | 1118 &new_changes); |
| 1134 } | 1119 } |
| 1135 base::AutoReset<DefaultSearchChangeOrigin> change_origin( | 1120 base::AutoReset<DefaultSearchChangeOrigin> change_origin( |
| 1136 &dsp_change_origin_, DSP_CHANGE_SYNC_ADD); | 1121 &dsp_change_origin_, DSP_CHANGE_SYNC_ADD); |
| 1137 // Force the local ID to kInvalidTemplateURLID so we can add it. | 1122 // Force the local ID to kInvalidTemplateURLID so we can add it. |
| 1138 TemplateURLData data(turl->data()); | 1123 TemplateURLData data(turl->data()); |
| 1139 data.id = kInvalidTemplateURLID; | 1124 data.id = kInvalidTemplateURLID; |
| 1140 TemplateURL* added = new TemplateURL(profile_, data); | 1125 TemplateURL* added = new TemplateURL(data); |
| 1141 if (Add(added)) | 1126 if (Add(added)) |
| 1142 MaybeUpdateDSEAfterSync(added); | 1127 MaybeUpdateDSEAfterSync(added); |
| 1143 } else if (iter->change_type() == syncer::SyncChange::ACTION_UPDATE) { | 1128 } else if (iter->change_type() == syncer::SyncChange::ACTION_UPDATE) { |
| 1144 if (!existing_turl) { | 1129 if (!existing_turl) { |
| 1145 error = sync_error_factory_->CreateAndUploadError( | 1130 error = sync_error_factory_->CreateAndUploadError( |
| 1146 FROM_HERE, | 1131 FROM_HERE, |
| 1147 "ProcessSyncChanges failed on ChangeType ACTION_UPDATE"); | 1132 "ProcessSyncChanges failed on ChangeType ACTION_UPDATE"); |
| 1148 continue; | 1133 continue; |
| 1149 } | 1134 } |
| 1150 if (existing_keyword_turl && (existing_keyword_turl != existing_turl)) { | 1135 if (existing_keyword_turl && (existing_keyword_turl != existing_turl)) { |
| 1151 // Resolve any conflicts with other entries so we can safely update the | 1136 // Resolve any conflicts with other entries so we can safely update the |
| 1152 // keyword. | 1137 // keyword. |
| 1153 ResolveSyncKeywordConflict(turl.get(), existing_keyword_turl, | 1138 ResolveSyncKeywordConflict(turl.get(), existing_keyword_turl, |
| 1154 &new_changes); | 1139 &new_changes); |
| 1155 } | 1140 } |
| 1156 UIThreadSearchTermsData search_terms_data(existing_turl->profile()); | 1141 if (UpdateNoNotify(existing_turl, *turl, search_terms_data())) { |
| 1157 if (UpdateNoNotify(existing_turl, *turl, search_terms_data)) { | |
| 1158 NotifyObservers(); | 1142 NotifyObservers(); |
| 1159 MaybeUpdateDSEAfterSync(existing_turl); | 1143 MaybeUpdateDSEAfterSync(existing_turl); |
| 1160 } | 1144 } |
| 1161 } else { | 1145 } else { |
| 1162 // We've unexpectedly received an ACTION_INVALID. | 1146 // We've unexpectedly received an ACTION_INVALID. |
| 1163 error = sync_error_factory_->CreateAndUploadError( | 1147 error = sync_error_factory_->CreateAndUploadError( |
| 1164 FROM_HERE, | 1148 FROM_HERE, |
| 1165 "ProcessSyncChanges received an ACTION_INVALID"); | 1149 "ProcessSyncChanges received an ACTION_INVALID"); |
| 1166 } | 1150 } |
| 1167 } | 1151 } |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1246 DCHECK(IsFromSync(local_turl, sync_data_map)); | 1230 DCHECK(IsFromSync(local_turl, sync_data_map)); |
| 1247 // This local search engine is already synced. If the timestamp differs | 1231 // This local search engine is already synced. If the timestamp differs |
| 1248 // from Sync, we need to update locally or to the cloud. Note that if the | 1232 // from Sync, we need to update locally or to the cloud. Note that if the |
| 1249 // timestamps are equal, we touch neither. | 1233 // timestamps are equal, we touch neither. |
| 1250 if (sync_turl->last_modified() > local_turl->last_modified()) { | 1234 if (sync_turl->last_modified() > local_turl->last_modified()) { |
| 1251 // We've received an update from Sync. We should replace all synced | 1235 // We've received an update from Sync. We should replace all synced |
| 1252 // fields in the local TemplateURL. Note that this includes the | 1236 // fields in the local TemplateURL. Note that this includes the |
| 1253 // TemplateURLID and the TemplateURL may have to be reparsed. This | 1237 // TemplateURLID and the TemplateURL may have to be reparsed. This |
| 1254 // also makes the local data's last_modified timestamp equal to Sync's, | 1238 // also makes the local data's last_modified timestamp equal to Sync's, |
| 1255 // avoiding an Update on the next MergeData call. | 1239 // avoiding an Update on the next MergeData call. |
| 1256 UIThreadSearchTermsData search_terms_data(local_turl->profile()); | 1240 if (UpdateNoNotify(local_turl, *sync_turl, search_terms_data())) |
| 1257 if (UpdateNoNotify(local_turl, *sync_turl, search_terms_data)) | |
| 1258 NotifyObservers(); | 1241 NotifyObservers(); |
| 1259 merge_result.set_num_items_modified( | 1242 merge_result.set_num_items_modified( |
| 1260 merge_result.num_items_modified() + 1); | 1243 merge_result.num_items_modified() + 1); |
| 1261 } else if (sync_turl->last_modified() < local_turl->last_modified()) { | 1244 } else if (sync_turl->last_modified() < local_turl->last_modified()) { |
| 1262 // Otherwise, we know we have newer data, so update Sync with our | 1245 // Otherwise, we know we have newer data, so update Sync with our |
| 1263 // data fields. | 1246 // data fields. |
| 1264 new_changes.push_back( | 1247 new_changes.push_back( |
| 1265 syncer::SyncChange(FROM_HERE, | 1248 syncer::SyncChange(FROM_HERE, |
| 1266 syncer::SyncChange::ACTION_UPDATE, | 1249 syncer::SyncChange::ACTION_UPDATE, |
| 1267 local_data_map[local_turl->sync_guid()])); | 1250 local_data_map[local_turl->sync_guid()])); |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1446 bool deduped = DeDupeEncodings(&data.input_encodings); | 1429 bool deduped = DeDupeEncodings(&data.input_encodings); |
| 1447 data.date_created = base::Time::FromInternalValue(specifics.date_created()); | 1430 data.date_created = base::Time::FromInternalValue(specifics.date_created()); |
| 1448 data.last_modified = base::Time::FromInternalValue(specifics.last_modified()); | 1431 data.last_modified = base::Time::FromInternalValue(specifics.last_modified()); |
| 1449 data.prepopulate_id = specifics.prepopulate_id(); | 1432 data.prepopulate_id = specifics.prepopulate_id(); |
| 1450 data.sync_guid = specifics.sync_guid(); | 1433 data.sync_guid = specifics.sync_guid(); |
| 1451 data.alternate_urls.clear(); | 1434 data.alternate_urls.clear(); |
| 1452 for (int i = 0; i < specifics.alternate_urls_size(); ++i) | 1435 for (int i = 0; i < specifics.alternate_urls_size(); ++i) |
| 1453 data.alternate_urls.push_back(specifics.alternate_urls(i)); | 1436 data.alternate_urls.push_back(specifics.alternate_urls(i)); |
| 1454 data.search_terms_replacement_key = specifics.search_terms_replacement_key(); | 1437 data.search_terms_replacement_key = specifics.search_terms_replacement_key(); |
| 1455 | 1438 |
| 1456 TemplateURL* turl = new TemplateURL(profile, data); | 1439 TemplateURL* turl = new TemplateURL(data); |
| 1457 UIThreadSearchTermsData search_terms_data(profile); | 1440 UIThreadSearchTermsData search_terms_data(profile); |
| 1458 // If this TemplateURL matches a built-in prepopulated template URL, it's | 1441 // If this TemplateURL matches a built-in prepopulated template URL, it's |
| 1459 // possible that sync is trying to modify fields that should not be touched. | 1442 // possible that sync is trying to modify fields that should not be touched. |
| 1460 // Revert these fields to the built-in values. | 1443 // Revert these fields to the built-in values. |
| 1461 UpdateTemplateURLIfPrepopulated(turl, profile); | 1444 UpdateTemplateURLIfPrepopulated(turl, profile); |
| 1462 DCHECK_NE(TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION, turl->GetType()); | 1445 DCHECK_NE(TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION, turl->GetType()); |
| 1463 if (reset_keyword || deduped) { | 1446 if (reset_keyword || deduped) { |
| 1464 if (reset_keyword) | 1447 if (reset_keyword) |
| 1465 turl->ResetKeywordIfNecessary(search_terms_data, true); | 1448 turl->ResetKeywordIfNecessary(search_terms_data, true); |
| 1466 syncer::SyncData sync_data = CreateSyncDataFromTemplateURL(*turl); | 1449 syncer::SyncData sync_data = CreateSyncDataFromTemplateURL(*turl); |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1554 DCHECK(initializers[i].keyword); | 1537 DCHECK(initializers[i].keyword); |
| 1555 DCHECK(initializers[i].url); | 1538 DCHECK(initializers[i].url); |
| 1556 DCHECK(initializers[i].content); | 1539 DCHECK(initializers[i].content); |
| 1557 | 1540 |
| 1558 // TemplateURLService ends up owning the TemplateURL, don't try and free | 1541 // TemplateURLService ends up owning the TemplateURL, don't try and free |
| 1559 // it. | 1542 // it. |
| 1560 TemplateURLData data; | 1543 TemplateURLData data; |
| 1561 data.short_name = base::UTF8ToUTF16(initializers[i].content); | 1544 data.short_name = base::UTF8ToUTF16(initializers[i].content); |
| 1562 data.SetKeyword(base::UTF8ToUTF16(initializers[i].keyword)); | 1545 data.SetKeyword(base::UTF8ToUTF16(initializers[i].keyword)); |
| 1563 data.SetURL(initializers[i].url); | 1546 data.SetURL(initializers[i].url); |
| 1564 TemplateURL* template_url = new TemplateURL(profile_, data); | 1547 TemplateURL* template_url = new TemplateURL(data); |
| 1565 AddNoNotify(template_url, true); | 1548 AddNoNotify(template_url, true); |
| 1566 | 1549 |
| 1567 // Set the first provided identifier to be the default. | 1550 // Set the first provided identifier to be the default. |
| 1568 if (i == 0) | 1551 if (i == 0) |
| 1569 default_search_manager_.SetUserSelectedDefaultSearchEngine(data); | 1552 default_search_manager_.SetUserSelectedDefaultSearchEngine(data); |
| 1570 } | 1553 } |
| 1571 } | 1554 } |
| 1572 | 1555 |
| 1573 // Request a server check for the correct Google URL if Google is the | 1556 // Request a server check for the correct Google URL if Google is the |
| 1574 // default search engine and not in headless mode. | 1557 // default search engine and not in headless mode. |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1611 if (best_fallback) | 1594 if (best_fallback) |
| 1612 keyword_to_template_map_[keyword] = best_fallback; | 1595 keyword_to_template_map_[keyword] = best_fallback; |
| 1613 else | 1596 else |
| 1614 keyword_to_template_map_.erase(keyword); | 1597 keyword_to_template_map_.erase(keyword); |
| 1615 } | 1598 } |
| 1616 | 1599 |
| 1617 if (!template_url->sync_guid().empty()) | 1600 if (!template_url->sync_guid().empty()) |
| 1618 guid_to_template_map_.erase(template_url->sync_guid()); | 1601 guid_to_template_map_.erase(template_url->sync_guid()); |
| 1619 // |provider_map_| is only initialized after loading has completed. | 1602 // |provider_map_| is only initialized after loading has completed. |
| 1620 if (loaded_) { | 1603 if (loaded_) { |
| 1621 UIThreadSearchTermsData search_terms_data(template_url->profile()); | 1604 provider_map_->Remove(template_url, search_terms_data()); |
| 1622 provider_map_->Remove(template_url, search_terms_data); | |
| 1623 } | 1605 } |
| 1624 } | 1606 } |
| 1625 | 1607 |
| 1626 void TemplateURLService::AddToMaps(TemplateURL* template_url) { | 1608 void TemplateURLService::AddToMaps(TemplateURL* template_url) { |
| 1627 bool template_url_is_omnibox_api = | 1609 bool template_url_is_omnibox_api = |
| 1628 template_url->GetType() == TemplateURL::OMNIBOX_API_EXTENSION; | 1610 template_url->GetType() == TemplateURL::OMNIBOX_API_EXTENSION; |
| 1629 const base::string16& keyword = template_url->keyword(); | 1611 const base::string16& keyword = template_url->keyword(); |
| 1630 KeywordToTemplateMap::const_iterator i = | 1612 KeywordToTemplateMap::const_iterator i = |
| 1631 keyword_to_template_map_.find(keyword); | 1613 keyword_to_template_map_.find(keyword); |
| 1632 if (i == keyword_to_template_map_.end()) { | 1614 if (i == keyword_to_template_map_.end()) { |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1822 return; | 1804 return; |
| 1823 | 1805 |
| 1824 size_t default_search_index; | 1806 size_t default_search_index; |
| 1825 ScopedVector<TemplateURLData> prepopulated_urls = | 1807 ScopedVector<TemplateURLData> prepopulated_urls = |
| 1826 TemplateURLPrepopulateData::GetPrepopulatedEngines( | 1808 TemplateURLPrepopulateData::GetPrepopulatedEngines( |
| 1827 profile ? profile->GetPrefs() : NULL, &default_search_index); | 1809 profile ? profile->GetPrefs() : NULL, &default_search_index); |
| 1828 | 1810 |
| 1829 for (size_t i = 0; i < prepopulated_urls.size(); ++i) { | 1811 for (size_t i = 0; i < prepopulated_urls.size(); ++i) { |
| 1830 if (prepopulated_urls[i]->prepopulate_id == prepopulate_id) { | 1812 if (prepopulated_urls[i]->prepopulate_id == prepopulate_id) { |
| 1831 MergeIntoPrepopulatedEngineData(template_url, prepopulated_urls[i]); | 1813 MergeIntoPrepopulatedEngineData(template_url, prepopulated_urls[i]); |
| 1832 template_url->CopyFrom(TemplateURL(profile, *prepopulated_urls[i])); | 1814 template_url->CopyFrom(TemplateURL(*prepopulated_urls[i])); |
| 1833 } | 1815 } |
| 1834 } | 1816 } |
| 1835 } | 1817 } |
| 1836 | 1818 |
| 1837 void TemplateURLService::MaybeUpdateDSEAfterSync(TemplateURL* synced_turl) { | 1819 void TemplateURLService::MaybeUpdateDSEAfterSync(TemplateURL* synced_turl) { |
| 1838 if (GetPrefs() && | 1820 if (GetPrefs() && |
| 1839 (synced_turl->sync_guid() == | 1821 (synced_turl->sync_guid() == |
| 1840 GetPrefs()->GetString(prefs::kSyncedDefaultSearchProviderGUID))) { | 1822 GetPrefs()->GetString(prefs::kSyncedDefaultSearchProviderGUID))) { |
| 1841 default_search_manager_.SetUserSelectedDefaultSearchEngine( | 1823 default_search_manager_.SetUserSelectedDefaultSearchEngine( |
| 1842 synced_turl->data()); | 1824 synced_turl->data()); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1905 history::SOURCE_BROWSED, false); | 1887 history::SOURCE_BROWSED, false); |
| 1906 } | 1888 } |
| 1907 | 1889 |
| 1908 void TemplateURLService::GoogleBaseURLChanged(const GURL& old_base_url) { | 1890 void TemplateURLService::GoogleBaseURLChanged(const GURL& old_base_url) { |
| 1909 WebDataService::KeywordBatchModeScoper keyword_scoper(service_.get()); | 1891 WebDataService::KeywordBatchModeScoper keyword_scoper(service_.get()); |
| 1910 bool something_changed = false; | 1892 bool something_changed = false; |
| 1911 for (TemplateURLVector::iterator i(template_urls_.begin()); | 1893 for (TemplateURLVector::iterator i(template_urls_.begin()); |
| 1912 i != template_urls_.end(); ++i) { | 1894 i != template_urls_.end(); ++i) { |
| 1913 TemplateURL* t_url = *i; | 1895 TemplateURL* t_url = *i; |
| 1914 if (t_url->HasGoogleBaseURLs(search_terms_data())) { | 1896 if (t_url->HasGoogleBaseURLs(search_terms_data())) { |
| 1915 TemplateURL updated_turl(t_url->profile(), t_url->data()); | 1897 TemplateURL updated_turl(t_url->data()); |
| 1916 updated_turl.ResetKeywordIfNecessary(search_terms_data(), false); | 1898 updated_turl.ResetKeywordIfNecessary(search_terms_data(), false); |
| 1917 KeywordToTemplateMap::const_iterator existing_entry = | 1899 KeywordToTemplateMap::const_iterator existing_entry = |
| 1918 keyword_to_template_map_.find(updated_turl.keyword()); | 1900 keyword_to_template_map_.find(updated_turl.keyword()); |
| 1919 if ((existing_entry != keyword_to_template_map_.end()) && | 1901 if ((existing_entry != keyword_to_template_map_.end()) && |
| 1920 (existing_entry->second != t_url)) { | 1902 (existing_entry->second != t_url)) { |
| 1921 // The new autogenerated keyword conflicts with another TemplateURL. | 1903 // The new autogenerated keyword conflicts with another TemplateURL. |
| 1922 // Overwrite it if it's replaceable; otherwise, leave |t_url| using its | 1904 // Overwrite it if it's replaceable; otherwise, leave |t_url| using its |
| 1923 // current keyword. (This will not prevent |t_url| from auto-updating | 1905 // current keyword. (This will not prevent |t_url| from auto-updating |
| 1924 // the keyword in the future if the conflicting TemplateURL disappears.) | 1906 // the keyword in the future if the conflicting TemplateURL disappears.) |
| 1925 // Note that we must still update |t_url| in this case, or the | 1907 // Note that we must still update |t_url| in this case, or the |
| 1926 // |provider_map_| will not be updated correctly. | 1908 // |provider_map_| will not be updated correctly. |
| 1927 if (CanReplace(existing_entry->second)) | 1909 if (CanReplace(existing_entry->second)) |
| 1928 RemoveNoNotify(existing_entry->second); | 1910 RemoveNoNotify(existing_entry->second); |
| 1929 else | 1911 else |
| 1930 updated_turl.data_.SetKeyword(t_url->keyword()); | 1912 updated_turl.data_.SetKeyword(t_url->keyword()); |
| 1931 } | 1913 } |
| 1932 something_changed = true; | 1914 something_changed = true; |
| 1933 // This will send the keyword change to sync. Note that other clients | 1915 // This will send the keyword change to sync. Note that other clients |
| 1934 // need to reset the keyword to an appropriate local value when this | 1916 // need to reset the keyword to an appropriate local value when this |
| 1935 // change arrives; see CreateTemplateURLFromTemplateURLAndSyncData(). | 1917 // change arrives; see CreateTemplateURLFromTemplateURLAndSyncData(). |
| 1936 UpdateNoNotify(t_url, updated_turl, | 1918 UpdateNoNotify(t_url, updated_turl, |
| 1937 OldBaseURLSearchTermsData(t_url->profile(), old_base_url.spec())); | 1919 OldBaseURLSearchTermsData(profile(), old_base_url.spec())); |
| 1938 } | 1920 } |
| 1939 } | 1921 } |
| 1940 if (something_changed) | 1922 if (something_changed) |
| 1941 NotifyObservers(); | 1923 NotifyObservers(); |
| 1942 } | 1924 } |
| 1943 | 1925 |
| 1944 void TemplateURLService::OnGoogleURLUpdated(GURL old_url, GURL new_url) { | 1926 void TemplateURLService::OnGoogleURLUpdated(GURL old_url, GURL new_url) { |
| 1945 if (loaded_) | 1927 if (loaded_) |
| 1946 GoogleBaseURLChanged(old_url); | 1928 GoogleBaseURLChanged(old_url); |
| 1947 } | 1929 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1980 const TemplateURLData* data, | 1962 const TemplateURLData* data, |
| 1981 DefaultSearchManager::Source source) { | 1963 DefaultSearchManager::Source source) { |
| 1982 if (!loaded_) { | 1964 if (!loaded_) { |
| 1983 // Set |initial_default_search_provider_| from the preferences. This is | 1965 // Set |initial_default_search_provider_| from the preferences. This is |
| 1984 // mainly so we can hold ownership until we get to the point where the list | 1966 // mainly so we can hold ownership until we get to the point where the list |
| 1985 // of keywords from Web Data is the owner of everything including the | 1967 // of keywords from Web Data is the owner of everything including the |
| 1986 // default. | 1968 // default. |
| 1987 bool changed = TemplateURL::MatchesData( | 1969 bool changed = TemplateURL::MatchesData( |
| 1988 initial_default_search_provider_.get(), data, search_terms_data()); | 1970 initial_default_search_provider_.get(), data, search_terms_data()); |
| 1989 initial_default_search_provider_.reset( | 1971 initial_default_search_provider_.reset( |
| 1990 data ? new TemplateURL(profile_, *data) : NULL); | 1972 data ? new TemplateURL(*data) : NULL); |
| 1991 default_search_provider_source_ = source; | 1973 default_search_provider_source_ = source; |
| 1992 return changed; | 1974 return changed; |
| 1993 } | 1975 } |
| 1994 | 1976 |
| 1995 // Prevent recursion if we update the value stored in default_search_manager_. | 1977 // Prevent recursion if we update the value stored in default_search_manager_. |
| 1996 // Note that we exclude the case of data == NULL because that could cause a | 1978 // Note that we exclude the case of data == NULL because that could cause a |
| 1997 // false positive for recursion when the initial_default_search_provider_ is | 1979 // false positive for recursion when the initial_default_search_provider_ is |
| 1998 // NULL due to policy. We'll never actually get recursion with data == NULL. | 1980 // NULL due to policy. We'll never actually get recursion with data == NULL. |
| 1999 if (source == default_search_provider_source_ && data != NULL && | 1981 if (source == default_search_provider_source_ && data != NULL && |
| 2000 TemplateURL::MatchesData(default_search_provider_, data, | 1982 TemplateURL::MatchesData(default_search_provider_, data, |
| (...skipping 23 matching lines...) Expand all Loading... |
| 2024 default_search_provider_ = | 2006 default_search_provider_ = |
| 2025 FindPrepopulatedTemplateURL(data->prepopulate_id); | 2007 FindPrepopulatedTemplateURL(data->prepopulate_id); |
| 2026 if (default_search_provider_) { | 2008 if (default_search_provider_) { |
| 2027 TemplateURLData update_data(*data); | 2009 TemplateURLData update_data(*data); |
| 2028 update_data.sync_guid = default_search_provider_->sync_guid(); | 2010 update_data.sync_guid = default_search_provider_->sync_guid(); |
| 2029 if (!default_search_provider_->safe_for_autoreplace()) { | 2011 if (!default_search_provider_->safe_for_autoreplace()) { |
| 2030 update_data.safe_for_autoreplace = false; | 2012 update_data.safe_for_autoreplace = false; |
| 2031 update_data.SetKeyword(default_search_provider_->keyword()); | 2013 update_data.SetKeyword(default_search_provider_->keyword()); |
| 2032 update_data.short_name = default_search_provider_->short_name(); | 2014 update_data.short_name = default_search_provider_->short_name(); |
| 2033 } | 2015 } |
| 2034 UIThreadSearchTermsData search_terms_data( | |
| 2035 default_search_provider_->profile()); | |
| 2036 UpdateNoNotify(default_search_provider_, | 2016 UpdateNoNotify(default_search_provider_, |
| 2037 TemplateURL(profile_, update_data), | 2017 TemplateURL(update_data), |
| 2038 search_terms_data); | 2018 search_terms_data()); |
| 2039 } else { | 2019 } else { |
| 2040 // Normally the prepopulated fallback should be present in | 2020 // Normally the prepopulated fallback should be present in |
| 2041 // |template_urls_|, but in a few cases it might not be: | 2021 // |template_urls_|, but in a few cases it might not be: |
| 2042 // (1) Tests that initialize the TemplateURLService in peculiar ways. | 2022 // (1) Tests that initialize the TemplateURLService in peculiar ways. |
| 2043 // (2) If the user deleted the pre-populated default and we subsequently | 2023 // (2) If the user deleted the pre-populated default and we subsequently |
| 2044 // lost their user-selected value. | 2024 // lost their user-selected value. |
| 2045 TemplateURL* new_dse = new TemplateURL(profile_, *data); | 2025 TemplateURL* new_dse = new TemplateURL(*data); |
| 2046 if (AddNoNotify(new_dse, true)) | 2026 if (AddNoNotify(new_dse, true)) |
| 2047 default_search_provider_ = new_dse; | 2027 default_search_provider_ = new_dse; |
| 2048 } | 2028 } |
| 2049 } else if (source == DefaultSearchManager::FROM_USER) { | 2029 } else if (source == DefaultSearchManager::FROM_USER) { |
| 2050 default_search_provider_ = GetTemplateURLForGUID(data->sync_guid); | 2030 default_search_provider_ = GetTemplateURLForGUID(data->sync_guid); |
| 2051 if (!default_search_provider_ && data->prepopulate_id) { | 2031 if (!default_search_provider_ && data->prepopulate_id) { |
| 2052 default_search_provider_ = | 2032 default_search_provider_ = |
| 2053 FindPrepopulatedTemplateURL(data->prepopulate_id); | 2033 FindPrepopulatedTemplateURL(data->prepopulate_id); |
| 2054 } | 2034 } |
| 2055 TemplateURLData new_data(*data); | 2035 TemplateURLData new_data(*data); |
| 2056 new_data.show_in_default_list = true; | 2036 new_data.show_in_default_list = true; |
| 2057 if (default_search_provider_) { | 2037 if (default_search_provider_) { |
| 2058 UIThreadSearchTermsData search_terms_data( | |
| 2059 default_search_provider_->profile()); | |
| 2060 UpdateNoNotify(default_search_provider_, | 2038 UpdateNoNotify(default_search_provider_, |
| 2061 TemplateURL(profile_, new_data), | 2039 TemplateURL(new_data), |
| 2062 search_terms_data); | 2040 search_terms_data()); |
| 2063 } else { | 2041 } else { |
| 2064 new_data.id = kInvalidTemplateURLID; | 2042 new_data.id = kInvalidTemplateURLID; |
| 2065 TemplateURL* new_dse = new TemplateURL(profile_, new_data); | 2043 TemplateURL* new_dse = new TemplateURL(new_data); |
| 2066 if (AddNoNotify(new_dse, true)) | 2044 if (AddNoNotify(new_dse, true)) |
| 2067 default_search_provider_ = new_dse; | 2045 default_search_provider_ = new_dse; |
| 2068 } | 2046 } |
| 2069 if (default_search_provider_ && GetPrefs()) { | 2047 if (default_search_provider_ && GetPrefs()) { |
| 2070 GetPrefs()->SetString( | 2048 GetPrefs()->SetString( |
| 2071 prefs::kSyncedDefaultSearchProviderGUID, | 2049 prefs::kSyncedDefaultSearchProviderGUID, |
| 2072 default_search_provider_->sync_guid()); | 2050 default_search_provider_->sync_guid()); |
| 2073 } | 2051 } |
| 2074 | 2052 |
| 2075 } | 2053 } |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2206 TemplateURLData data(url->data()); | 2184 TemplateURLData data(url->data()); |
| 2207 data.short_name = title; | 2185 data.short_name = title; |
| 2208 data.SetKeyword(keyword); | 2186 data.SetKeyword(keyword); |
| 2209 if (search_url != data.url()) { | 2187 if (search_url != data.url()) { |
| 2210 data.SetURL(search_url); | 2188 data.SetURL(search_url); |
| 2211 // The urls have changed, reset the favicon url. | 2189 // The urls have changed, reset the favicon url. |
| 2212 data.favicon_url = GURL(); | 2190 data.favicon_url = GURL(); |
| 2213 } | 2191 } |
| 2214 data.safe_for_autoreplace = false; | 2192 data.safe_for_autoreplace = false; |
| 2215 data.last_modified = time_provider_(); | 2193 data.last_modified = time_provider_(); |
| 2216 UIThreadSearchTermsData search_terms_data(url->profile()); | 2194 return UpdateNoNotify(url, TemplateURL(data), search_terms_data()); |
| 2217 return UpdateNoNotify(url, TemplateURL(profile_, data), search_terms_data); | |
| 2218 } | 2195 } |
| 2219 | 2196 |
| 2220 void TemplateURLService::NotifyObservers() { | 2197 void TemplateURLService::NotifyObservers() { |
| 2221 if (!loaded_) | 2198 if (!loaded_) |
| 2222 return; | 2199 return; |
| 2223 | 2200 |
| 2224 FOR_EACH_OBSERVER(TemplateURLServiceObserver, model_observers_, | 2201 FOR_EACH_OBSERVER(TemplateURLServiceObserver, model_observers_, |
| 2225 OnTemplateURLServiceChanged()); | 2202 OnTemplateURLServiceChanged()); |
| 2226 } | 2203 } |
| 2227 | 2204 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2265 } | 2242 } |
| 2266 } | 2243 } |
| 2267 | 2244 |
| 2268 if (default_from_prefs) { | 2245 if (default_from_prefs) { |
| 2269 default_search_provider_ = NULL; | 2246 default_search_provider_ = NULL; |
| 2270 default_search_provider_source_ = DefaultSearchManager::FROM_POLICY; | 2247 default_search_provider_source_ = DefaultSearchManager::FROM_POLICY; |
| 2271 TemplateURLData new_data(*default_from_prefs); | 2248 TemplateURLData new_data(*default_from_prefs); |
| 2272 if (new_data.sync_guid.empty()) | 2249 if (new_data.sync_guid.empty()) |
| 2273 new_data.sync_guid = base::GenerateGUID(); | 2250 new_data.sync_guid = base::GenerateGUID(); |
| 2274 new_data.created_by_policy = true; | 2251 new_data.created_by_policy = true; |
| 2275 TemplateURL* new_dse = new TemplateURL(profile_, new_data); | 2252 TemplateURL* new_dse = new TemplateURL(new_data); |
| 2276 if (AddNoNotify(new_dse, true)) | 2253 if (AddNoNotify(new_dse, true)) |
| 2277 default_search_provider_ = new_dse; | 2254 default_search_provider_ = new_dse; |
| 2278 } | 2255 } |
| 2279 } | 2256 } |
| 2280 | 2257 |
| 2281 void TemplateURLService::ResetTemplateURLGUID(TemplateURL* url, | 2258 void TemplateURLService::ResetTemplateURLGUID(TemplateURL* url, |
| 2282 const std::string& guid) { | 2259 const std::string& guid) { |
| 2283 DCHECK(loaded_); | 2260 DCHECK(loaded_); |
| 2284 DCHECK(!guid.empty()); | 2261 DCHECK(!guid.empty()); |
| 2285 | 2262 |
| 2286 TemplateURLData data(url->data()); | 2263 TemplateURLData data(url->data()); |
| 2287 data.sync_guid = guid; | 2264 data.sync_guid = guid; |
| 2288 UIThreadSearchTermsData search_terms_data(url->profile()); | 2265 UpdateNoNotify(url, TemplateURL(data), search_terms_data()); |
| 2289 UpdateNoNotify(url, TemplateURL(profile_, data), search_terms_data); | |
| 2290 } | 2266 } |
| 2291 | 2267 |
| 2292 base::string16 TemplateURLService::UniquifyKeyword(const TemplateURL& turl, | 2268 base::string16 TemplateURLService::UniquifyKeyword(const TemplateURL& turl, |
| 2293 bool force) { | 2269 bool force) { |
| 2294 if (!force) { | 2270 if (!force) { |
| 2295 // Already unique. | 2271 // Already unique. |
| 2296 if (!GetTemplateURLForKeyword(turl.keyword())) | 2272 if (!GetTemplateURLForKeyword(turl.keyword())) |
| 2297 return turl.keyword(); | 2273 return turl.keyword(); |
| 2298 | 2274 |
| 2299 // First, try to return the generated keyword for the TemplateURL (except | 2275 // First, try to return the generated keyword for the TemplateURL (except |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2350 base::string16 new_keyword = UniquifyKeyword(*loser, false); | 2326 base::string16 new_keyword = UniquifyKeyword(*loser, false); |
| 2351 DCHECK(!GetTemplateURLForKeyword(new_keyword)); | 2327 DCHECK(!GetTemplateURLForKeyword(new_keyword)); |
| 2352 if (applied_turl_is_better) { | 2328 if (applied_turl_is_better) { |
| 2353 // Just set the keyword of |unapplied_sync_turl|. The caller is responsible | 2329 // Just set the keyword of |unapplied_sync_turl|. The caller is responsible |
| 2354 // for adding or updating unapplied_sync_turl in the local model. | 2330 // for adding or updating unapplied_sync_turl in the local model. |
| 2355 unapplied_sync_turl->data_.SetKeyword(new_keyword); | 2331 unapplied_sync_turl->data_.SetKeyword(new_keyword); |
| 2356 } else { | 2332 } else { |
| 2357 // Update |applied_sync_turl| in the local model with the new keyword. | 2333 // Update |applied_sync_turl| in the local model with the new keyword. |
| 2358 TemplateURLData data(applied_sync_turl->data()); | 2334 TemplateURLData data(applied_sync_turl->data()); |
| 2359 data.SetKeyword(new_keyword); | 2335 data.SetKeyword(new_keyword); |
| 2360 UIThreadSearchTermsData search_terms_data(applied_sync_turl->profile()); | |
| 2361 if (UpdateNoNotify( | 2336 if (UpdateNoNotify( |
| 2362 applied_sync_turl, TemplateURL(profile_, data), search_terms_data)) | 2337 applied_sync_turl, TemplateURL(data), search_terms_data())) |
| 2363 NotifyObservers(); | 2338 NotifyObservers(); |
| 2364 } | 2339 } |
| 2365 // The losing TemplateURL should have their keyword updated. Send a change to | 2340 // The losing TemplateURL should have their keyword updated. Send a change to |
| 2366 // the server to reflect this change. | 2341 // the server to reflect this change. |
| 2367 syncer::SyncData sync_data = CreateSyncDataFromTemplateURL(*loser); | 2342 syncer::SyncData sync_data = CreateSyncDataFromTemplateURL(*loser); |
| 2368 change_list->push_back(syncer::SyncChange(FROM_HERE, | 2343 change_list->push_back(syncer::SyncChange(FROM_HERE, |
| 2369 syncer::SyncChange::ACTION_UPDATE, | 2344 syncer::SyncChange::ACTION_UPDATE, |
| 2370 sync_data)); | 2345 sync_data)); |
| 2371 } | 2346 } |
| 2372 | 2347 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2425 // This TemplateURL was either removed or overwritten in the local model. | 2400 // This TemplateURL was either removed or overwritten in the local model. |
| 2426 // Remove the entry from the local data so it isn't pushed up to Sync. | 2401 // Remove the entry from the local data so it isn't pushed up to Sync. |
| 2427 local_data->erase(guid); | 2402 local_data->erase(guid); |
| 2428 } | 2403 } |
| 2429 } | 2404 } |
| 2430 | 2405 |
| 2431 if (should_add_sync_turl) { | 2406 if (should_add_sync_turl) { |
| 2432 // Force the local ID to kInvalidTemplateURLID so we can add it. | 2407 // Force the local ID to kInvalidTemplateURLID so we can add it. |
| 2433 TemplateURLData data(sync_turl->data()); | 2408 TemplateURLData data(sync_turl->data()); |
| 2434 data.id = kInvalidTemplateURLID; | 2409 data.id = kInvalidTemplateURLID; |
| 2435 TemplateURL* added = new TemplateURL(profile_, data); | 2410 TemplateURL* added = new TemplateURL(data); |
| 2436 base::AutoReset<DefaultSearchChangeOrigin> change_origin( | 2411 base::AutoReset<DefaultSearchChangeOrigin> change_origin( |
| 2437 &dsp_change_origin_, DSP_CHANGE_SYNC_ADD); | 2412 &dsp_change_origin_, DSP_CHANGE_SYNC_ADD); |
| 2438 if (Add(added)) | 2413 if (Add(added)) |
| 2439 MaybeUpdateDSEAfterSync(added); | 2414 MaybeUpdateDSEAfterSync(added); |
| 2440 merge_result->set_num_items_added( | 2415 merge_result->set_num_items_added( |
| 2441 merge_result->num_items_added() + 1); | 2416 merge_result->num_items_added() + 1); |
| 2442 } | 2417 } |
| 2443 } | 2418 } |
| 2444 | 2419 |
| 2445 void TemplateURLService::PatchMissingSyncGUIDs( | 2420 void TemplateURLService::PatchMissingSyncGUIDs( |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2487 | 2462 |
| 2488 TemplateURL* TemplateURLService::CreateTemplateURLForExtension( | 2463 TemplateURL* TemplateURLService::CreateTemplateURLForExtension( |
| 2489 const ExtensionKeyword& extension_keyword) { | 2464 const ExtensionKeyword& extension_keyword) { |
| 2490 TemplateURLData data; | 2465 TemplateURLData data; |
| 2491 data.short_name = base::UTF8ToUTF16(extension_keyword.extension_name); | 2466 data.short_name = base::UTF8ToUTF16(extension_keyword.extension_name); |
| 2492 data.SetKeyword(base::UTF8ToUTF16(extension_keyword.extension_keyword)); | 2467 data.SetKeyword(base::UTF8ToUTF16(extension_keyword.extension_keyword)); |
| 2493 // This URL is not actually used for navigation. It holds the extension's | 2468 // This URL is not actually used for navigation. It holds the extension's |
| 2494 // ID, as well as forcing the TemplateURL to be treated as a search keyword. | 2469 // ID, as well as forcing the TemplateURL to be treated as a search keyword. |
| 2495 data.SetURL(std::string(extensions::kExtensionScheme) + "://" + | 2470 data.SetURL(std::string(extensions::kExtensionScheme) + "://" + |
| 2496 extension_keyword.extension_id + "/?q={searchTerms}"); | 2471 extension_keyword.extension_id + "/?q={searchTerms}"); |
| 2497 return new TemplateURL(profile_, data); | 2472 return new TemplateURL(data); |
| 2498 } | 2473 } |
| 2499 | 2474 |
| 2500 TemplateURL* TemplateURLService::FindTemplateURLForExtension( | 2475 TemplateURL* TemplateURLService::FindTemplateURLForExtension( |
| 2501 const std::string& extension_id, | 2476 const std::string& extension_id, |
| 2502 TemplateURL::Type type) { | 2477 TemplateURL::Type type) { |
| 2503 DCHECK_NE(TemplateURL::NORMAL, type); | 2478 DCHECK_NE(TemplateURL::NORMAL, type); |
| 2504 for (TemplateURLVector::const_iterator i = template_urls_.begin(); | 2479 for (TemplateURLVector::const_iterator i = template_urls_.begin(); |
| 2505 i != template_urls_.end(); ++i) { | 2480 i != template_urls_.end(); ++i) { |
| 2506 if ((*i)->GetType() == type && | 2481 if ((*i)->GetType() == type && |
| 2507 (*i)->GetExtensionId() == extension_id) | 2482 (*i)->GetExtensionId() == extension_id) |
| (...skipping 30 matching lines...) Expand all Loading... |
| 2538 | 2513 |
| 2539 if (most_recently_intalled_default) { | 2514 if (most_recently_intalled_default) { |
| 2540 base::AutoReset<DefaultSearchChangeOrigin> change_origin( | 2515 base::AutoReset<DefaultSearchChangeOrigin> change_origin( |
| 2541 &dsp_change_origin_, DSP_CHANGE_OVERRIDE_SETTINGS_EXTENSION); | 2516 &dsp_change_origin_, DSP_CHANGE_OVERRIDE_SETTINGS_EXTENSION); |
| 2542 default_search_manager_.SetExtensionControlledDefaultSearchEngine( | 2517 default_search_manager_.SetExtensionControlledDefaultSearchEngine( |
| 2543 most_recently_intalled_default->data()); | 2518 most_recently_intalled_default->data()); |
| 2544 } else { | 2519 } else { |
| 2545 default_search_manager_.ClearExtensionControlledDefaultSearchEngine(); | 2520 default_search_manager_.ClearExtensionControlledDefaultSearchEngine(); |
| 2546 } | 2521 } |
| 2547 } | 2522 } |
| OLD | NEW |