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
3 // found in the LICENSE file.
5 // Some Google related utility functions.
7 #ifndef CHROME_BROWSER_GOOGLE_GOOGLE_UTIL_H__
8 #define CHROME_BROWSER_GOOGLE_GOOGLE_UTIL_H__
12 #include "base/basictypes.h"
17 // This namespace provides various helpers around handling Google-related URLs
18 // and state relating to Google Chrome distributions (such as RLZ).
19 namespace google_util
{
21 // True iff |str| contains a "q=" query parameter with a non-empty value.
22 // |str| should be a query or a hash fragment, without the ? or # (as
23 // returned by GURL::query() or GURL::ref().
24 bool HasGoogleSearchQueryParam(const std::string
& str
);
26 // The query key that identifies a Google Extended API request for Instant.
27 const char kInstantExtendedAPIParam
[] = "espv";
29 GURL
LinkDoctorBaseURL();
30 void SetMockLinkDoctorBaseURLForTesting();
32 // Returns the Google locale. This is the same string as
33 // AppendGoogleLocaleParam adds to the URL, only without the leading "hl".
34 std::string
GetGoogleLocale();
36 // Adds the Google locale string to the URL (e.g., hl=en-US). This does not
37 // check to see if the param already exists.
38 GURL
AppendGoogleLocaleParam(const GURL
& url
);
40 // String version of AppendGoogleLocaleParam.
41 std::string
StringAppendGoogleLocaleParam(const std::string
& url
);
43 // Returns the Google country code string for the given profile.
44 std::string
GetGoogleCountryCode(Profile
* profile
);
46 // Returns the Google search URL for the given profile.
47 GURL
GetGoogleSearchURL(Profile
* profile
);
49 // Returns in |brand| the brand code or distribution tag that has been
50 // assigned to a partner. Returns false if the information is not available.
51 bool GetBrand(std::string
* brand
);
53 // Returns in |brand| the reactivation brand code or distribution tag
54 // that has been assigned to a partner for reactivating a dormant chrome
55 // install. Returns false if the information is not available.
56 bool GetReactivationBrand(std::string
* brand
);
58 // Returns the Google base URL specified on the command line, if it exists.
59 // This performs some fixup and sanity-checking to ensure that the resulting URL
60 // is valid and has no query or ref.
61 GURL
CommandLineGoogleBaseURL();
63 // Returns true if a Google base URL was specified on the command line and |url|
64 // begins with that base URL. This uses a simple string equality check.
65 bool StartsWithCommandLineGoogleBaseURL(const GURL
& url
);
67 // WARNING: The following IsGoogleXXX() functions use heuristics to rule out
68 // "obviously false" answers. They do NOT guarantee that the string in question
69 // is actually on a Google-owned domain, just that it looks plausible. If you
70 // need to restrict some behavior to only happen on Google's officially-owned
71 // domains, use TransportSecurityState::IsGooglePinnedProperty() instead.
73 // Designate whether or not a URL checking function also checks for specific
74 // subdomains, or only "www" and empty subdomains.
75 enum SubdomainPermission
{
80 // Designate whether or not a URL checking function also checks for standard
81 // ports (80 for http, 443 for https), or if it allows all port numbers.
83 ALLOW_NON_STANDARD_PORTS
,
84 DISALLOW_NON_STANDARD_PORTS
,
87 // True if |host| is "[www.]google.<TLD>" with a valid TLD. If
88 // |subdomain_permission| is ALLOW_SUBDOMAIN, we check against host
89 // "*.google.<TLD>" instead.
91 // If the Google base URL has been overridden on the command line, this function
92 // will also return true for any URL whose hostname exactly matches the hostname
93 // of the URL specified on the command line. In this case,
94 // |subdomain_permission| is ignored.
95 bool IsGoogleHostname(const std::string
& host
,
96 SubdomainPermission subdomain_permission
);
98 // True if |url| is a valid URL with a host that returns true for
99 // IsGoogleHostname(), and an HTTP or HTTPS scheme. If |port_permission| is
100 // DISALLOW_NON_STANDARD_PORTS, this also requires |url| to use the standard
101 // port for its scheme (80 for HTTP, 443 for HTTPS).
103 // Note that this only checks for google.<TLD> domains, but not other Google
104 // properties. There is code in variations_http_header_provider.cc that checks
105 // for additional Google properties, which can be moved here if more callers
106 // are interested in this in the future.
107 bool IsGoogleDomainUrl(const GURL
& url
,
108 SubdomainPermission subdomain_permission
,
109 PortPermission port_permission
);
111 // True if |url| represents a valid Google home page URL.
112 bool IsGoogleHomePageUrl(const GURL
& url
);
114 // True if |url| represents a valid Google search URL.
115 bool IsGoogleSearchUrl(const GURL
& url
);
117 // True if a build is strictly organic, according to its brand code.
118 bool IsOrganic(const std::string
& brand
);
120 // True if a build should run as organic during first run. This uses
121 // a slightly different set of brand codes from the standard IsOrganic
123 bool IsOrganicFirstRun(const std::string
& brand
);
125 // True if |brand| is an internet cafe brand code.
126 bool IsInternetCafeBrandCode(const std::string
& brand
);
128 // This class is meant to be used only from test code, and sets the brand
129 // code returned by the function GetBrand() above while the object exists.
130 class BrandForTesting
{
132 explicit BrandForTesting(const std::string
& brand
);
137 DISALLOW_COPY_AND_ASSIGN(BrandForTesting
);
140 } // namespace google_util
142 #endif // CHROME_BROWSER_GOOGLE_GOOGLE_UTIL_H__