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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 return true; | 77 return true; |
78 return (url1 != NULL) && (url2 != NULL) && | 78 return (url1 != NULL) && (url2 != NULL) && |
79 (url1->short_name() == url2->short_name()) && | 79 (url1->short_name() == url2->short_name()) && |
80 url1->HasSameKeywordAs(*url2) && | 80 url1->HasSameKeywordAs(*url2) && |
81 (url1->url() == url2->url()) && | 81 (url1->url() == url2->url()) && |
82 (url1->suggestions_url() == url2->suggestions_url()) && | 82 (url1->suggestions_url() == url2->suggestions_url()) && |
83 (url1->instant_url() == url2->instant_url()) && | 83 (url1->instant_url() == url2->instant_url()) && |
84 (url1->favicon_url() == url2->favicon_url()) && | 84 (url1->favicon_url() == url2->favicon_url()) && |
85 (url1->safe_for_autoreplace() == url2->safe_for_autoreplace()) && | 85 (url1->safe_for_autoreplace() == url2->safe_for_autoreplace()) && |
86 (url1->show_in_default_list() == url2->show_in_default_list()) && | 86 (url1->show_in_default_list() == url2->show_in_default_list()) && |
87 (url1->input_encodings() == url2->input_encodings()); | 87 (url1->input_encodings() == url2->input_encodings()) && |
| 88 (url1->alternate_urls() == url2->alternate_urls()); |
88 } | 89 } |
89 | 90 |
90 const char kFirstPotentialEngineHistogramName[] = | 91 const char kFirstPotentialEngineHistogramName[] = |
91 "Search.FirstPotentialEngineCalled"; | 92 "Search.FirstPotentialEngineCalled"; |
92 | 93 |
93 // Values for an enumerated histogram used to track whenever | 94 // Values for an enumerated histogram used to track whenever |
94 // FirstPotentialDefaultEngine is called, and from where. | 95 // FirstPotentialDefaultEngine is called, and from where. |
95 enum FirstPotentialEngineCaller { | 96 enum FirstPotentialEngineCaller { |
96 FIRST_POTENTIAL_CALLSITE_FIND_NEW_DSP, | 97 FIRST_POTENTIAL_CALLSITE_FIND_NEW_DSP, |
97 FIRST_POTENTIAL_CALLSITE_FIND_NEW_DSP_PROCESSING_SYNC_CHANGES, | 98 FIRST_POTENTIAL_CALLSITE_FIND_NEW_DSP_PROCESSING_SYNC_CHANGES, |
(...skipping 1195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1293 se_specifics->set_safe_for_autoreplace(turl.safe_for_autoreplace()); | 1294 se_specifics->set_safe_for_autoreplace(turl.safe_for_autoreplace()); |
1294 se_specifics->set_originating_url(turl.originating_url().spec()); | 1295 se_specifics->set_originating_url(turl.originating_url().spec()); |
1295 se_specifics->set_date_created(turl.date_created().ToInternalValue()); | 1296 se_specifics->set_date_created(turl.date_created().ToInternalValue()); |
1296 se_specifics->set_input_encodings(JoinString(turl.input_encodings(), ';')); | 1297 se_specifics->set_input_encodings(JoinString(turl.input_encodings(), ';')); |
1297 se_specifics->set_show_in_default_list(turl.show_in_default_list()); | 1298 se_specifics->set_show_in_default_list(turl.show_in_default_list()); |
1298 se_specifics->set_suggestions_url(turl.suggestions_url()); | 1299 se_specifics->set_suggestions_url(turl.suggestions_url()); |
1299 se_specifics->set_prepopulate_id(turl.prepopulate_id()); | 1300 se_specifics->set_prepopulate_id(turl.prepopulate_id()); |
1300 se_specifics->set_instant_url(turl.instant_url()); | 1301 se_specifics->set_instant_url(turl.instant_url()); |
1301 se_specifics->set_last_modified(turl.last_modified().ToInternalValue()); | 1302 se_specifics->set_last_modified(turl.last_modified().ToInternalValue()); |
1302 se_specifics->set_sync_guid(turl.sync_guid()); | 1303 se_specifics->set_sync_guid(turl.sync_guid()); |
| 1304 se_specifics->set_alternate_urls(turl.SerializeAlternateURLs()); |
1303 return syncer::SyncData::CreateLocalData(se_specifics->sync_guid(), | 1305 return syncer::SyncData::CreateLocalData(se_specifics->sync_guid(), |
1304 se_specifics->keyword(), | 1306 se_specifics->keyword(), |
1305 specifics); | 1307 specifics); |
1306 } | 1308 } |
1307 | 1309 |
1308 // static | 1310 // static |
1309 TemplateURL* TemplateURLService::CreateTemplateURLFromTemplateURLAndSyncData( | 1311 TemplateURL* TemplateURLService::CreateTemplateURLFromTemplateURLAndSyncData( |
1310 Profile* profile, | 1312 Profile* profile, |
1311 TemplateURL* existing_turl, | 1313 TemplateURL* existing_turl, |
1312 const syncer::SyncData& sync_data, | 1314 const syncer::SyncData& sync_data, |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1352 base::SplitString(specifics.input_encodings(), ';', &data.input_encodings); | 1354 base::SplitString(specifics.input_encodings(), ';', &data.input_encodings); |
1353 // If the server data has duplicate encodings, we'll want to push an update | 1355 // If the server data has duplicate encodings, we'll want to push an update |
1354 // below to correct it. Note that we also fix this in | 1356 // below to correct it. Note that we also fix this in |
1355 // GetSearchProvidersUsingKeywordResult(), since otherwise we'd never correct | 1357 // GetSearchProvidersUsingKeywordResult(), since otherwise we'd never correct |
1356 // local problems for clients which have disabled search engine sync. | 1358 // local problems for clients which have disabled search engine sync. |
1357 bool deduped = DeDupeEncodings(&data.input_encodings); | 1359 bool deduped = DeDupeEncodings(&data.input_encodings); |
1358 data.date_created = base::Time::FromInternalValue(specifics.date_created()); | 1360 data.date_created = base::Time::FromInternalValue(specifics.date_created()); |
1359 data.last_modified = base::Time::FromInternalValue(specifics.last_modified()); | 1361 data.last_modified = base::Time::FromInternalValue(specifics.last_modified()); |
1360 data.prepopulate_id = specifics.prepopulate_id(); | 1362 data.prepopulate_id = specifics.prepopulate_id(); |
1361 data.sync_guid = specifics.sync_guid(); | 1363 data.sync_guid = specifics.sync_guid(); |
| 1364 data.DeserializeAndSetAlternateURLs(specifics.alternate_urls()); |
1362 | 1365 |
1363 TemplateURL* turl = new TemplateURL(profile, data); | 1366 TemplateURL* turl = new TemplateURL(profile, data); |
1364 DCHECK(!turl->IsExtensionKeyword()); | 1367 DCHECK(!turl->IsExtensionKeyword()); |
1365 if (reset_keyword || deduped) { | 1368 if (reset_keyword || deduped) { |
1366 if (reset_keyword) | 1369 if (reset_keyword) |
1367 turl->ResetKeywordIfNecessary(true); | 1370 turl->ResetKeywordIfNecessary(true); |
1368 syncer::SyncData sync_data = CreateSyncDataFromTemplateURL(*turl); | 1371 syncer::SyncData sync_data = CreateSyncDataFromTemplateURL(*turl); |
1369 change_list->push_back( | 1372 change_list->push_back( |
1370 syncer::SyncChange(FROM_HERE, | 1373 syncer::SyncChange(FROM_HERE, |
1371 syncer::SyncChange::ACTION_UPDATE, | 1374 syncer::SyncChange::ACTION_UPDATE, |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1619 bool enabled = false; | 1622 bool enabled = false; |
1620 std::string search_url; | 1623 std::string search_url; |
1621 std::string suggest_url; | 1624 std::string suggest_url; |
1622 std::string instant_url; | 1625 std::string instant_url; |
1623 std::string icon_url; | 1626 std::string icon_url; |
1624 std::string encodings; | 1627 std::string encodings; |
1625 std::string short_name; | 1628 std::string short_name; |
1626 std::string keyword; | 1629 std::string keyword; |
1627 std::string id_string; | 1630 std::string id_string; |
1628 std::string prepopulate_id; | 1631 std::string prepopulate_id; |
| 1632 std::string alternate_urls; |
1629 if (t_url) { | 1633 if (t_url) { |
1630 DCHECK(!t_url->IsExtensionKeyword()); | 1634 DCHECK(!t_url->IsExtensionKeyword()); |
1631 enabled = true; | 1635 enabled = true; |
1632 search_url = t_url->url(); | 1636 search_url = t_url->url(); |
1633 suggest_url = t_url->suggestions_url(); | 1637 suggest_url = t_url->suggestions_url(); |
1634 instant_url = t_url->instant_url(); | 1638 instant_url = t_url->instant_url(); |
1635 GURL icon_gurl = t_url->favicon_url(); | 1639 GURL icon_gurl = t_url->favicon_url(); |
1636 if (!icon_gurl.is_empty()) | 1640 if (!icon_gurl.is_empty()) |
1637 icon_url = icon_gurl.spec(); | 1641 icon_url = icon_gurl.spec(); |
1638 encodings = JoinString(t_url->input_encodings(), ';'); | 1642 encodings = JoinString(t_url->input_encodings(), ';'); |
1639 short_name = UTF16ToUTF8(t_url->short_name()); | 1643 short_name = UTF16ToUTF8(t_url->short_name()); |
1640 keyword = UTF16ToUTF8(t_url->keyword()); | 1644 keyword = UTF16ToUTF8(t_url->keyword()); |
1641 id_string = base::Int64ToString(t_url->id()); | 1645 id_string = base::Int64ToString(t_url->id()); |
1642 prepopulate_id = base::Int64ToString(t_url->prepopulate_id()); | 1646 prepopulate_id = base::Int64ToString(t_url->prepopulate_id()); |
| 1647 alternate_urls = t_url->SerializeAlternateURLs(); |
1643 } | 1648 } |
1644 prefs->SetBoolean(prefs::kDefaultSearchProviderEnabled, enabled); | 1649 prefs->SetBoolean(prefs::kDefaultSearchProviderEnabled, enabled); |
1645 prefs->SetString(prefs::kDefaultSearchProviderSearchURL, search_url); | 1650 prefs->SetString(prefs::kDefaultSearchProviderSearchURL, search_url); |
1646 prefs->SetString(prefs::kDefaultSearchProviderSuggestURL, suggest_url); | 1651 prefs->SetString(prefs::kDefaultSearchProviderSuggestURL, suggest_url); |
1647 prefs->SetString(prefs::kDefaultSearchProviderInstantURL, instant_url); | 1652 prefs->SetString(prefs::kDefaultSearchProviderInstantURL, instant_url); |
1648 prefs->SetString(prefs::kDefaultSearchProviderIconURL, icon_url); | 1653 prefs->SetString(prefs::kDefaultSearchProviderIconURL, icon_url); |
1649 prefs->SetString(prefs::kDefaultSearchProviderEncodings, encodings); | 1654 prefs->SetString(prefs::kDefaultSearchProviderEncodings, encodings); |
1650 prefs->SetString(prefs::kDefaultSearchProviderName, short_name); | 1655 prefs->SetString(prefs::kDefaultSearchProviderName, short_name); |
1651 prefs->SetString(prefs::kDefaultSearchProviderKeyword, keyword); | 1656 prefs->SetString(prefs::kDefaultSearchProviderKeyword, keyword); |
1652 prefs->SetString(prefs::kDefaultSearchProviderID, id_string); | 1657 prefs->SetString(prefs::kDefaultSearchProviderID, id_string); |
1653 prefs->SetString(prefs::kDefaultSearchProviderPrepopulateID, prepopulate_id); | 1658 prefs->SetString(prefs::kDefaultSearchProviderPrepopulateID, prepopulate_id); |
| 1659 prefs->SetString(prefs::kDefaultSearchProviderAlternateURLs, alternate_urls); |
1654 } | 1660 } |
1655 | 1661 |
1656 bool TemplateURLService::LoadDefaultSearchProviderFromPrefs( | 1662 bool TemplateURLService::LoadDefaultSearchProviderFromPrefs( |
1657 scoped_ptr<TemplateURL>* default_provider, | 1663 scoped_ptr<TemplateURL>* default_provider, |
1658 bool* is_managed) { | 1664 bool* is_managed) { |
1659 PrefService* prefs = GetPrefs(); | 1665 PrefService* prefs = GetPrefs(); |
1660 if (!prefs || !prefs->HasPrefPath(prefs::kDefaultSearchProviderSearchURL)) | 1666 if (!prefs || !prefs->HasPrefPath(prefs::kDefaultSearchProviderSearchURL)) |
1661 return false; | 1667 return false; |
1662 | 1668 |
1663 const PrefService::Preference* pref = | 1669 const PrefService::Preference* pref = |
(...skipping 28 matching lines...) Expand all Loading... |
1692 prefs->GetString(prefs::kDefaultSearchProviderSuggestURL); | 1698 prefs->GetString(prefs::kDefaultSearchProviderSuggestURL); |
1693 std::string instant_url = | 1699 std::string instant_url = |
1694 prefs->GetString(prefs::kDefaultSearchProviderInstantURL); | 1700 prefs->GetString(prefs::kDefaultSearchProviderInstantURL); |
1695 std::string icon_url = | 1701 std::string icon_url = |
1696 prefs->GetString(prefs::kDefaultSearchProviderIconURL); | 1702 prefs->GetString(prefs::kDefaultSearchProviderIconURL); |
1697 std::string encodings = | 1703 std::string encodings = |
1698 prefs->GetString(prefs::kDefaultSearchProviderEncodings); | 1704 prefs->GetString(prefs::kDefaultSearchProviderEncodings); |
1699 std::string id_string = prefs->GetString(prefs::kDefaultSearchProviderID); | 1705 std::string id_string = prefs->GetString(prefs::kDefaultSearchProviderID); |
1700 std::string prepopulate_id = | 1706 std::string prepopulate_id = |
1701 prefs->GetString(prefs::kDefaultSearchProviderPrepopulateID); | 1707 prefs->GetString(prefs::kDefaultSearchProviderPrepopulateID); |
| 1708 std::string alternate_urls = |
| 1709 prefs->GetString(prefs::kDefaultSearchProviderAlternateURLs); |
1702 | 1710 |
1703 TemplateURLData data; | 1711 TemplateURLData data; |
1704 data.short_name = name; | 1712 data.short_name = name; |
1705 data.SetKeyword(keyword); | 1713 data.SetKeyword(keyword); |
1706 data.SetURL(search_url); | 1714 data.SetURL(search_url); |
1707 data.suggestions_url = suggest_url; | 1715 data.suggestions_url = suggest_url; |
1708 data.instant_url = instant_url; | 1716 data.instant_url = instant_url; |
1709 data.favicon_url = GURL(icon_url); | 1717 data.favicon_url = GURL(icon_url); |
1710 data.show_in_default_list = true; | 1718 data.show_in_default_list = true; |
| 1719 data.DeserializeAndSetAlternateURLs(alternate_urls); |
1711 base::SplitString(encodings, ';', &data.input_encodings); | 1720 base::SplitString(encodings, ';', &data.input_encodings); |
1712 if (!id_string.empty() && !*is_managed) { | 1721 if (!id_string.empty() && !*is_managed) { |
1713 int64 value; | 1722 int64 value; |
1714 base::StringToInt64(id_string, &value); | 1723 base::StringToInt64(id_string, &value); |
1715 data.id = value; | 1724 data.id = value; |
1716 } | 1725 } |
1717 if (!prepopulate_id.empty() && !*is_managed) { | 1726 if (!prepopulate_id.empty() && !*is_managed) { |
1718 int value; | 1727 int value; |
1719 base::StringToInt(prepopulate_id, &value); | 1728 base::StringToInt(prepopulate_id, &value); |
1720 data.prepopulate_id = value; | 1729 data.prepopulate_id = value; |
(...skipping 801 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2522 // TODO(mpcomplete): If we allow editing extension keywords, then those | 2531 // TODO(mpcomplete): If we allow editing extension keywords, then those |
2523 // should be persisted to disk and synced. | 2532 // should be persisted to disk and synced. |
2524 if (template_url->sync_guid().empty() && | 2533 if (template_url->sync_guid().empty() && |
2525 !template_url->IsExtensionKeyword()) { | 2534 !template_url->IsExtensionKeyword()) { |
2526 template_url->data_.sync_guid = base::GenerateGUID(); | 2535 template_url->data_.sync_guid = base::GenerateGUID(); |
2527 if (service_.get()) | 2536 if (service_.get()) |
2528 service_->UpdateKeyword(template_url->data()); | 2537 service_->UpdateKeyword(template_url->data()); |
2529 } | 2538 } |
2530 } | 2539 } |
2531 } | 2540 } |
OLD | NEW |