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> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/string16.h" | |
14 | 13 |
15 class GURL; | 14 class GURL; |
16 class Profile; | 15 class Profile; |
17 | 16 |
18 // This namespace provides various helpers around handling Google-related URLs | 17 // This namespace provides various helpers around handling Google-related URLs |
19 // and state relating to Google Chrome distributions (such as RLZ). | 18 // and state relating to Google Chrome distributions (such as RLZ). |
20 namespace google_util { | 19 namespace google_util { |
21 | 20 |
22 // The query key that identifies a Google Extended API request for Instant. | |
23 const char kInstantExtendedAPIParam[] = "espv"; | 21 const char kInstantExtendedAPIParam[] = "espv"; |
24 | 22 |
25 GURL LinkDoctorBaseURL(); | 23 GURL LinkDoctorBaseURL(); |
26 void SetMockLinkDoctorBaseURLForTesting(); | 24 void SetMockLinkDoctorBaseURLForTesting(); |
27 | 25 |
28 // Adds the Google locale string to the URL (e.g., hl=en-US). This does not | 26 // Adds the Google locale string to the URL (e.g., hl=en-US). This does not |
29 // check to see if the param already exists. | 27 // check to see if the param already exists. |
30 GURL AppendGoogleLocaleParam(const GURL& url); | 28 GURL AppendGoogleLocaleParam(const GURL& url); |
31 | 29 |
32 // String version of AppendGoogleLocaleParam. | 30 // String version of AppendGoogleLocaleParam. |
33 std::string StringAppendGoogleLocaleParam(const std::string& url); | 31 std::string StringAppendGoogleLocaleParam(const std::string& url); |
34 | 32 |
35 // Adds the Google TLD string for the given profile to the URL (e.g., sd=com). | 33 // Adds the Google TLD string for the given profile to the URL (e.g., sd=com). |
36 // This does not check to see if the param already exists. | 34 // This does not check to see if the param already exists. |
37 GURL AppendGoogleTLDParam(Profile* profile, const GURL& url); | 35 GURL AppendGoogleTLDParam(Profile* profile, const GURL& url); |
38 | 36 |
39 // Returns in |brand| the brand code or distribution tag that has been | 37 // Returns in |brand| the brand code or distribution tag that has been |
40 // assigned to a partner. Returns false if the information is not available. | 38 // assigned to a partner. Returns false if the information is not available. |
41 bool GetBrand(std::string* brand); | 39 bool GetBrand(std::string* brand); |
42 | 40 |
43 // Returns in |brand| the reactivation brand code or distribution tag | 41 // Returns in |brand| the reactivation brand code or distribution tag |
44 // that has been assigned to a partner for reactivating a dormant chrome | 42 // that has been assigned to a partner for reactivating a dormant chrome |
45 // install. Returns false if the information is not available. | 43 // install. Returns false if the information is not available. |
46 bool GetReactivationBrand(std::string* brand); | 44 bool GetReactivationBrand(std::string* brand); |
47 | 45 |
48 // Returns in the search terms used to create the Google search URL |url|. | |
49 string16 GetSearchTermsFromGoogleSearchURL(const std::string& url); | |
50 | |
51 // WARNING: The following IsGoogleXXX() functions use heuristics to rule out | 46 // WARNING: The following IsGoogleXXX() functions use heuristics to rule out |
52 // "obviously false" answers. They do NOT guarantee that the string in question | 47 // "obviously false" answers. They do NOT guarantee that the string in question |
53 // is actually on a Google-owned domain, just that it looks plausible. If you | 48 // is actually on a Google-owned domain, just that it looks plausible. If you |
54 // need to restrict some behavior to only happen on Google's officially-owned | 49 // need to restrict some behavior to only happen on Google's officially-owned |
55 // domains, use TransportSecurityState::IsGooglePinnedProperty() instead. | 50 // domains, use TransportSecurityState::IsGooglePinnedProperty() instead. |
56 | 51 |
57 // Designate whether or not a URL checking function also checks for specific | 52 // Designate whether or not a URL checking function also checks for specific |
58 // subdomains, or only "www" and empty subdomains. | 53 // subdomains, or only "www" and empty subdomains. |
59 enum SubdomainPermission { | 54 enum SubdomainPermission { |
60 ALLOW_SUBDOMAIN, | 55 ALLOW_SUBDOMAIN, |
(...skipping 16 matching lines...) Expand all Loading... |
77 PortPermission port_permission); | 72 PortPermission port_permission); |
78 // True if |host| is "[www.]google.<TLD>" with a valid TLD. If | 73 // True if |host| is "[www.]google.<TLD>" with a valid TLD. If |
79 // |subdomain_permission| is ALLOW_SUBDOMAIN, we check against host | 74 // |subdomain_permission| is ALLOW_SUBDOMAIN, we check against host |
80 // "*.google.<TLD>" instead. | 75 // "*.google.<TLD>" instead. |
81 bool IsGoogleHostname(const std::string& host, | 76 bool IsGoogleHostname(const std::string& host, |
82 SubdomainPermission subdomain_permission); | 77 SubdomainPermission subdomain_permission); |
83 // True if |url| represents a valid Google home page URL. | 78 // True if |url| represents a valid Google home page URL. |
84 bool IsGoogleHomePageUrl(const std::string& url); | 79 bool IsGoogleHomePageUrl(const std::string& url); |
85 // True if |url| represents a valid Google search URL. | 80 // True if |url| represents a valid Google search URL. |
86 bool IsGoogleSearchUrl(const std::string& url); | 81 bool IsGoogleSearchUrl(const std::string& url); |
87 // True if |url| represents a valid Google search URL used by the Instant | |
88 // Extended API. | |
89 bool IsInstantExtendedAPIGoogleSearchUrl(const std::string& url); | |
90 | 82 |
91 // True if a build is strictly organic, according to its brand code. | 83 // True if a build is strictly organic, according to its brand code. |
92 bool IsOrganic(const std::string& brand); | 84 bool IsOrganic(const std::string& brand); |
93 | 85 |
94 // True if a build should run as organic during first run. This uses | 86 // True if a build should run as organic during first run. This uses |
95 // a slightly different set of brand codes from the standard IsOrganic | 87 // a slightly different set of brand codes from the standard IsOrganic |
96 // method. | 88 // method. |
97 bool IsOrganicFirstRun(const std::string& brand); | 89 bool IsOrganicFirstRun(const std::string& brand); |
98 | 90 |
99 // True if |brand| is an internet cafe brand code. | 91 // True if |brand| is an internet cafe brand code. |
100 bool IsInternetCafeBrandCode(const std::string& brand); | 92 bool IsInternetCafeBrandCode(const std::string& brand); |
101 | 93 |
102 // This class is meant to be used only from test code, and sets the brand | 94 // This class is meant to be used only from test code, and sets the brand |
103 // code returned by the function GetBrand() above while the object exists. | 95 // code returned by the function GetBrand() above while the object exists. |
104 class BrandForTesting { | 96 class BrandForTesting { |
105 public: | 97 public: |
106 explicit BrandForTesting(const std::string& brand); | 98 explicit BrandForTesting(const std::string& brand); |
107 ~BrandForTesting(); | 99 ~BrandForTesting(); |
108 | 100 |
109 private: | 101 private: |
110 std::string brand_; | 102 std::string brand_; |
111 DISALLOW_COPY_AND_ASSIGN(BrandForTesting); | 103 DISALLOW_COPY_AND_ASSIGN(BrandForTesting); |
112 }; | 104 }; |
113 | 105 |
114 } // namespace google_util | 106 } // namespace google_util |
115 | 107 |
116 #endif // CHROME_BROWSER_GOOGLE_GOOGLE_UTIL_H__ | 108 #endif // CHROME_BROWSER_GOOGLE_GOOGLE_UTIL_H__ |
OLD | NEW |