| 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 // Some Google related utility functions. | 5 // Some Google related utility functions. |
| 6 | 6 |
| 7 #ifndef CHROME_BROWSER_GOOGLE_GOOGLE_UTIL_H__ | 7 #ifndef CHROME_BROWSER_GOOGLE_GOOGLE_UTIL_H__ |
| 8 #define CHROME_BROWSER_GOOGLE_GOOGLE_UTIL_H__ | 8 #define CHROME_BROWSER_GOOGLE_GOOGLE_UTIL_H__ |
| 9 | 9 |
| 10 #include <string> | 10 #include <string> |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 DISALLOW_SUBDOMAIN, | 62 DISALLOW_SUBDOMAIN, |
| 63 }; | 63 }; |
| 64 | 64 |
| 65 // Designate whether or not a URL checking function also checks for standard | 65 // Designate whether or not a URL checking function also checks for standard |
| 66 // ports (80 for http, 443 for https), or if it allows all port numbers. | 66 // ports (80 for http, 443 for https), or if it allows all port numbers. |
| 67 enum PortPermission { | 67 enum PortPermission { |
| 68 ALLOW_NON_STANDARD_PORTS, | 68 ALLOW_NON_STANDARD_PORTS, |
| 69 DISALLOW_NON_STANDARD_PORTS, | 69 DISALLOW_NON_STANDARD_PORTS, |
| 70 }; | 70 }; |
| 71 | 71 |
| 72 // True if |url| is an HTTP[S] request with host "[www.]google.<TLD>". If | 72 // Returns true if a Google base URL was specified on the command line and |url| |
| 73 // |subdomain_permission| is ALLOW_SUBDOMAIN, this checks against host | 73 // begins with that base URL. This uses a simple string equality check. |
| 74 // "*.google.<TLD>" instead. If |port_permission| is ALLOW_NON_STANDARD_PORTS, | 74 bool StartsWithCommandLineGoogleBaseURL(const GURL& url); |
| 75 // this also allows ports other than 80 for http or 443 for https. | 75 |
| 76 bool IsGoogleDomainUrl(const std::string& url, | |
| 77 SubdomainPermission subdomain_permission, | |
| 78 PortPermission port_permission); | |
| 79 // True if |host| is "[www.]google.<TLD>" with a valid TLD. If | 76 // True if |host| is "[www.]google.<TLD>" with a valid TLD. If |
| 80 // |subdomain_permission| is ALLOW_SUBDOMAIN, we check against host | 77 // |subdomain_permission| is ALLOW_SUBDOMAIN, we check against host |
| 81 // "*.google.<TLD>" instead. | 78 // "*.google.<TLD>" instead. |
| 79 // |
| 80 // If the Google base URL has been overridden on the command line, this function |
| 81 // will also return true for any URL whose hostname exactly matches the hostname |
| 82 // of the URL specified on the command line. In this case, |
| 83 // |subdomain_permission| is ignored. |
| 82 bool IsGoogleHostname(const std::string& host, | 84 bool IsGoogleHostname(const std::string& host, |
| 83 SubdomainPermission subdomain_permission); | 85 SubdomainPermission subdomain_permission); |
| 86 // True if |url| is a valid URL with a host that returns true for |
| 87 // IsGoogleHostname(), and an HTTP or HTTPS scheme. If |port_permission| is |
| 88 // DISALLOW_NON_STANDARD_PORTS, this also requires |url| to use the standard |
| 89 // port for its scheme (80 for HTTP, 443 for HTTPS). |
| 90 bool IsGoogleDomainUrl(const GURL& url, |
| 91 SubdomainPermission subdomain_permission, |
| 92 PortPermission port_permission); |
| 84 // True if |url| represents a valid Google home page URL. | 93 // True if |url| represents a valid Google home page URL. |
| 85 bool IsGoogleHomePageUrl(const std::string& url); | 94 bool IsGoogleHomePageUrl(const GURL& url); |
| 86 // True if |url| represents a valid Google search URL. | 95 // True if |url| represents a valid Google search URL. |
| 87 bool IsGoogleSearchUrl(const std::string& url); | 96 bool IsGoogleSearchUrl(const GURL& url); |
| 88 | 97 |
| 89 // True if a build is strictly organic, according to its brand code. | 98 // True if a build is strictly organic, according to its brand code. |
| 90 bool IsOrganic(const std::string& brand); | 99 bool IsOrganic(const std::string& brand); |
| 91 | 100 |
| 92 // True if a build should run as organic during first run. This uses | 101 // True if a build should run as organic during first run. This uses |
| 93 // a slightly different set of brand codes from the standard IsOrganic | 102 // a slightly different set of brand codes from the standard IsOrganic |
| 94 // method. | 103 // method. |
| 95 bool IsOrganicFirstRun(const std::string& brand); | 104 bool IsOrganicFirstRun(const std::string& brand); |
| 96 | 105 |
| 97 // True if |brand| is an internet cafe brand code. | 106 // True if |brand| is an internet cafe brand code. |
| 98 bool IsInternetCafeBrandCode(const std::string& brand); | 107 bool IsInternetCafeBrandCode(const std::string& brand); |
| 99 | 108 |
| 100 // This class is meant to be used only from test code, and sets the brand | 109 // This class is meant to be used only from test code, and sets the brand |
| 101 // code returned by the function GetBrand() above while the object exists. | 110 // code returned by the function GetBrand() above while the object exists. |
| 102 class BrandForTesting { | 111 class BrandForTesting { |
| 103 public: | 112 public: |
| 104 explicit BrandForTesting(const std::string& brand); | 113 explicit BrandForTesting(const std::string& brand); |
| 105 ~BrandForTesting(); | 114 ~BrandForTesting(); |
| 106 | 115 |
| 107 private: | 116 private: |
| 108 std::string brand_; | 117 std::string brand_; |
| 109 DISALLOW_COPY_AND_ASSIGN(BrandForTesting); | 118 DISALLOW_COPY_AND_ASSIGN(BrandForTesting); |
| 110 }; | 119 }; |
| 111 | 120 |
| 112 } // namespace google_util | 121 } // namespace google_util |
| 113 | 122 |
| 114 #endif // CHROME_BROWSER_GOOGLE_GOOGLE_UTIL_H__ | 123 #endif // CHROME_BROWSER_GOOGLE_GOOGLE_UTIL_H__ |
| OLD | NEW |