• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 //
5 // Some Google related utility functions.
6 
7 #ifndef CHROME_BROWSER_GOOGLE_GOOGLE_UTIL_H__
8 #define CHROME_BROWSER_GOOGLE_GOOGLE_UTIL_H__
9 
10 #include <string>
11 
12 #include "base/basictypes.h"
13 
14 class GURL;
15 class Profile;
16 
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 {
20 
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);
25 
26 // The query key that identifies a Google Extended API request for Instant.
27 const char kInstantExtendedAPIParam[] = "espv";
28 
29 GURL LinkDoctorBaseURL();
30 void SetMockLinkDoctorBaseURLForTesting();
31 
32 // Adds the Google locale string to the URL (e.g., hl=en-US).  This does not
33 // check to see if the param already exists.
34 GURL AppendGoogleLocaleParam(const GURL& url);
35 
36 // String version of AppendGoogleLocaleParam.
37 std::string StringAppendGoogleLocaleParam(const std::string& url);
38 
39 // Adds the Google TLD string for the given profile to the URL (e.g., sd=com).
40 // This does not check to see if the param already exists.
41 GURL AppendGoogleTLDParam(Profile* profile, const GURL& url);
42 
43 // Returns in |brand| the brand code or distribution tag that has been
44 // assigned to a partner. Returns false if the information is not available.
45 bool GetBrand(std::string* brand);
46 
47 // Returns in |brand| the reactivation brand code or distribution tag
48 // that has been assigned to a partner for reactivating a dormant chrome
49 // install. Returns false if the information is not available.
50 bool GetReactivationBrand(std::string* brand);
51 
52 // WARNING: The following IsGoogleXXX() functions use heuristics to rule out
53 // "obviously false" answers.  They do NOT guarantee that the string in question
54 // is actually on a Google-owned domain, just that it looks plausible.  If you
55 // need to restrict some behavior to only happen on Google's officially-owned
56 // domains, use TransportSecurityState::IsGooglePinnedProperty() instead.
57 
58 // Designate whether or not a URL checking function also checks for specific
59 // subdomains, or only "www" and empty subdomains.
60 enum SubdomainPermission {
61   ALLOW_SUBDOMAIN,
62   DISALLOW_SUBDOMAIN,
63 };
64 
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.
67 enum PortPermission {
68   ALLOW_NON_STANDARD_PORTS,
69   DISALLOW_NON_STANDARD_PORTS,
70 };
71 
72 // Returns true if a Google base URL was specified on the command line and |url|
73 // begins with that base URL.  This uses a simple string equality check.
74 bool StartsWithCommandLineGoogleBaseURL(const GURL& url);
75 
76 // True if |host| is "[www.]google.<TLD>" with a valid TLD. If
77 // |subdomain_permission| is ALLOW_SUBDOMAIN, we check against host
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.
84 bool IsGoogleHostname(const std::string& host,
85                       SubdomainPermission subdomain_permission);
86 
87 // True if |url| is a valid URL with a host that returns true for
88 // IsGoogleHostname(), and an HTTP or HTTPS scheme.  If |port_permission| is
89 // DISALLOW_NON_STANDARD_PORTS, this also requires |url| to use the standard
90 // port for its scheme (80 for HTTP, 443 for HTTPS).
91 //
92 // Note that this only checks for google.<TLD> domains, but not other Google
93 // properties. There is code in variations_http_header_provider.cc that checks
94 // for additional Google properties, which can be moved here if more callers
95 // are interested in this in the future.
96 bool IsGoogleDomainUrl(const GURL& url,
97                        SubdomainPermission subdomain_permission,
98                        PortPermission port_permission);
99 
100 // True if |url| represents a valid Google home page URL.
101 bool IsGoogleHomePageUrl(const GURL& url);
102 
103 // True if |url| represents a valid Google search URL.
104 bool IsGoogleSearchUrl(const GURL& url);
105 
106 // True if a build is strictly organic, according to its brand code.
107 bool IsOrganic(const std::string& brand);
108 
109 // True if a build should run as organic during first run. This uses
110 // a slightly different set of brand codes from the standard IsOrganic
111 // method.
112 bool IsOrganicFirstRun(const std::string& brand);
113 
114 // True if |brand| is an internet cafe brand code.
115 bool IsInternetCafeBrandCode(const std::string& brand);
116 
117 // This class is meant to be used only from test code, and sets the brand
118 // code returned by the function GetBrand() above while the object exists.
119 class BrandForTesting {
120  public:
121   explicit BrandForTesting(const std::string& brand);
122   ~BrandForTesting();
123 
124  private:
125   std::string brand_;
126   DISALLOW_COPY_AND_ASSIGN(BrandForTesting);
127 };
128 
129 }  // namespace google_util
130 
131 #endif  // CHROME_BROWSER_GOOGLE_GOOGLE_UTIL_H__
132