Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(287)

Side by Side Diff: chrome/browser/google/google_util.cc

Issue 18119005: Misc. cleanup: (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #include "chrome/browser/google/google_util.h" 5 #include "chrome/browser/google/google_util.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 return true; 145 return true;
146 } 146 }
147 147
148 bool GetReactivationBrand(std::string* brand) { 148 bool GetReactivationBrand(std::string* brand) {
149 brand->clear(); 149 brand->clear();
150 return true; 150 return true;
151 } 151 }
152 152
153 #endif 153 #endif
154 154
155 bool IsGoogleDomainUrl(const GURL& url,
156 SubdomainPermission subdomain_permission,
157 PortPermission port_permission) {
158 return url.is_valid() && (url.SchemeIs("http") || url.SchemeIs("https")) &&
159 (url.port().empty() || (port_permission == ALLOW_NON_STANDARD_PORTS)) &&
160 google_util::IsGoogleHostname(url.host(), subdomain_permission);
161 }
162
163 bool IsGoogleHostname(const std::string& host, 155 bool IsGoogleHostname(const std::string& host,
164 SubdomainPermission subdomain_permission) { 156 SubdomainPermission subdomain_permission) {
165 size_t tld_length = net::registry_controlled_domains::GetRegistryLength( 157 size_t tld_length = net::registry_controlled_domains::GetRegistryLength(
166 host, 158 host,
167 net::registry_controlled_domains::EXCLUDE_UNKNOWN_REGISTRIES, 159 net::registry_controlled_domains::EXCLUDE_UNKNOWN_REGISTRIES,
168 net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES); 160 net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES);
169 if ((tld_length == 0) || (tld_length == std::string::npos)) 161 if ((tld_length == 0) || (tld_length == std::string::npos))
170 return false; 162 return false;
171 std::string host_minus_tld(host, 0, host.length() - tld_length); 163 std::string host_minus_tld(host, 0, host.length() - tld_length);
172 if (LowerCaseEqualsASCII(host_minus_tld, "google.")) 164 if (LowerCaseEqualsASCII(host_minus_tld, "google."))
173 return true; 165 return true;
174 if (subdomain_permission == ALLOW_SUBDOMAIN) 166 if (subdomain_permission == ALLOW_SUBDOMAIN)
175 return EndsWith(host_minus_tld, ".google.", false); 167 return EndsWith(host_minus_tld, ".google.", false);
176 return LowerCaseEqualsASCII(host_minus_tld, "www.google."); 168 return LowerCaseEqualsASCII(host_minus_tld, "www.google.");
177 } 169 }
178 170
171 bool IsGoogleDomainUrl(const GURL& url,
172 SubdomainPermission subdomain_permission,
173 PortPermission port_permission) {
174 return url.is_valid() && (url.SchemeIs("http") || url.SchemeIs("https")) &&
175 (url.port().empty() || (port_permission == ALLOW_NON_STANDARD_PORTS)) &&
176 google_util::IsGoogleHostname(url.host(), subdomain_permission);
177 }
178
179 bool IsGoogleHomePageUrl(const GURL& url) { 179 bool IsGoogleHomePageUrl(const GURL& url) {
180 // First check to see if this has a Google domain. 180 // First check to see if this has a Google domain.
181 if (!IsGoogleDomainUrl(url, DISALLOW_SUBDOMAIN, DISALLOW_NON_STANDARD_PORTS)) 181 if (!IsGoogleDomainUrl(url, DISALLOW_SUBDOMAIN, DISALLOW_NON_STANDARD_PORTS))
182 return false; 182 return false;
183 183
184 // Make sure the path is a known home page path. 184 // Make sure the path is a known home page path.
185 std::string path(url.path()); 185 std::string path(url.path());
186 if (path != "/" && path != "/webhp" && 186 return (path == "/") || (path == "/webhp") ||
187 !StartsWithASCII(path, "/ig", false)) { 187 StartsWithASCII(path, "/ig", false);
188 return false;
189 }
190
191 return true;
192 } 188 }
193 189
194 bool IsGoogleSearchUrl(const GURL& url) { 190 bool IsGoogleSearchUrl(const GURL& url) {
195 // First check to see if this has a Google domain. 191 // First check to see if this has a Google domain.
196 if (!IsGoogleDomainUrl(url, DISALLOW_SUBDOMAIN, DISALLOW_NON_STANDARD_PORTS)) 192 if (!IsGoogleDomainUrl(url, DISALLOW_SUBDOMAIN, DISALLOW_NON_STANDARD_PORTS))
197 return false; 193 return false;
198 194
199 // Make sure the path is a known search path. 195 // Make sure the path is a known search path.
200 std::string path(url.path()); 196 std::string path(url.path());
201 bool has_valid_path = false; 197 bool is_home_page_base = (path == "/webhp") || (path == "/");
Jered 2013/06/28 21:57:28 nit: You could extract a helper function and call
Peter Kasting 2013/06/28 22:16:02 Done.
202 bool is_home_page_base = false; 198 if (!is_home_page_base && (path != "/search"))
203 if (path == "/search") {
204 has_valid_path = true;
205 } else if (path == "/webhp" || path == "/") {
206 // Note that we allow both "/" and "" paths, but GURL spits them
207 // both out as just "/".
208 has_valid_path = true;
209 is_home_page_base = true;
210 }
211 if (!has_valid_path)
212 return false; 199 return false;
213 200
214 // Check for query parameter in URL parameter and hash fragment, depending on 201 // Check for query parameter in URL parameter and hash fragment, depending on
215 // the path type. 202 // the path type.
216 std::string query(url.query()); 203 return HasGoogleSearchQueryParam(url.ref()) ||
217 std::string ref(url.ref()); 204 (!is_home_page_base && HasGoogleSearchQueryParam(url.query()));
218 return HasGoogleSearchQueryParam(ref) ||
219 (!is_home_page_base && HasGoogleSearchQueryParam(query));
220 } 205 }
221 206
222 bool IsOrganic(const std::string& brand) { 207 bool IsOrganic(const std::string& brand) {
223 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 208 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
224 if (command_line.HasSwitch(switches::kOrganicInstall)) 209 if (command_line.HasSwitch(switches::kOrganicInstall))
225 return true; 210 return true;
226 211
227 #if defined(OS_MACOSX) 212 #if defined(OS_MACOSX)
228 if (brand.empty()) { 213 if (brand.empty()) {
229 // An empty brand string on Mac is used for channels other than stable, 214 // An empty brand string on Mac is used for channels other than stable,
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 const char* const kBrands[] = { 259 const char* const kBrands[] = {
275 "CHIQ", "CHSG", "HLJY", "NTMO", "OOBA", "OOBB", "OOBC", "OOBD", "OOBE", 260 "CHIQ", "CHSG", "HLJY", "NTMO", "OOBA", "OOBB", "OOBC", "OOBD", "OOBE",
276 "OOBF", "OOBG", "OOBH", "OOBI", "OOBJ", "IDCM", 261 "OOBF", "OOBG", "OOBH", "OOBI", "OOBJ", "IDCM",
277 }; 262 };
278 const char* const* end = &kBrands[arraysize(kBrands)]; 263 const char* const* end = &kBrands[arraysize(kBrands)];
279 const char* const* found = std::find(&kBrands[0], end, brand); 264 const char* const* found = std::find(&kBrands[0], end, brand);
280 return found != end; 265 return found != end;
281 } 266 }
282 267
283 } // namespace google_util 268 } // namespace google_util
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698