Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

Side by Side Diff: chrome/browser/search_engines/template_url_service.cc

Issue 10908226: Introduces a search term extraction mechanism working for arbitrary search providers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Removed version_46.sql, committed separately. Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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]);
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
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 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
1620 bool enabled = false; 1627 bool enabled = false;
1621 std::string search_url; 1628 std::string search_url;
1622 std::string suggest_url; 1629 std::string suggest_url;
1623 std::string instant_url; 1630 std::string instant_url;
1624 std::string icon_url; 1631 std::string icon_url;
1625 std::string encodings; 1632 std::string encodings;
1626 std::string short_name; 1633 std::string short_name;
1627 std::string keyword; 1634 std::string keyword;
1628 std::string id_string; 1635 std::string id_string;
1629 std::string prepopulate_id; 1636 std::string prepopulate_id;
1637 ListValue alternate_urls;
1630 if (t_url) { 1638 if (t_url) {
1631 DCHECK(!t_url->IsExtensionKeyword()); 1639 DCHECK(!t_url->IsExtensionKeyword());
1632 enabled = true; 1640 enabled = true;
1633 search_url = t_url->url(); 1641 search_url = t_url->url();
1634 suggest_url = t_url->suggestions_url(); 1642 suggest_url = t_url->suggestions_url();
1635 instant_url = t_url->instant_url(); 1643 instant_url = t_url->instant_url();
1636 GURL icon_gurl = t_url->favicon_url(); 1644 GURL icon_gurl = t_url->favicon_url();
1637 if (!icon_gurl.is_empty()) 1645 if (!icon_gurl.is_empty())
1638 icon_url = icon_gurl.spec(); 1646 icon_url = icon_gurl.spec();
1639 encodings = JoinString(t_url->input_encodings(), ';'); 1647 encodings = JoinString(t_url->input_encodings(), ';');
1640 short_name = UTF16ToUTF8(t_url->short_name()); 1648 short_name = UTF16ToUTF8(t_url->short_name());
1641 keyword = UTF16ToUTF8(t_url->keyword()); 1649 keyword = UTF16ToUTF8(t_url->keyword());
1642 id_string = base::Int64ToString(t_url->id()); 1650 id_string = base::Int64ToString(t_url->id());
1643 prepopulate_id = base::Int64ToString(t_url->prepopulate_id()); 1651 prepopulate_id = base::Int64ToString(t_url->prepopulate_id());
1652 for (size_t i = 0; i < t_url->alternate_urls().size(); ++i)
1653 alternate_urls.AppendString(t_url->alternate_urls()[i]);
1644 } 1654 }
1645 prefs->SetBoolean(prefs::kDefaultSearchProviderEnabled, enabled); 1655 prefs->SetBoolean(prefs::kDefaultSearchProviderEnabled, enabled);
1646 prefs->SetString(prefs::kDefaultSearchProviderSearchURL, search_url); 1656 prefs->SetString(prefs::kDefaultSearchProviderSearchURL, search_url);
1647 prefs->SetString(prefs::kDefaultSearchProviderSuggestURL, suggest_url); 1657 prefs->SetString(prefs::kDefaultSearchProviderSuggestURL, suggest_url);
1648 prefs->SetString(prefs::kDefaultSearchProviderInstantURL, instant_url); 1658 prefs->SetString(prefs::kDefaultSearchProviderInstantURL, instant_url);
1649 prefs->SetString(prefs::kDefaultSearchProviderIconURL, icon_url); 1659 prefs->SetString(prefs::kDefaultSearchProviderIconURL, icon_url);
1650 prefs->SetString(prefs::kDefaultSearchProviderEncodings, encodings); 1660 prefs->SetString(prefs::kDefaultSearchProviderEncodings, encodings);
1651 prefs->SetString(prefs::kDefaultSearchProviderName, short_name); 1661 prefs->SetString(prefs::kDefaultSearchProviderName, short_name);
1652 prefs->SetString(prefs::kDefaultSearchProviderKeyword, keyword); 1662 prefs->SetString(prefs::kDefaultSearchProviderKeyword, keyword);
1653 prefs->SetString(prefs::kDefaultSearchProviderID, id_string); 1663 prefs->SetString(prefs::kDefaultSearchProviderID, id_string);
1654 prefs->SetString(prefs::kDefaultSearchProviderPrepopulateID, prepopulate_id); 1664 prefs->SetString(prefs::kDefaultSearchProviderPrepopulateID, prepopulate_id);
1665 prefs->Set(prefs::kDefaultSearchProviderAlternateURLs, alternate_urls);
1655 } 1666 }
1656 1667
1657 bool TemplateURLService::LoadDefaultSearchProviderFromPrefs( 1668 bool TemplateURLService::LoadDefaultSearchProviderFromPrefs(
1658 scoped_ptr<TemplateURL>* default_provider, 1669 scoped_ptr<TemplateURL>* default_provider,
1659 bool* is_managed) { 1670 bool* is_managed) {
1660 PrefService* prefs = GetPrefs(); 1671 PrefService* prefs = GetPrefs();
1661 if (!prefs || !prefs->HasPrefPath(prefs::kDefaultSearchProviderSearchURL)) 1672 if (!prefs || !prefs->HasPrefPath(prefs::kDefaultSearchProviderSearchURL))
1662 return false; 1673 return false;
1663 1674
1664 const PrefService::Preference* pref = 1675 const PrefService::Preference* pref =
(...skipping 28 matching lines...) Expand all
1693 prefs->GetString(prefs::kDefaultSearchProviderSuggestURL); 1704 prefs->GetString(prefs::kDefaultSearchProviderSuggestURL);
1694 std::string instant_url = 1705 std::string instant_url =
1695 prefs->GetString(prefs::kDefaultSearchProviderInstantURL); 1706 prefs->GetString(prefs::kDefaultSearchProviderInstantURL);
1696 std::string icon_url = 1707 std::string icon_url =
1697 prefs->GetString(prefs::kDefaultSearchProviderIconURL); 1708 prefs->GetString(prefs::kDefaultSearchProviderIconURL);
1698 std::string encodings = 1709 std::string encodings =
1699 prefs->GetString(prefs::kDefaultSearchProviderEncodings); 1710 prefs->GetString(prefs::kDefaultSearchProviderEncodings);
1700 std::string id_string = prefs->GetString(prefs::kDefaultSearchProviderID); 1711 std::string id_string = prefs->GetString(prefs::kDefaultSearchProviderID);
1701 std::string prepopulate_id = 1712 std::string prepopulate_id =
1702 prefs->GetString(prefs::kDefaultSearchProviderPrepopulateID); 1713 prefs->GetString(prefs::kDefaultSearchProviderPrepopulateID);
1714 const ListValue* alternate_urls =
1715 prefs->GetList(prefs::kDefaultSearchProviderAlternateURLs);
1703 1716
1704 TemplateURLData data; 1717 TemplateURLData data;
1705 data.short_name = name; 1718 data.short_name = name;
1706 data.SetKeyword(keyword); 1719 data.SetKeyword(keyword);
1707 data.SetURL(search_url); 1720 data.SetURL(search_url);
1708 data.suggestions_url = suggest_url; 1721 data.suggestions_url = suggest_url;
1709 data.instant_url = instant_url; 1722 data.instant_url = instant_url;
1710 data.favicon_url = GURL(icon_url); 1723 data.favicon_url = GURL(icon_url);
1711 data.show_in_default_list = true; 1724 data.show_in_default_list = true;
1725 data.alternate_urls.clear();
1726 for (size_t i = 0; i < alternate_urls->GetSize(); ++i) {
1727 std::string alternate_url;
1728 if (alternate_urls->GetString(i, &alternate_url))
1729 data.alternate_urls.push_back(alternate_url);
1730 }
1712 base::SplitString(encodings, ';', &data.input_encodings); 1731 base::SplitString(encodings, ';', &data.input_encodings);
1713 if (!id_string.empty() && !*is_managed) { 1732 if (!id_string.empty() && !*is_managed) {
1714 int64 value; 1733 int64 value;
1715 base::StringToInt64(id_string, &value); 1734 base::StringToInt64(id_string, &value);
1716 data.id = value; 1735 data.id = value;
1717 } 1736 }
1718 if (!prepopulate_id.empty() && !*is_managed) { 1737 if (!prepopulate_id.empty() && !*is_managed) {
1719 int value; 1738 int value;
1720 base::StringToInt(prepopulate_id, &value); 1739 base::StringToInt(prepopulate_id, &value);
1721 data.prepopulate_id = value; 1740 data.prepopulate_id = value;
(...skipping 802 matching lines...) Expand 10 before | Expand all | Expand 10 after
2524 // TODO(mpcomplete): If we allow editing extension keywords, then those 2543 // TODO(mpcomplete): If we allow editing extension keywords, then those
2525 // should be persisted to disk and synced. 2544 // should be persisted to disk and synced.
2526 if (template_url->sync_guid().empty() && 2545 if (template_url->sync_guid().empty() &&
2527 !template_url->IsExtensionKeyword()) { 2546 !template_url->IsExtensionKeyword()) {
2528 template_url->data_.sync_guid = base::GenerateGUID(); 2547 template_url->data_.sync_guid = base::GenerateGUID();
2529 if (service_.get()) 2548 if (service_.get())
2530 service_->UpdateKeyword(template_url->data()); 2549 service_->UpdateKeyword(template_url->data());
2531 } 2550 }
2532 } 2551 }
2533 } 2552 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698