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 "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/environment.h" | 10 #include "base/environment.h" |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
78 return true; | 78 return true; |
79 return (url1 != NULL) && (url2 != NULL) && | 79 return (url1 != NULL) && (url2 != NULL) && |
80 (url1->short_name() == url2->short_name()) && | 80 (url1->short_name() == url2->short_name()) && |
81 url1->HasSameKeywordAs(*url2) && | 81 url1->HasSameKeywordAs(*url2) && |
82 (url1->url() == url2->url()) && | 82 (url1->url() == url2->url()) && |
83 (url1->suggestions_url() == url2->suggestions_url()) && | 83 (url1->suggestions_url() == url2->suggestions_url()) && |
84 (url1->instant_url() == url2->instant_url()) && | 84 (url1->instant_url() == url2->instant_url()) && |
85 (url1->favicon_url() == url2->favicon_url()) && | 85 (url1->favicon_url() == url2->favicon_url()) && |
86 (url1->safe_for_autoreplace() == url2->safe_for_autoreplace()) && | 86 (url1->safe_for_autoreplace() == url2->safe_for_autoreplace()) && |
87 (url1->show_in_default_list() == url2->show_in_default_list()) && | 87 (url1->show_in_default_list() == url2->show_in_default_list()) && |
88 (url1->input_encodings() == url2->input_encodings()); | 88 (url1->input_encodings() == url2->input_encodings()) && |
89 (url1->alternate_urls() == url2->alternate_urls()); | |
89 } | 90 } |
90 | 91 |
91 const char kFirstPotentialEngineHistogramName[] = | 92 const char kFirstPotentialEngineHistogramName[] = |
92 "Search.FirstPotentialEngineCalled"; | 93 "Search.FirstPotentialEngineCalled"; |
93 | 94 |
94 // Values for an enumerated histogram used to track whenever | 95 // Values for an enumerated histogram used to track whenever |
95 // FirstPotentialDefaultEngine is called, and from where. | 96 // FirstPotentialDefaultEngine is called, and from where. |
96 enum FirstPotentialEngineCaller { | 97 enum FirstPotentialEngineCaller { |
97 FIRST_POTENTIAL_CALLSITE_FIND_NEW_DSP, | 98 FIRST_POTENTIAL_CALLSITE_FIND_NEW_DSP, |
98 FIRST_POTENTIAL_CALLSITE_FIND_NEW_DSP_PROCESSING_SYNC_CHANGES, | 99 FIRST_POTENTIAL_CALLSITE_FIND_NEW_DSP_PROCESSING_SYNC_CHANGES, |
(...skipping 1195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1294 se_specifics->set_safe_for_autoreplace(turl.safe_for_autoreplace()); | 1295 se_specifics->set_safe_for_autoreplace(turl.safe_for_autoreplace()); |
1295 se_specifics->set_originating_url(turl.originating_url().spec()); | 1296 se_specifics->set_originating_url(turl.originating_url().spec()); |
1296 se_specifics->set_date_created(turl.date_created().ToInternalValue()); | 1297 se_specifics->set_date_created(turl.date_created().ToInternalValue()); |
1297 se_specifics->set_input_encodings(JoinString(turl.input_encodings(), ';')); | 1298 se_specifics->set_input_encodings(JoinString(turl.input_encodings(), ';')); |
1298 se_specifics->set_show_in_default_list(turl.show_in_default_list()); | 1299 se_specifics->set_show_in_default_list(turl.show_in_default_list()); |
1299 se_specifics->set_suggestions_url(turl.suggestions_url()); | 1300 se_specifics->set_suggestions_url(turl.suggestions_url()); |
1300 se_specifics->set_prepopulate_id(turl.prepopulate_id()); | 1301 se_specifics->set_prepopulate_id(turl.prepopulate_id()); |
1301 se_specifics->set_instant_url(turl.instant_url()); | 1302 se_specifics->set_instant_url(turl.instant_url()); |
1302 se_specifics->set_last_modified(turl.last_modified().ToInternalValue()); | 1303 se_specifics->set_last_modified(turl.last_modified().ToInternalValue()); |
1303 se_specifics->set_sync_guid(turl.sync_guid()); | 1304 se_specifics->set_sync_guid(turl.sync_guid()); |
1305 for (size_t i = 0; i < turl.alternate_urls().size(); ++i) | |
1306 se_specifics->add_alternate_urls(turl.alternate_urls()[i]); | |
Peter Kasting
2012/10/02 21:47:59
Would be nice if we could just call a "set_alterna
beaudoin
2012/10/03 22:46:52
Unfortunately, here is the complete interface gene
| |
1307 | |
1304 return syncer::SyncData::CreateLocalData(se_specifics->sync_guid(), | 1308 return syncer::SyncData::CreateLocalData(se_specifics->sync_guid(), |
1305 se_specifics->keyword(), | 1309 se_specifics->keyword(), |
1306 specifics); | 1310 specifics); |
1307 } | 1311 } |
1308 | 1312 |
1309 // static | 1313 // static |
1310 TemplateURL* TemplateURLService::CreateTemplateURLFromTemplateURLAndSyncData( | 1314 TemplateURL* TemplateURLService::CreateTemplateURLFromTemplateURLAndSyncData( |
1311 Profile* profile, | 1315 Profile* profile, |
1312 TemplateURL* existing_turl, | 1316 TemplateURL* existing_turl, |
1313 const syncer::SyncData& sync_data, | 1317 const syncer::SyncData& sync_data, |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1353 base::SplitString(specifics.input_encodings(), ';', &data.input_encodings); | 1357 base::SplitString(specifics.input_encodings(), ';', &data.input_encodings); |
1354 // If the server data has duplicate encodings, we'll want to push an update | 1358 // If the server data has duplicate encodings, we'll want to push an update |
1355 // below to correct it. Note that we also fix this in | 1359 // below to correct it. Note that we also fix this in |
1356 // GetSearchProvidersUsingKeywordResult(), since otherwise we'd never correct | 1360 // GetSearchProvidersUsingKeywordResult(), since otherwise we'd never correct |
1357 // local problems for clients which have disabled search engine sync. | 1361 // local problems for clients which have disabled search engine sync. |
1358 bool deduped = DeDupeEncodings(&data.input_encodings); | 1362 bool deduped = DeDupeEncodings(&data.input_encodings); |
1359 data.date_created = base::Time::FromInternalValue(specifics.date_created()); | 1363 data.date_created = base::Time::FromInternalValue(specifics.date_created()); |
1360 data.last_modified = base::Time::FromInternalValue(specifics.last_modified()); | 1364 data.last_modified = base::Time::FromInternalValue(specifics.last_modified()); |
1361 data.prepopulate_id = specifics.prepopulate_id(); | 1365 data.prepopulate_id = specifics.prepopulate_id(); |
1362 data.sync_guid = specifics.sync_guid(); | 1366 data.sync_guid = specifics.sync_guid(); |
1367 data.alternate_urls.clear(); | |
1368 for (int i = 0; i < specifics.alternate_urls_size(); ++i) | |
1369 data.alternate_urls.push_back(specifics.alternate_urls(i)); | |
1363 | 1370 |
1364 TemplateURL* turl = new TemplateURL(profile, data); | 1371 TemplateURL* turl = new TemplateURL(profile, data); |
1365 DCHECK(!turl->IsExtensionKeyword()); | 1372 DCHECK(!turl->IsExtensionKeyword()); |
1366 if (reset_keyword || deduped) { | 1373 if (reset_keyword || deduped) { |
1367 if (reset_keyword) | 1374 if (reset_keyword) |
1368 turl->ResetKeywordIfNecessary(true); | 1375 turl->ResetKeywordIfNecessary(true); |
1369 syncer::SyncData sync_data = CreateSyncDataFromTemplateURL(*turl); | 1376 syncer::SyncData sync_data = CreateSyncDataFromTemplateURL(*turl); |
1370 change_list->push_back( | 1377 change_list->push_back( |
1371 syncer::SyncChange(FROM_HERE, | 1378 syncer::SyncChange(FROM_HERE, |
1372 syncer::SyncChange::ACTION_UPDATE, | 1379 syncer::SyncChange::ACTION_UPDATE, |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1645 prefs->SetBoolean(prefs::kDefaultSearchProviderEnabled, enabled); | 1652 prefs->SetBoolean(prefs::kDefaultSearchProviderEnabled, enabled); |
1646 prefs->SetString(prefs::kDefaultSearchProviderSearchURL, search_url); | 1653 prefs->SetString(prefs::kDefaultSearchProviderSearchURL, search_url); |
1647 prefs->SetString(prefs::kDefaultSearchProviderSuggestURL, suggest_url); | 1654 prefs->SetString(prefs::kDefaultSearchProviderSuggestURL, suggest_url); |
1648 prefs->SetString(prefs::kDefaultSearchProviderInstantURL, instant_url); | 1655 prefs->SetString(prefs::kDefaultSearchProviderInstantURL, instant_url); |
1649 prefs->SetString(prefs::kDefaultSearchProviderIconURL, icon_url); | 1656 prefs->SetString(prefs::kDefaultSearchProviderIconURL, icon_url); |
1650 prefs->SetString(prefs::kDefaultSearchProviderEncodings, encodings); | 1657 prefs->SetString(prefs::kDefaultSearchProviderEncodings, encodings); |
1651 prefs->SetString(prefs::kDefaultSearchProviderName, short_name); | 1658 prefs->SetString(prefs::kDefaultSearchProviderName, short_name); |
1652 prefs->SetString(prefs::kDefaultSearchProviderKeyword, keyword); | 1659 prefs->SetString(prefs::kDefaultSearchProviderKeyword, keyword); |
1653 prefs->SetString(prefs::kDefaultSearchProviderID, id_string); | 1660 prefs->SetString(prefs::kDefaultSearchProviderID, id_string); |
1654 prefs->SetString(prefs::kDefaultSearchProviderPrepopulateID, prepopulate_id); | 1661 prefs->SetString(prefs::kDefaultSearchProviderPrepopulateID, prepopulate_id); |
1662 ListValue alternate_urls_value; | |
Peter Kasting
2012/10/02 21:47:59
Nit: Move this up to with the other temps above, n
beaudoin
2012/10/03 22:46:52
Done.
| |
1663 if (t_url) { | |
1664 for (size_t i = 0; i < t_url->alternate_urls().size(); ++i) | |
1665 alternate_urls_value.AppendString(t_url->alternate_urls()[i]); | |
1666 } | |
1667 prefs->Set(prefs::kDefaultSearchProviderAlternateURLs, alternate_urls_value); | |
1655 } | 1668 } |
1656 | 1669 |
1657 bool TemplateURLService::LoadDefaultSearchProviderFromPrefs( | 1670 bool TemplateURLService::LoadDefaultSearchProviderFromPrefs( |
1658 scoped_ptr<TemplateURL>* default_provider, | 1671 scoped_ptr<TemplateURL>* default_provider, |
1659 bool* is_managed) { | 1672 bool* is_managed) { |
1660 PrefService* prefs = GetPrefs(); | 1673 PrefService* prefs = GetPrefs(); |
1661 if (!prefs || !prefs->HasPrefPath(prefs::kDefaultSearchProviderSearchURL)) | 1674 if (!prefs || !prefs->HasPrefPath(prefs::kDefaultSearchProviderSearchURL)) |
1662 return false; | 1675 return false; |
1663 | 1676 |
1664 const PrefService::Preference* pref = | 1677 const PrefService::Preference* pref = |
(...skipping 28 matching lines...) Expand all Loading... | |
1693 prefs->GetString(prefs::kDefaultSearchProviderSuggestURL); | 1706 prefs->GetString(prefs::kDefaultSearchProviderSuggestURL); |
1694 std::string instant_url = | 1707 std::string instant_url = |
1695 prefs->GetString(prefs::kDefaultSearchProviderInstantURL); | 1708 prefs->GetString(prefs::kDefaultSearchProviderInstantURL); |
1696 std::string icon_url = | 1709 std::string icon_url = |
1697 prefs->GetString(prefs::kDefaultSearchProviderIconURL); | 1710 prefs->GetString(prefs::kDefaultSearchProviderIconURL); |
1698 std::string encodings = | 1711 std::string encodings = |
1699 prefs->GetString(prefs::kDefaultSearchProviderEncodings); | 1712 prefs->GetString(prefs::kDefaultSearchProviderEncodings); |
1700 std::string id_string = prefs->GetString(prefs::kDefaultSearchProviderID); | 1713 std::string id_string = prefs->GetString(prefs::kDefaultSearchProviderID); |
1701 std::string prepopulate_id = | 1714 std::string prepopulate_id = |
1702 prefs->GetString(prefs::kDefaultSearchProviderPrepopulateID); | 1715 prefs->GetString(prefs::kDefaultSearchProviderPrepopulateID); |
1716 const ListValue* alternate_urls = | |
1717 prefs->GetList(prefs::kDefaultSearchProviderAlternateURLs); | |
1703 | 1718 |
1704 TemplateURLData data; | 1719 TemplateURLData data; |
1705 data.short_name = name; | 1720 data.short_name = name; |
1706 data.SetKeyword(keyword); | 1721 data.SetKeyword(keyword); |
1707 data.SetURL(search_url); | 1722 data.SetURL(search_url); |
1708 data.suggestions_url = suggest_url; | 1723 data.suggestions_url = suggest_url; |
1709 data.instant_url = instant_url; | 1724 data.instant_url = instant_url; |
1710 data.favicon_url = GURL(icon_url); | 1725 data.favicon_url = GURL(icon_url); |
1711 data.show_in_default_list = true; | 1726 data.show_in_default_list = true; |
1727 data.alternate_urls.clear(); | |
1728 std::string alternate_url; | |
Peter Kasting
2012/10/02 21:47:59
Nit: Declare inside loop (the efficiency loss does
beaudoin
2012/10/03 22:46:52
Done.
| |
1729 for (size_t i = 0; i < alternate_urls->GetSize(); ++i) { | |
1730 if (alternate_urls->GetString(i, &alternate_url)) | |
1731 data.alternate_urls.push_back(alternate_url); | |
Peter Kasting
2012/10/02 21:47:59
Isn't there some helper already that can return a
beaudoin
2012/10/03 22:46:52
I think the problem is that ListValue does not gua
Peter Kasting
2012/10/03 22:59:33
It's fine to not address this in this CL. We may
| |
1732 } | |
1712 base::SplitString(encodings, ';', &data.input_encodings); | 1733 base::SplitString(encodings, ';', &data.input_encodings); |
1713 if (!id_string.empty() && !*is_managed) { | 1734 if (!id_string.empty() && !*is_managed) { |
1714 int64 value; | 1735 int64 value; |
1715 base::StringToInt64(id_string, &value); | 1736 base::StringToInt64(id_string, &value); |
1716 data.id = value; | 1737 data.id = value; |
1717 } | 1738 } |
1718 if (!prepopulate_id.empty() && !*is_managed) { | 1739 if (!prepopulate_id.empty() && !*is_managed) { |
1719 int value; | 1740 int value; |
1720 base::StringToInt(prepopulate_id, &value); | 1741 base::StringToInt(prepopulate_id, &value); |
1721 data.prepopulate_id = value; | 1742 data.prepopulate_id = value; |
(...skipping 802 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2524 // TODO(mpcomplete): If we allow editing extension keywords, then those | 2545 // TODO(mpcomplete): If we allow editing extension keywords, then those |
2525 // should be persisted to disk and synced. | 2546 // should be persisted to disk and synced. |
2526 if (template_url->sync_guid().empty() && | 2547 if (template_url->sync_guid().empty() && |
2527 !template_url->IsExtensionKeyword()) { | 2548 !template_url->IsExtensionKeyword()) { |
2528 template_url->data_.sync_guid = base::GenerateGUID(); | 2549 template_url->data_.sync_guid = base::GenerateGUID(); |
2529 if (service_.get()) | 2550 if (service_.get()) |
2530 service_->UpdateKeyword(template_url->data()); | 2551 service_->UpdateKeyword(template_url->data()); |
2531 } | 2552 } |
2532 } | 2553 } |
2533 } | 2554 } |
OLD | NEW |