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

Side by Side Diff: components/search_engines/template_url_service.cc

Issue 2487633003: Change behaivor to decide whether a search engine should be shown in the default list (Closed)
Patch Set: Update based on Peter and Nicolas's comments. Created 4 years, 1 month 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/search_engines/template_url_service.h" 5 #include "components/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 377 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 // We don't have a TemplateURL with keyword. We still may not allow this 388 // We don't have a TemplateURL with keyword. We still may not allow this
389 // keyword if there's evidence we may have created this keyword before and 389 // keyword if there's evidence we may have created this keyword before and
390 // the user renamed it (because, for instance, the keyword is a common word 390 // the user renamed it (because, for instance, the keyword is a common word
391 // that may interfere with search queries). An easy heuristic for this is 391 // that may interfere with search queries). An easy heuristic for this is
392 // whether the user has a TemplateURL that has been manually modified (e.g., 392 // whether the user has a TemplateURL that has been manually modified (e.g.,
393 // renamed) connected to the same host. 393 // renamed) connected to the same host.
394 return !url.is_valid() || url.host().empty() || 394 return !url.is_valid() || url.host().empty() ||
395 CanAddAutogeneratedKeywordForHost(url.host()); 395 CanAddAutogeneratedKeywordForHost(url.host());
396 } 396 }
397 397
398 bool TemplateURLService::ShowInDefaultList(const TemplateURL* t_url) {
399 return (t_url == default_search_provider_ || t_url->prepopulate_id() > 0 ||
400 t_url->created_by_policy()) &&
401 t_url->SupportsReplacement(search_terms_data());
402 }
403
398 void TemplateURLService::AddMatchingKeywords( 404 void TemplateURLService::AddMatchingKeywords(
399 const base::string16& prefix, 405 const base::string16& prefix,
400 bool supports_replacement_only, 406 bool supports_replacement_only,
401 TURLsAndMeaningfulLengths* matches) { 407 TURLsAndMeaningfulLengths* matches) {
402 AddMatchingKeywordsHelper( 408 AddMatchingKeywordsHelper(
403 keyword_to_turl_and_length_, prefix, supports_replacement_only, matches); 409 keyword_to_turl_and_length_, prefix, supports_replacement_only, matches);
404 } 410 }
405 411
406 void TemplateURLService::AddMatchingDomainKeywords( 412 void TemplateURLService::AddMatchingDomainKeywords(
407 const base::string16& prefix, 413 const base::string16& prefix,
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 } 476 }
471 477
472 TemplateURL* TemplateURLService::AddExtensionControlledTURL( 478 TemplateURL* TemplateURLService::AddExtensionControlledTURL(
473 std::unique_ptr<TemplateURL> template_url, 479 std::unique_ptr<TemplateURL> template_url,
474 std::unique_ptr<TemplateURL::AssociatedExtensionInfo> info) { 480 std::unique_ptr<TemplateURL::AssociatedExtensionInfo> info) {
475 DCHECK(loaded_); 481 DCHECK(loaded_);
476 DCHECK(template_url); 482 DCHECK(template_url);
477 DCHECK_EQ(kInvalidTemplateURLID, template_url->id()); 483 DCHECK_EQ(kInvalidTemplateURLID, template_url->id());
478 DCHECK(info); 484 DCHECK(info);
479 DCHECK_NE(TemplateURL::NORMAL, template_url->type()); 485 DCHECK_NE(TemplateURL::NORMAL, template_url->type());
480 DCHECK_EQ(info->wants_to_be_default_engine,
481 template_url->show_in_default_list());
482 DCHECK( 486 DCHECK(
483 !FindTemplateURLForExtension(info->extension_id, template_url->type())); 487 !FindTemplateURLForExtension(info->extension_id, template_url->type()));
484 template_url->extension_info_.swap(info); 488 template_url->extension_info_.swap(info);
485 489
486 KeywordWebDataService::BatchModeScoper scoper(web_data_service_.get()); 490 KeywordWebDataService::BatchModeScoper scoper(web_data_service_.get());
487 TemplateURL* template_url_ptr = AddNoNotify(std::move(template_url), true); 491 TemplateURL* template_url_ptr = AddNoNotify(std::move(template_url), true);
488 if (template_url_ptr) { 492 if (template_url_ptr) {
489 if (template_url_ptr->extension_info_->wants_to_be_default_engine) { 493 if (template_url_ptr->extension_info_->wants_to_be_default_engine) {
490 UpdateExtensionDefaultSearchEngine(); 494 UpdateExtensionDefaultSearchEngine();
491 } 495 }
(...skipping 745 matching lines...) Expand 10 before | Expand all | Expand 10 after
1237 specifics.mutable_search_engine(); 1241 specifics.mutable_search_engine();
1238 se_specifics->set_short_name(base::UTF16ToUTF8(turl.short_name())); 1242 se_specifics->set_short_name(base::UTF16ToUTF8(turl.short_name()));
1239 se_specifics->set_keyword(base::UTF16ToUTF8(turl.keyword())); 1243 se_specifics->set_keyword(base::UTF16ToUTF8(turl.keyword()));
1240 se_specifics->set_favicon_url(turl.favicon_url().spec()); 1244 se_specifics->set_favicon_url(turl.favicon_url().spec());
1241 se_specifics->set_url(turl.url()); 1245 se_specifics->set_url(turl.url());
1242 se_specifics->set_safe_for_autoreplace(turl.safe_for_autoreplace()); 1246 se_specifics->set_safe_for_autoreplace(turl.safe_for_autoreplace());
1243 se_specifics->set_originating_url(turl.originating_url().spec()); 1247 se_specifics->set_originating_url(turl.originating_url().spec());
1244 se_specifics->set_date_created(turl.date_created().ToInternalValue()); 1248 se_specifics->set_date_created(turl.date_created().ToInternalValue());
1245 se_specifics->set_input_encodings( 1249 se_specifics->set_input_encodings(
1246 base::JoinString(turl.input_encodings(), ";")); 1250 base::JoinString(turl.input_encodings(), ";"));
1247 se_specifics->set_show_in_default_list(turl.show_in_default_list());
1248 se_specifics->set_suggestions_url(turl.suggestions_url()); 1251 se_specifics->set_suggestions_url(turl.suggestions_url());
1249 se_specifics->set_prepopulate_id(turl.prepopulate_id()); 1252 se_specifics->set_prepopulate_id(turl.prepopulate_id());
1250 se_specifics->set_instant_url(turl.instant_url()); 1253 se_specifics->set_instant_url(turl.instant_url());
1251 if (!turl.image_url().empty()) 1254 if (!turl.image_url().empty())
1252 se_specifics->set_image_url(turl.image_url()); 1255 se_specifics->set_image_url(turl.image_url());
1253 se_specifics->set_new_tab_url(turl.new_tab_url()); 1256 se_specifics->set_new_tab_url(turl.new_tab_url());
1254 if (!turl.search_url_post_params().empty()) 1257 if (!turl.search_url_post_params().empty())
1255 se_specifics->set_search_url_post_params(turl.search_url_post_params()); 1258 se_specifics->set_search_url_post_params(turl.search_url_post_params());
1256 if (!turl.suggestions_url_post_params().empty()) { 1259 if (!turl.suggestions_url_post_params().empty()) {
1257 se_specifics->set_suggestions_url_post_params( 1260 se_specifics->set_suggestions_url_post_params(
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1317 data.SetURL(specifics.url()); 1320 data.SetURL(specifics.url());
1318 data.suggestions_url = specifics.suggestions_url(); 1321 data.suggestions_url = specifics.suggestions_url();
1319 data.instant_url = specifics.instant_url(); 1322 data.instant_url = specifics.instant_url();
1320 data.image_url = specifics.image_url(); 1323 data.image_url = specifics.image_url();
1321 data.new_tab_url = specifics.new_tab_url(); 1324 data.new_tab_url = specifics.new_tab_url();
1322 data.search_url_post_params = specifics.search_url_post_params(); 1325 data.search_url_post_params = specifics.search_url_post_params();
1323 data.suggestions_url_post_params = specifics.suggestions_url_post_params(); 1326 data.suggestions_url_post_params = specifics.suggestions_url_post_params();
1324 data.instant_url_post_params = specifics.instant_url_post_params(); 1327 data.instant_url_post_params = specifics.instant_url_post_params();
1325 data.image_url_post_params = specifics.image_url_post_params(); 1328 data.image_url_post_params = specifics.image_url_post_params();
1326 data.favicon_url = GURL(specifics.favicon_url()); 1329 data.favicon_url = GURL(specifics.favicon_url());
1327 data.show_in_default_list = specifics.show_in_default_list();
1328 data.safe_for_autoreplace = specifics.safe_for_autoreplace(); 1330 data.safe_for_autoreplace = specifics.safe_for_autoreplace();
1329 data.input_encodings = base::SplitString( 1331 data.input_encodings = base::SplitString(
1330 specifics.input_encodings(), ";", 1332 specifics.input_encodings(), ";",
1331 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); 1333 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
1332 // If the server data has duplicate encodings, we'll want to push an update 1334 // If the server data has duplicate encodings, we'll want to push an update
1333 // below to correct it. Note that we also fix this in 1335 // below to correct it. Note that we also fix this in
1334 // GetSearchProvidersUsingKeywordResult(), since otherwise we'd never correct 1336 // GetSearchProvidersUsingKeywordResult(), since otherwise we'd never correct
1335 // local problems for clients which have disabled search engine sync. 1337 // local problems for clients which have disabled search engine sync.
1336 bool deduped = DeDupeEncodings(&data.input_encodings); 1338 bool deduped = DeDupeEncodings(&data.input_encodings);
1337 data.date_created = base::Time::FromInternalValue(specifics.date_created()); 1339 data.date_created = base::Time::FromInternalValue(specifics.date_created());
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
1634 if (!urls) 1636 if (!urls)
1635 return true; 1637 return true;
1636 for (TemplateURLSet::const_iterator i(urls->begin()); i != urls->end(); ++i) { 1638 for (TemplateURLSet::const_iterator i(urls->begin()); i != urls->end(); ++i) {
1637 if (!(*i)->safe_for_autoreplace()) 1639 if (!(*i)->safe_for_autoreplace())
1638 return false; 1640 return false;
1639 } 1641 }
1640 return true; 1642 return true;
1641 } 1643 }
1642 1644
1643 bool TemplateURLService::CanReplace(const TemplateURL* t_url) { 1645 bool TemplateURLService::CanReplace(const TemplateURL* t_url) {
1644 return (t_url != default_search_provider_ && !t_url->show_in_default_list() && 1646 return !ShowInDefaultList(t_url) && t_url->safe_for_autoreplace();
1645 t_url->safe_for_autoreplace());
1646 } 1647 }
1647 1648
1648 TemplateURL* TemplateURLService::FindNonExtensionTemplateURLForKeyword( 1649 TemplateURL* TemplateURLService::FindNonExtensionTemplateURLForKeyword(
1649 const base::string16& keyword) { 1650 const base::string16& keyword) {
1650 TemplateURL* keyword_turl = GetTemplateURLForKeyword(keyword); 1651 TemplateURL* keyword_turl = GetTemplateURLForKeyword(keyword);
1651 if (!keyword_turl || (keyword_turl->type() == TemplateURL::NORMAL)) 1652 if (!keyword_turl || (keyword_turl->type() == TemplateURL::NORMAL))
1652 return keyword_turl; 1653 return keyword_turl;
1653 // The extension keyword in the model may be hiding a replaceable 1654 // The extension keyword in the model may be hiding a replaceable
1654 // non-extension keyword. Look for it. 1655 // non-extension keyword. Look for it.
1655 for (const auto& turl : template_urls_) { 1656 for (const auto& turl : template_urls_) {
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
1960 if (AddNoNotify(std::move(new_dse_ptr), true)) 1961 if (AddNoNotify(std::move(new_dse_ptr), true))
1961 default_search_provider_ = new_dse; 1962 default_search_provider_ = new_dse;
1962 } 1963 }
1963 } else if (source == DefaultSearchManager::FROM_USER) { 1964 } else if (source == DefaultSearchManager::FROM_USER) {
1964 default_search_provider_ = GetTemplateURLForGUID(data->sync_guid); 1965 default_search_provider_ = GetTemplateURLForGUID(data->sync_guid);
1965 if (!default_search_provider_ && data->prepopulate_id) { 1966 if (!default_search_provider_ && data->prepopulate_id) {
1966 default_search_provider_ = 1967 default_search_provider_ =
1967 FindPrepopulatedTemplateURL(data->prepopulate_id); 1968 FindPrepopulatedTemplateURL(data->prepopulate_id);
1968 } 1969 }
1969 TemplateURLData new_data(*data); 1970 TemplateURLData new_data(*data);
1970 new_data.show_in_default_list = true;
1971 if (default_search_provider_) { 1971 if (default_search_provider_) {
1972 UpdateNoNotify(default_search_provider_, TemplateURL(new_data)); 1972 UpdateNoNotify(default_search_provider_, TemplateURL(new_data));
1973 } else { 1973 } else {
1974 new_data.id = kInvalidTemplateURLID; 1974 new_data.id = kInvalidTemplateURLID;
1975 std::unique_ptr<TemplateURL> new_dse_ptr = 1975 std::unique_ptr<TemplateURL> new_dse_ptr =
1976 base::MakeUnique<TemplateURL>(new_data); 1976 base::MakeUnique<TemplateURL>(new_data);
1977 TemplateURL* new_dse = new_dse_ptr.get(); 1977 TemplateURL* new_dse = new_dse_ptr.get();
1978 if (AddNoNotify(std::move(new_dse_ptr), true)) 1978 if (AddNoNotify(std::move(new_dse_ptr), true))
1979 default_search_provider_ = new_dse; 1979 default_search_provider_ = new_dse;
1980 } 1980 }
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after
2473 2473
2474 if (most_recently_intalled_default) { 2474 if (most_recently_intalled_default) {
2475 base::AutoReset<DefaultSearchChangeOrigin> change_origin( 2475 base::AutoReset<DefaultSearchChangeOrigin> change_origin(
2476 &dsp_change_origin_, DSP_CHANGE_OVERRIDE_SETTINGS_EXTENSION); 2476 &dsp_change_origin_, DSP_CHANGE_OVERRIDE_SETTINGS_EXTENSION);
2477 default_search_manager_.SetExtensionControlledDefaultSearchEngine( 2477 default_search_manager_.SetExtensionControlledDefaultSearchEngine(
2478 most_recently_intalled_default->data()); 2478 most_recently_intalled_default->data());
2479 } else { 2479 } else {
2480 default_search_manager_.ClearExtensionControlledDefaultSearchEngine(); 2480 default_search_manager_.ClearExtensionControlledDefaultSearchEngine();
2481 } 2481 }
2482 } 2482 }
OLDNEW
« no previous file with comments | « components/search_engines/template_url_service.h ('k') | components/search_engines/template_url_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698