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 se_specifics->set_alternate_urls(turl.SerializeAlternateURLs()); |
1304 return syncer::SyncData::CreateLocalData(se_specifics->sync_guid(), | 1306 return syncer::SyncData::CreateLocalData(se_specifics->sync_guid(), |
1305 se_specifics->keyword(), | 1307 se_specifics->keyword(), |
1306 specifics); | 1308 specifics); |
1307 } | 1309 } |
1308 | 1310 |
1309 // static | 1311 // static |
1310 TemplateURL* TemplateURLService::CreateTemplateURLFromTemplateURLAndSyncData( | 1312 TemplateURL* TemplateURLService::CreateTemplateURLFromTemplateURLAndSyncData( |
1311 Profile* profile, | 1313 Profile* profile, |
1312 TemplateURL* existing_turl, | 1314 TemplateURL* existing_turl, |
1313 const syncer::SyncData& sync_data, | 1315 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); | 1355 base::SplitString(specifics.input_encodings(), ';', &data.input_encodings); |
1354 // If the server data has duplicate encodings, we'll want to push an update | 1356 // 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 | 1357 // below to correct it. Note that we also fix this in |
1356 // GetSearchProvidersUsingKeywordResult(), since otherwise we'd never correct | 1358 // GetSearchProvidersUsingKeywordResult(), since otherwise we'd never correct |
1357 // local problems for clients which have disabled search engine sync. | 1359 // local problems for clients which have disabled search engine sync. |
1358 bool deduped = DeDupeEncodings(&data.input_encodings); | 1360 bool deduped = DeDupeEncodings(&data.input_encodings); |
1359 data.date_created = base::Time::FromInternalValue(specifics.date_created()); | 1361 data.date_created = base::Time::FromInternalValue(specifics.date_created()); |
1360 data.last_modified = base::Time::FromInternalValue(specifics.last_modified()); | 1362 data.last_modified = base::Time::FromInternalValue(specifics.last_modified()); |
1361 data.prepopulate_id = specifics.prepopulate_id(); | 1363 data.prepopulate_id = specifics.prepopulate_id(); |
1362 data.sync_guid = specifics.sync_guid(); | 1364 data.sync_guid = specifics.sync_guid(); |
| 1365 data.DeserializeAndSetAlternateURLs(specifics.alternate_urls()); |
1363 | 1366 |
1364 TemplateURL* turl = new TemplateURL(profile, data); | 1367 TemplateURL* turl = new TemplateURL(profile, data); |
1365 DCHECK(!turl->IsExtensionKeyword()); | 1368 DCHECK(!turl->IsExtensionKeyword()); |
1366 if (reset_keyword || deduped) { | 1369 if (reset_keyword || deduped) { |
1367 if (reset_keyword) | 1370 if (reset_keyword) |
1368 turl->ResetKeywordIfNecessary(true); | 1371 turl->ResetKeywordIfNecessary(true); |
1369 syncer::SyncData sync_data = CreateSyncDataFromTemplateURL(*turl); | 1372 syncer::SyncData sync_data = CreateSyncDataFromTemplateURL(*turl); |
1370 change_list->push_back( | 1373 change_list->push_back( |
1371 syncer::SyncChange(FROM_HERE, | 1374 syncer::SyncChange(FROM_HERE, |
1372 syncer::SyncChange::ACTION_UPDATE, | 1375 syncer::SyncChange::ACTION_UPDATE, |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1620 bool enabled = false; | 1623 bool enabled = false; |
1621 std::string search_url; | 1624 std::string search_url; |
1622 std::string suggest_url; | 1625 std::string suggest_url; |
1623 std::string instant_url; | 1626 std::string instant_url; |
1624 std::string icon_url; | 1627 std::string icon_url; |
1625 std::string encodings; | 1628 std::string encodings; |
1626 std::string short_name; | 1629 std::string short_name; |
1627 std::string keyword; | 1630 std::string keyword; |
1628 std::string id_string; | 1631 std::string id_string; |
1629 std::string prepopulate_id; | 1632 std::string prepopulate_id; |
| 1633 std::string alternate_urls; |
1630 if (t_url) { | 1634 if (t_url) { |
1631 DCHECK(!t_url->IsExtensionKeyword()); | 1635 DCHECK(!t_url->IsExtensionKeyword()); |
1632 enabled = true; | 1636 enabled = true; |
1633 search_url = t_url->url(); | 1637 search_url = t_url->url(); |
1634 suggest_url = t_url->suggestions_url(); | 1638 suggest_url = t_url->suggestions_url(); |
1635 instant_url = t_url->instant_url(); | 1639 instant_url = t_url->instant_url(); |
1636 GURL icon_gurl = t_url->favicon_url(); | 1640 GURL icon_gurl = t_url->favicon_url(); |
1637 if (!icon_gurl.is_empty()) | 1641 if (!icon_gurl.is_empty()) |
1638 icon_url = icon_gurl.spec(); | 1642 icon_url = icon_gurl.spec(); |
1639 encodings = JoinString(t_url->input_encodings(), ';'); | 1643 encodings = JoinString(t_url->input_encodings(), ';'); |
1640 short_name = UTF16ToUTF8(t_url->short_name()); | 1644 short_name = UTF16ToUTF8(t_url->short_name()); |
1641 keyword = UTF16ToUTF8(t_url->keyword()); | 1645 keyword = UTF16ToUTF8(t_url->keyword()); |
1642 id_string = base::Int64ToString(t_url->id()); | 1646 id_string = base::Int64ToString(t_url->id()); |
1643 prepopulate_id = base::Int64ToString(t_url->prepopulate_id()); | 1647 prepopulate_id = base::Int64ToString(t_url->prepopulate_id()); |
| 1648 alternate_urls = t_url->SerializeAlternateURLs(); |
1644 } | 1649 } |
1645 prefs->SetBoolean(prefs::kDefaultSearchProviderEnabled, enabled); | 1650 prefs->SetBoolean(prefs::kDefaultSearchProviderEnabled, enabled); |
1646 prefs->SetString(prefs::kDefaultSearchProviderSearchURL, search_url); | 1651 prefs->SetString(prefs::kDefaultSearchProviderSearchURL, search_url); |
1647 prefs->SetString(prefs::kDefaultSearchProviderSuggestURL, suggest_url); | 1652 prefs->SetString(prefs::kDefaultSearchProviderSuggestURL, suggest_url); |
1648 prefs->SetString(prefs::kDefaultSearchProviderInstantURL, instant_url); | 1653 prefs->SetString(prefs::kDefaultSearchProviderInstantURL, instant_url); |
1649 prefs->SetString(prefs::kDefaultSearchProviderIconURL, icon_url); | 1654 prefs->SetString(prefs::kDefaultSearchProviderIconURL, icon_url); |
1650 prefs->SetString(prefs::kDefaultSearchProviderEncodings, encodings); | 1655 prefs->SetString(prefs::kDefaultSearchProviderEncodings, encodings); |
1651 prefs->SetString(prefs::kDefaultSearchProviderName, short_name); | 1656 prefs->SetString(prefs::kDefaultSearchProviderName, short_name); |
1652 prefs->SetString(prefs::kDefaultSearchProviderKeyword, keyword); | 1657 prefs->SetString(prefs::kDefaultSearchProviderKeyword, keyword); |
1653 prefs->SetString(prefs::kDefaultSearchProviderID, id_string); | 1658 prefs->SetString(prefs::kDefaultSearchProviderID, id_string); |
1654 prefs->SetString(prefs::kDefaultSearchProviderPrepopulateID, prepopulate_id); | 1659 prefs->SetString(prefs::kDefaultSearchProviderPrepopulateID, prepopulate_id); |
| 1660 prefs->SetString(prefs::kDefaultSearchProviderAlternateURLs, alternate_urls); |
1655 } | 1661 } |
1656 | 1662 |
1657 bool TemplateURLService::LoadDefaultSearchProviderFromPrefs( | 1663 bool TemplateURLService::LoadDefaultSearchProviderFromPrefs( |
1658 scoped_ptr<TemplateURL>* default_provider, | 1664 scoped_ptr<TemplateURL>* default_provider, |
1659 bool* is_managed) { | 1665 bool* is_managed) { |
1660 PrefService* prefs = GetPrefs(); | 1666 PrefService* prefs = GetPrefs(); |
1661 if (!prefs || !prefs->HasPrefPath(prefs::kDefaultSearchProviderSearchURL)) | 1667 if (!prefs || !prefs->HasPrefPath(prefs::kDefaultSearchProviderSearchURL)) |
1662 return false; | 1668 return false; |
1663 | 1669 |
1664 const PrefService::Preference* pref = | 1670 const PrefService::Preference* pref = |
(...skipping 28 matching lines...) Expand all Loading... |
1693 prefs->GetString(prefs::kDefaultSearchProviderSuggestURL); | 1699 prefs->GetString(prefs::kDefaultSearchProviderSuggestURL); |
1694 std::string instant_url = | 1700 std::string instant_url = |
1695 prefs->GetString(prefs::kDefaultSearchProviderInstantURL); | 1701 prefs->GetString(prefs::kDefaultSearchProviderInstantURL); |
1696 std::string icon_url = | 1702 std::string icon_url = |
1697 prefs->GetString(prefs::kDefaultSearchProviderIconURL); | 1703 prefs->GetString(prefs::kDefaultSearchProviderIconURL); |
1698 std::string encodings = | 1704 std::string encodings = |
1699 prefs->GetString(prefs::kDefaultSearchProviderEncodings); | 1705 prefs->GetString(prefs::kDefaultSearchProviderEncodings); |
1700 std::string id_string = prefs->GetString(prefs::kDefaultSearchProviderID); | 1706 std::string id_string = prefs->GetString(prefs::kDefaultSearchProviderID); |
1701 std::string prepopulate_id = | 1707 std::string prepopulate_id = |
1702 prefs->GetString(prefs::kDefaultSearchProviderPrepopulateID); | 1708 prefs->GetString(prefs::kDefaultSearchProviderPrepopulateID); |
| 1709 std::string alternate_urls = |
| 1710 prefs->GetString(prefs::kDefaultSearchProviderAlternateURLs); |
1703 | 1711 |
1704 TemplateURLData data; | 1712 TemplateURLData data; |
1705 data.short_name = name; | 1713 data.short_name = name; |
1706 data.SetKeyword(keyword); | 1714 data.SetKeyword(keyword); |
1707 data.SetURL(search_url); | 1715 data.SetURL(search_url); |
1708 data.suggestions_url = suggest_url; | 1716 data.suggestions_url = suggest_url; |
1709 data.instant_url = instant_url; | 1717 data.instant_url = instant_url; |
1710 data.favicon_url = GURL(icon_url); | 1718 data.favicon_url = GURL(icon_url); |
1711 data.show_in_default_list = true; | 1719 data.show_in_default_list = true; |
| 1720 data.DeserializeAndSetAlternateURLs(alternate_urls); |
1712 base::SplitString(encodings, ';', &data.input_encodings); | 1721 base::SplitString(encodings, ';', &data.input_encodings); |
1713 if (!id_string.empty() && !*is_managed) { | 1722 if (!id_string.empty() && !*is_managed) { |
1714 int64 value; | 1723 int64 value; |
1715 base::StringToInt64(id_string, &value); | 1724 base::StringToInt64(id_string, &value); |
1716 data.id = value; | 1725 data.id = value; |
1717 } | 1726 } |
1718 if (!prepopulate_id.empty() && !*is_managed) { | 1727 if (!prepopulate_id.empty() && !*is_managed) { |
1719 int value; | 1728 int value; |
1720 base::StringToInt(prepopulate_id, &value); | 1729 base::StringToInt(prepopulate_id, &value); |
1721 data.prepopulate_id = value; | 1730 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 | 2533 // TODO(mpcomplete): If we allow editing extension keywords, then those |
2525 // should be persisted to disk and synced. | 2534 // should be persisted to disk and synced. |
2526 if (template_url->sync_guid().empty() && | 2535 if (template_url->sync_guid().empty() && |
2527 !template_url->IsExtensionKeyword()) { | 2536 !template_url->IsExtensionKeyword()) { |
2528 template_url->data_.sync_guid = base::GenerateGUID(); | 2537 template_url->data_.sync_guid = base::GenerateGUID(); |
2529 if (service_.get()) | 2538 if (service_.get()) |
2530 service_->UpdateKeyword(template_url->data()); | 2539 service_->UpdateKeyword(template_url->data()); |
2531 } | 2540 } |
2532 } | 2541 } |
2533 } | 2542 } |
OLD | NEW |