diff options
author | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-28 22:52:19 +0000 |
---|---|---|
committer | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-28 22:52:19 +0000 |
commit | bba9e63bdb8de860a20f2979c49cb814552d3ee3 (patch) | |
tree | 85fb36329ca1fa9dcbca6bbf8090ef80b1c7b466 /chrome/browser/google/google_util.cc | |
parent | 28b6d3554a56f6611b74bad1e1baf24e38ec7070 (diff) | |
download | chromium_src-bba9e63bdb8de860a20f2979c49cb814552d3ee3.zip chromium_src-bba9e63bdb8de860a20f2979c49cb814552d3ee3.tar.gz chromium_src-bba9e63bdb8de860a20f2979c49cb814552d3ee3.tar.bz2 |
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
Diffstat (limited to 'chrome/browser/google/google_util.cc')
-rw-r--r-- | chrome/browser/google/google_util.cc | 77 |
1 files changed, 37 insertions, 40 deletions
diff --git a/chrome/browser/google/google_util.cc b/chrome/browser/google/google_util.cc index 5a5befb..8211ecc 100644 --- a/chrome/browser/google/google_util.cc +++ b/chrome/browser/google/google_util.cc @@ -35,16 +35,25 @@ #define LINKDOCTOR_SERVER_REQUEST_URL std::string() #endif + +// Helpers -------------------------------------------------------------------- + namespace { const char* brand_for_testing = NULL; - bool gUseMockLinkDoctorBaseURLForTesting = false; -} // anonymous namespace +bool IsPathHomePageBase(const std::string& path) { + return (path == "/") || (path == "/webhp"); +} + +} // namespace + namespace google_util { +// Global functions ----------------------------------------------------------- + bool HasGoogleSearchQueryParam(const std::string& str) { url_parse::Component query(0, str.length()), key, value; while (url_parse::ExtractQueryKeyValue(str.c_str(), &query, &key, @@ -65,15 +74,6 @@ void SetMockLinkDoctorBaseURLForTesting() { gUseMockLinkDoctorBaseURLForTesting = true; } -BrandForTesting::BrandForTesting(const std::string& brand) : brand_(brand) { - DCHECK(brand_for_testing == NULL); - brand_for_testing = brand_.c_str(); -} - -BrandForTesting::~BrandForTesting() { - brand_for_testing = NULL; -} - GURL AppendGoogleLocaleParam(const GURL& url) { // Google does not yet recognize 'nb' for Norwegian Bokmal, but it uses // 'no' for that. @@ -152,14 +152,6 @@ bool GetReactivationBrand(std::string* brand) { #endif -bool IsGoogleDomainUrl(const GURL& url, - SubdomainPermission subdomain_permission, - PortPermission port_permission) { - return url.is_valid() && (url.SchemeIs("http") || url.SchemeIs("https")) && - (url.port().empty() || (port_permission == ALLOW_NON_STANDARD_PORTS)) && - google_util::IsGoogleHostname(url.host(), subdomain_permission); -} - bool IsGoogleHostname(const std::string& host, SubdomainPermission subdomain_permission) { size_t tld_length = net::registry_controlled_domains::GetRegistryLength( @@ -176,6 +168,14 @@ bool IsGoogleHostname(const std::string& host, return LowerCaseEqualsASCII(host_minus_tld, "www.google."); } +bool IsGoogleDomainUrl(const GURL& url, + SubdomainPermission subdomain_permission, + PortPermission port_permission) { + return url.is_valid() && (url.SchemeIs("http") || url.SchemeIs("https")) && + (url.port().empty() || (port_permission == ALLOW_NON_STANDARD_PORTS)) && + google_util::IsGoogleHostname(url.host(), subdomain_permission); +} + bool IsGoogleHomePageUrl(const GURL& url) { // First check to see if this has a Google domain. if (!IsGoogleDomainUrl(url, DISALLOW_SUBDOMAIN, DISALLOW_NON_STANDARD_PORTS)) @@ -183,12 +183,7 @@ bool IsGoogleHomePageUrl(const GURL& url) { // Make sure the path is a known home page path. std::string path(url.path()); - if (path != "/" && path != "/webhp" && - !StartsWithASCII(path, "/ig", false)) { - return false; - } - - return true; + return IsPathHomePageBase(path) || StartsWithASCII(path, "/ig", false); } bool IsGoogleSearchUrl(const GURL& url) { @@ -198,25 +193,14 @@ bool IsGoogleSearchUrl(const GURL& url) { // Make sure the path is a known search path. std::string path(url.path()); - bool has_valid_path = false; - bool is_home_page_base = false; - if (path == "/search") { - has_valid_path = true; - } else if (path == "/webhp" || path == "/") { - // Note that we allow both "/" and "" paths, but GURL spits them - // both out as just "/". - has_valid_path = true; - is_home_page_base = true; - } - if (!has_valid_path) + bool is_home_page_base = IsPathHomePageBase(path); + if (!is_home_page_base && (path != "/search")) return false; // Check for query parameter in URL parameter and hash fragment, depending on // the path type. - std::string query(url.query()); - std::string ref(url.ref()); - return HasGoogleSearchQueryParam(ref) || - (!is_home_page_base && HasGoogleSearchQueryParam(query)); + return HasGoogleSearchQueryParam(url.ref()) || + (!is_home_page_base && HasGoogleSearchQueryParam(url.query())); } bool IsOrganic(const std::string& brand) { @@ -280,4 +264,17 @@ bool IsInternetCafeBrandCode(const std::string& brand) { return found != end; } + +// BrandForTesting ------------------------------------------------------------ + +BrandForTesting::BrandForTesting(const std::string& brand) : brand_(brand) { + DCHECK(brand_for_testing == NULL); + brand_for_testing = brand_.c_str(); +} + +BrandForTesting::~BrandForTesting() { + brand_for_testing = NULL; +} + + } // namespace google_util |