From bba9e63bdb8de860a20f2979c49cb814552d3ee3 Mon Sep 17 00:00:00 2001 From: "pkasting@chromium.org" Date: Fri, 28 Jun 2013 22:52:19 +0000 Subject: Misc. cleanup: * Reduce indenting levels * Align args per style guide * Improve (or remove) comments * Pass around TemplateURL*s where convenient and safe instead of converting to/from keywords. This generally simplifies things slightly and will be useful for subsequent changes that need the TemplateURL*s in more places. * Don't handle DCHECK failure * Nuke long-outdated disabled KeywordProvider unittest * Attempt (and probably fail) to put SearchProvider::CreateSearchSuggestion() args in some sort of order * Remove using directives where they don't save lines * Follow style guide class declaration order * Use OVERRIDE * Make function declaration and definition order match * Shorten/simplify code * Put all three IsGoogleXXX() functions that take URLs in one group * Eliminate unnecessary #includes * Add GetDefaultSearchURLForSearchTerms() function to c/b/search_engines/util.h since many disparate callers want to do that (and in a subsequent change I'll want to slightly modify how that works) * Fix presubmit warning about mismatched braces * Remove unnecessary ResetDefaultTemplateURL() calls from ToolbarModel tests BUG=249197 TEST=none R=cpu@chromium.org, jered@chromium.org Review URL: https://codereview.chromium.org/18119005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@209228 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/search_engines/template_url.h | 2 ++ .../template_url_prepopulate_data_unittest.cc | 8 ++++---- chrome/browser/search_engines/template_url_service.cc | 4 ++-- chrome/browser/search_engines/template_url_service.h | 8 ++++---- chrome/browser/search_engines/util.cc | 14 ++++++++++++++ chrome/browser/search_engines/util.h | 4 ++++ 6 files changed, 30 insertions(+), 10 deletions(-) (limited to 'chrome/browser/search_engines') diff --git a/chrome/browser/search_engines/template_url.h b/chrome/browser/search_engines/template_url.h index 084aaef..b8149f7 100644 --- a/chrome/browser/search_engines/template_url.h +++ b/chrome/browser/search_engines/template_url.h @@ -59,8 +59,10 @@ class TemplateURLRef { // The search terms (query). const string16 search_terms; + // The original (input) query. string16 original_query; + // The optional assisted query stats, aka AQS, used for logging purposes. // This string contains impressions of all autocomplete matches shown // at the query submission time. For privacy reasons, we require the diff --git a/chrome/browser/search_engines/template_url_prepopulate_data_unittest.cc b/chrome/browser/search_engines/template_url_prepopulate_data_unittest.cc index 115abc7..cf6799f 100644 --- a/chrome/browser/search_engines/template_url_prepopulate_data_unittest.cc +++ b/chrome/browser/search_engines/template_url_prepopulate_data_unittest.cc @@ -304,13 +304,13 @@ TEST_F(TemplateURLPrepopulateDataTest, GetEngineTypeAdvanced) { TemplateURLPrepopulateData::GetEngineType(kYahooURLs[i])); } // URLs for engines not present in country-specific lists. - std::string kNigmaURL = "http://www.nigma.ru/?s={searchTerms}&arg1=value1"; EXPECT_EQ(SEARCH_ENGINE_NIGMA, - TemplateURLPrepopulateData::GetEngineType(kNigmaURL)); + TemplateURLPrepopulateData::GetEngineType( + "http://www.nigma.ru/?s={searchTerms}&arg1=value1")); // Search URL for which no prepopulated search provider exists. - std::string kExampleSearchURL = "http://example.net/search?q={searchTerms}"; EXPECT_EQ(SEARCH_ENGINE_OTHER, - TemplateURLPrepopulateData::GetEngineType(kExampleSearchURL)); + TemplateURLPrepopulateData::GetEngineType( + "http://example.net/search?q={searchTerms}")); EXPECT_EQ(SEARCH_ENGINE_OTHER, TemplateURLPrepopulateData::GetEngineType("invalid:search:url")); } diff --git a/chrome/browser/search_engines/template_url_service.cc b/chrome/browser/search_engines/template_url_service.cc index f3483f6..813f488 100644 --- a/chrome/browser/search_engines/template_url_service.cc +++ b/chrome/browser/search_engines/template_url_service.cc @@ -410,7 +410,7 @@ bool TemplateURLService::CanReplaceKeyword( void TemplateURLService::FindMatchingKeywords( const string16& prefix, bool support_replacement_only, - std::vector* matches) const { + TemplateURLVector* matches) const { // Sanity check args. if (prefix.empty()) return; @@ -434,7 +434,7 @@ void TemplateURLService::FindMatchingKeywords( for (KeywordToTemplateMap::const_iterator i(match_range.first); i != match_range.second; ++i) { if (!support_replacement_only || i->second->url_ref().SupportsReplacement()) - matches->push_back(i->first); + matches->push_back(i->second); } } diff --git a/chrome/browser/search_engines/template_url_service.h b/chrome/browser/search_engines/template_url_service.h index 83826d5..724f771 100644 --- a/chrome/browser/search_engines/template_url_service.h +++ b/chrome/browser/search_engines/template_url_service.h @@ -118,12 +118,12 @@ class TemplateURLService : public WebDataServiceConsumer, const GURL& url, TemplateURL** template_url_to_replace); - // Returns (in |matches|) all keywords beginning with |prefix|, sorted - // shortest-first. If support_replacement_only is true, only keywords that - // support replacement are returned. + // Returns (in |matches|) all TemplateURLs whose keywords begin with |prefix|, + // sorted shortest keyword-first. If |support_replacement_only| is true, only + // TemplateURLs that support replacement are returned. void FindMatchingKeywords(const string16& prefix, bool support_replacement_only, - std::vector* matches) const; + TemplateURLVector* matches) const; // Looks up |keyword| and returns the element it maps to. Returns NULL if // the keyword was not found. diff --git a/chrome/browser/search_engines/util.cc b/chrome/browser/search_engines/util.cc index b477350..fbef1cc 100644 --- a/chrome/browser/search_engines/util.cc +++ b/chrome/browser/search_engines/util.cc @@ -39,6 +39,20 @@ string16 GetDefaultSearchEngineName(Profile* profile) { return default_provider->short_name(); } +GURL GetDefaultSearchURLForSearchTerms(Profile* profile, + const string16& terms) { + DCHECK(profile); + const TemplateURL* default_provider = + TemplateURLServiceFactory::GetForProfile(profile)-> + GetDefaultSearchProvider(); + if (!default_provider) + return GURL(); + const TemplateURLRef& search_url = default_provider->url_ref(); + DCHECK(search_url.SupportsReplacement()); + TemplateURLRef::SearchTermsArgs search_terms_args(terms); + return GURL(search_url.ReplaceSearchTerms(search_terms_args)); +} + void RemoveDuplicatePrepopulateIDs( WebDataService* service, const ScopedVector& prepopulated_urls, diff --git a/chrome/browser/search_engines/util.h b/chrome/browser/search_engines/util.h index 912748d..b496e2a 100644 --- a/chrome/browser/search_engines/util.h +++ b/chrome/browser/search_engines/util.h @@ -23,6 +23,10 @@ class WebDataService; // none is set. |profile| may be NULL. string16 GetDefaultSearchEngineName(Profile* profile); +// Returns a GURL that searches for |terms| using the default search engine of +// |profile|. +GURL GetDefaultSearchURLForSearchTerms(Profile* profile, const string16& terms); + // Modifies |prepopulated_url| so that it contains user-modified fields from // |original_turl|. Both URLs must have the same prepopulate_id. void MergeIntoPrepopulatedEngineData(TemplateURLData* prepopulated_url, -- cgit v1.1